351de95e02974c4fd4f3af0b6e486faa6305d9d4
[reactos.git] / rostests / apitests / w32knapi / ntgdi / NtGdiDeleteObjectApp.c
1
2 INT
3 Test_NtGdiDeleteObjectApp(PTESTINFO pti)
4 {
5 HDC hdc;
6 HBITMAP hbmp;
7 HBRUSH hbrush;
8 HPEN hpen;
9
10 /* Try to delete 0 */
11 SetLastError(0);
12 TEST(NtGdiDeleteObjectApp(0) == 0);
13 TEST(GetLastError() == 0);
14
15 /* Try to delete something with a stockbit */
16 SetLastError(0);
17 TEST(NtGdiDeleteObjectApp((PVOID)(GDI_HANDLE_STOCK_MASK | 0x1234)) == 1);
18 TEST(GetLastError() == 0);
19
20 /* Delete a compatible DC */
21 SetLastError(0);
22 hdc = CreateCompatibleDC(NULL);
23 ASSERT(IsHandleValid(hdc) == 1);
24 TEST(NtGdiDeleteObjectApp(hdc) == 1);
25 TEST(GetLastError() == 0);
26 TEST(IsHandleValid(hdc) == 0);
27
28 /* Delete a display DC */
29 SetLastError(0);
30 hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
31 ASSERT(IsHandleValid(hdc) == 1);
32 TEST((hpen=SelectObject(hdc, GetStockObject(WHITE_PEN))) != NULL);
33 SelectObject(hdc, hpen);
34 TEST(NtGdiDeleteObjectApp(hdc) != 0);
35 TEST(GetLastError() == 0);
36 TEST(IsHandleValid(hdc) == 1);
37 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
38 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
39
40 /* Once more */
41 SetLastError(0);
42 hdc = GetDC(0);
43 ASSERT(IsHandleValid(hdc) == 1);
44 TEST(NtGdiDeleteObjectApp(hdc) != 0);
45 TEST(GetLastError() == 0);
46 TEST(IsHandleValid(hdc) == 1);
47 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
48 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
49 /* Make sure */
50 TEST(NtUserCallOneParam((DWORD_PTR)hdc, ONEPARAM_ROUTINE_RELEASEDC) == 0);
51
52 /* Delete a display DC */
53 SetLastError(0);
54 hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
55 ASSERT(IsHandleValid(hdc) == 1);
56 TEST(NtGdiDeleteObjectApp(hdc) != 0);
57 TEST(GetLastError() == 0);
58 TEST(IsHandleValid(hdc) == 1);
59 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
60 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
61
62 /* Once more */
63 SetLastError(0);
64 hdc = GetDC(0);
65 ASSERT(IsHandleValid(hdc) == 1);
66 TEST(NtGdiDeleteObjectApp(hdc) != 0);
67 TEST(GetLastError() == 0);
68 TEST(IsHandleValid(hdc) == 1);
69 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
70 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
71
72 /* Delete a brush */
73 SetLastError(0);
74 hbrush = CreateSolidBrush(0x123456);
75 ASSERT(IsHandleValid(hbrush) == 1);
76 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
77 TEST(GetLastError() == 0);
78 TEST(IsHandleValid(hbrush) == 0);
79
80 /* Try to delete a stock brush */
81 SetLastError(0);
82 hbrush = GetStockObject(BLACK_BRUSH);
83 ASSERT(IsHandleValid(hbrush) == 1);
84 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
85 TEST(GetLastError() == 0);
86 TEST(IsHandleValid(hbrush) == 1);
87
88 /* Delete a bitmap */
89 SetLastError(0);
90 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
91 ASSERT(IsHandleValid(hbmp) == 1);
92 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
93 TEST(GetLastError() == 0);
94 TEST(IsHandleValid(hbmp) == 0);
95
96 /* Create a DC for further use */
97 hdc = CreateCompatibleDC(NULL);
98 ASSERT(hdc);
99
100 /* Try to delete a brush that is selected into a DC */
101 SetLastError(0);
102 hbrush = CreateSolidBrush(0x123456);
103 ASSERT(IsHandleValid(hbrush) == 1);
104 TEST(NtGdiSelectBrush(hdc, hbrush));
105 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
106 TEST(GetLastError() == 0);
107 TEST(IsHandleValid(hbrush) == 1);
108
109 /* Try to delete a bitmap that is selected into a DC */
110 SetLastError(0);
111 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
112 ASSERT(IsHandleValid(hbmp) == 1);
113 TEST(NtGdiSelectBitmap(hdc, hbmp));
114
115 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
116 TEST(GetLastError() == 0);
117 TEST(IsHandleValid(hbmp) == 1);
118
119 /* Bitmap get's deleted as soon as we dereference it */
120 NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
121 TEST(IsHandleValid(hbmp) == 0);
122
123 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
124 TEST(GetLastError() == 0);
125 TEST(IsHandleValid(hbmp) == 0);
126
127 /* Try to delete a brush that is selected into a DC */
128 SetLastError(0);
129 hbrush = CreateSolidBrush(123);
130 ASSERT(IsHandleValid(hbrush) == 1);
131 TEST(NtGdiSelectBrush(hdc, hbrush));
132
133 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
134 TEST(GetLastError() == 0);
135 TEST(IsHandleValid(hbrush) == 1);
136
137 return APISTATUS_NORMAL;
138 }