[ros-diffs] [tkreuzer] 40217: Add one test for NtGdiDeleteObjectApp, and a bunch of tests for NtGdiSaveDC and NtGdiRestoreDC.

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Wed Mar 25 04:51:23 CET 2009


Author: tkreuzer
Date: Wed Mar 25 06:51:22 2009
New Revision: 40217

URL: http://svn.reactos.org/svn/reactos?rev=40217&view=rev
Log:
Add one test for NtGdiDeleteObjectApp, and a bunch of tests for NtGdiSaveDC and NtGdiRestoreDC.

Added:
    trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c   (with props)
    trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c   (with props)
Modified:
    trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c
    trunk/rostests/apitests/w32knapi/testlist.c

Modified: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c
URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c?rev=40217&r1=40216&r2=40217&view=diff
==============================================================================
--- trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/w32knapi/ntgdi/NtGdiDeleteObjectApp.c [iso-8859-1] Wed Mar 25 06:51:22 2009
@@ -11,6 +11,11 @@
     SetLastError(0);
     ret = NtGdiDeleteObjectApp(0);
     TEST(ret == 0);
+    TEST(GetLastError() == 0);
+
+    /* Try to delete something with a stockbit */
+    SetLastError(0);
+    TEST(NtGdiDeleteObjectApp((PVOID)(GDI_HANDLE_STOCK_MASK | 0x1234)) == 1);
     TEST(GetLastError() == 0);
 
     /* Delete a DC */
@@ -74,6 +79,7 @@
     ASSERT(hbmp);
     TEST(IsHandleValid(hbmp) == 1);
     TEST(NtGdiSelectBitmap(hdc, hbmp));
+
     ret = NtGdiDeleteObjectApp(hbmp);
     TEST(ret == 1);
     TEST(GetLastError() == 0);

