Пример #1
0
    // 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);
    }
Пример #2
0
    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);
    }
Пример #3
0
    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);
    }
Пример #4
0
    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);
 }
Пример #6
0
        public static IntPtr GetDC(HandleRef hWnd)
        {
            IntPtr hDc = IntGetDC(hWnd);

            if (hDc == IntPtr.Zero)
            {
                throw new Win32Exception();
            }

            return(HandleCollector.Add(hDc, NativeMethods.CommonHandles.HDC));
        }
Пример #7
0
    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);
    }
Пример #8
0
 public static IntPtr CreateBrushIndirect(NativeMethods.LOGBRUSH lb)
 {
     return(HandleCollector.Add(IntCreateBrushIndirect(lb), NativeMethods.CommonHandles.GDI));
 }
Пример #9
0
 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;
 }
Пример #11
0
 public static IntPtr CreateIC(string lpszDriverName, string lpszDeviceName, string lpszOutput, HandleRef /*DEVMODE*/ lpInitData)
 {
     return(HandleCollector.Add(IntCreateIC(lpszDriverName, lpszDeviceName, lpszOutput, lpInitData), SafeNativeMethods.CommonHandles.HDC));
 }
Пример #12
0
 public LimitedResource()
 {
     s_hc.Add();
     Console.WriteLine($"LimitedREsource create. Count={s_hc.Count}");
 }
Пример #13
0
 public static IntPtr CreatePatternBrush(HandleRef hbmp)
 {
     return(HandleCollector.Add(IntCreatePatternBrush(hbmp), NativeMethods.CommonHandles.GDI));
 }
Пример #14
0
 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));
 }
Пример #15
0
 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));
 }
Пример #16
0
 public static IntPtr CreateHalftonePalette(HandleRef hdc)
 {
     return(HandleCollector.Add(IntCreateHalftonePalette(hdc), NativeMethods.CommonHandles.GDI));
 }
Пример #17
0
 public static IntPtr CreateSolidBrush(int crColor)
 {
     return(HandleCollector.Add(IntCreateSolidBrush(crColor), NativeMethods.CommonHandles.GDI));
 }
Пример #18
0
    // 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;
    }
Пример #19
0
 public static IntPtr CreatePen(int nStyle, int nWidth, int crColor)
 {
     return(HandleCollector.Add(IntCreatePen(nStyle, nWidth, crColor), NativeMethods.CommonHandles.GDI));
 }
Пример #20
0
 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));
 }
Пример #21
0
 public static IntPtr GetDC(HandleRef hWnd)
 {
     return(HandleCollector.Add(IntGetDC(hWnd), SafeNativeMethods.CommonHandles.HDC));
 }
Пример #22
0
 public static IntPtr CreateRectRgn(int x1, int y1, int x2, int y2)
 {
     return(HandleCollector.Add(IntCreateRectRgn(x1, y1, x2, y2), NativeMethods.CommonHandles.GDI));
 }
Пример #23
0
 public LimitedResource()
 {
     s_hc.Add();
     Console.WriteLine("LimitedResource create. Count={0}", s_hc.Count);
 }
Пример #24
0
 public static IntPtr CreateCompatibleBitmap(HandleRef hDC, int width, int height)
 {
     return(HandleCollector.Add(IntCreateCompatibleBitmap(hDC, width, height), NativeMethods.CommonHandles.GDI));
 }
Пример #25
0
 public void A() => _handleCollector.Add();
Пример #26
0
 public HandleCollectorTest()
 {
     s_hc.Add();
 }
Пример #27
0
 public LimitedResource()
 {
     //告诉HandleCollector堆中又增加了一个LimitedResource
     s_hc.Add();
     Console.WriteLine("LimitedResource count={0}", s_hc.Count);
 }
Пример #28
0
    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;
    }
Пример #29
0
 public LimitedResource()
 {
     // Сообщаем HandleCollector, что в кучу добавлен еще один объект LimitedResource
     s_hc.Add();
     Console.WriteLine("LimitedResource create. Count={0}", s_hc.Count);
 }
Пример #30
0
            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}");
            }