ef4daa228bd3d3a8e194e870a05af92f770cbb8a
[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 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 brush */
28 SetLastError(0);
29 hbrush = CreateSolidBrush(0x123456);
30 ASSERT(IsHandleValid(hbrush) == 1);
31 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
32 TEST(GetLastError() == 0);
33 TEST(IsHandleValid(hbrush) == 0);
34
35 /* Try to delete a stock brush */
36 SetLastError(0);
37 hbrush = GetStockObject(BLACK_BRUSH);
38 ASSERT(IsHandleValid(hbrush) == 1);
39 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
40 TEST(GetLastError() == 0);
41 TEST(IsHandleValid(hbrush) == 1);
42
43 /* Delete a bitmap */
44 SetLastError(0);
45 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
46 ASSERT(IsHandleValid(hbmp) == 1);
47 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
48 TEST(GetLastError() == 0);
49 TEST(IsHandleValid(hbmp) == 0);
50
51 /* Create a DC for further use */
52 hdc = CreateCompatibleDC(NULL);
53 ASSERT(hdc);
54
55 /* Try to delete a brush that is selected into a DC */
56 SetLastError(0);
57 hbrush = CreateSolidBrush(0x123456);
58 ASSERT(IsHandleValid(hbrush) == 1);
59 TEST(NtGdiSelectBrush(hdc, hbrush));
60 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
61 TEST(GetLastError() == 0);
62 TEST(IsHandleValid(hbrush) == 1);
63
64 /* Try to delete a bitmap that is selected into a DC */
65 SetLastError(0);
66 hbmp = CreateBitmap(10, 10, 1, 1, NULL);
67 ASSERT(IsHandleValid(hbmp) == 1);
68 TEST(NtGdiSelectBitmap(hdc, hbmp));
69
70 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
71 TEST(GetLastError() == 0);
72 TEST(IsHandleValid(hbmp) == 1);
73
74 /* Bitmap get's deleted as soon as we dereference it */
75 NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP));
76 TEST(IsHandleValid(hbmp) == 0);
77
78 TEST(NtGdiDeleteObjectApp(hbmp) == 1);
79 TEST(GetLastError() == 0);
80 TEST(IsHandleValid(hbmp) == 0);
81
82 /* Try to delete a brush that is selected into a DC */
83 SetLastError(0);
84 hbrush = CreateSolidBrush(123);
85 ASSERT(IsHandleValid(hbrush) == 1);
86 TEST(NtGdiSelectBrush(hdc, hbrush));
87
88 TEST(NtGdiDeleteObjectApp(hbrush) == 1);
89 TEST(GetLastError() == 0);
90 TEST(IsHandleValid(hbrush) == 1);
91
92 return APISTATUS_NORMAL;
93 }