示例#1
0
 public virtual bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   UIntPtr ip1;
   UInt32 iValue;
   try {
   strLoc = "Loc_743wg";
   iValue = 16;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_865sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = 0;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_9743sg! Wrong value returned");
   }             
   strLoc = "Loc_87453sg";
   iValue = UInt32.MaxValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != 2147483647){
   iCountErrors++;
   Console.WriteLine("Err_97253rdg! Wrong value returned, {0} {1}", ip1.GetHashCode(), iValue);
   }             
   strLoc = "Loc_87453sg";
   iValue = UInt32.MinValue;
   ip1 = new UIntPtr(iValue);
   iCountTestcases++;
   if(ip1.GetHashCode() != iValue){
   iCountErrors++;
   Console.WriteLine("Err_93756sg! Wrong value returned");
   }             
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
示例#2
0
 public static void Equals(UIntPtr ptr1, object obj, bool expected)
 {
     if (obj is UIntPtr)
     {
         UIntPtr ptr2 = (UIntPtr)obj;
         Assert.Equal(expected, ptr1 == ptr2);
         Assert.Equal(!expected, ptr1 != ptr2);
         Assert.Equal(expected, ptr1.GetHashCode().Equals(ptr2.GetHashCode()));
     }
     Assert.Equal(expected, ptr1.Equals(obj));
     Assert.Equal(ptr1.GetHashCode(), ptr1.GetHashCode());
 }
示例#3
0
    public static void GetHashCodeRespectAllBits()
    {
        var ptr1 = new UIntPtr(0x123456FFFFFFFF);
        var ptr2 = new UIntPtr(0x654321FFFFFFFF);

        Assert.NotEqual(ptr1.GetHashCode(), ptr2.GetHashCode());
    }
示例#4
0
    public bool PosTest3()
    {
        bool retVal = true;

        const string c_TEST_ID   = "P003";
        const string c_TEST_DESC = "PosTest3: UIntPtr with a value greater than Int32.MaxValue";
        string       errorDesc;

        UIntPtr uiPtr;
        int     actualValue, expectedValue;
        bool    actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = (UInt32)Int32.MaxValue + (UInt32)TestLibrary.Generator.GetInt32(-55);
            uiPtr         = new UIntPtr(ui);
            expectedValue = unchecked ((Int32)((Int64)ui)) & 0x7fffffff;

            actualValue = uiPtr.GetHashCode();

            actualResult = actualValue == expectedValue;

            if (!actualResult)
            {
                errorDesc = "Actual hash code is not " + expectedValue + " as expected: Actual(" + actualValue + ")";
                TestLibrary.TestFramework.LogError("005" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("006" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return(retVal);
    }
示例#5
0
    public bool PosTest4()
    {
        bool retVal = true;

        try
        {
            ulong          addressOne = 0x123456FFFFFFFFUL;
            ulong          addressTwo = 0x654321FFFFFFFFUL;
            System.UIntPtr ipOne      = new UIntPtr(addressOne);
            System.UIntPtr ipTwo      = new UIntPtr(addressTwo);
            if (ipOne.GetHashCode() == ipTwo.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("004", "expect different hashcodes.");
                retVal = false;
            }
        }
        catch (System.OverflowException ex)
        {
            if (System.IntPtr.Size == 4)
            {
                // ok, that's what it should be
                return(retVal);
            }
            else
            {
                TestLibrary.TestFramework.LogError("004", "IntPtr should not have thrown an OverflowException: " + ex.ToString());
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }
        return(retVal);
    }
示例#6
0
    public static unsafe void TestBasics()
    {
        UIntPtr p;
        uint i;
        ulong l;

        if (sizeof(void*) == 4)
        {
            // Skip UIntPtr tests on 32-bit platforms
            return;
        }

        int size = UIntPtr.Size;
        Assert.Equal(size, sizeof(void*));

        TestPointer(UIntPtr.Zero, 0);

        i = 42;
        TestPointer(new UIntPtr(i), i);
        TestPointer((UIntPtr)i, i);

        i = 42;
        TestPointer(new UIntPtr(i), i);

        l = 0x0fffffffffffffff;
        TestPointer(new UIntPtr(l), l);
        TestPointer((UIntPtr)l, l);

        void* pv = new UIntPtr(42).ToPointer();
        TestPointer(new UIntPtr(pv), 42);
        TestPointer((UIntPtr)pv, 42);

        p = UIntPtr.Add(new UIntPtr(42), 5);
        TestPointer(p, 42 + 5);

        // Add is spected NOT to generate an OverflowException
        p = UIntPtr.Add(new UIntPtr(0xffffffffffffffff), 5);
        unchecked
        {
            TestPointer(p, (long)0x0000000000000004);
        }

        p = UIntPtr.Subtract(new UIntPtr(42), 5);
        TestPointer(p, 42 - 5);

        bool b;
        p = new UIntPtr(42);
        b = p.Equals(null);
        Assert.False(b);
        b = p.Equals((object)42);
        Assert.False(b);
        b = p.Equals((object)(new UIntPtr(42)));
        Assert.True(b);

        int h = p.GetHashCode();
        int h2 = p.GetHashCode();
        Assert.Equal(h, h2);

        p = new UIntPtr(42);
        i = (uint)p;
        Assert.Equal(i, 42u);
        l = (ulong)p;
        Assert.Equal(l, 42u);
        UIntPtr p2;
        p2 = (UIntPtr)i;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)l;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)(p.ToPointer());
        Assert.Equal(p, p2);
        p2 = new UIntPtr(40) + 2;
        Assert.Equal(p, p2);
        p2 = new UIntPtr(44) - 2;
        Assert.Equal(p, p2);

        p = new UIntPtr(0x7fffffffffffffff);
        Assert.Throws<OverflowException>(() => (uint)p);
    }
示例#7
0
 /// <summary>
 ///   Gets a hash for <see cref="ClassDescription" />.
 /// <para>Since EFL 1.24.</para>
 /// </summary>
 /// <returns>A hash code.</returns>
 public override int GetHashCode()
 => version.GetHashCode() ^ name.GetHashCode(StringComparison.Ordinal)
 ^ class_type ^ data_size.GetHashCode();
示例#8
0
 /// <summary>
 ///   Gets a hash for <see cref="TextCursorCursor" />.
 /// <para>Since EFL 1.24.</para>
 /// </summary>
 /// <returns>A hash code.</returns>
 public override int GetHashCode()
 => obj.GetHashCode() ^ pos.GetHashCode()
 ^ node.GetHashCode() ^ changed.GetHashCode();
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ _key.GetHashCode() ^ counter.GetHashCode() ^ subkey_count.GetHashCode() ^ _subkey_name.GetHashCode() ^ subkey_name_size.GetHashCode() ^ subkey_name_len.GetHashCode() ^ subkey_name_u8.GetHashCode());
 }
