Authors: Michael Kaufmann <hallo@michael-kaufmann.ch>, Huw Davies <huw@codeweavers...
[wine] / dlls / gdi / tests / bitmap.c
1 /*
2  * Unit test suite for bitmaps
3  *
4  * Copyright 2004 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22 #include <assert.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28
29 #include "wine/test.h"
30
31
32 static void test_createdibitmap(void)
33 {
34     HDC hdc, hdcmem;
35     BITMAPINFOHEADER bmih;
36     BITMAP bm;
37     HBITMAP hbm, hbm_colour, hbm_old;
38     INT screen_depth;
39
40     hdc = GetDC(0);
41     screen_depth = GetDeviceCaps(hdc, BITSPIXEL);
42     memset(&bmih, 0, sizeof(bmih));
43     bmih.biSize = sizeof(bmih);
44     bmih.biWidth = 10;
45     bmih.biHeight = 10;
46     bmih.biPlanes = 1;
47     bmih.biBitCount = 32;
48     bmih.biCompression = BI_RGB;
49  
50     /* First create an un-initialised bitmap.  The depth of the bitmap
51        should match that of the hdc and not that supplied in bmih.
52     */
53
54     /* First try 32 bits */
55     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
56     ok(hbm != NULL, "CreateDIBitmap failed\n");
57     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
58
59     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
60     DeleteObject(hbm);
61     
62     /* Then 16 */
63     bmih.biBitCount = 16;
64     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
65     ok(hbm != NULL, "CreateDIBitmap failed\n");
66     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
67
68     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
69     DeleteObject(hbm);
70
71     /* Then 1 */
72     bmih.biBitCount = 1;
73     hbm = CreateDIBitmap(hdc, &bmih, 0, NULL, NULL, 0);
74     ok(hbm != NULL, "CreateDIBitmap failed\n");
75     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
76
77     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
78     DeleteObject(hbm);
79
80     /* Now with a monochrome dc we expect a monochrome bitmap */
81     hdcmem = CreateCompatibleDC(hdc);
82
83     /* First try 32 bits */
84     bmih.biBitCount = 32;
85     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
86     ok(hbm != NULL, "CreateDIBitmap failed\n");
87     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
88
89     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
90     DeleteObject(hbm);
91     
92     /* Then 16 */
93     bmih.biBitCount = 16;
94     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
95     ok(hbm != NULL, "CreateDIBitmap failed\n");
96     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
97
98     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
99     DeleteObject(hbm);
100     
101     /* Then 1 */
102     bmih.biBitCount = 1;
103     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
104     ok(hbm != NULL, "CreateDIBitmap failed\n");
105     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
106
107     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
108     DeleteObject(hbm);
109
110     /* Now select a polychrome bitmap into the dc and we expect
111        screen_depth bitmaps again */
112     hbm_colour = CreateCompatibleBitmap(hdc, 1, 1);
113     hbm_old = SelectObject(hdcmem, hbm_colour);
114
115     /* First try 32 bits */
116     bmih.biBitCount = 32;
117     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
118     ok(hbm != NULL, "CreateDIBitmap failed\n");
119     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
120
121     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
122     DeleteObject(hbm);
123     
124     /* Then 16 */
125     bmih.biBitCount = 16;
126     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
127     ok(hbm != NULL, "CreateDIBitmap failed\n");
128     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
129
130     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
131     DeleteObject(hbm);
132     
133     /* Then 1 */
134     bmih.biBitCount = 1;
135     hbm = CreateDIBitmap(hdcmem, &bmih, 0, NULL, NULL, 0);
136     ok(hbm != NULL, "CreateDIBitmap failed\n");
137     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
138
139     ok(bm.bmBitsPixel == screen_depth, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, screen_depth);
140     DeleteObject(hbm);
141
142     SelectObject(hdcmem, hbm_old);
143     DeleteObject(hbm_colour);
144     DeleteDC(hdcmem);
145
146     /* If hdc == 0 then we get a 1 bpp bitmap */
147     bmih.biBitCount = 32;
148     hbm = CreateDIBitmap(0, &bmih, 0, NULL, NULL, 0);
149     ok(hbm != NULL, "CreateDIBitmap failed\n");
150     ok(GetObject(hbm, sizeof(bm), &bm), "GetObject failed\n");
151
152     ok(bm.bmBitsPixel == 1, "CreateDIBitmap created bitmap of incorrect depth %d != %d\n", bm.bmBitsPixel, 1);
153     DeleteObject(hbm);
154     
155     ReleaseDC(0, hdc);
156 }
157
158 START_TEST(bitmap)
159 {
160     test_createdibitmap();
161 }