1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for CreatePen
5  * PROGRAMMERS:     Timo Kreuzer
6  */
7 
8 #include <apitest.h>
9 
10 #include <wingdi.h>
11 #include <winddi.h>
12 #include <include/ntgdityp.h>
13 #include <include/ntgdihdl.h>
14 
15 void Test_CreatePen()
16 {
17 	HPEN hPen;
18 	LOGPEN logpen;
19 
20 	SetLastError(ERROR_SUCCESS);
21 	hPen = CreatePen(PS_DASHDOT, 5, RGB(1,2,3));
22 	ok(hPen != 0, "CreatePen failed\n");
23 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
24 
25 	/* Test if we have a PEN */
26 	ok(GDI_HANDLE_GET_TYPE(hPen) == GDI_OBJECT_TYPE_PEN, "Expected GDI_OBJECT_TYPE_PEN, got %lu\n", GDI_HANDLE_GET_TYPE(hPen));
27 
28 	ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
29 	ok(logpen.lopnStyle == PS_DASHDOT, "Expected PS_DASHDOT, got %u\n", logpen.lopnStyle);
30 	ok(logpen.lopnWidth.x == 5, "Expected 5, got %lu\n", logpen.lopnWidth.x);
31 	ok(logpen.lopnColor == RGB(1,2,3), "Expected %x, got %x\n", (unsigned)RGB(1,2,3), (unsigned)logpen.lopnColor);
32 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
33 	if(hPen)
34 		ok(DeleteObject(hPen), "DeleteObject failed\n");
35 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
36 
37 	/* PS_GEOMETRIC | PS_DASHDOT = 0x00001011 will become PS_SOLID */
38 	SetLastError(ERROR_SUCCESS);
39 	logpen.lopnStyle = 22;
40 	hPen = CreatePen(PS_GEOMETRIC | PS_DASHDOT, 5, RGB(1,2,3));
41 	ok(hPen != 0, "CreatePen failed\n");
42 	ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
43 	ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
44 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
45 	if(hPen)
46 		ok(DeleteObject(hPen), "DeleteObject failed\n");
47 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
48 
49 	/* PS_USERSTYLE will become PS_SOLID */
50 	logpen.lopnStyle = 22;
51 	SetLastError(ERROR_SUCCESS);
52 	hPen = CreatePen(PS_USERSTYLE, 5, RGB(1,2,3));
53 	ok(hPen != 0, "CreatePen failed\n");
54 	ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
55 	ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
56 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
57 	if(hPen)
58 		ok(DeleteObject(hPen), "DeleteObject failed\n");
59 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
60 
61 	/* PS_ALTERNATE will become PS_SOLID */
62 	logpen.lopnStyle = 22;
63 	SetLastError(ERROR_SUCCESS);
64 	hPen = CreatePen(PS_ALTERNATE, 5, RGB(1,2,3));
65 	ok(hPen != 0, "CreatePen failed\n");
66 	ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
67 	ok(logpen.lopnStyle == PS_SOLID, "Expected PS_SOLID, got %u\n", logpen.lopnStyle);
68 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
69 	if(hPen)
70 		ok(DeleteObject(hPen), "DeleteObject failed\n");
71 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
72 
73 	/* PS_INSIDEFRAME is ok */
74 	logpen.lopnStyle = 22;
75 	SetLastError(ERROR_SUCCESS);
76 	hPen = CreatePen(PS_INSIDEFRAME, 5, RGB(1,2,3));
77 	ok(hPen != 0, "CreatePen failed\n");
78 	ok(GetObject(hPen, sizeof(logpen), &logpen), "GetObject failed\n");
79 	ok(logpen.lopnStyle == PS_INSIDEFRAME, "Expected PS_INSIDEFRAME, got %u\n", logpen.lopnStyle);
80 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
81 	if(hPen)
82 		ok(DeleteObject(hPen), "DeleteObject failed\n");
83 	ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %lu\n", GetLastError());
84 }
85 
86 START_TEST(CreatePen)
87 {
88     Test_CreatePen();
89 }
90 
91