示例#10
0
 /// <summary>Gets a hash code for the current instance.</summary>
 /// <returns>A hash code for the current instance.</returns>
 public override int GetHashCode()
 {
     return(_value.GetHashCode());
 }
示例#11
0
 /// <inheritdoc/>
 public override int GetHashCode() => _value.GetHashCode();
 public override int GetHashCode()
 {
     return(fmtid.GetHashCode() + pid.GetHashCode());
 }
示例#13
0
    public virtual bool runTest()
    {
        Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
        int     iCountErrors    = 0;
        int     iCountTestcases = 0;
        String  strLoc          = "Loc_000oo";
        UIntPtr ip1;
        UInt32  iValue;

        try {
            strLoc = "Loc_743wg";
            iValue = 16;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.GetHashCode() != iValue)
            {
                iCountErrors++;
                Console.WriteLine("Err_865sg! Wrong value returned");
            }
            strLoc = "Loc_87453sg";
            iValue = 0;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.GetHashCode() != iValue)
            {
                iCountErrors++;
                Console.WriteLine("Err_9743sg! Wrong value returned");
            }
            strLoc = "Loc_87453sg";
            iValue = UInt32.MaxValue;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.GetHashCode() != 2147483647)
            {
                iCountErrors++;
                Console.WriteLine("Err_97253rdg! Wrong value returned, {0} {1}", ip1.GetHashCode(), iValue);
            }
            strLoc = "Loc_87453sg";
            iValue = UInt32.MinValue;
            ip1    = new UIntPtr(iValue);
            iCountTestcases++;
            if (ip1.GetHashCode() != iValue)
            {
                iCountErrors++;
                Console.WriteLine("Err_93756sg! Wrong value returned");
            }
        } catch (Exception exc_general) {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general);
        }
        if (iCountErrors == 0)
        {
            Console.Error.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.Error.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
 public override int GetHashCode()
 {
     return(this.GetType().FullName.GetHashCode() ^ _key.GetHashCode() ^ counter.GetHashCode() ^ value_count.GetHashCode() ^ _value_name.GetHashCode() ^ value_name_size.GetHashCode() ^ value_name_len.GetHashCode() ^ value_type.GetHashCode() ^ _value_data.GetHashCode() ^ value_data_size.GetHashCode() ^ value_actual_data_size.GetHashCode() ^ value_expanded_type.GetHashCode() ^ _value_data_expanded.GetHashCode() ^ value_data_expanded_charsize.GetHashCode() ^ value_name_u8.GetHashCode() ^ value_name_u8_len.GetHashCode() ^ value_data_u8.GetHashCode() ^ value_data_u8_size.GetHashCode() ^ value_data_expanded_u8.GetHashCode() ^ value_data_expanded_u8_size.GetHashCode());
 }
示例#15
0
    public static unsafe void TestBasics()
    {
        UIntPtr p;
        uint    i;
        ulong   l;

        if (sizeof(void *) == 4)
        {
            // Skip UIntPtr tests on 32-bit platforms
            return;
        }

        int size = UIntPtr.Size;

        Assert.Equal(size, sizeof(void *));

        TestPointer(UIntPtr.Zero, 0);

        i = 42;
        TestPointer(new UIntPtr(i), i);
        TestPointer((UIntPtr)i, i);

        i = 42;
        TestPointer(new UIntPtr(i), i);

        l = 0x0fffffffffffffff;
        TestPointer(new UIntPtr(l), l);
        TestPointer((UIntPtr)l, l);

        void *pv = new UIntPtr(42).ToPointer();

        TestPointer(new UIntPtr(pv), 42);
        TestPointer((UIntPtr)pv, 42);

        p = UIntPtr.Add(new UIntPtr(42), 5);
        TestPointer(p, 42 + 5);

        // Add is spected NOT to generate an OverflowException
        p = UIntPtr.Add(new UIntPtr(0xffffffffffffffff), 5);
        unchecked
        {
            TestPointer(p, (long)0x0000000000000004);
        }

        p = UIntPtr.Subtract(new UIntPtr(42), 5);
        TestPointer(p, 42 - 5);

        bool b;

        p = new UIntPtr(42);
        b = p.Equals(null);
        Assert.False(b);
        b = p.Equals((object)42);
        Assert.False(b);
        b = p.Equals((object)(new UIntPtr(42)));
        Assert.True(b);

        int h  = p.GetHashCode();
        int h2 = p.GetHashCode();

        Assert.Equal(h, h2);

        p = new UIntPtr(42);
        i = (uint)p;
        Assert.Equal(i, 42u);
        l = (ulong)p;
        Assert.Equal(l, 42u);
        UIntPtr p2;

        p2 = (UIntPtr)i;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)l;
        Assert.Equal(p, p2);
        p2 = (UIntPtr)(p.ToPointer());
        Assert.Equal(p, p2);
        p2 = new UIntPtr(40) + 2;
        Assert.Equal(p, p2);
        p2 = new UIntPtr(44) - 2;
        Assert.Equal(p, p2);

        p = new UIntPtr(0x7fffffffffffffff);
        Assert.Throws <OverflowException>(() => (uint)p);
    }
