[GDI32_APITEST]
[reactos.git] / rostests / apitests / gdi32 / CreateBitmap.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CreateBitmap
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #include <stdio.h>
9 #include <wine/test.h>
10 #include <windows.h>
11
12 #define DEFAULT_BITMAP 21
13
14 void Test_CreateBitmap_Params()
15 {
16 HBITMAP hbmp;
17
18 /* All of these should get us the default bitmap */
19 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
20 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
21 hbmp = CreateBitmap(1, 0, 0, 0, NULL);
22 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
23 hbmp = CreateBitmap(0, 1, 0, 0, NULL);
24 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
25 hbmp = CreateBitmap(0, 1, 1, 0, NULL);
26 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
27 hbmp = CreateBitmap(0, 1, 63, 33, NULL);
28 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
29 hbmp = CreateBitmap(0, -4, -32, 233, NULL);
30 ok(hbmp == GetStockObject(21), "should get the default bitmap\n");
31
32 SetLastError(0);
33 hbmp = CreateBitmap(1, -1, 1, 0, NULL);
34 ok(hbmp == 0, "\n");
35 ok_err(ERROR_INVALID_PARAMETER);
36
37 SetLastError(0);
38 hbmp = CreateBitmap(-1, 1, 1, 0, NULL);
39 ok(hbmp == 0, "\n");
40 ok_err(ERROR_INVALID_PARAMETER);
41
42 SetLastError(0);
43 hbmp = CreateBitmap(-1, 1, 1, 1, NULL);
44 ok(hbmp == 0, "\n");
45 ok_err(ERROR_INVALID_PARAMETER);
46
47 SetLastError(0);
48 hbmp = CreateBitmap(1, -1, 1, 1, NULL);
49 ok(hbmp == 0, "\n");
50 ok_err(ERROR_INVALID_PARAMETER);
51
52 /* Check if an overflow in cPlanes * cBitsPixel is handled */
53 SetLastError(0);
54 hbmp = CreateBitmap(1, 1, 2, 0x80000004, NULL);
55 ok(hbmp == 0, "\n");
56 ok_err(ERROR_INVALID_PARAMETER);
57
58 /* Check for maximum width */
59 hbmp = CreateBitmap(0x7FFFFFF, 1, 1, 1, NULL);
60 ok(hbmp != 0, "\n");
61 DeleteObject(hbmp);
62 SetLastError(0);
63 hbmp = CreateBitmap(0x8000000, 1, 1, 1, NULL);
64 ok(hbmp == 0, "\n");
65 ok_err(ERROR_INVALID_PARAMETER);
66
67 /* Check for maximum height */
68 hbmp = CreateBitmap(1, 0x1FFFFF00, 1, 1, NULL);
69 ok(hbmp != 0, "\n");
70 DeleteObject(hbmp);
71 SetLastError(0);
72 hbmp = CreateBitmap(1, 0x1FFFFFFF, 1, 1, NULL);
73 ok(hbmp == 0, "\n");
74 ok_err(0);
75
76 /* Check for overflow in width * height */
77 hbmp = CreateBitmap(0x20000, 0x1FFFF, 1, 1, NULL);
78 ok(hbmp != 0, "\n");
79 DeleteObject(hbmp);
80 SetLastError(0);
81 hbmp = CreateBitmap(0x20000, 0x20000, 1, 1, NULL);
82 ok(hbmp == 0, "\n");
83 ok_err(0);
84
85 /* Check huge allocation */
86 SetLastError(0);
87 hbmp = CreateBitmap(0x2000, 0x20000, 32, 1, NULL);
88 ok(hbmp == 0, "\n");
89 ok_err(ERROR_INVALID_PARAMETER);
90
91 }
92
93 void Test_CreateBitmap()
94 {
95 HBITMAP hbmp;
96 BITMAP bitmap;
97 int result;
98
99 hbmp = CreateBitmap(0, 0, 0, 0, NULL);
100 ok(hbmp != 0, "should get a 1x1 bitmap\n");
101 ok(hbmp == GetStockObject(DEFAULT_BITMAP), "\n");
102 result = GetObject(hbmp, sizeof(bitmap), &bitmap);
103 ok(result > 0, "result = %d\n", result);
104 ok(bitmap.bmType == 0, "bmType = %ld\n", bitmap.bmType);
105 ok(bitmap.bmWidth == 1, "bmWidth = %ld\n", bitmap.bmWidth);
106 ok(bitmap.bmHeight == 1, "bmHeight = %ld\n", bitmap.bmHeight);
107 ok(bitmap.bmWidthBytes == 2, "bmWidthBytes = %ld\n", bitmap.bmWidthBytes);
108 ok(bitmap.bmPlanes == 1, "bmPlanes = %d\n", bitmap.bmPlanes);
109 ok(bitmap.bmBitsPixel == 1, "bmBitsPixel = %d\n", bitmap.bmBitsPixel);
110 ok(bitmap.bmBits == 0, "bmBits = %p\n", bitmap.bmBits);
111 DeleteObject(hbmp);
112
113 hbmp = CreateBitmap(1, 2, 1, 1, NULL);
114 ok(hbmp != 0, "should get a 1x2 bitmap\n");
115 result = GetObject(hbmp, sizeof(bitmap), &bitmap);
116 ok(result > 0, "result = %d\n", result);
117 ok(bitmap.bmType == 0, "bmType = %ld\n", bitmap.bmType);
118 ok(bitmap.bmWidth == 1, "bmWidth = %ld\n", bitmap.bmWidth);
119 ok(bitmap.bmHeight == 2, "bmHeight = %ld\n", bitmap.bmHeight);
120 ok(bitmap.bmWidthBytes == 2, "bmWidthBytes = %ld\n", bitmap.bmWidthBytes);
121 ok(bitmap.bmPlanes == 1, "bmPlanes = %d\n", bitmap.bmPlanes);
122 ok(bitmap.bmBitsPixel == 1, "bmBitsPixel = %d\n", bitmap.bmBitsPixel);
123 ok(bitmap.bmBits == 0, "bmBits = %p\n", bitmap.bmBits);
124 DeleteObject(hbmp);
125
126
127 }
128
129 START_TEST(CreateBitmap)
130 {
131 Test_CreateBitmap_Params();
132 Test_CreateBitmap();
133 }
134