1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for NtGdiDoPalette 5 * PROGRAMMERS: 6 */ 7 8 #include <win32nt.h> 9 10 HPALETTE 11 CreateTestPalette() 12 { 13 struct 14 { 15 LOGPALETTE logpal; 16 PALETTEENTRY entry[5]; 17 } palstruct = 18 { {0x300,5, 19 { {1,2,3,0} }}, 20 { {22,33,44,PC_RESERVED}, 21 {11,55,77,PC_EXPLICIT}, 22 {00,77,66,PC_RESERVED | PC_NOCOLLAPSE}, 23 {12,34,56,78}} }; 24 25 return CreatePalette((LOGPALETTE*)&palstruct); 26 } 27 28 void 29 Test_NtGdiDoPalette_GdiPalAnimate(void) 30 { 31 HPALETTE hPal; 32 PALETTEENTRY palEntries[5] = { 33 {0,0,0,0}, 34 {0xff,0xff,0xff,0}, 35 {0x33,0x66,0x99,0}, 36 {0x25,0x84,0x14,0}, 37 {0x12,0x34,0x56,0x11}}; 38 PALETTEENTRY palEntries2[5]; 39 40 /* Test stock palette */ 41 SetLastError(ERROR_SUCCESS); 42 ok_long(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE), 0, 1, palEntries, GdiPalAnimate, FALSE), 0); 43 ok_long(GetLastError(), ERROR_SUCCESS); 44 45 46 /* Test pEntries = NULL */ 47 hPal = CreateTestPalette(); 48 ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalAnimate, TRUE), 0); 49 ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalAnimate, FALSE), 0); 50 DeleteObject(hPal); 51 52 /* Test PC_RESERVED */ 53 hPal = CreateTestPalette(); 54 ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, TRUE), 2); 55 DeleteObject(hPal); 56 57 hPal = CreateTestPalette(); 58 ok_long(NtGdiDoPalette(hPal, 1, 5, palEntries, GdiPalAnimate, TRUE), 2); 59 DeleteObject(hPal); 60 61 hPal = CreateTestPalette(); 62 ok_long(NtGdiDoPalette(hPal, 2, 5, palEntries, GdiPalAnimate, TRUE), 1); 63 DeleteObject(hPal); 64 65 hPal = CreateTestPalette(); 66 ok_long(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, TRUE), 1); 67 DeleteObject(hPal); 68 69 hPal = CreateTestPalette(); 70 ok_long(NtGdiDoPalette(hPal, 4, 5, palEntries, GdiPalAnimate, TRUE), 0); 71 DeleteObject(hPal); 72 73 hPal = CreateTestPalette(); 74 ok_long(NtGdiDoPalette(hPal, 5, 5, palEntries, GdiPalAnimate, TRUE), 0); 75 DeleteObject(hPal); 76 77 hPal = CreateTestPalette(); 78 ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, FALSE), 2); 79 DeleteObject(hPal); 80 81 hPal = CreateTestPalette(); 82 ok_long(NtGdiDoPalette(hPal, 3, 5, palEntries, GdiPalAnimate, FALSE), 1); 83 DeleteObject(hPal); 84 85 /* Test if entries are set correctly */ 86 hPal = CreateTestPalette(); 87 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalAnimate, TRUE); 88 NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE); 89 ok_int(palEntries2[0].peRed, 1); 90 ok_int(palEntries2[0].peGreen, 2); 91 ok_int(palEntries2[0].peBlue, 3); 92 ok_int(palEntries2[0].peFlags, 0); 93 ok_int(palEntries2[1].peRed, palEntries[1].peRed); 94 ok_int(palEntries2[1].peGreen, palEntries[1].peGreen); 95 ok_int(palEntries2[1].peBlue, palEntries[1].peBlue); 96 ok_int(palEntries2[1].peFlags, palEntries[1].peFlags); 97 ok_int(palEntries2[2].peRed, 11); 98 ok_int(palEntries2[2].peGreen, 55); 99 ok_int(palEntries2[2].peBlue, 77); 100 ok_int(palEntries2[2].peFlags, PC_EXPLICIT); 101 ok_int(palEntries2[3].peRed, palEntries[3].peRed); 102 ok_int(palEntries2[3].peGreen, palEntries[3].peGreen); 103 ok_int(palEntries2[3].peBlue, palEntries[3].peBlue); 104 ok_int(palEntries2[3].peFlags, palEntries[3].peFlags); 105 DeleteObject(hPal); 106 107 } 108 109 void 110 Test_NtGdiDoPalette_GdiPalSetEntries(void) 111 { 112 HDC hDC; 113 HPALETTE hPal, hOldPal; 114 PALETTEENTRY palEntries[5] = { 115 {0,0,0,0}, 116 {0xff,0xff,0xff,0}, 117 {0x33,0x66,0x99,0}, 118 {0x25,0x84,0x14,0}, 119 {0x12,0x34,0x56,0x11}}; 120 PALETTEENTRY palEntries2[5]; 121 122 hPal = CreateTestPalette(); 123 124 /* Test invalid handle */ 125 SetLastError(ERROR_SUCCESS); 126 ok_long(NtGdiDoPalette((HPALETTE)23, 0, 1, palEntries, GdiPalSetEntries, TRUE), 0); 127 ok_long(GetLastError(), ERROR_SUCCESS); 128 129 /* Test system palette */ 130 ok_long(NtGdiDoPalette(GetStockObject(DEFAULT_PALETTE), 0, 1, palEntries, GdiPalSetEntries, TRUE), 0); 131 ok_long(GetLastError(), ERROR_SUCCESS); 132 133 ok_long(NtGdiDoPalette(hPal, 0, 1, palEntries, GdiPalSetEntries, TRUE), 1); 134 ok_long(NtGdiDoPalette(hPal, 0, 2, palEntries, GdiPalSetEntries, TRUE), 2); 135 ok_long(NtGdiDoPalette(hPal, 0, 3, palEntries, GdiPalSetEntries, TRUE), 3); 136 ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE), 5); 137 ok_long(NtGdiDoPalette(hPal, 0, 6, palEntries, GdiPalSetEntries, TRUE), 5); 138 ok_long(NtGdiDoPalette(hPal, 3, 6, palEntries, GdiPalSetEntries, TRUE), 2); 139 // TEST(NtGdiDoPalette(hPal, 4, 23247, palEntries, GdiPalSetEntries, TRUE), 0); 140 141 /* Test bInbound, FALSE */ 142 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE); 143 ZeroMemory(palEntries2, sizeof(palEntries2)); 144 ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalSetEntries, FALSE), 5); 145 /* we should get the old values returned in our buffer! */ 146 ok_int(memcmp(palEntries2, palEntries, sizeof(palEntries)), 0); 147 148 /* check what we have in our palette now */ 149 ZeroMemory(palEntries2, sizeof(palEntries2)); 150 ok_long(NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE), 5); 151 ok_int(memcmp(palEntries2, palEntries, sizeof(palEntries)), 0); 152 153 ok_long(NtGdiDoPalette(hPal, 0, 4, palEntries2, GdiPalSetEntries, TRUE), 4); 154 ok_long(GetLastError(), ERROR_SUCCESS); 155 156 /* Test if entries are set correctly */ 157 hPal = CreateTestPalette(); 158 NtGdiDoPalette(hPal, 0, 5, palEntries, GdiPalSetEntries, TRUE); 159 NtGdiDoPalette(hPal, 0, 5, palEntries2, GdiPalGetEntries, FALSE); 160 ok_int(palEntries2[0].peRed, 0); 161 ok_int(palEntries2[0].peGreen, 0); 162 ok_int(palEntries2[0].peBlue, 0); 163 ok_int(palEntries2[0].peFlags, 0); 164 165 /* Test that the buffer was not changed */ 166 167 168 /* Test with palette selected into dc */ 169 hDC = CreateCompatibleDC(NULL); 170 hOldPal = SelectPalette(hDC, hPal, 0); 171 ok_long(NtGdiDoPalette(hPal, 0, 4, palEntries, GdiPalSetEntries, TRUE), 4); 172 SelectPalette(hDC, hOldPal, 0); 173 174 /* Test pEntries = NULL */ 175 ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, TRUE), 0); 176 177 } 178 179 void 180 Test_NtGdiDoPalette_GdiPalGetEntries(void) 181 { 182 HPALETTE hPal; 183 184 hPal = CreateTestPalette(); 185 186 /* Test pEntries = NULL */ 187 ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, TRUE), 0); 188 ok_long(NtGdiDoPalette(hPal, 0, 1, NULL, GdiPalGetEntries, FALSE), 5); 189 ok_long(NtGdiDoPalette(hPal, 2, 1, NULL, GdiPalGetEntries, FALSE), 5); 190 ok_long(NtGdiDoPalette(hPal, 20, 1, NULL, GdiPalGetEntries, FALSE), 5); 191 ok_long(NtGdiDoPalette(hPal, -20, 1, NULL, GdiPalGetEntries, FALSE), 5); 192 ok_long(NtGdiDoPalette(hPal, 2, 0, NULL, GdiPalGetEntries, FALSE), 5); 193 194 195 // Test flags 0xf0 196 197 } 198 199 void 200 Test_NtGdiDoPalette_GetSystemPalette(void) 201 { 202 203 } 204 205 void 206 Test_NtGdiDoPalette_GetBIBColorTable(void) 207 { 208 209 } 210 211 void 212 Test_NtGdiDoPalette_SetDIBColorTable(void) 213 { 214 HDC hdc; 215 HBITMAP hbmp; 216 BYTE *pjBits; 217 218 struct 219 { 220 BITMAPINFOHEADER bmiHeader; 221 ULONG bmiColors[10]; 222 } bmi; 223 224 hdc = CreateCompatibleDC(0); 225 ok(hdc != NULL, "hdc was NULL.\n"); 226 227 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 228 bmi.bmiHeader.biWidth = 10; 229 bmi.bmiHeader.biHeight = 10; 230 bmi.bmiHeader.biPlanes = 1; 231 bmi.bmiHeader.biBitCount = 8; 232 bmi.bmiHeader.biCompression = BI_RGB; 233 bmi.bmiHeader.biSizeImage = 0; 234 bmi.bmiHeader.biXPelsPerMeter = 1; 235 bmi.bmiHeader.biYPelsPerMeter = 1; 236 bmi.bmiHeader.biClrUsed = 9; 237 bmi.bmiHeader.biClrImportant = 9; 238 bmi.bmiColors[0] = 0x000000; 239 bmi.bmiColors[1] = 0x202020; 240 bmi.bmiColors[2] = 0x404040; 241 bmi.bmiColors[3] = 0x606060; 242 bmi.bmiColors[4] = 0x808080; 243 bmi.bmiColors[5] = 0xA0A0A0; 244 bmi.bmiColors[6] = 0xC0C0C0; 245 bmi.bmiColors[7] = 0xE0E0E0; 246 bmi.bmiColors[8] = 0xffffff; 247 hbmp = CreateDIBSection(hdc, (BITMAPINFO*)&bmi, DIB_PAL_COLORS, (PVOID*)&pjBits, NULL, 0); 248 ok(hbmp != NULL, "hbmp was NULL.\n"); 249 ok(pjBits != NULL, "pjBits was NULL.\n"); 250 251 SelectObject(hdc, hbmp); 252 253 pjBits[0] = 8; 254 pjBits[1] = 1; 255 pjBits[2] = 2; 256 pjBits[3] = 3; 257 258 bmi.bmiColors[8] = 0x000000; 259 bmi.bmiColors[7] = 0x202020; 260 bmi.bmiColors[6] = 0x404040; 261 bmi.bmiColors[5] = 0x606060; 262 bmi.bmiColors[4] = 0x808080; 263 bmi.bmiColors[3] = 0xA0A0A0; 264 bmi.bmiColors[2] = 0xC0C0C0; 265 bmi.bmiColors[1] = 0xE0E0E0; 266 bmi.bmiColors[0] = 0xffffff; 267 ok_long(NtGdiDoPalette(hdc, 0, 9, &bmi.bmiColors, GdiPalSetColorTable, FALSE), 9); 268 269 SetDCPenColor(hdc, 0xE0E0E0); 270 SetDCBrushColor(hdc, 0x202020); 271 Rectangle(hdc, 0, 0, 10, 10); 272 273 DeleteDC(hdc); 274 DeleteObject(hbmp); 275 } 276 277 START_TEST(NtGdiDoPalette) 278 { 279 Test_NtGdiDoPalette_GdiPalAnimate(); 280 Test_NtGdiDoPalette_GdiPalSetEntries(); 281 Test_NtGdiDoPalette_GdiPalGetEntries(); 282 Test_NtGdiDoPalette_GetSystemPalette(); 283 Test_NtGdiDoPalette_GetBIBColorTable(); 284 Test_NtGdiDoPalette_SetDIBColorTable(); 285 } 286