Esempio n. 1
0
    // 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;
    }
Esempio n. 2
0
 public static void Reset()
 {
     GC.Collect();
     GC.WaitForPendingFinalizers();
     GC.Collect();
     s_hc = new HandleCollector("hc", 100);
 }
Esempio n. 3
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;
    }
Esempio n. 4
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));
        }
Esempio n. 5
0
    // 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;
    }
Esempio n. 6
0
    // 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);
    }
Esempio n. 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);
    }
Esempio n. 8
0
    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;
    }
Esempio n. 9
0
    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;
    }
Esempio n. 10
0
 public static IntPtr CreateBrushIndirect(NativeMethods.LOGBRUSH lb)
 {
     return(HandleCollector.Add(IntCreateBrushIndirect(lb), NativeMethods.CommonHandles.GDI));
 }
Esempio n. 11
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;
    }
Esempio n. 12
0
    // 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;
    }
Esempio n. 13
0
 public static bool DeleteObject(HandleRef hObject)
 {
     HandleCollector.Remove((IntPtr)hObject, NativeMethods.CommonHandles.GDI);
     return(IntDeleteObject(hObject));
 }
Esempio n. 14
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;
    }
Esempio n. 15
0
 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);
 }
Esempio n. 17
0
 public static IntPtr CreateHalftonePalette(HandleRef hdc)
 {
     return(HandleCollector.Add(IntCreateHalftonePalette(hdc), NativeMethods.CommonHandles.GDI));
 }
Esempio n. 18
0
    // 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);
    }
Esempio n. 19
0
 public static IntPtr GetDC(HandleRef hWnd)
 {
     return(HandleCollector.Add(IntGetDC(hWnd), SafeNativeMethods.CommonHandles.HDC));
 }
Esempio n. 20
0
 public static IntPtr CreatePatternBrush(HandleRef hbmp)
 {
     return(HandleCollector.Add(IntCreatePatternBrush(hbmp), NativeMethods.CommonHandles.GDI));
 }
Esempio n. 21
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));
 }
Esempio n. 22
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));
 }
Esempio n. 23
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));
 }
Esempio n. 24
0
 public static IntPtr CreatePen(int nStyle, int nWidth, int crColor)
 {
     return(HandleCollector.Add(IntCreatePen(nStyle, nWidth, crColor), NativeMethods.CommonHandles.GDI));
 }
Esempio n. 25
0
 public ICallForTest1Tests()
 {
     _handleCollector = new HandleCollector("call", 1, 10);
 }
Esempio n. 26
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));
 }
Esempio n. 27
0
 public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
 {
     HandleCollector.Remove((IntPtr)hDC, NativeMethods.CommonHandles.HDC);
     return(IntReleaseDC(hWnd, hDC));
 }
Esempio n. 28
0
 public static IntPtr CreateRectRgn(int x1, int y1, int x2, int y2)
 {
     return(HandleCollector.Add(IntCreateRectRgn(x1, y1, x2, y2), NativeMethods.CommonHandles.GDI));
 }
Esempio n. 29
0
 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;
 }