[ROSTESTS:APITESTS]
[reactos.git] / rostests / apitests / gdi32 / SetDCPenColor.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetDCPenColor
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12
13 void Test_SetDCPenColor()
14 {
15 HDC hScreenDC, hDC;
16 HBITMAP hbmp, hbmpOld;
17
18 // Test an incorrect DC
19 SetLastError(ERROR_SUCCESS);
20 ok(SetDCPenColor(0, RGB(0,0,0)) == CLR_INVALID, "\n");
21 ok(GetLastError() == ERROR_INVALID_PARAMETER, "\n");
22
23 // Get the Screen DC
24 hScreenDC = GetDC(NULL);
25 ok(hScreenDC != 0, "GetDC failed, skipping tests\n");
26 if (hScreenDC == NULL) return;
27
28 // Test the screen DC
29 SetDCPenColor(hScreenDC, RGB(1,2,3));
30 ok(SetDCPenColor(hScreenDC, RGB(4,5,6)) == RGB(1,2,3), "\n");
31
32 // Create a new DC
33 hDC = CreateCompatibleDC(hScreenDC);
34 ReleaseDC(0, hScreenDC);
35 ok(hDC != 0, "CreateCompatibleDC failed, skipping tests\n");
36 if (!hDC) return;
37
38 // Select the DC_PEN and check if the pen returned by a new call is DC_PEN
39 SelectObject(hDC, GetStockObject(DC_PEN));
40 ok(SelectObject(hDC, GetStockObject(BLACK_PEN)) == GetStockObject(DC_PEN), "\n");
41
42 // Test an incorrect color, yes windows sets the color!
43 SetDCPenColor(hDC, 0x21123456);
44 ok(SetDCPenColor(hDC, RGB(0,0,0)) == 0x21123456, "\n");
45
46 // Test CLR_INVALID, it sets CLR_INVALID!
47 SetDCPenColor(hDC, CLR_INVALID);
48 ok(SetDCPenColor(hDC, RGB(0,0,0)) == CLR_INVALID, "\n");
49
50 hbmp = CreateBitmap(10, 10, 1, 32, NULL);
51 ok(hbmp != 0, "CreateBitmap failed, skipping tests\n");
52 if (!hbmp) return;
53 hbmpOld = SelectObject(hDC, hbmp);
54 #if 0 // this only works on 32 bpp screen resolution
55 ok(hbmpOld != NULL, "\n");
56 SelectObject(hDC, GetStockObject(DC_PEN));
57 SetDCPenColor(hDC, 0x123456);
58 MoveToEx(hDC, 0, 0, NULL);
59 LineTo(hDC, 10, 0);
60 ok(GetPixel(hDC, 5, 0) == 0x123456, "\n");
61 #endif
62
63 // Delete the DC
64 SelectObject(hDC, hbmpOld);
65 DeleteDC(hDC);
66 }
67
68 START_TEST(SetDCPenColor)
69 {
70 Test_SetDCPenColor();
71 }
72