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