[SHELL32_APITEST] -Add some tests for SHParseDisplayName for CORE-12882.
[reactos.git] / rostests / apitests / gdi32 / GetDIBColorTable.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for ...
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11
12 void Test_GetDIBColorTable()
13 {
14 struct
15 {
16 BITMAPINFOHEADER bmiHeader;
17 ULONG bmiColors[8];
18 } bmibuffer;
19 BITMAPINFO *pbmi = (PVOID)&bmibuffer;
20 HBITMAP hbmp, hbmpOld;
21 HDC hdc;
22 PBYTE pjBits;
23 UINT cColors;
24 ULONG aulColors[257];
25
26 hdc = CreateCompatibleDC(0);
27 ok(hdc != 0, "failed\n");
28
29 SetLastError(0);
30 cColors = GetDIBColorTable(hdc, 0, 257, (RGBQUAD*)aulColors);
31 ok_long(cColors, 2);
32 ok_err(0);
33 ok_long(aulColors[0], 0x000000);
34 ok_long(aulColors[1], 0xffffff);
35
36 hbmp = CreateBitmap(1, 1, 1, 1, NULL);
37 ok(hbmp != 0, "\n");
38 hbmpOld = SelectObject(hdc, hbmp);
39 ok(hbmpOld != 0, "Failed to select bitmap\n");
40 cColors = GetDIBColorTable(hdc, 0, 257, (RGBQUAD*)aulColors);
41 ok_long(cColors, 2);
42 ok_err(0);
43 ok_long(aulColors[0], 0x000000);
44 ok_long(aulColors[1], 0xffffff);
45 SelectObject(hdc, hbmpOld);
46 DeleteObject(hbmp);
47
48 /* Initialize a BITMAPINFO */
49 pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
50 pbmi->bmiHeader.biWidth = 2;
51 pbmi->bmiHeader.biHeight = 2;
52 pbmi->bmiHeader.biPlanes = 1;
53 pbmi->bmiHeader.biBitCount = 8;
54 pbmi->bmiHeader.biCompression = BI_RGB;
55 pbmi->bmiHeader.biSizeImage = 0;
56 pbmi->bmiHeader.biXPelsPerMeter = 1;
57 pbmi->bmiHeader.biYPelsPerMeter = 1;
58 pbmi->bmiHeader.biClrUsed = 3;
59 pbmi->bmiHeader.biClrImportant = 0;
60 bmibuffer.bmiColors[0] = 0xff0000;
61 bmibuffer.bmiColors[1] = 0x00ff00;
62 bmibuffer.bmiColors[2] = 0x0000ff;
63
64 hbmp = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, (PVOID*)&pjBits, 0, 0 );
65 ok( hbmp != NULL, "error=%ld\n", GetLastError() );
66 SelectObject(hdc, hbmp);
67
68 cColors = GetDIBColorTable(hdc, 0, 257, (RGBQUAD*)aulColors);
69 ok_long(cColors, 256);
70 ok_long(aulColors[0], 0xff0000);
71 ok_long(aulColors[1], 0x00ff00);
72 ok_long(aulColors[2], 0x0000ff);
73 ok_long(aulColors[3], 0x000000);
74
75
76 cColors = SetDIBColorTable(hdc, 0, 4, (RGBQUAD*)aulColors);
77 ok_long(cColors, 4);
78
79 aulColors[3] = 0x000F0F;
80 cColors = SetDIBColorTable(hdc, 0, 4, (RGBQUAD*)aulColors);
81 ok_long(cColors, 4);
82
83 cColors = GetDIBColorTable(hdc, 0, 257, (RGBQUAD*)aulColors);
84 ok_long(cColors, 256);
85 ok_long(aulColors[0], 0xff0000);
86 ok_long(aulColors[1], 0x00ff00);
87 ok_long(aulColors[2], 0x0000ff);
88 ok_long(aulColors[3], 0x000F0F);
89
90
91 SelectObject(hdc, GetStockObject(21));
92 DeleteObject(hbmp);
93
94 bmibuffer.bmiColors[0] = 1;
95 bmibuffer.bmiColors[1] = 2;
96 bmibuffer.bmiColors[2] = 3;
97
98 hbmp = CreateDIBSection(hdc, pbmi, DIB_PAL_COLORS, (PVOID*)&pjBits, 0, 0 );
99 ok( hbmp != NULL, "error=%ld\n", GetLastError() );
100 SelectObject(hdc, hbmp);
101
102
103 }
104
105 START_TEST(GetDIBColorTable)
106 {
107 Test_GetDIBColorTable();
108 }
109