[ROSTESTS]
[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 brush */
53 SetLastError(0);
54 hbrush = CreateSolidBrush(0x123456);
55 ASSERT(IsHandleValid(hbrush) == 1);
56 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
57 TEST(GetLastError() == 0);
58 TEST(IsHandleValid(hbrush) == 0);
59
60 /* Try to delete a stock brush */
61 SetLastError(0);
62 hbrush = GetStockObject(BLACK_BRUSH);
63 ASSERT(IsHandleValid(hbrush) == 1);
64 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
65 TEST(GetLastError() == 0);
66 TEST(IsHandleValid(hbrush) == 1);
67
68 /* Delete a bitmap */
69 SetLastError(0);
70 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
71 ASSERT(IsHandleValid(hbmp) == 1);
72 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
73 TEST(GetLastError() == 0);
74 TEST(IsHandleValid(hbmp) == 0);
75
76 /* Create a DC for further use */
77 hdc = CreateCompatibleDC(NULL);
78 ASSERT(hdc);
79
80 /* Try to delete a brush that is selected into a DC */
81 SetLastError(0);
82 hbrush = CreateSolidBrush(0x123456);
83 ASSERT(IsHandleValid(hbrush) == 1);
84 TEST(NtGdiSelectBrush(hdc, hbrush));
85 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
86 TEST(GetLastError() == 0);
87 TEST(IsHandleValid(hbrush) == 1);
88
89 /* Try to delete a bitmap that is selected into a DC */
90 SetLastError(0);
91 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
92 ASSERT(IsHandleValid(hbmp) == 1);
93 TEST(NtGdiSelectBitmap(hdc, hbmp));
94
95 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
96 TEST(GetLastError() == 0);
97 TEST(IsHandleValid(hbmp) == 1);
98
99 /* Bitmap get's deleted as soon as we dereference it */
100 NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
101 TEST(IsHandleValid(hbmp) == 0);
102
103 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
104 TEST(GetLastError() == 0);
105 TEST(IsHandleValid(hbmp) == 0);
106
107 /* Try to delete a brush that is selected into a DC */
108 SetLastError(0);
109 hbrush = CreateSolidBrush(123);
110 ASSERT(IsHandleValid(hbrush) == 1);
111 TEST(NtGdiSelectBrush(hdc, hbrush));
112
113 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
114 TEST(GetLastError() == 0);
115 TEST(IsHandleValid(hbrush) == 1);
116
117 return APISTATUS_NORMAL;
118 }