1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL - See COPYING in the top level directory 4 * PURPOSE: Test for SetPixel 5 * PROGRAMMERS: Timo Kreuzer 6 */ 7 8 #include <apitest.h> 9 10 #include <wingdi.h> 11 #include <mmsystem.h> 12 13 static struct 14 { 15 WORD palVersion; 16 WORD palNumEntries; 17 PALETTEENTRY logpalettedata[8]; 18 } gpal = 19 { 20 0x300, 8, 21 { 22 { 0x10, 0x20, 0x30, PC_NOCOLLAPSE }, 23 { 0x20, 0x30, 0x40, PC_NOCOLLAPSE }, 24 { 0x30, 0x40, 0x50, PC_NOCOLLAPSE }, 25 { 0x40, 0x50, 0x60, PC_NOCOLLAPSE }, 26 { 0x50, 0x60, 0x70, PC_NOCOLLAPSE }, 27 { 0x60, 0x70, 0x80, PC_NOCOLLAPSE }, 28 { 0x70, 0x80, 0x90, PC_NOCOLLAPSE }, 29 { 0x80, 0x90, 0xA0, PC_NOCOLLAPSE }, 30 } 31 }; 32 33 void Test_SetPixel_Params() 34 { 35 HDC hdc; 36 37 SetLastError(0); 38 ok_long(SetPixel(0, 0, 0, RGB(255,255,255)), -1); 39 ok_err(ERROR_INVALID_HANDLE); 40 41 /* Test an info DC */ 42 hdc = CreateICA("DISPLAY", NULL, NULL, NULL); 43 ok(hdc != 0, "\n"); 44 SetLastError(0); 45 ok_long(SetPixel(hdc, 0, 0, 0), -1); 46 ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), -1); 47 ok_err(0); 48 DeleteDC(hdc); 49 50 /* Test a mem DC without selecting a bitmap */ 51 hdc = CreateCompatibleDC(NULL); 52 ok(hdc != 0, "\n"); 53 SetLastError(0); 54 ok_long(SetPixel(hdc, 0, 0, 0), -1); 55 ok_err(0); 56 DeleteDC(hdc); 57 58 /* Test deleted DC */ 59 ok_long(SetPixel(hdc, 0, 0, 0), -1); 60 61 } 62 63 void Test_SetPixel_PAL() 64 { 65 struct 66 { 67 BITMAPINFOHEADER bmiHeader; 68 WORD bmiColors[8]; 69 } bmibuffer; 70 BITMAPINFO *pbmi = (PVOID)&bmibuffer; 71 HBITMAP hbmp; 72 HDC hdc; 73 HPALETTE hpal, hpalOld; 74 PULONG pulBits; 75 USHORT i; 76 77 /* Initialize the BITMAPINFO */ 78 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 79 pbmi->bmiHeader.biWidth = 1; 80 pbmi->bmiHeader.biHeight = 1; 81 pbmi->bmiHeader.biPlanes = 1; 82 pbmi->bmiHeader.biBitCount = 8; 83 pbmi->bmiHeader.biCompression = BI_RGB; 84 pbmi->bmiHeader.biSizeImage = 0; 85 pbmi->bmiHeader.biXPelsPerMeter = 1; 86 pbmi->bmiHeader.biYPelsPerMeter = 1; 87 pbmi->bmiHeader.biClrUsed = 8; 88 pbmi->bmiHeader.biClrImportant = 0; 89 for( i = 0; i < 8; i++ ) 90 { 91 bmibuffer.bmiColors[i] = i + 1; 92 } 93 94 /* Create a memory DC */ 95 hdc = CreateCompatibleDC(0); 96 ok(hdc != 0, "failed\n"); 97 98 /* Create a DIB section and select it */ 99 hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 ); 100 ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError()); 101 ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n"); 102 103 ok_long(SetPixel(hdc, 0, 0, 0), 0); 104 ok_long(pulBits[0], 8); 105 ok_long(SetPixel(hdc, 0, 0, 1), 0); 106 ok_long(pulBits[0], 8); 107 ok_long(SetPixel(hdc, 0, 0, RGB(255,255,255)), 0xc0dcc0); 108 ok_long(pulBits[0], 7); 109 110 ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x80); 111 ok_long(pulBits[0], 0); 112 113 /* Test DIBINDEX */ 114 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x80); 115 ok_long(pulBits[0], 0); 116 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x8000); 117 ok_long(pulBits[0], 1); 118 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0xc0dcc0); 119 ok_long(pulBits[0], 7); 120 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0); 121 ok_long(pulBits[0], 8); 122 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0); 123 ok_long(pulBits[0], 126); 124 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0); 125 ok_long(pulBits[0], 0x56); 126 127 /* Test PALETTEINDEX */ 128 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0); 129 ok_long(pulBits[0], 8); 130 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x80); 131 ok_long(pulBits[0], 0); 132 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(2)), 0x8000); 133 ok_long(pulBits[0], 1); 134 135 /* Delete the DIB section */ 136 DeleteObject(hbmp); 137 138 139 /* Initialize the logical palette and select it */ 140 hpal = CreatePalette((LOGPALETTE*)&gpal); 141 hpalOld = SelectPalette(hdc, hpal, FALSE); 142 ok(hpalOld != NULL, "error=%ld\n", GetLastError()); 143 144 145 /* Create a DIB section and select it */ 146 hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pulBits, 0, 0 ); 147 ok(hbmp != NULL, "CreateDIBSection failed with error %ld\n", GetLastError()); 148 ok(SelectObject(hdc, hbmp) != 0, "SelectObject failed\n"); 149 150 ok_long(SetPixel(hdc, 0, 0, 0), 0); 151 ok_long(pulBits[0], 8); 152 153 ok_long(SetPixel(hdc, 0, 0, RGB(255,0,0)), 0x605040); 154 ok_long(pulBits[0], 2); 155 156 /* Test DIBINDEX */ 157 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0)), 0x403020); 158 ok_long(pulBits[0], 0); 159 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(1)), 0x504030); 160 ok_long(pulBits[0], 1); 161 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(7)), 0x302010); 162 ok_long(pulBits[0], 7); 163 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(8)), 0); 164 ok_long(pulBits[0], 8); 165 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(126)), 0); 166 ok_long(pulBits[0], 126); 167 ok_long(SetPixel(hdc, 0, 0, DIBINDEX(0x123456)), 0); 168 ok_long(pulBits[0], 0x56); 169 170 /* Test PALETTEINDEX */ 171 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(0)), 0x302010); 172 ok_long(pulBits[0], 7); 173 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(1)), 0x403020); 174 ok_long(pulBits[0], 0); 175 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(253)), 0x302010); 176 ok_long(pulBits[0], 7); 177 ok_long(SetPixel(hdc, 0, 0, PALETTEINDEX(254)), 0x302010); 178 ok_long(pulBits[0], 7); 179 180 181 } 182 183 START_TEST(SetPixel) 184 { 185 Test_SetPixel_Params(); 186 Test_SetPixel_PAL(); 187 } 188 189