[WIN32K]
[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 TEST(x) ok(x, #x"\n")
13 #define RTEST(x) ok(x, #x"\n")
14
15 void Test_GetDIBits()
16 {
17 HDC hDCScreen;
18 HBITMAP hBitmap;
19 BITMAPINFO bi;
20 INT ScreenBpp;
21
22 hDCScreen = GetDC(NULL);
23 ok(hDCScreen != 0, "GetDC failed, skipping tests\n");
24 if (hDCScreen == NULL) return;
25
26 hBitmap = CreateCompatibleBitmap(hDCScreen, 16, 16);
27 RTEST(hBitmap != NULL);
28
29 /* misc */
30 SetLastError(ERROR_SUCCESS);
31 RTEST(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0);
32 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
33
34 SetLastError(ERROR_SUCCESS);
35 RTEST(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0);
36 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
37
38 SetLastError(ERROR_SUCCESS);
39 RTEST(GetDIBits((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0) == 0);
40 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
41
42 SetLastError(ERROR_SUCCESS);
43 RTEST(GetDIBits((HDC)2345, hBitmap, 0, 15, NULL, &bi, 0) == 0);
44 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
45
46
47
48 /* null hdc */
49 SetLastError(ERROR_SUCCESS);
50 ZeroMemory(&bi, sizeof(BITMAPINFO));
51 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
52 RTEST(GetDIBits(NULL, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0);
53 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
54
55 /* null bitmap */
56 SetLastError(ERROR_SUCCESS);
57 ZeroMemory(&bi, sizeof(BITMAPINFO));
58 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
59 RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0);
60 RTEST(GetLastError() == ERROR_SUCCESS);
61
62 /* 0 scan lines */
63 SetLastError(ERROR_SUCCESS);
64 ZeroMemory(&bi, sizeof(BITMAPINFO));
65 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
66 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 0, NULL, &bi, DIB_RGB_COLORS) > 0);
67 RTEST(GetLastError() == ERROR_SUCCESS);
68
69 /* null bitmap info - crashes XP*/
70 //SetLastError(ERROR_SUCCESS);
71 //RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
72 //RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
73
74 /* bad bmi colours (uUsage) */
75 SetLastError(ERROR_SUCCESS);
76 ZeroMemory(&bi, sizeof(BITMAPINFO));
77 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
78 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, 100) == 0);
79 RTEST(GetLastError() == ERROR_SUCCESS);
80 RTEST(bi.bmiHeader.biWidth == 0);
81 RTEST(bi.bmiHeader.biHeight == 0);
82 RTEST(bi.bmiHeader.biBitCount == 0);
83 RTEST(bi.bmiHeader.biSizeImage == 0);
84
85 /* basic call */
86 SetLastError(ERROR_SUCCESS);
87 ZeroMemory(&bi, sizeof(BITMAPINFO));
88 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
89 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) > 0);
90 RTEST(GetLastError() == ERROR_SUCCESS);
91 ScreenBpp = GetDeviceCaps(hDCScreen, BITSPIXEL);
92 RTEST(bi.bmiHeader.biWidth == 16);
93 RTEST(bi.bmiHeader.biHeight == 16);
94 RTEST(bi.bmiHeader.biBitCount == ScreenBpp);
95 RTEST(bi.bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8));
96
97 DeleteObject(hBitmap);
98 ReleaseDC(NULL, hDCScreen);
99 }
100
101 START_TEST(GetDIBits)
102 {
103 Test_GetDIBits();
104 }
105