[GDI32_APITEST]
authorRafal Harabien <rafalh@reactos.org>
Sat, 26 Mar 2011 15:23:10 +0000 (15:23 +0000)
committerRafal Harabien <rafalh@reactos.org>
Sat, 26 Mar 2011 15:23:10 +0000 (15:23 +0000)
Improve CreatePen and GetCurrentObject tests

svn path=/trunk/; revision=51160

rostests/apitests/gdi32/CreatePen.c
rostests/apitests/gdi32/GetCurrentObject.c

index d45d171..2c79156 100644 (file)
@@ -19,50 +19,68 @@ void Test_CreatePen()
 
        SetLastError(ERROR_SUCCESS);
        hPen = CreatePen(PS_DASHDOT, 5, RGB(1,2,3));
-       ok(hPen != 0, "\n");
+       ok(hPen != 0, "CreatePen failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Test if we have a PEN */
-       ok(GDI_HANDLE_GET_TYPE(hPen) == GDI_OBJECT_TYPE_PEN, "\n");
+       ok(GDI_HANDLE_GET_TYPE(hPen) == GDI_OBJECT_TYPE_PEN, "Expected GDI_OBJECT_TYPE_PEN, got %lu\n", GDI_HANDLE_GET_TYPE(hPen));
 
-       GetObject(hPen, sizeof(logpen), &logpen);
-       ok(logpen.lopnStyle == PS_DASHDOT, "\n");
-       ok(logpen.lopnWidth.x == 5, "\n");
-       ok(logpen.lopnColor == RGB(1,2,3), "\n");
-       DeleteObject(hPen);
+       ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
+       ok(logpen.lopnStyle == PS_DASHDOT, "Expected PS_DASHDOT, got %u\n", logpen.lopnStyle);
+       ok(logpen.lopnWidth.x == 5, "Expected 5, got %lu\n", logpen.lopnWidth.x);
+       ok(logpen.lopnColor == RGB(1,2,3), "Expected %x, got %x\n", (unsigned)RGB(1,2,3), (unsigned)logpen.lopnColor);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+       if(hPen)
+               ok(DeleteObject(hPen), "DeleteObject failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* PS_GEOMETRIC | PS_DASHDOT = 0x00001011 will become PS_SOLID */
+       SetLastError(ERROR_SUCCESS);
        logpen.lopnStyle = 22;
        hPen = CreatePen(PS_GEOMETRIC | PS_DASHDOT, 5, RGB(1,2,3));
-       ok(hPen != 0, "\n");
-       GetObject(hPen, sizeof(logpen), &logpen);
-       ok(logpen.lopnStyle == PS_SOLID, "\n");
-       DeleteObject(hPen);
+       ok(hPen != 0, "CreatePen failed\n");
+       ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
+       ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+       if(hPen)
+               ok(DeleteObject(hPen), "DeleteObject failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* PS_USERSTYLE will become PS_SOLID */
        logpen.lopnStyle = 22;
+       SetLastError(ERROR_SUCCESS);
        hPen = CreatePen(PS_USERSTYLE, 5, RGB(1,2,3));
-       ok(hPen != 0, "\n");
-       GetObject(hPen, sizeof(logpen), &logpen);
-       ok(logpen.lopnStyle == PS_SOLID, "\n");
-       DeleteObject(hPen);
+       ok(hPen != 0, "CreatePen failed\n");
+       ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
+       ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+       if(hPen)
+               ok(DeleteObject(hPen), "DeleteObject failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* PS_ALTERNATE will become PS_SOLID */
        logpen.lopnStyle = 22;
+       SetLastError(ERROR_SUCCESS);
        hPen = CreatePen(PS_ALTERNATE, 5, RGB(1,2,3));
-       ok(hPen != 0, "\n");
-       GetObject(hPen, sizeof(logpen), &logpen);
-       ok(logpen.lopnStyle == PS_SOLID, "\n");
-       DeleteObject(hPen);
+       ok(hPen != 0, "CreatePen failed\n");
+       ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
+       ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+       if(hPen)
+               ok(DeleteObject(hPen), "DeleteObject failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* PS_INSIDEFRAME is ok */
        logpen.lopnStyle = 22;
+       SetLastError(ERROR_SUCCESS);
        hPen = CreatePen(PS_INSIDEFRAME, 5, RGB(1,2,3));
-       ok(hPen != 0, "\n");
-       GetObject(hPen, sizeof(logpen), &logpen);
-       ok(logpen.lopnStyle == PS_INSIDEFRAME, "\n");
-       DeleteObject(hPen);
-
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       ok(hPen != 0, "CreatePen failed\n");
+       ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
+       ok(logpen.lopnStyle == PS_INSIDEFRAME, "Expected PS_INSIDEFRAME, got %u\n", logpen.lopnStyle);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+       if(hPen)
+               ok(DeleteObject(hPen), "DeleteObject failed\n");
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 }
 
 START_TEST(CreatePen)
index c8389eb..d56eb2e 100644 (file)
@@ -17,6 +17,7 @@ void Test_GetCurrentObject()
        HWND hWnd;
        HDC hDC;
        HBITMAP hBmp;
+       HGDIOBJ hObj;
 
        /* Create a window */
        hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
@@ -27,121 +28,147 @@ void Test_GetCurrentObject()
 
        /* Test NULL DC */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(NULL, 0) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
-
-       SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(NULL, OBJ_BITMAP) == 0, "\n");
-       ok(GetCurrentObject(NULL, OBJ_BRUSH) == 0, "\n");
-       ok(GetCurrentObject(NULL, OBJ_COLORSPACE) == 0, "\n");
-       ok(GetCurrentObject(NULL, OBJ_FONT) == 0, "\n");
-       ok(GetCurrentObject(NULL, OBJ_PAL) == 0, "\n");
-       ok(GetCurrentObject(NULL, OBJ_PEN) == 0, "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(NULL, 0);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
+
+       SetLastError(ERROR_SUCCESS);
+       hObj = GetCurrentObject(NULL, OBJ_BITMAP);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       hObj = GetCurrentObject(NULL, OBJ_BRUSH);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       hObj = GetCurrentObject(NULL, OBJ_COLORSPACE);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       hObj = GetCurrentObject(NULL, OBJ_FONT);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       hObj = GetCurrentObject(NULL, OBJ_PAL);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       hObj = GetCurrentObject(NULL, OBJ_PEN);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Test invalid DC handle */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject((HDC)-123, 0) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject((HDC)-123, 0);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject((HDC)-123, OBJ_BITMAP) == 0, "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject((HDC)-123, OBJ_BITMAP);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Test invalid types */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 0) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 0);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 3) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 3);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 4) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 4);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 8) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 8);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 9) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 9);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 10) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 10);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 12) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 12);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, 13) == 0, "\n");
-       ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
+       hObj = GetCurrentObject(hDC, 13);
+       ok(hObj == 0, "Expected 0, got %p\n", hObj);
+       ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %lu\n", GetLastError());
 
        /* Default bitmap */
        SetLastError(ERROR_SUCCESS);
        hBmp = GetCurrentObject(hDC, OBJ_BITMAP);
-       ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Other bitmap */
        SetLastError(ERROR_SUCCESS);
        SelectObject(hDC, GetStockObject(21));
        ok(hBmp == GetCurrentObject(hDC, OBJ_BITMAP), "\n");
-       ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       ok(GDI_HANDLE_GET_TYPE(hBmp) == GDI_OBJECT_TYPE_BITMAP, "Expected GDI_OBJECT_TYPE_BITMAP, got %lu\n", GDI_HANDLE_GET_TYPE(hBmp));
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Default brush */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, OBJ_BRUSH) == GetStockObject(WHITE_BRUSH), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_BRUSH);
+       ok(hObj == GetStockObject(WHITE_BRUSH), "Expected %p, got %p\n", GetStockObject(WHITE_BRUSH), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Other brush */
        SetLastError(ERROR_SUCCESS);
        SelectObject(hDC, GetStockObject(BLACK_BRUSH));
-       ok(GetCurrentObject(hDC, OBJ_BRUSH) == GetStockObject(BLACK_BRUSH), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_BRUSH);
+       ok(hObj == GetStockObject(BLACK_BRUSH), "Expected %p, got %p\n", GetStockObject(BLACK_BRUSH), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Default colorspace */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, OBJ_COLORSPACE) == GetStockObject(20), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_COLORSPACE);
+       ok(hObj == GetStockObject(20), "Expected %p, got %p\n", GetStockObject(20), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Default font */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, OBJ_FONT) == GetStockObject(SYSTEM_FONT), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_FONT);
+       ok(hObj == GetStockObject(SYSTEM_FONT), "Expected %p, got %p\n", GetStockObject(SYSTEM_FONT), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Other font */
        SetLastError(ERROR_SUCCESS);
        SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
-       ok(GetCurrentObject(hDC, OBJ_FONT) == GetStockObject(DEFAULT_GUI_FONT), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_FONT);
+       ok(hObj == GetStockObject(DEFAULT_GUI_FONT), "Expected %p, got %p\n", GetStockObject(DEFAULT_GUI_FONT), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Default palette */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, OBJ_PAL) == GetStockObject(DEFAULT_PALETTE), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_PAL);
+       ok(hObj == GetStockObject(DEFAULT_PALETTE), "Expected %p, got %p\n", GetStockObject(DEFAULT_PALETTE), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Default pen */
        SetLastError(ERROR_SUCCESS);
-       ok(GetCurrentObject(hDC, OBJ_PEN) == GetStockObject(BLACK_PEN), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_PEN);
+       ok(hObj == GetStockObject(BLACK_PEN), "Expected %p, got %p\n", GetStockObject(BLACK_PEN), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* Other pen */
        SetLastError(ERROR_SUCCESS);
        SelectObject(hDC, GetStockObject(WHITE_PEN));
-       ok(GetCurrentObject(hDC, OBJ_PEN) == GetStockObject(WHITE_PEN), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_PEN);
+       ok(hObj == GetStockObject(WHITE_PEN), "Expected %p, got %p\n", GetStockObject(WHITE_PEN), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        /* DC pen */
        SetLastError(ERROR_SUCCESS);
        SelectObject(hDC, GetStockObject(DC_PEN));
-       ok(GetCurrentObject(hDC, OBJ_PEN) == GetStockObject(DC_PEN), "\n");
-       ok(GetLastError() == ERROR_SUCCESS, "\n");
+       hObj = GetCurrentObject(hDC, OBJ_PEN);
+       ok(hObj == GetStockObject(DC_PEN), "Expected %p, got %p\n", GetStockObject(DC_PEN), hObj);
+       ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
 
        ReleaseDC(hWnd, hDC);
        DestroyWindow(hWnd);