Example #1
0
    public static void  RuntimeFieldHandleTest()
    {
        Type               t = typeof(Derived);
        FieldInfo          f = t.GetField(nameof(Base.MyField));
        RuntimeFieldHandle h = f.FieldHandle;

        Assert.True(h.Value != IntPtr.Zero);

        Assert.Equal(h.GetHashCode(), h.GetHashCode());
        Assert.Equal(default(RuntimeFieldHandle).GetHashCode(), default(RuntimeFieldHandle).GetHashCode());

        Assert.True(h.Equals(h));
        Assert.False(h.Equals(default(RuntimeFieldHandle)));
        Assert.False(default(RuntimeFieldHandle).Equals(h));
        Assert.True(default(RuntimeFieldHandle).Equals(default(RuntimeFieldHandle)));

        Assert.True(h.Equals((object)h));
        Assert.True(((IEquatable <RuntimeFieldHandle>)h).Equals(h));
        Assert.False(h.Equals(new object()));
        Assert.False(h.Equals(null));

        Assert.False(h == default(RuntimeFieldHandle));
        Assert.True(h != default(RuntimeFieldHandle));

        IntPtr             hPtr = RuntimeFieldHandle.ToIntPtr(h);
        RuntimeFieldHandle hNew = RuntimeFieldHandle.FromIntPtr(hPtr);

        Assert.True(h.Equals(hNew));
        Assert.True(hNew.Equals(h));
    }
    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify a hashcode of RuntimeFieldHandle is not equal to object");

        try
        {
            RuntimeFieldHandle rfh = new RuntimeFieldHandle();
            object obj = new object();

            if (rfh.GetHashCode() == obj.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001.1", "Method GetHashCode Err !");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    public bool PosTest1()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify two hashcode of RuntimeFieldHandle equals");

        try
        {
            RuntimeFieldHandle rfh1 = new RuntimeFieldHandle();
            RuntimeFieldHandle rfh2 = new RuntimeFieldHandle();

            if (rfh1.GetHashCode() != rfh2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001.1", "Method GetHashCode Err !");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
Example #4
0
    public static void DefaultRuntimeFieldHandleHashCodeTest()
    {
        RuntimeFieldHandle rfh1 = new RuntimeFieldHandle();
        RuntimeFieldHandle rfh2 = new RuntimeFieldHandle();

        Assert.Equal(rfh1.GetHashCode(), rfh2.GetHashCode());
    }
    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify a hashcode of RuntimeFieldHandle is not equal to object");

        try
        {
            RuntimeFieldHandle rfh = new RuntimeFieldHandle();
            object             obj = new object();

            if (rfh.GetHashCode() == obj.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001.1", "Method GetHashCode Err !");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
    public bool PosTest1()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest1: Verify two hashcode of RuntimeFieldHandle equals");

        try
        {
            RuntimeFieldHandle rfh1 = new RuntimeFieldHandle();
            RuntimeFieldHandle rfh2 = new RuntimeFieldHandle();

            if (rfh1.GetHashCode() != rfh2.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("001.1", "Method GetHashCode Err !");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }