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 #ifdef _WIN64 36 /* Test upper 32 bits */ 37 SetLastError(0); 38 hdc = (HDC)((ULONG64)CreateCompatibleDC(NULL) | 0xFFFFFFFF00000000ULL); 39 ok_int(GdiIsHandleValid(hdc), 1); 40 ok_int(NtGdiDeleteObjectApp(hdc), 1); 41 ok_long(GetLastError(), 0); 42 ok_int(GdiIsHandleValid(hdc), 0); 43 44 SetLastError(0); 45 hdc = (HDC)((ULONG64)CreateCompatibleDC(NULL) | 0x537F9F2F00000000ULL); 46 ok_int(GdiIsHandleValid(hdc), 1); 47 ok_int(NtGdiDeleteObjectApp(hdc), 1); 48 ok_long(GetLastError(), 0); 49 ok_int(GdiIsHandleValid(hdc), 0); 50 #endif 51 52 /* Delete a display DC */ 53 SetLastError(0); 54 hdc = CreateDC("DISPLAY", NULL, NULL, NULL); 55 ok_int(GdiIsHandleValid(hdc), 1); 56 ok((hpen=SelectObject(hdc, GetStockObject(WHITE_PEN))) != NULL, "hpen was NULL.\n"); 57 SelectObject(hdc, hpen); 58 ok(NtGdiDeleteObjectApp(hdc) != 0, "NtGdiDeleteObjectApp(hdc) was zero.\n"); 59 ok_long(GetLastError(), 0); 60 ok_int(GdiIsHandleValid(hdc), 1); 61 ok_ptr(SelectObject(hdc, GetStockObject(WHITE_PEN)), NULL); 62 ok_long(GetLastError(), ERROR_INVALID_PARAMETER); 63 64 /* Once more */ 65 SetLastError(0); 66 hdc = GetDC(0); 67 ok_int(GdiIsHandleValid(hdc), 1); 68 ok(NtGdiDeleteObjectApp(hdc) != 0, "NtGdiDeleteObjectApp(hdc) was zero.\n"); 69 ok_long(GetLastError(), 0); 70 ok_int(GdiIsHandleValid(hdc), 1); 71 ok_ptr(SelectObject(hdc, GetStockObject(WHITE_PEN)), NULL); 72 ok_long(GetLastError(), ERROR_INVALID_PARAMETER); 73 /* Make sure */ 74 ok_ptr((void *)NtUserCallOneParam((DWORD_PTR)hdc, ONEPARAM_ROUTINE_RELEASEDC), NULL); 75 76 77 /* Delete a brush */ 78 SetLastError(0); 79 hbrush = CreateSolidBrush(0x123456); 80 ok_int(GdiIsHandleValid(hbrush), 1); 81 ok_int(NtGdiDeleteObjectApp(hbrush), 1); 82 ok_long(GetLastError(), 0); 83 ok_int(GdiIsHandleValid(hbrush), 0); 84 85 /* Try to delete a stock brush */ 86 SetLastError(0); 87 hbrush = GetStockObject(BLACK_BRUSH); 88 ok_int(GdiIsHandleValid(hbrush), 1); 89 ok_int(NtGdiDeleteObjectApp(hbrush), 1); 90 ok_long(GetLastError(), 0); 91 ok_int(GdiIsHandleValid(hbrush), 1); 92 93 /* Delete a bitmap */ 94 SetLastError(0); 95 hbmp = CreateBitmap(10, 10, 1, 1, NULL); 96 ok_int(GdiIsHandleValid(hbmp), 1); 97 ok_int(NtGdiDeleteObjectApp(hbmp), 1); 98 ok_long(GetLastError(), 0); 99 ok_int(GdiIsHandleValid(hbmp), 0); 100 101 /* Create a DC for further use */ 102 hdc = CreateCompatibleDC(NULL); 103 ok(hdc != NULL, "hdc was NULL.\n"); 104 105 /* Try to delete a brush that is selected into a DC */ 106 SetLastError(0); 107 hbrush = CreateSolidBrush(0x123456); 108 ok_int(GdiIsHandleValid(hbrush), 1); 109 ok(NtGdiSelectBrush(hdc, hbrush) != NULL, "NtGdiSelectBrush(hdc, hbrush) was NULL.\n"); 110 ok_int(NtGdiDeleteObjectApp(hbrush), 1); 111 ok_long(GetLastError(), 0); 112 ok_int(GdiIsHandleValid(hbrush), 1); 113 114 /* Try to delete a bitmap that is selected into a DC */ 115 SetLastError(0); 116 hbmp = CreateBitmap(10, 10, 1, 1, NULL); 117 ok_int(GdiIsHandleValid(hbmp), 1); 118 ok(NtGdiSelectBitmap(hdc, hbmp) != NULL, "NtGdiSelectBitmap(hdc, hbmp) was NULL.\n"); 119 120 ok_int(NtGdiDeleteObjectApp(hbmp), 1); 121 ok_long(GetLastError(), 0); 122 ok_int(GdiIsHandleValid(hbmp), 1); 123 124 /* Bitmap get's deleted as soon as we dereference it */ 125 NtGdiSelectBitmap(hdc, GetStockObject(DEFAULT_BITMAP)); 126 ok_int(GdiIsHandleValid(hbmp), 0); 127 128 ok_int(NtGdiDeleteObjectApp(hbmp), 1); 129 ok_long(GetLastError(), 0); 130 ok_int(GdiIsHandleValid(hbmp), 0); 131 132 /* Try to delete a brush that is selected into a DC */ 133 SetLastError(0); 134 hbrush = CreateSolidBrush(123); 135 ok_int(GdiIsHandleValid(hbrush), 1); 136 ok(NtGdiSelectBrush(hdc, hbrush) != NULL, "NtGdiSelectBrush(hdc, hbrush) was NULL.\n"); 137 138 ok_int(NtGdiDeleteObjectApp(hbrush), 1); 139 ok_long(GetLastError(), 0); 140 ok_int(GdiIsHandleValid(hbrush), 1); 141 } 142