示例#16
0
文件: UIntPtr.cs 项目: kkurni/corefx
 public static void TestEquals(UIntPtr ptr1, object obj, bool expected)
 {
     if (obj is UIntPtr)
     {
         UIntPtr ptr2 = (UIntPtr)obj;
         Assert.Equal(expected, ptr1 == ptr2);
         Assert.Equal(!expected, ptr1 != ptr2);
         Assert.Equal(expected, ptr1.GetHashCode().Equals(ptr2.GetHashCode()));
     }
     Assert.Equal(expected, ptr1.Equals(obj));
     Assert.Equal(ptr1.GetHashCode(), ptr1.GetHashCode());
 }
示例#17
0
文件: UIntPtr.cs 项目: kkurni/corefx
 public static void TestGetHashCodeRespectAllBits()
 {
     var ptr1 = new UIntPtr(0x123456FFFFFFFF);
     var ptr2 = new UIntPtr(0x654321FFFFFFFF);
     Assert.NotEqual(ptr1.GetHashCode(), ptr2.GetHashCode());
 }
示例#18
0
    public bool PosTest4()
    {
        bool retVal = true;
        try
        {
            ulong addressOne = 0x123456FFFFFFFFUL;
            ulong addressTwo = 0x654321FFFFFFFFUL;
            System.UIntPtr ipOne = new UIntPtr(addressOne);
            System.UIntPtr ipTwo = new UIntPtr(addressTwo);
            if (ipOne.GetHashCode() == ipTwo.GetHashCode())
            {
                TestLibrary.TestFramework.LogError("004", "expect different hashcodes.");
                retVal = false;
            }
        }
        catch (System.OverflowException ex)
        {
            if (System.IntPtr.Size == 4)
            {
                // ok, that's what it should be
                return retVal;
            }
            else
		   	{
                TestLibrary.TestFramework.LogError("004", "IntPtr should not have thrown an OverflowException: " + ex.ToString());
                retVal = false;
		   	}
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
示例#19
0
    public bool PosTest2()
    {
        bool retVal = true;

        const string c_TEST_ID = "P002";
        const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value ";
        string errorDesc;

        UIntPtr uiPtr;
        int actualValue, expectedValue;
        bool actualResult;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
        try
        {
            UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
            uiPtr = new UIntPtr(ui);
            expectedValue = (Int32)ui;
            actualValue = uiPtr.GetHashCode();

            actualResult = actualValue == expectedValue;

            if (!actualResult)
            {
                errorDesc = "Actual hash code is not " + expectedValue + " as expected: Actual(" + actualValue + ")";
                TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            errorDesc = "Unexpected exception: " + e;
            TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
            retVal = false;
        }

        return retVal;
    }
示例#20
0
 public override int GetHashCode() => id.GetHashCode();