public bool PosTest1() { bool retVal = true; const string c_TEST_ID = "P001"; const string c_TEST_DESC = "PosTest1: random UInt32 value"; string errorDesc; UIntPtr actualUIntPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { UInt32 ui = this.GetUInt32(); actualUIntPtr = new UIntPtr(ui); actualResult = actualUIntPtr.ToUInt32() == ui; if (!actualResult) { errorDesc = "Actual UIntPtr value is not " + ui + " as expected: Actual(" + actualUIntPtr + ")"; TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { errorDesc = "Unexpected exception: " + e; TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } return retVal; }
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"; UInt32 iValue; UIntPtr ip1; try { strLoc = "Loc_743wg"; iValue = 16; ip1 = new UIntPtr(iValue); iCountTestcases++; if(ip1.ToUInt32() != iValue){ iCountErrors++; Console.WriteLine("Err_2975sf! Wrong value returned"); } strLoc = "Loc_0084wf"; iValue = 0; ip1 = new UIntPtr(iValue); iCountTestcases++; if(ip1.ToUInt32() != iValue){ iCountErrors++; Console.WriteLine("Err_974325sdg! Wrong value returned"); } strLoc = "Loc_93476sdg"; iValue = UInt32.MaxValue; ip1 = new UIntPtr(iValue); iCountTestcases++; if(ip1.ToUInt32() != iValue){ iCountErrors++; Console.WriteLine("Err_07536tsg! Wrong value returned"); } iValue = UInt32.MinValue; ip1 = new UIntPtr(iValue); if(ip1.ToUInt32() != iValue){ iCountErrors++; Console.WriteLine("Err_9875wrsg! 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; } }
private static void VerifyPointer(UIntPtr ptr, ulong expected) { Assert.Equal(expected, ptr.ToUInt64()); uint expected32 = (uint)expected; if (expected32 != expected) { Assert.Throws<OverflowException>(() => ptr.ToUInt32()); return; } Assert.Equal(expected32, ptr.ToUInt32()); Assert.Equal(expected.ToString(), ptr.ToString()); Assert.Equal(ptr, new UIntPtr(expected)); Assert.True(ptr == new UIntPtr(expected)); Assert.False(ptr != new UIntPtr(expected)); Assert.NotEqual(ptr, new UIntPtr(expected + 1)); Assert.False(ptr == new UIntPtr(expected + 1)); Assert.True(ptr != new UIntPtr(expected + 1)); }
private static void TestPointer(UIntPtr p, ulong expected) { ulong l = p.ToUInt64(); Assert.Equal(expected, l); uint expected32 = (uint)expected; if (expected32 != expected) { Assert.Throws<OverflowException>(() => p.ToUInt32()); return; } { uint i = p.ToUInt32(); Assert.Equal(expected32, i); } string s = p.ToString(); string sExpected = expected.ToString(); Assert.Equal(s, sExpected); Assert.True(p == new UIntPtr(expected)); Assert.Equal(p, new UIntPtr(expected)); Assert.False(p == new UIntPtr(expected + 1)); Assert.NotEqual(p, new UIntPtr(expected + 1)); Assert.False(p != new UIntPtr(expected)); Assert.True(p != new UIntPtr(expected + 1)); }
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; UInt32 actualUI, expectedUI; UIntPtr uiPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { expectedUI = (UInt32)TestLibrary.Generator.GetInt32(-55); uiPtr = new UIntPtr(expectedUI); actualUI = uiPtr.ToUInt32(); actualResult = actualUI == expectedUI; if (!actualResult) { errorDesc = "Actual UInt32 from UIntPtr is not " + expectedUI + " as expected: Actual(" + actualUI + ")"; 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; }
public bool PosTest4() { bool retVal = true; const string c_TEST_ID = "P004"; const string c_TEST_DESC = "PosTest4: UIntPtr with a value UInt32.MaxValue"; string errorDesc; UInt32 actualUI, expectedUI; UIntPtr uiPtr; bool actualResult; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { expectedUI = UInt32.MaxValue; uiPtr = new UIntPtr(expectedUI); actualUI = uiPtr.ToUInt32(); actualResult = actualUI == expectedUI; if (!actualResult) { errorDesc = "Actual hash code is not " + expectedUI + " as expected: Actual(" + actualUI + ")"; 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; }
private static void TestPointer(UIntPtr p, ulong expected) { ulong l = p.ToUInt64(); Assert.Equal(l, expected); uint expected32 = (uint)expected; if (expected32 != expected) { try { uint i = p.ToUInt32(); Assert.True(false, "ToUInt32() should have thrown."); } catch (OverflowException) { } return; } { uint i = p.ToUInt32(); Assert.Equal(i, expected32); } String s = p.ToString(); String sExpected = expected.ToString(); Assert.Equal(s, sExpected); bool b; b = (p == new UIntPtr(expected)); Assert.True(b); b = (p == new UIntPtr(expected + 1)); Assert.False(b); b = (p != new UIntPtr(expected)); Assert.False(b); b = (p != new UIntPtr(expected + 1)); Assert.True(b); }
private UIntPtr Get64KLimit(UIntPtr a) { const uint count = 0x10000; return((a.ToUInt32() + count) & ~(count - 1u)); }
public byte[] ReadRam(UIntPtr address, int length, EndiannessType endianness, bool absoluteAddress = false) { byte[] readBytes = new byte[length]; // Get local address uint localAddress; if (absoluteAddress) { localAddress = _io?.GetRelativeAddress(address, length) ?? 0; } else { localAddress = address.ToUInt32(); } localAddress &= ~0x80000000; if (EndiannessUtilities.DataIsMisaligned(address, length, EndiannessType.Big)) { return(readBytes); } /// Fix endianness switch (endianness) { case EndiannessType.Little: // Address is not little endian, fix: localAddress = EndiannessUtilities.SwapAddressEndianness(localAddress, length); if (localAddress + length > _ram.Length) { break; } Buffer.BlockCopy(_ram, (int)localAddress, readBytes, 0, length); break; case EndiannessType.Big: // Read padded if misaligned address byte[] swapBytes; uint alignedAddress = EndiannessUtilities.AlignedAddressFloor(localAddress); int alignedReadByteCount = (readBytes.Length / 4) * 4 + 8; if (alignedAddress + alignedReadByteCount > _ram.Length) { break; } swapBytes = new byte[alignedReadByteCount]; // Read memory Buffer.BlockCopy(_ram, (int)alignedAddress, swapBytes, 0, swapBytes.Length); swapBytes = EndiannessUtilities.SwapByteEndianness(swapBytes); // Copy memory Buffer.BlockCopy(swapBytes, (int)(localAddress - alignedAddress), readBytes, 0, readBytes.Length); break; } return(readBytes); }
internal static uint HeapSize(UIntPtr heapAddress) { UIntPtr heapSize = HeapSize(GetProcessHeap(), 0, heapAddress); return(heapSize.ToUInt32()); }
public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts) { var del = VTableHelpers.GetMethodDelegate <RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5); HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt32(), offset, length, out enumContexts)); }
public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo) { activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt32(), startingLineNumber, flags, pVarResult, out excepInfo); }
unsafe static char *memmove(char *dest, char *src, UIntPtr count) { Buffer.MemoryCopy((void *)src, (void *)dest, count.ToUInt32(), count.ToUInt32()); return(dest); }
private IntPtr WindowProc(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam) { switch (msg) { #region keyboard case 0x100: /*WM_KEYDOWN*/ { var keyCode = wParam.ToUInt32(); if (wParam.ToUInt64() < 256) { Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode]; Keyboard.Instance.keyStates[keyCode] = KeyState.Down; } if (keyCode == (int)Key.Enter) { Ime.ImeBuffer.Enqueue('\n'); return(new IntPtr(1)); } //DEBUG only begin if (keyCode == (int)Key.Escape) { Application.Quit(); } //DEBUG only end return(IntPtr.Zero); } case 0x101: /*WM_KEYUP*/ { var keyCode = wParam.ToUInt32(); if (wParam.ToUInt64() < 256) { Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode]; Keyboard.Instance.keyStates[keyCode] = KeyState.Up; } return(IntPtr.Zero); } #endregion #region mouse case 0x0201: //WM_LBUTTONDOWN Mouse.Instance.LeftButtonState = KeyState.Down; return(IntPtr.Zero); case 0x0202: //WM_LBUTTONUP Mouse.Instance.LeftButtonState = KeyState.Up; return(IntPtr.Zero); case 0x0203: //WM_LBUTTONDBLCLK return(IntPtr.Zero); case 0x0206: //WM_RBUTTONDBLCLK return(IntPtr.Zero); case 0x0204: //WM_RBUTTONDOWN Mouse.Instance.RightButtonState = KeyState.Down; return(IntPtr.Zero); case 0x0205: //WM_RBUTTONUP Mouse.Instance.RightButtonState = KeyState.Up; return(IntPtr.Zero); case 0x020A: //WM_MOUSEWHEEL Mouse.Instance.MouseWheel = ((short)(wParam.ToUInt64() >> 16)); return(IntPtr.Zero); case 0x0200: //WM_MOUSEMOVE var p = new POINT { X = unchecked ((short)lParam), Y = unchecked ((short)((uint)lParam >> 16)) }; Mouse.Instance.Position = new Point(p.X, p.Y); return(IntPtr.Zero); #endregion #region ime //http://blog.csdn.net/shuilan0066/article/details/7679825 case 0x0286: /*WM_IME_CHAR*/ { char c = (char)wParam; if (c > 0 && !char.IsControl(c)) { Ime.ImeBuffer.Enqueue(c); } return(IntPtr.Zero); } case 0x0102: /*WM_CHAR*/ { char c = (char)wParam; if (c > 0 && !char.IsControl(c)) { Ime.ImeBuffer.Enqueue(c); } return(IntPtr.Zero); } #endregion case 0x2: //WM_DESTROY PostQuitMessage(0); //DEBUG only begin Application.Quit(); //DEBUG only end return(IntPtr.Zero); } return(DefWindowProc(hWnd, msg, wParam, lParam)); }