Revert r47130, it was already comitted.
[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
9 /* Try to delete 0 */
10 SetLastError(0);
11 TEST(NtGdiDeleteObjectApp(0) == 0);
12 TEST(GetLastError() == 0);
13
14 /* Try to delete something with a stockbit */
15 SetLastError(0);
16 TEST(NtGdiDeleteObjectApp((PVOID)(GDI_HANDLE_STOCK_MASK | 0x1234)) == 1);
17 TEST(GetLastError() == 0);
18
19 /* Delete a compatible DC */
20 SetLastError(0);
21 hdc = CreateCompatibleDC(NULL);
22 ASSERT(IsHandleValid(hdc) == 1);
23 TEST(NtGdiDeleteObjectApp(hdc) == 1);
24 TEST(GetLastError() == 0);
25 TEST(IsHandleValid(hdc) == 0);
26
27 /* Delete a display DC */
28 SetLastError(0);
29 hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
30 ASSERT(IsHandleValid(hdc) == 1);
31 TEST(NtGdiDeleteObjectApp(hdc) != 0);
32 TEST(GetLastError() == 0);
33 TEST(IsHandleValid(hdc) == 1);
34 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
35 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
36
37 /* Once more */
38 SetLastError(0);
39 hdc = GetDC(0);
40 ASSERT(IsHandleValid(hdc) == 1);
41 TEST(NtGdiDeleteObjectApp(hdc) != 0);
42 TEST(GetLastError() == 0);
43 TEST(IsHandleValid(hdc) == 1);
44 TEST(SelectObject(hdc, GetStockObject(WHITE_PEN)) == NULL);
45 TESTX(GetLastError() == ERROR_INVALID_PARAMETER, "GetLasterror returned 0x%08x\n", (unsigned int)GetLastError());
46
47 /* Delete a brush */
48 SetLastError(0);
49 hbrush = CreateSolidBrush(0x123456);
50 ASSERT(IsHandleValid(hbrush) == 1);
51 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
52 TEST(GetLastError() == 0);
53 TEST(IsHandleValid(hbrush) == 0);
54
55 /* Try to delete a stock brush */
56 SetLastError(0);
57 hbrush = GetStockObject(BLACK_BRUSH);
58 ASSERT(IsHandleValid(hbrush) == 1);
59 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
60 TEST(GetLastError() == 0);
61 TEST(IsHandleValid(hbrush) == 1);
62
63 /* Delete a bitmap */
64 SetLastError(0);
65 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
66 ASSERT(IsHandleValid(hbmp) == 1);
67 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
68 TEST(GetLastError() == 0);
69 TEST(IsHandleValid(hbmp) == 0);
70
71 /* Create a DC for further use */
72 hdc = CreateCompatibleDC(NULL);
73 ASSERT(hdc);
74
75 /* Try to delete a brush that is selected into a DC */
76 SetLastError(0);
77 hbrush = CreateSolidBrush(0x123456);
78 ASSERT(IsHandleValid(hbrush) == 1);
79 TEST(NtGdiSelectBrush(hdc, hbrush));
80 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
81 TEST(GetLastError() == 0);
82 TEST(IsHandleValid(hbrush) == 1);
83
84 /* Try to delete a bitmap that is selected into a DC */
85 SetLastError(0);
86 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
87 ASSERT(IsHandleValid(hbmp) == 1);
88 TEST(NtGdiSelectBitmap(hdc, hbmp));
89
90 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
91 TEST(GetLastError() == 0);
92 TEST(IsHandleValid(hbmp) == 1);
93
94 /* Bitmap get's deleted as soon as we dereference it */
95 NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
96 TEST(IsHandleValid(hbmp) == 0);
97
98 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
99 TEST(GetLastError() == 0);
100 TEST(IsHandleValid(hbmp) == 0);
101
102 /* Try to delete a brush that is selected into a DC */
103 SetLastError(0);
104 hbrush = CreateSolidBrush(123);
105 ASSERT(IsHandleValid(hbrush) == 1);
106 TEST(NtGdiSelectBrush(hdc, hbrush));
107
108 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
109 TEST(GetLastError() == 0);
110 TEST(IsHandleValid(hbrush) == 1);
111
112 return APISTATUS_NORMAL;
113 }