Added: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c
URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c?rev=40217&view=auto
==============================================================================
--- trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c (added)
+++ trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c [iso-8859-1] Wed Mar 25 06:51:22 2009
@@ -1,0 +1,192 @@
+
+
+static HBRUSH hbrush;
+static HBITMAP hbitmap;
+static HPEN hpen;
+static HFONT hfont;
+static HRGN hrgn, hrgn2;
+
+static
+void
+SetSpecialDCState(HDC hdc)
+{
+    /* Select spcial Objects */
+    SelectObject(hdc, hbrush);
+    SelectObject(hdc, hpen);
+    SelectObject(hdc, hbitmap);
+    SelectObject(hdc, hfont);
+    SelectObject(hdc, hrgn);
+
+    /* Colors */
+    SetDCBrushColor(hdc, RGB(12,34,56));
+    SetDCPenColor(hdc, RGB(23,34,45));
+
+    /* Coordinates */
+    SetMapMode(hdc, MM_ANISOTROPIC);
+    SetGraphicsMode(hdc, GM_ADVANCED);
+    SetWindowOrgEx(hdc, 12, 34, NULL);
+    SetViewportOrgEx(hdc, 56, 78, NULL);
+    SetWindowExtEx(hdc, 123, 456, NULL);
+    SetViewportExtEx(hdc, 234, 567, NULL);
+
+
+
+}
+
+static
+void
+SetSpecialDCState2(HDC hdc)
+{
+    /* Select spcial Objects */
+    SelectObject(hdc, GetStockObject(DC_BRUSH));
+    SelectObject(hdc, GetStockObject(DC_PEN));
+    SelectObject(hdc, GetStockObject(DEFAULT_BITMAP));
+    SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT));
+    SelectObject(hdc, hrgn2);
+
+    /* Colors */
+    SetDCBrushColor(hdc, RGB(65,43,21));
+    SetDCPenColor(hdc, RGB(54,43,32));
+
+    /* Coordinates */
+    SetMapMode(hdc, MM_ISOTROPIC);
+    SetGraphicsMode(hdc, GM_COMPATIBLE);
+    SetWindowOrgEx(hdc, 43, 21, NULL);
+    SetViewportOrgEx(hdc, 87, 65, NULL);
+    SetWindowExtEx(hdc, 654, 321, NULL);
+    SetViewportExtEx(hdc, 765, 432, NULL);
+
+
+}
+
+static
+void
+Test_IsSpecialState(PTESTINFO pti, HDC hdc, BOOL bMemDC)
+{
+    POINT pt;
+    SIZE sz;
+
+    /* Test Objects */
+    TEST(SelectObject(hdc, GetStockObject(DC_BRUSH)) == hbrush);
+    TEST(SelectObject(hdc, GetStockObject(DC_PEN)) == hpen);
+    TEST(SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)) == hfont);
+    if (bMemDC)
+    {
+        TEST(SelectObject(hdc, GetStockObject(DEFAULT_BITMAP)) == hbitmap);
+        TEST(SelectObject(hdc, hrgn2) == (PVOID)1);
+    }
+    else
+    {
+        TEST(SelectObject(hdc, GetStockObject(DEFAULT_BITMAP)) == 0);
+        TEST(SelectObject(hdc, hrgn2) == (PVOID)2);
+    }
+
+    /* Test colors */
+    TEST(GetDCBrushColor(hdc) == RGB(12,34,56));
+    TEST(GetDCPenColor(hdc) == RGB(23,34,45));
+
+    /* Test coordinates */
+    TEST(GetMapMode(hdc) == MM_ANISOTROPIC);
+    TEST(GetGraphicsMode(hdc) == GM_ADVANCED);
+    GetWindowOrgEx(hdc, &pt);
+    TEST(pt.x == 12);
+    TEST(pt.y == 34);
+    GetViewportOrgEx(hdc, &pt);
+    TEST(pt.x == 56);
+    TEST(pt.y == 78);
+    GetWindowExtEx(hdc, &sz);
+    TESTX(sz.cx == 123, "sz.cx == %ld\n", sz.cx);
+    TESTX(sz.cy == 456, "sz.cy == %ld\n", sz.cy);
+    GetViewportExtEx(hdc, &sz);
+    TEST(sz.cx == 234);
+    TEST(sz.cy == 567);
+
+
+}
+
+
+static
+void
+Test_SaveRestore(PTESTINFO pti, HDC hdc, BOOL bMemDC)
+{
+    SetSpecialDCState(hdc);
+    NtGdiSaveDC(hdc);
+    SetSpecialDCState2(hdc);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, 2) == 0);
+    TEST(GetLastError() == ERROR_INVALID_PARAMETER);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, 0) == 0);
+    TEST(GetLastError() == ERROR_INVALID_PARAMETER);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, -2) == 0);
+    TEST(GetLastError() == ERROR_INVALID_PARAMETER);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, 1) == 1);
+    TEST(GetLastError() == 0);
+
+    Test_IsSpecialState(pti, hdc, bMemDC);
+}
+
+
+INT
+Test_NtGdiRestoreDC(PTESTINFO pti)
+{
+    HDC hdc;
+
+    hdc = CreateCompatibleDC(0);
+    ASSERT(IsHandleValid(hdc));
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(0, -10) == 0);
+    TEST(GetLastError() == ERROR_INVALID_HANDLE);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, 0) == 0);
+    TEST(GetLastError() == ERROR_INVALID_PARAMETER);
+
+    SetLastError(0);
+    TEST(NtGdiRestoreDC(hdc, 1) == 0);
+    TEST(GetLastError() == ERROR_INVALID_PARAMETER);
+
+    /* Initialize objects */
+    hbrush = CreateSolidBrush(12345);
+    ASSERT(IsHandleValid(hbrush));
+    hpen = CreatePen(PS_SOLID, 4, RGB(10,12,32));
+    ASSERT(IsHandleValid(hpen));
+    hbitmap = CreateBitmap(10, 10, 1, 1, NULL);
+    ASSERT(IsHandleValid(hbitmap));
+    hfont = CreateFont(10, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, 
+                OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
+                DEFAULT_PITCH, "Arial");
+    ASSERT(IsHandleValid(hfont));
+    hrgn = CreateRectRgn(12, 14, 14, 17);
+    ASSERT(IsHandleValid(hrgn));
+    hrgn2 = CreateRectRgn(1, 1, 2, 2);
+    ASSERT(IsHandleValid(hrgn2));
+
+    /* Test mem dc */
+    Test_SaveRestore(pti, hdc, TRUE);
+    DeleteDC(hdc);
+
+    /* Test screen DC */
+    hdc = GetDC(0);
+    ASSERT(IsHandleValid(hdc));
+    Test_SaveRestore(pti, hdc, FALSE);
+    ReleaseDC(0, hdc);
+
+    /* Test info dc */
+    hdc = CreateICW(L"DISPLAY", NULL, NULL, NULL);
+    ASSERT(IsHandleValid(hdc));
+    Test_SaveRestore(pti, hdc, FALSE);
+    DeleteDC(hdc);
+
+
+
+    return APISTATUS_NORMAL;
+}
+

