// should throw InvalidOperationException if removing when Count == 0 public bool RemoveTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); if (hc.Count != 0) { Console.WriteLine("Count value not zero: {0}!", hc.Count); Console.WriteLine("RemoveTest Aborted!"); return false; } try { hc.Remove(); } catch (InvalidOperationException) { Console.WriteLine("RemoveTest Passed!"); return true; } Console.WriteLine("RemoveTest Failed!"); return false; }
public static void Reset() { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); s_hc = new HandleCollector("hc", 100); }
public bool RemoveTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); for (int i = 1; i <= 1000; i++) { hc.Add(); } for (int i = 999; i >= 0; i--) { hc.Remove(); if (hc.Count != i) { Console.WriteLine("RemoveTest Failed!"); return false; } } Console.WriteLine("RemoveTest Passed!"); return true; }
public static IntPtr GetDC(HandleRef hWnd) { IntPtr hDc = IntGetDC(hWnd); if (hDc == IntPtr.Zero) { throw new Win32Exception(); } return(HandleCollector.Add(hDc, NativeMethods.CommonHandles.HDC)); }
// count should be 0 by default public bool EmptyTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); if (hc.Count != 0) { Console.WriteLine("EmptyTest Failed!"); return false; } Console.WriteLine("EmptyTest Passed!"); return true; }
// count should be 0 by default public bool EmptyTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); if (hc.Count != 0) { Console.WriteLine("EmptyTest Failed!"); return(false); } Console.WriteLine("EmptyTest Passed!"); return(true); }
public bool AddTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); for (int i = 1; i <= 1000; i++) { hc.Add(); if (hc.Count != i) { Console.WriteLine("AddTest Failed!"); return(false); } } Console.WriteLine("AddTest Passed!"); return(true); }
public bool GetName() { _totalTestCount++; int count = 0; HandleCollector hc = null; string[] names = { String.Empty, "a", "name", "name with spaces", new String('a', 50000), "\uA112\uA0E4\uA0F9" }; foreach (string s in names) { hc = new HandleCollector(s, 0); if (hc.Name == s) count++; } if (count != names.Length) { Console.WriteLine("GetNameTest Failed!"); return false; } return true; }
public bool GetMaximumThresholdTest() { _totalTestCount++; int count = 0; HandleCollector hc = null; int[] maxValues = { 0, 1, 2, 3, 1000, 10000, Int32.MaxValue / 2, Int32.MaxValue }; foreach (int i in maxValues) { hc = new HandleCollector(null, 0, i); if (hc.MaximumThreshold == i) count++; } if (count != maxValues.Length) { Console.WriteLine("GetMaximumThresholdTest Failed!"); return false; } return true; }
public static IntPtr CreateBrushIndirect(NativeMethods.LOGBRUSH lb) { return(HandleCollector.Add(IntCreateBrushIndirect(lb), NativeMethods.CommonHandles.GDI)); }
// should throw InvalidOperationException if adding when Count == int.MaxValue // unfortunately this test takes too long to run (~30 mins on a 1.8MHz machine) public bool AddTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, int.MaxValue); for (int i = 1; i < int.MaxValue; i++) { hc.Add(); if (hc.Count != i) { Console.WriteLine("AddTest Failed!1"); Console.WriteLine("i: {0}", i); Console.WriteLine("count: {0}", hc.Count); return false; } } try { hc.Add(); // int.MaxValue+1 } catch (InvalidOperationException) { Console.WriteLine("AddTest Passed!"); return true; } Console.WriteLine("AddTest Failed!2"); Console.WriteLine(hc.Count); return false; }
// tests various invalid constructor values public bool ConstructorTest() { _totalTestCount++; HandleCollector hc = null; int count = 0; int testcount = 0; try { testcount++; // negative maxThreshold hc = new HandleCollector(null, 0, -1); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // negative initialThreshold hc = new HandleCollector(null, -1, 0); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // negative maxThreshold & initialThreshold hc = new HandleCollector(null, -1, -1); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // maxThreshold < initialThreshold hc = new HandleCollector(null, 1, 0); } catch (System.ArgumentException) { count++; } if (count < testcount) { Console.WriteLine("ConstructorTest Failed!"); return false; } Console.WriteLine("ConstructorTest Passed!"); return true; }
public static bool DeleteObject(HandleRef hObject) { HandleCollector.Remove((IntPtr)hObject, NativeMethods.CommonHandles.GDI); return(IntDeleteObject(hObject)); }
public bool MixedTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); int i, j, k; for (i = 1; i <= 100; i++) { hc.Add(); if (hc.Count != i) { Console.WriteLine("MixedTest1 Failed!"); return false; } } i--; for (j = 1; j <= 50; j++) { hc.Remove(); if (hc.Count != i - j) { Console.WriteLine("MixedTest2 Failed!"); return false; } } j--; for (k = 1; k <= 50; k++) { hc.Add(); if (hc.Count != (i - j) + k) { Console.WriteLine("MixedTest3 Failed!"); return false; } } k--; // do check here if (hc.Count != (i - j + k)) { Console.WriteLine("MixedTest Failed!"); Console.WriteLine("Count: {0}", hc.Count); Console.WriteLine("{0}", (i - j + k)); return false; } Console.WriteLine("MixedTest Passed!"); return true; }
public static IntPtr CreateSolidBrush(int crColor) { return(HandleCollector.Add(IntCreateSolidBrush(crColor), NativeMethods.CommonHandles.GDI)); }
protected override void Dispose(bool disposing) { HandleCollector.Remove(_collectorId); base.Dispose(disposing); }
public static IntPtr CreateHalftonePalette(HandleRef hdc) { return(HandleCollector.Add(IntCreateHalftonePalette(hdc), NativeMethods.CommonHandles.GDI)); }
// tests various invalid constructor values public bool ConstructorTest() { _totalTestCount++; HandleCollector hc = null; int count = 0; int testcount = 0; try { testcount++; // negative maxThreshold hc = new HandleCollector(null, 0, -1); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // negative initialThreshold hc = new HandleCollector(null, -1, 0); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // negative maxThreshold & initialThreshold hc = new HandleCollector(null, -1, -1); } catch (System.ArgumentOutOfRangeException) { count++; } try { testcount++; // maxThreshold < initialThreshold hc = new HandleCollector(null, 1, 0); } catch (System.ArgumentException) { count++; } if (count < testcount) { Console.WriteLine("ConstructorTest Failed!"); return(false); } Console.WriteLine("ConstructorTest Passed!"); return(true); }
public static IntPtr GetDC(HandleRef hWnd) { return(HandleCollector.Add(IntGetDC(hWnd), SafeNativeMethods.CommonHandles.HDC)); }
public static IntPtr CreatePatternBrush(HandleRef hbmp) { return(HandleCollector.Add(IntCreatePatternBrush(hbmp), NativeMethods.CommonHandles.GDI)); }
public static IntPtr CreateBitmap(int nWidth, int nHeight, int nPlanes, int nBitsPerPixel, byte[] lpvBits) { return(HandleCollector.Add(IntCreateBitmapByte(nWidth, nHeight, nPlanes, nBitsPerPixel, lpvBits), NativeMethods.CommonHandles.GDI)); }
public static IntPtr CreateDIBSection(HandleRef hdc, HandleRef pbmi, int iUsage, byte[] ppvBits, IntPtr hSection, int dwOffset) { return(HandleCollector.Add(IntCreateDIBSection(hdc, pbmi, iUsage, ppvBits, hSection, dwOffset), NativeMethods.CommonHandles.GDI)); }
public static IntPtr CreateIC(string lpszDriverName, string lpszDeviceName, string lpszOutput, HandleRef /*DEVMODE*/ lpInitData) { return(HandleCollector.Add(IntCreateIC(lpszDriverName, lpszDeviceName, lpszOutput, lpInitData), SafeNativeMethods.CommonHandles.HDC)); }
public static IntPtr CreatePen(int nStyle, int nWidth, int crColor) { return(HandleCollector.Add(IntCreatePen(nStyle, nWidth, crColor), NativeMethods.CommonHandles.GDI)); }
public ICallForTest1Tests() { _handleCollector = new HandleCollector("call", 1, 10); }
public static IntPtr CopyImageAsCursor(HandleRef hImage, int uType, int cxDesired, int cyDesired, int fuFlags) { return(HandleCollector.Add(IntCopyImage(hImage, uType, cxDesired, cyDesired, fuFlags), NativeMethods.CommonHandles.Cursor)); }
public static int ReleaseDC(HandleRef hWnd, HandleRef hDC) { HandleCollector.Remove((IntPtr)hDC, NativeMethods.CommonHandles.HDC); return(IntReleaseDC(hWnd, hDC)); }
public static IntPtr CreateRectRgn(int x1, int y1, int x2, int y2) { return(HandleCollector.Add(IntCreateRectRgn(x1, y1, x2, y2), NativeMethods.CommonHandles.GDI)); }
public static IntPtr CreateCompatibleBitmap(HandleRef hDC, int width, int height) { return(HandleCollector.Add(IntCreateCompatibleBitmap(hDC, width, height), NativeMethods.CommonHandles.GDI)); }
protected WpfSafeHandle(bool ownsHandle, int collectorId) : base(ownsHandle) { HandleCollector.Add(collectorId); _collectorId = collectorId; }