Set svn:eol-style "native" for all apitest stuff
[reactos.git] / rostests / apitests / gdi32api / tests / GetDIBits.c
1 INT
2 Test_GetDIBits(PTESTINFO pti)
3 {
4 HDC hDCScreen;
5 HBITMAP hBitmap;
6 BITMAPINFO bi;
7 INT ScreenBpp;
8
9 hDCScreen = GetDC(NULL);
10 if (hDCScreen == NULL)
11 {
12 return FALSE;
13 }
14
15 hBitmap = CreateCompatibleBitmap(hDCScreen, 16, 16);
16 RTEST(hBitmap != NULL);
17
18 /* misc */
19 SetLastError(ERROR_SUCCESS);
20 RTEST(GetDIBits(0, 0, 0, 0, NULL, NULL, 0) == 0);
21 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
22
23 SetLastError(ERROR_SUCCESS);
24 RTEST(GetDIBits((HDC)2345, 0, 0, 0, NULL, NULL, 0) == 0);
25 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
26
27 SetLastError(ERROR_SUCCESS);
28 RTEST(GetDIBits((HDC)2345, hBitmap, 0, 0, NULL, NULL, 0) == 0);
29 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
30
31 SetLastError(ERROR_SUCCESS);
32 RTEST(GetDIBits((HDC)2345, hBitmap, 0, 15, NULL, &bi, 0) == 0);
33 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
34
35
36
37 /* null hdc */
38 SetLastError(ERROR_SUCCESS);
39 ZeroMemory(&bi, sizeof(BITMAPINFO));
40 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
41 RTEST(GetDIBits(NULL, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0);
42 RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
43
44 /* null bitmap */
45 SetLastError(ERROR_SUCCESS);
46 ZeroMemory(&bi, sizeof(BITMAPINFO));
47 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
48 RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, &bi, DIB_RGB_COLORS) == 0);
49 RTEST(GetLastError() == ERROR_SUCCESS);
50
51 /* 0 scan lines */
52 SetLastError(ERROR_SUCCESS);
53 ZeroMemory(&bi, sizeof(BITMAPINFO));
54 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
55 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 0, NULL, &bi, DIB_RGB_COLORS) > 0);
56 RTEST(GetLastError() == ERROR_SUCCESS);
57
58 /* null bitmap info - crashes XP*/
59 //SetLastError(ERROR_SUCCESS);
60 //RTEST(GetDIBits(hDCScreen, NULL, 0, 15, NULL, NULL, DIB_RGB_COLORS) == 0);
61 //RTEST(GetLastError() == ERROR_INVALID_PARAMETER);
62
63 /* bad bmi colours (uUsage) */
64 SetLastError(ERROR_SUCCESS);
65 ZeroMemory(&bi, sizeof(BITMAPINFO));
66 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
67 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, 100) == 0);
68 RTEST(GetLastError() == ERROR_SUCCESS);
69 RTEST(bi.bmiHeader.biWidth == 0);
70 RTEST(bi.bmiHeader.biHeight == 0);
71 RTEST(bi.bmiHeader.biBitCount == 0);
72 RTEST(bi.bmiHeader.biSizeImage == 0);
73
74 /* basic call */
75 SetLastError(ERROR_SUCCESS);
76 ZeroMemory(&bi, sizeof(BITMAPINFO));
77 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
78 RTEST(GetDIBits(hDCScreen, hBitmap, 0, 15, NULL, &bi, DIB_RGB_COLORS) > 0);
79 RTEST(GetLastError() == ERROR_SUCCESS);
80 ScreenBpp = GetDeviceCaps(hDCScreen, BITSPIXEL);
81 RTEST(bi.bmiHeader.biWidth == 16);
82 RTEST(bi.bmiHeader.biHeight == 16);
83 RTEST(bi.bmiHeader.biBitCount == ScreenBpp);
84 RTEST(bi.bmiHeader.biSizeImage == (16 * 16) * (ScreenBpp / 8));
85
86 DeleteObject(hBitmap);
87 ReleaseDC(NULL, hDCScreen);
88 return APISTATUS_NORMAL;
89 }