summaryrefslogtreecommitdiff
path: root/tests/src/CoreMangLib
diff options
context:
space:
mode:
authorKevin Jones <kevin@vcsjones.com>2016-03-04 12:22:36 -0500
committerKevin Jones <kevin@vcsjones.com>2016-03-04 16:43:41 -0500
commit7688c54a9a9938e45625937270e9d29deab62824 (patch)
tree65ff1704702e767bf5bc8f133fe30507c12ac08f /tests/src/CoreMangLib
parent4707152ea16ca35af2c87f43db3536001f1d0e6b (diff)
downloadcoreclr-7688c54a9a9938e45625937270e9d29deab62824.tar.gz
coreclr-7688c54a9a9938e45625937270e9d29deab62824.tar.bz2
coreclr-7688c54a9a9938e45625937270e9d29deab62824.zip
Improve GetHashCode for IntPtr/UIntPtr on 64-bit.
The GetHashCode behavior on IntPtr and UIntPtr truncated the upper 32 bits. This change uses the behavior of long and ulong, respectively, to generate the hash code. UIntPtr no longer strips off the top-most bit for GetHashCode purposes. Fix #3506
Diffstat (limited to 'tests/src/CoreMangLib')
-rw-r--r--tests/src/CoreMangLib/cti/system/intptr/intptrgethashcode.cs37
-rw-r--r--tests/src/CoreMangLib/cti/system/uintptr/uintptrgethashcode.cs39
2 files changed, 75 insertions, 1 deletions
diff --git a/tests/src/CoreMangLib/cti/system/intptr/intptrgethashcode.cs b/tests/src/CoreMangLib/cti/system/intptr/intptrgethashcode.cs
index dd32ebe7fe..82c234386c 100644
--- a/tests/src/CoreMangLib/cti/system/intptr/intptrgethashcode.cs
+++ b/tests/src/CoreMangLib/cti/system/intptr/intptrgethashcode.cs
@@ -34,6 +34,7 @@ public class IntPtrGetHashCode
retVal = PosTest1() && retVal;
retVal = PosTest2() && retVal;
retVal = PosTest3() && retVal;
+ retVal = PosTest4() && retVal;
return retVal;
}
@@ -100,4 +101,40 @@ public class IntPtrGetHashCode
}
return retVal;
}
+
+ public bool PosTest4()
+ {
+ bool retValue = true;
+ try
+ {
+ long addressOne = 0x123456FFFFFFFFL;
+ long addressTwo = 0x654321FFFFFFFFL;
+ System.IntPtr ipOne = new IntPtr(addressOne);
+ System.IntPtr ipTwo = new IntPtr(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(id, String.Format("IntPtr should not have thrown an OverflowException for value {0}: ", i) + ex.ToString());
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
+ retVal = false;
+ }
+ return retVal;
+ }
}
diff --git a/tests/src/CoreMangLib/cti/system/uintptr/uintptrgethashcode.cs b/tests/src/CoreMangLib/cti/system/uintptr/uintptrgethashcode.cs
index 3b7fb544b6..b39fb271c1 100644
--- a/tests/src/CoreMangLib/cti/system/uintptr/uintptrgethashcode.cs
+++ b/tests/src/CoreMangLib/cti/system/uintptr/uintptrgethashcode.cs
@@ -37,6 +37,7 @@ public class UIntPtrGetHashCode
retVal = PosTest1() && retVal;
retVal = PosTest2() && retVal;
retVal = PosTest3() && retVal;
+ retVal = PosTest4() && retVal;
return retVal;
}
@@ -135,7 +136,7 @@ public class UIntPtrGetHashCode
{
UInt32 ui = (UInt32)Int32.MaxValue + (UInt32)TestLibrary.Generator.GetInt32(-55);
uiPtr = new UIntPtr(ui);
- expectedValue = unchecked((Int32)((Int64)ui)) & 0x7fffffff;
+ expectedValue = unchecked((Int32)((Int64)ui));
actualValue = uiPtr.GetHashCode();
@@ -157,5 +158,41 @@ public class UIntPtrGetHashCode
return retVal;
}
+
+ public bool PosTest4()
+ {
+ bool retValue = true;
+ try
+ {
+ long addressOne = 0x123456FFFFFFFFL;
+ long addressTwo = 0x654321FFFFFFFFL;
+ 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(id, String.Format("IntPtr should not have thrown an OverflowException for value {0}: ", i) + ex.ToString());
+ retVal = false;
+ }
+ }
+ catch (Exception e)
+ {
+ TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
+ retVal = false;
+ }
+ return retVal;
+ }
}