[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / GetDIBits.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for GetDIBits
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 #define ok_err(dwErr) ok(GetLastError() == dwErr, "LastError is wrong, expected %d, got %ld\n", dwErr, GetLastError())
13
14 void Test_GetDIBits()
15 {
16 HDC hdcScreen, hdcMem;
17 HBITMAP hbmp;
18 PBITMAPINFO pbi;
19 INT ret, ScreenBpp;
20 DWORD ajBits[10] = {0xff, 0x00, 0xcc, 0xf0, 0x0f};
21
22 pbi = malloc(sizeof(BITMAPV5HEADER) + 256 * sizeof(DWORD));
23
24 hdcScreen = GetDC(NULL);
25 ok(hdcScreen != 0, "GetDC failed, skipping tests\n");
26 if (hdcScreen == NULL) return;
27
28 hdcMem = CreateCompatibleDC(0);
29 ok(hdcMem != 0, "CreateCompatibleDC failed, skipping tests\n");
30 if (hdcMem == NULL) return;
31
32 hbmp = CreateCompatibleBitmap(hdcScreen, 16, 16);
33 ok(hbmp != NULL, "CreateCompatibleBitmap failed\n");
34
35 /* misc */
36 SetLastError(ERROR_SUCCESS);
37 ok(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
38 ok_err(ERROR_INVALID_PARAMETER);
39
40 SetLastError(ERROR_SUCCESS);
41 ok(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0, "\n");
42 ok_err(ERROR_INVALID_PARAMETER);
43
44 SetLastError(ERROR_SUCCESS);
45 ok(GetDIBits((HDC)2345, hbmp, 0, 0, NULL, NULL, 0) == 0, "\n");
46 ok_err(ERROR_INVALID_PARAMETER);
47
48 SetLastError(ERROR_SUCCESS);
49 ok(GetDIBits((HDC)2345, hbmp, 0, 15, NULL, pbi, 0) == 0, "\n");
50 ok_err(ERROR_INVALID_PARAMETER);
51
52
53
54 /* null hdc */
55 SetLastError(ERROR_SUCCESS);
56 ZeroMemory(pbi, sizeof(BITMAPINFO));
57 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
58 ok(GetDIBits(NULL, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
59 ok_err(ERROR_INVALID_PARAMETER);
60
61 /* null bitmap */
62 SetLastError(ERROR_SUCCESS);
63 ZeroMemory(pbi, sizeof(BITMAPINFO));
64 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
65 ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "\n");
66 ok_err(ERROR_SUCCESS);
67
68 /* 0 scan lines */
69 SetLastError(ERROR_SUCCESS);
70 ZeroMemory(pbi, sizeof(BITMAPINFO));
71 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
72 ok(GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
73 ok_err(ERROR_SUCCESS);
74
75 /* null bitmap info - crashes XP*/
76 //SetLastError(ERROR_SUCCESS);
77 //ok(GetDIBits(hdcScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
78 //ok(GetLastError() == ERROR_INVALID_PARAMETER);
79
80 /* bad bmi colours (uUsage) */
81 SetLastError(ERROR_SUCCESS);
82 ZeroMemory(pbi, sizeof(BITMAPINFO));
83 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
84 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, 100) == 0, "\n");
85 ok_err(ERROR_SUCCESS);
86 ok(pbi->bmiHeader.biWidth == 0, "\n");
87 ok(pbi->bmiHeader.biHeight == 0, "\n");
88 ok(pbi->bmiHeader.biBitCount == 0, "\n");
89 ok(pbi->bmiHeader.biSizeImage == 0, "\n");
90
91 /* basic call */
92 SetLastError(ERROR_SUCCESS);
93 ZeroMemory(pbi, sizeof(BITMAPINFO));
94 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
95 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
96 ok_err(ERROR_SUCCESS);
97 ScreenBpp = GetDeviceCaps(hdcScreen, BITSPIXEL);
98 ok(pbi->bmiHeader.biWidth == 16, "\n");
99 ok(pbi->bmiHeader.biHeight == 16, "\n");
100 ok(pbi->bmiHeader.biBitCount == ScreenBpp, "\n");
101 ok(pbi->bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8), "\n");
102
103 /* Test if COREHEADER is supported */
104 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER);
105 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "\n");
106 ok(pbi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER), "\n");
107
108 /* Test different header sizes */
109 pbi->bmiHeader.biSize = sizeof(BITMAPCOREHEADER) + 4;
110 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n");
111 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 4;
112 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) == 0, "should fail.\n");
113 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER);
114 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n");
115 pbi->bmiHeader.biSize = sizeof(BITMAPV5HEADER) + 4;
116 ok(GetDIBits(hdcScreen, hbmp, 0, 15, NULL, pbi, DIB_RGB_COLORS) > 0, "should not fail.\n");
117
118
119 DeleteObject(hbmp);
120
121 /* Test a mono bitmap */
122 hbmp = CreateBitmap(13, 7, 1, 1, ajBits);
123 ok(hbmp != 0, "failed to create bitmap\n");
124 ZeroMemory(pbi, sizeof(BITMAPINFO));
125 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
126 ret = GetDIBits(hdcScreen, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS);
127 ok(ret == 1, "%d\n", ret);
128 ok(pbi->bmiHeader.biWidth == 13, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth);
129 ok(pbi->bmiHeader.biHeight == 7, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight);
130 ok(pbi->bmiHeader.biBitCount == 1, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount);
131 ok(pbi->bmiHeader.biSizeImage == 28, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage);
132
133 /* Test a mono bitmap with values set */
134 ZeroMemory(pbi, sizeof(BITMAPINFO));
135 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
136 pbi->bmiHeader.biWidth = 12;
137 pbi->bmiHeader.biHeight = 9;
138 pbi->bmiHeader.biPlanes = 1;
139 pbi->bmiHeader.biBitCount = 32;
140 pbi->bmiHeader.biCompression = BI_RGB;
141 pbi->bmiHeader.biSizeImage = 123;
142 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
143 ok(ret == 1, "%d\n", ret);
144 ok(pbi->bmiHeader.biWidth == 12, "pbi->bmiHeader.biWidth = %ld\n", pbi->bmiHeader.biWidth);
145 ok(pbi->bmiHeader.biHeight == 9, "pbi->bmiHeader.biHeight = %ld\n", pbi->bmiHeader.biHeight);
146 ok(pbi->bmiHeader.biBitCount == 32, "pbi->bmiHeader.biBitCount = %d\n", pbi->bmiHeader.biBitCount);
147 ok(pbi->bmiHeader.biSizeImage == 432, "pbi->bmiHeader.biSizeImage = %ld\n", pbi->bmiHeader.biSizeImage);
148
149 /* Set individual values */
150 ZeroMemory(pbi, sizeof(BITMAPINFO));
151 pbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
152 pbi->bmiHeader.biWidth = 12;
153 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
154 ok(ret == 1, "%d\n", ret);
155 pbi->bmiHeader.biWidth = 0;
156 pbi->bmiHeader.biSizeImage = 123;
157 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
158 ok(ret == 0, "%d\n", ret);
159 pbi->bmiHeader.biSizeImage = 0;
160 pbi->bmiHeader.biCompression = BI_RGB;
161 ret = GetDIBits(hdcScreen, hbmp, 0, 5, NULL, pbi, DIB_RGB_COLORS);
162 ok(ret == 0, "%d\n", ret);
163
164 DeleteObject(hbmp);
165 DeleteDC(hdcMem);
166 ReleaseDC(NULL, hdcScreen);
167 }
168
169 START_TEST(GetDIBits)
170 {
171 Test_GetDIBits();
172 }
173