[SHELL32_APITEST] -Add some tests for SHParseDisplayName for CORE-12882.
[reactos.git] / rostests / apitests / gdi32 / SetDIBits.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetDIBits
5 * PROGRAMMERS: Jérôme Gardou
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11
12 void Test_SetDIBits()
13 {
14 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
15 ULONG* dibBuffer;
16 BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
17 char bits1bpp[] = {0x80, 0, 0, 0};
18 HBITMAP hbmp;
19 int ret;
20
21 ZeroMemory(buffer, sizeof(buffer));
22
23 pBMI->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
24 pBMI->bmiHeader.biWidth=2;
25 pBMI->bmiHeader.biHeight=1;
26 pBMI->bmiHeader.biPlanes=1;
27 pBMI->bmiHeader.biBitCount=32;
28 pBMI->bmiHeader.biCompression=BI_RGB;
29 pBMI->bmiHeader.biSizeImage=0;
30 pBMI->bmiHeader.biXPelsPerMeter=0;
31 pBMI->bmiHeader.biYPelsPerMeter=0;
32 pBMI->bmiHeader.biClrUsed=0;
33 pBMI->bmiHeader.biClrImportant=0;
34
35 hbmp = CreateDIBSection(NULL, pBMI, DIB_RGB_COLORS, (PVOID*)&dibBuffer, NULL, 0);
36 ok(hbmp!=NULL, "Failed to create a DIB section\n");
37
38 pBMI->bmiHeader.biBitCount = 1;
39 pBMI->bmiColors[0].rgbBlue = 0xFF;
40 pBMI->bmiColors[0].rgbGreen = 0;
41 pBMI->bmiColors[0].rgbRed = 0xFF;
42
43 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
44 ok(ret == 1, "Copied %i scanlines\n", ret);
45
46 ok(dibBuffer[0] == 0, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer[0]);
47 ok(dibBuffer[1] == 0xFF00FF, "Wrong color 0x%08x after SetDIBits\n", (unsigned int)dibBuffer[1]);
48
49 DeleteObject(hbmp);
50 }
51
52 void Test_SetDIBits_1bpp()
53 {
54 char buffer[sizeof(BITMAPINFOHEADER)+2*sizeof(RGBQUAD)];
55 HDC hdc;
56 BITMAPINFO* pBMI = (BITMAPINFO*)buffer;
57 char bits1bpp[] = {0x80, 0, 0, 0};
58 HBITMAP hbmp;
59 int ret;
60 COLORREF color;
61
62 hdc = CreateCompatibleDC(0);
63 if(!hdc)
64 {
65 trace("No device contexr !?\n");
66 return;
67 }
68
69 ZeroMemory(buffer, sizeof(buffer));
70
71 pBMI->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
72 pBMI->bmiHeader.biWidth=2;
73 pBMI->bmiHeader.biHeight=1;
74 pBMI->bmiHeader.biPlanes=1;
75 pBMI->bmiHeader.biBitCount=1;
76 pBMI->bmiHeader.biCompression=BI_RGB;
77 pBMI->bmiHeader.biSizeImage=0;
78 pBMI->bmiHeader.biXPelsPerMeter=0;
79 pBMI->bmiHeader.biYPelsPerMeter=0;
80 pBMI->bmiHeader.biClrUsed=2;
81 pBMI->bmiHeader.biClrImportant=0;
82 pBMI->bmiColors[0].rgbBlue = 0xFF;
83 pBMI->bmiColors[0].rgbGreen = 0xFF;
84 pBMI->bmiColors[0].rgbRed = 0xFF;
85
86 hbmp = CreateBitmap(2, 1, 1, 1, NULL);
87 ok(hbmp!=NULL, "Failed to create a monochrome bitmap\n");
88
89 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
90 ok(ret == 1, "Copied %i scanlines\n", ret);
91
92 hbmp = SelectObject(hdc, hbmp);
93 ok(hbmp != NULL, "Could not select the bitmap into the context.\n");
94 color = GetPixel(hdc, 0,0);
95 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color);
96 color = GetPixel(hdc, 1,0);
97 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color);
98
99 hbmp = SelectObject(hdc, hbmp);
100
101 /* Try something else than 0xFFFFFF */
102 pBMI->bmiColors[0].rgbBlue = 0xFF;
103 pBMI->bmiColors[0].rgbGreen = 0;
104 pBMI->bmiColors[0].rgbRed = 0;
105
106 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
107 ok(ret == 1, "Copied %i scanlines\n", ret);
108
109 hbmp = SelectObject(hdc, hbmp);
110 ok(hbmp != NULL, "Could not select the bitmap into the context.\n");
111 color = GetPixel(hdc, 0,0);
112 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color);
113 color = GetPixel(hdc, 1,0);
114 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color);
115
116 hbmp = SelectObject(hdc, hbmp);
117
118 /* Special : try 0 */
119 pBMI->bmiColors[0].rgbBlue = 0;
120 pBMI->bmiColors[0].rgbGreen = 0;
121 pBMI->bmiColors[0].rgbRed = 0;
122
123 ret = SetDIBits(NULL, hbmp, 0, 1, bits1bpp, pBMI, DIB_RGB_COLORS);
124 ok(ret == 1, "Copied %i scanlines\n", ret);
125
126 hbmp = SelectObject(hdc, hbmp);
127 ok(hbmp != NULL, "Could not select the bitmap into the context.\n");
128 color = GetPixel(hdc, 0,0);
129 ok(color == 0, "Wrong color at 0,0 : 0x%08x\n", (UINT)color);
130 color = GetPixel(hdc, 1,0);
131 ok(color == 0xFFFFFF, "Wrong color at 1,0 : 0x%08x\n", (UINT)color);
132
133 hbmp = SelectObject(hdc, hbmp);
134 DeleteObject(hbmp);
135 DeleteDC(hdc);
136 }
137
138 START_TEST(SetDIBits)
139 {
140 Test_SetDIBits();
141 Test_SetDIBits_1bpp();
142 }