1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiSelectPen
5  * PROGRAMMERS:
6  */
7 
8 #include "../win32nt.h"
9 
10 START_TEST(NtGdiSelectPen)
11 {
12     HDC hDC;
13     HPEN hPen, hOldPen;
14     LOGBRUSH logbrush;
15 
16     hDC = GetDC(NULL);
17     ASSERT(hDC);
18 
19     hPen = GetStockObject(WHITE_PEN);
20 
21     /* Test NULL DC */
22     SetLastError(ERROR_SUCCESS);
23     hOldPen = NtGdiSelectPen(NULL, hPen);
24     TEST(hOldPen == NULL);
25     TEST(GetLastError() == ERROR_SUCCESS);
26 
27     /* Test invalid DC */
28     SetLastError(ERROR_SUCCESS);
29     hOldPen = NtGdiSelectPen((HDC)((ULONG_PTR)hDC & 0x0000ffff), hPen);
30     TEST(hOldPen == NULL);
31     TEST(GetLastError() == ERROR_SUCCESS);
32 
33     /* Test NULL pen */
34     SetLastError(ERROR_SUCCESS);
35     hOldPen = NtGdiSelectPen(hDC, NULL);
36     TEST(hOldPen == NULL);
37     TEST(GetLastError() == ERROR_SUCCESS);
38 
39     /* Test invalid pen */
40     SetLastError(ERROR_SUCCESS);
41     hOldPen = NtGdiSelectPen(hDC, (HPEN)((ULONG_PTR)hPen & 0x0000ffff));
42     TEST(hOldPen == NULL);
43     TEST(GetLastError() == ERROR_SUCCESS);
44 
45     /* Test valid pen */
46     SelectObject(hDC, GetStockObject(BLACK_PEN));
47     SetLastError(ERROR_SUCCESS);
48     hOldPen = NtGdiSelectPen(hDC, hPen);
49     TEST(hOldPen == GetStockObject(BLACK_PEN));
50     hOldPen = NtGdiSelectPen(hDC, hOldPen);
51     TEST(hOldPen == hPen);
52     TEST(GetLastError() == ERROR_SUCCESS);
53 
54     /* Test extpen */
55     SetLastError(ERROR_SUCCESS);
56     logbrush.lbStyle = BS_SOLID;
57     logbrush.lbColor = RGB(0x12,0x34,0x56);
58     hPen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &logbrush, 0, NULL);
59     ASSERT(hPen);
60     hOldPen = NtGdiSelectPen(hDC, hPen);
61     TEST(hOldPen != NULL);
62     hOldPen = NtGdiSelectPen(hDC, hOldPen);
63     TEST(hOldPen == hPen);
64     TEST(GetLastError() == ERROR_SUCCESS);
65 
66     /* Test deleting pen */
67     SetLastError(ERROR_SUCCESS);
68     hOldPen = NtGdiSelectPen(hDC, hPen);
69     TEST(DeleteObject(hPen) == 1);
70     hOldPen = NtGdiSelectPen(hDC, hOldPen);
71     TEST(hOldPen == hPen);
72     TEST(GetLastError() == ERROR_SUCCESS);
73 
74     /* Test that fallback pen is BLACK_PEN */
75 
76     DeleteDC(hDC);
77 }
78