1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiSelectBrush
5  * PROGRAMMERS:
6  */
7 
8 #include "../win32nt.h"
9 
10 START_TEST(NtGdiSelectBrush)
11 {
12     HDC hDC;
13     HBRUSH hBrush, hOldBrush;
14     DC_ATTR *pdcattr;
15 
16     hDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
17 
18     hBrush = GetStockObject(GRAY_BRUSH);
19 
20     /* Test NULL DC */
21     SetLastError(ERROR_SUCCESS);
22     hOldBrush = NtGdiSelectBrush(NULL, hBrush);
23     TEST(hOldBrush == NULL);
24     TEST(GetLastError() == ERROR_SUCCESS);
25 
26     /* Test invalid DC */
27     SetLastError(ERROR_SUCCESS);
28     hOldBrush = NtGdiSelectBrush((HDC)((ULONG_PTR)hDC & 0x0000ffff), hBrush);
29     TEST(hOldBrush == NULL);
30     TEST(GetLastError() == ERROR_SUCCESS);
31 
32     /* Test NULL brush */
33     SetLastError(ERROR_SUCCESS);
34     hOldBrush = NtGdiSelectBrush(hDC, NULL);
35     TEST(hOldBrush == NULL);
36     TEST(GetLastError() == ERROR_SUCCESS);
37 
38     /* Test invalid brush */
39     SetLastError(ERROR_SUCCESS);
40     hOldBrush = NtGdiSelectBrush(hDC, (HBRUSH)((ULONG_PTR)hBrush & 0x0000ffff));
41     TEST(hOldBrush == NULL);
42     TEST(GetLastError() == ERROR_SUCCESS);
43 
44     SetLastError(ERROR_SUCCESS);
45     hOldBrush = NtGdiSelectBrush(hDC, hBrush);
46     TEST(hOldBrush != NULL);
47     hOldBrush = NtGdiSelectBrush(hDC, hOldBrush);
48     TEST(hOldBrush == hBrush);
49     TEST(GetLastError() == ERROR_SUCCESS);
50 
51     /* Begin with a white brush */
52     NtGdiSelectBrush(hDC, GetStockObject(WHITE_BRUSH));
53     /* Select a brush in user mode */
54     SelectObject(hDC, GetStockObject(BLACK_BRUSH));
55     /* See what we get returned */
56     hOldBrush = NtGdiSelectBrush(hDC, GetStockObject(WHITE_BRUSH));
57     TEST(hOldBrush == GetStockObject(BLACK_BRUSH));
58 
59 
60     /* Begin with a white brush */
61     NtGdiSelectBrush(hDC, GetStockObject(WHITE_BRUSH));
62 
63     pdcattr = GdiGetHandleUserData(hDC);
64     /* Change the brush in user mode, without setting flags */
65     pdcattr->hbrush = (HBRUSH)12345;
66 
67     hOldBrush = NtGdiSelectBrush(hDC, GetStockObject(BLACK_BRUSH));
68     TEST(hOldBrush == (HBRUSH)12345);
69 
70 
71     DeleteDC(hDC);
72 }
73 
74