本文整理汇总了C#中UIntPtr.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# UIntPtr.Equals方法的具体用法?C# UIntPtr.Equals怎么用?C# UIntPtr.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIntPtr
的用法示例。
在下文中一共展示了UIntPtr.Equals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: runTest
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;
UIntPtr ip2;
UInt32 iValue;
try {
strLoc = "Loc_743wg";
iValue = 16;
ip1 = new UIntPtr(iValue);
ip2 = new UIntPtr(iValue);
iCountTestcases++;
if(!ip1.Equals(ip2)){
iCountErrors++;
Console.WriteLine("Err_865sg! Wrong value returned");
}
strLoc = "Loc_9047tdsg";
iValue = 16;
ip1 = new UIntPtr(iValue);
ip2 = new UIntPtr(iValue*2);
iCountTestcases++;
if(ip1.Equals(ip2)){
iCountErrors++;
Console.WriteLine("Err_9765sgf! Wrong value returned");
}
strLoc = "Loc_98736zdg";
iValue = 16;
ip1 = new UIntPtr(iValue);
iCountTestcases++;
if(ip1.Equals(iValue)){
iCountErrors++;
Console.WriteLine("Err_9756gf! Wrong value returned");
}
strLoc = "Loc_98736zdg";
iValue = 16;
ip1 = new UIntPtr(iValue);
iCountTestcases++;
if(ip1.Equals(null)){
iCountErrors++;
Console.WriteLine("Err_973sdg! 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: TestEquals
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());
}
示例3: TestBasics
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);
}
示例4: PosTest6
public bool PosTest6()
{
bool retVal = true;
const string c_TEST_ID = "P006";
const string c_TEST_DESC = "PosTest6: UIntPtr vs IntPtr";
string errorDesc;
UIntPtr uiPtr;
IntPtr iPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
void * ptr = (void *)TestLibrary.Generator.GetInt32(-55);
uiPtr = new UIntPtr(ptr);
iPtr = new IntPtr(ptr);
actualResult = !uiPtr.Equals(iPtr);
if (!actualResult)
{
errorDesc = "UIntPtr " + uiPtr + " should not equal IntPtr " + iPtr;
TestLibrary.TestFramework.LogError("011" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("012" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例5: PosTest5
public bool PosTest5()
{
bool retVal = true;
const string c_TEST_ID = "P005";
const string c_TEST_DESC = "PosTest5: UIntPtr vs Object";
string errorDesc;
UIntPtr srcUIntPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
object obj = new object();
srcUIntPtr = new UIntPtr();
actualResult = !srcUIntPtr.Equals(obj);
if (!actualResult)
{
errorDesc = "UIntPtr " + srcUIntPtr + " should not equal object" + obj;
TestLibrary.TestFramework.LogError("009" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("010" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例6: PosTest4
public bool PosTest4()
{
bool retVal = true;
const string c_TEST_ID = "P004";
const string c_TEST_DESC = "PosTest4: UIntPtr vs UInt32";
string errorDesc;
UIntPtr srcUIntPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
srcUIntPtr = new UIntPtr(ui);
actualResult = !srcUIntPtr.Equals(ui);
if (!actualResult)
{
errorDesc = "UIntPtr " + srcUIntPtr + " should not equal UInt" + ui;
TestLibrary.TestFramework.LogError("007" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("008" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例7: PosTest3
public bool PosTest3()
{
bool retVal = true;
const string c_TEST_ID = "P003";
const string c_TEST_DESC = "PosTest3: two UIntPtrs with random value";
string errorDesc;
UIntPtr uiPtrA, uiPtrB;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
UInt32 uiA = (UInt32)TestLibrary.Generator.GetInt32(-55);
UInt32 uiB = (UInt32)TestLibrary.Generator.GetInt32(-55);
uiPtrA = new UIntPtr(uiA);
uiPtrB = new UIntPtr(uiB);
actualResult = uiPtrA.Equals(uiPtrB);
actualResult = !((uiA == uiB) ^ actualResult);
if (!actualResult)
{
errorDesc = "UIntPtr " + uiPtrA + " vs UIntPtr " + uiPtrB + " is " + actualResult +
", that differs from UInt32 " + uiA + " vs UInt32 " + uiB;
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;
}