Propchange: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiRestoreDC.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c
URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c?rev=40217&view=auto
==============================================================================
--- trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c (added)
+++ trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c [iso-8859-1] Wed Mar 25 06:51:22 2009
@@ -1,0 +1,45 @@
+
+INT
+Test_NtGdiSaveDC(PTESTINFO pti)
+{
+    HDC hdc;
+    HWND hwnd;
+
+    /* Test 0 hdc */
+    TEST(NtGdiSaveDC(0) == 0);
+
+    /* Test info dc */
+    hdc = CreateICW(L"DISPLAY",NULL,NULL,NULL);
+    TEST(hdc);
+    TEST(NtGdiSaveDC(hdc) == 1);
+    TEST(NtGdiSaveDC(hdc) == 2);
+    DeleteDC(hdc);
+
+    /* Test display dc */
+    hdc = GetDC(0);
+    TEST(hdc);
+    TEST(NtGdiSaveDC(hdc) == 1);
+    TEST(NtGdiSaveDC(hdc) == 2);
+    ReleaseDC(0, hdc);
+
+    /* Test a mem DC */
+    hdc = CreateCompatibleDC(0);
+    TEST(hdc);
+    TEST(NtGdiSaveDC(hdc) == 1);
+    TEST(NtGdiSaveDC(hdc) == 2);
+    DeleteDC(hdc);
+
+	/* Create a window */
+	hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+	                    10, 10, 100, 100,
+	                    NULL, NULL, g_hInstance, 0);
+    hdc = GetDC(hwnd);
+    TEST(hdc);
+    TEST(NtGdiSaveDC(hdc) == 1);
+    NtGdiRestoreDC(hdc, 1);
+    ReleaseDC(hwnd, hdc);
+    DestroyWindow(hwnd);
+
+    return APISTATUS_NORMAL;
+}
+

Propchange: trunk/rostests/apitests/w32knapi/ntgdi/NtGdiSaveDC.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/rostests/apitests/w32knapi/testlist.c
URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/w32knapi/testlist.c?rev=40217&r1=40216&r2=40217&view=diff
==============================================================================
--- trunk/rostests/apitests/w32knapi/testlist.c [iso-8859-1] (original)
+++ trunk/rostests/apitests/w32knapi/testlist.c [iso-8859-1] Wed Mar 25 06:51:22 2009
@@ -25,6 +25,8 @@
 #include "ntgdi/NtGdiGetFontResourceInfoInternalW.c"
 #include "ntgdi/NtGdiGetRandomRgn.c"
 #include "ntgdi/NtGdiPolyPolyDraw.c"
+#include "ntgdi/NtGdiRestoreDC.c"
+#include "ntgdi/NtGdiSaveDC.c"
 #include "ntgdi/NtGdiSelectBitmap.c"
 #include "ntgdi/NtGdiSelectBrush.c"
 #include "ntgdi/NtGdiSelectFont.c"
@@ -85,6 +87,8 @@
 	{ L"NtGdiGetFontResourceInfoInternalW", Test_NtGdiGetFontResourceInfoInternalW },
 	{ L"NtGdiGetRandomRgn", Test_NtGdiGetRandomRgn },
 	{ L"NtGdiPolyPolyDraw", Test_NtGdiPolyPolyDraw },
+	{ L"NtGdiRestoreDC", Test_NtGdiRestoreDC },
+	{ L"NtGdiSaveDC", Test_NtGdiSaveDC },
 	{ L"NtGdiSetBitmapBits", Test_NtGdiSetBitmapBits },
 	{ L"NtGdiSetDIBitsToDeviceInternal", Test_NtGdiSetDIBitsToDeviceInternal },
 	{ L"NtGdiSelectBitmap", Test_NtGdiSelectBitmap },



More information about the Ros-diffs mailing list