2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtUserSelectPalette
12 PALENTRY(BYTE r
, BYTE g
, BYTE b
)
23 START_TEST(NtUserSelectPalette
)
25 HINSTANCE hinst
= GetModuleHandle(NULL
);
26 HPALETTE hPal
, hOldPal
;
32 PALETTEENTRY entry
[20];
35 ZeroMemory(&pal
, sizeof(pal
));
37 pal
.logpal
.palVersion
= 0x300;
38 pal
.logpal
.palNumEntries
= 6;
39 pal
.entry
[0] = PALENTRY(0,0,0);
40 pal
.entry
[1] = PALENTRY(255,255,255);
41 pal
.entry
[2] = PALENTRY(128,128,128);
42 pal
.entry
[3] = PALENTRY(128,0,0);
43 pal
.entry
[4] = PALENTRY(0,128,0);
44 pal
.entry
[5] = PALENTRY(0,0,128);
46 hPal
= CreatePalette(&pal
.logpal
);
48 TEST(DeleteObject(hPal
) == 1);
49 hPal
= CreatePalette(&pal
.logpal
);
53 hWnd
= CreateWindowW(L
"BUTTON", L
"TestWindow", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
54 CW_USEDEFAULT
, CW_USEDEFAULT
, 100, 100,
55 NULL
, NULL
, hinst
, 0);
58 hCompDC
= CreateCompatibleDC(hDC
);
62 SetLastError(ERROR_SUCCESS
);
63 hOldPal
= NtUserSelectPalette(NULL
, hPal
, 0);
65 TEST(GetLastError() == ERROR_SUCCESS
);
68 SetLastError(ERROR_SUCCESS
);
69 hOldPal
= NtUserSelectPalette((HDC
)-1, hPal
, 0);
71 TEST(GetLastError() == ERROR_SUCCESS
);
73 /* Test NULL palette */
74 SetLastError(ERROR_SUCCESS
);
75 hOldPal
= NtUserSelectPalette(hDC
, NULL
, 0);
77 TEST(GetLastError() == ERROR_SUCCESS
);
79 /* Test invalid palette */
80 SetLastError(ERROR_SUCCESS
);
81 hOldPal
= NtUserSelectPalette(hDC
, (HPALETTE
)-1, 0);
83 TEST(GetLastError() == ERROR_SUCCESS
);
85 /* Test valid palette */
86 hOldPal
= NtUserSelectPalette(hDC
, hPal
, 0);
88 TEST(hOldPal
== GetStockObject(DEFAULT_PALETTE
));
90 /* We cannot Delete the palette */
91 TEST(DeleteObject(hPal
) == 0);
93 /* We can still select the Palette into a compatible DC */
94 hOldPal
= NtUserSelectPalette(hCompDC
, hPal
, 0);
102 GetClientRect(hWnd
, &rect
);
103 FillRect(hDC
, &rect
, GetSysColorBrush(COLOR_BTNSHADOW
));
105 TEST(GetNearestColor(hDC
, RGB(0,0,0)) == RGB(0,0,0));
106 TEST(GetNearestColor(hDC
, RGB(0,0,1)) == RGB(0,0,1));
108 ReleaseDC(hWnd
, hDC
);
114 BITMAPINFOHEADER bmih
= {sizeof(BITMAPINFOHEADER
), // biSize
119 BI_RGB
, // biCompression
121 92, // biXPelsPerMeter
122 92, // biYPelsPerMeter
124 6}; // biClrImportant
125 BYTE bits
[3][3] = {{0,1,2},{3,4,5},{6,1,2}};
129 BITMAPINFOHEADER bmih
;
131 } bmi
= {{sizeof(BITMAPINFOHEADER
),3,3,1,8,BI_RGB
,0,92,92,6,6},
132 {{0,0,0,0},{255,255,255,0},{255,0,0,0},
133 {0,255,0,0},{0,0,255,0},{128,128,128,0}}};
135 hBmp
= CreateDIBitmap(hCompDC
, &bmih
, CBM_INIT
, &bits
, (BITMAPINFO
*)&bmi
, DIB_RGB_COLORS
);
139 TEST(NtGdiSelectBitmap(hCompDC
, hBmp
));
140 hOldPal
= NtUserSelectPalette(hCompDC
, hPal
, 0);
141 TEST(hOldPal
!= NULL
);
142 RealizePalette(hCompDC
);
144 TEST(GetNearestColor(hCompDC
, RGB(0,0,0)) == RGB(0,0,0));
145 TEST(GetNearestColor(hCompDC
, RGB(0,0,1)) == RGB(0,0,0));
146 TEST(GetNearestColor(hCompDC
, RGB(100,0,0)) == RGB(0,0,0));
147 TEST(GetNearestColor(hCompDC
, RGB(250,250,250)) == RGB(255,255,255));
148 TEST(GetNearestColor(hCompDC
, RGB(120,100,110)) == RGB(128,128,128));
150 printf("nearest = 0x%x\n", GetNearestColor(hCompDC
, RGB(120,100,110)));