// 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); }
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 bool StressTest() { _totalTestCount++; HandleCollector hc = new HandleCollector(null, 1); for (int i = 1; i <= 10000000; i++) { hc.Add(); if (hc.Count != i) { Console.WriteLine("StressTest1 Failed!"); return(false); } } for (int i = 9999999; i <= 0; i++) { hc.Remove(); if (hc.Count != i) { Console.WriteLine("StressTest2 Failed!"); return(false); } } Console.WriteLine("StressTest Passed!"); return(true); }
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 LimitedResource() { m_count = s_count++; // Tell the HandleCollector a LimitedResource has been added to the heap s_hc.Add(); Console.WriteLine("LimitedResource create. Count={0},({1})", s_hc.Count, m_count); }
public static IntPtr GetDC(HandleRef hWnd) { IntPtr hDc = IntGetDC(hWnd); if (hDc == IntPtr.Zero) { throw new Win32Exception(); } return(HandleCollector.Add(hDc, NativeMethods.CommonHandles.HDC)); }
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 static IntPtr CreateBrushIndirect(NativeMethods.LOGBRUSH lb) { return(HandleCollector.Add(IntCreateBrushIndirect(lb), NativeMethods.CommonHandles.GDI)); }
public NotepadWriter(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; _handleCollector.Add(); _process = Process.Start(@"C:\\Windows\\System32\\notepad.exe"); }
protected WpfSafeHandle(bool ownsHandle, int collectorId) : base(ownsHandle) { HandleCollector.Add(collectorId); _collectorId = collectorId; }
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 LimitedResource() { s_hc.Add(); Console.WriteLine($"LimitedREsource create. Count={s_hc.Count}"); }
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 CreateHalftonePalette(HandleRef hdc) { return(HandleCollector.Add(IntCreateHalftonePalette(hdc), NativeMethods.CommonHandles.GDI)); }
public static IntPtr CreateSolidBrush(int crColor) { return(HandleCollector.Add(IntCreateSolidBrush(crColor), 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; }
public static IntPtr CreatePen(int nStyle, int nWidth, int crColor) { return(HandleCollector.Add(IntCreatePen(nStyle, nWidth, crColor), NativeMethods.CommonHandles.GDI)); }
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 IntPtr GetDC(HandleRef hWnd) { return(HandleCollector.Add(IntGetDC(hWnd), SafeNativeMethods.CommonHandles.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 LimitedResource() { s_hc.Add(); Console.WriteLine("LimitedResource create. Count={0}", s_hc.Count); }
public static IntPtr CreateCompatibleBitmap(HandleRef hDC, int width, int height) { return(HandleCollector.Add(IntCreateCompatibleBitmap(hDC, width, height), NativeMethods.CommonHandles.GDI)); }
public void A() => _handleCollector.Add();
public HandleCollectorTest() { s_hc.Add(); }
public LimitedResource() { //告诉HandleCollector堆中又增加了一个LimitedResource s_hc.Add(); Console.WriteLine("LimitedResource count={0}", s_hc.Count); }
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 LimitedResource() { // Сообщаем HandleCollector, что в кучу добавлен еще один объект LimitedResource s_hc.Add(); Console.WriteLine("LimitedResource create. Count={0}", s_hc.Count); }
private static readonly HandleCollector hc = new HandleCollector("Resource", 3); // ha 3-at elérte ebből a példányok száma, akkor meghívódik a GC, de csak akkor szabadít fel, ha unrooted public Resource() { hc.Add(); Console.WriteLine($"Resource created: {hc.Count}"); }