1 /*
2  * PROJECT:         ReactOS api tests
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * PURPOSE:         Test for NtGdiDeleteObjectApp
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
10 START_TEST(NtGdiDeleteObjectApp)
11 {
12     HDC hdc;
13     HBITMAP hbmp;
14     HBRUSH hbrush;
15     HPEN hpen;
16 
17     /* Try to delete 0 */
18     SetLastError(0);
19     ok_int(NtGdiDeleteObjectApp(0), 0);
20     ok_long(GetLastError(), 0);
21 
22     /* Try to delete something with a stockbit */
23     SetLastError(0);
24     ok_int(NtGdiDeleteObjectApp((PVOID)(GDI_HANDLE_STOCK_MASK | 0x1234)), 1);
25     ok_long(GetLastError(), 0);
26 
27     /* Delete a compatible DC */
28     SetLastError(0);
29     hdc = CreateCompatibleDC(NULL);
30     ok_int(GdiIsHandleValid(hdc), 1);
31     ok_int(NtGdiDeleteObjectApp(hdc), 1);
32     ok_long(GetLastError(), 0);
33     ok_int(GdiIsHandleValid(hdc), 0);
34 
35     /* Delete a display DC */
36     SetLastError(0);
37     hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
38     ok_int(GdiIsHandleValid(hdc), 1);
39     ok((hpen=SelectObject(hdc, GetStockObject(WHITE_PEN))) != NULL, "hpen was NULL.\n");
40     SelectObject(hdc, hpen);
41     ok(NtGdiDeleteObjectApp(hdc) != 0, "NtGdiDeleteObjectApp(hdc) was zero.\n");
42     ok_long(GetLastError(), 0);
43     ok_int(GdiIsHandleValid(hdc), 1);
44     ok_ptr(SelectObject(hdc, GetStockObject(WHITE_PEN)), NULL);
45     ok_long(GetLastError(), ERROR_INVALID_PARAMETER);
46 
47     /* Once more */
48     SetLastError(0);
49     hdc = GetDC(0);
50     ok_int(GdiIsHandleValid(hdc), 1);
51     ok(NtGdiDeleteObjectApp(hdc) != 0, "NtGdiDeleteObjectApp(hdc) was zero.\n");
52     ok_long(GetLastError(), 0);
53     ok_int(GdiIsHandleValid(hdc), 1);
54     ok_ptr(SelectObject(hdc, GetStockObject(WHITE_PEN)), NULL);
55     ok_long(GetLastError(), ERROR_INVALID_PARAMETER);
56     /* Make sure */
57     ok_ptr((void *)NtUserCallOneParam((DWORD_PTR)hdc, ONEPARAM_ROUTINE_RELEASEDC), NULL);
58 
59     /* Delete a brush */
60     SetLastError(0);
61     hbrush = CreateSolidBrush(0x123456);
62     ok_int(GdiIsHandleValid(hbrush), 1);
63     ok_int(NtGdiDeleteObjectApp(hbrush), 1);
64     ok_long(GetLastError(), 0);
65     ok_int(GdiIsHandleValid(hbrush), 0);
66 
67     /* Try to delete a stock brush */
68     SetLastError(0);
69     hbrush = GetStockObject(BLACK_BRUSH);
70     ok_int(GdiIsHandleValid(hbrush), 1);
71     ok_int(NtGdiDeleteObjectApp(hbrush), 1);
72     ok_long(GetLastError(), 0);
73     ok_int(GdiIsHandleValid(hbrush), 1);
74 
75     /* Delete a bitmap */
76     SetLastError(0);
77     hbmp = CreateBitmap(10, 10, 1, 1, NULL);
78     ok_int(GdiIsHandleValid(hbmp), 1);
79     ok_int(NtGdiDeleteObjectApp(hbmp), 1);
80     ok_long(GetLastError(), 0);
81     ok_int(GdiIsHandleValid(hbmp), 0);
82 
83     /* Create a DC for further use */
84     hdc = CreateCompatibleDC(NULL);
85     ok(hdc != NULL, "hdc was NULL.\n");
86 
87     /* Try to delete a brush that is selected into a DC */
88     SetLastError(0);
89     hbrush = CreateSolidBrush(0x123456);
90     ok_int(GdiIsHandleValid(hbrush), 1);
91     ok(NtGdiSelectBrush(hdc, hbrush) != NULL, "NtGdiSelectBrush(hdc, hbrush) was NULL.\n");
92     ok_int(NtGdiDeleteObjectApp(hbrush), 1);
93     ok_long(GetLastError(), 0);
94     ok_int(GdiIsHandleValid(hbrush), 1);
95 
96     /* Try to delete a bitmap that is selected into a DC */
97     SetLastError(0);
98     hbmp = CreateBitmap(10, 10, 1, 1, NULL);
99     ok_int(GdiIsHandleValid(hbmp), 1);
100     ok(NtGdiSelectBitmap(hdc, hbmp) != NULL, "NtGdiSelectBitmap(hdc, hbmp) was NULL.\n");
101 
102     ok_int(NtGdiDeleteObjectApp(hbmp), 1);
103     ok_long(GetLastError(), 0);
104     ok_int(GdiIsHandleValid(hbmp), 1);
105 
106     /* Bitmap get's deleted as soon as we dereference it */
107     NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
108     ok_int(GdiIsHandleValid(hbmp), 0);
109 
110     ok_int(NtGdiDeleteObjectApp(hbmp), 1);
111     ok_long(GetLastError(), 0);
112     ok_int(GdiIsHandleValid(hbmp), 0);
113 
114     /* Try to delete a brush that is selected into a DC */
115     SetLastError(0);
116     hbrush = CreateSolidBrush(123);
117     ok_int(GdiIsHandleValid(hbrush), 1);
118     ok(NtGdiSelectBrush(hdc, hbrush) != NULL, "NtGdiSelectBrush(hdc, hbrush) was NULL.\n");
119 
120     ok_int(NtGdiDeleteObjectApp(hbrush), 1);
121     ok_long(GetLastError(), 0);
122     ok_int(GdiIsHandleValid(hbrush), 1);
123 }
124