1 /* File generated automatically from tools/winapi/tests.dat; do not edit! */
2 /* This file can be copied, modified and distributed without restriction. */
3 
4 /*
5  * Unit tests for data structure packing
6  */
7 
8 #define WINE_NOWINSOCK
9 
10 #include <stdarg.h>
11 #include "windef.h"
12 #include "winbase.h"
13 #include "wtypes.h"
14 #include "winreg.h"
15 #include "shlwapi.h"
16 
17 #include "wine/test.h"
18 
19 /***********************************************************************
20  * Compatibility macros
21  */
22 
23 #define DWORD_PTR UINT_PTR
24 #define LONG_PTR INT_PTR
25 #define ULONG_PTR UINT_PTR
26 
27 /***********************************************************************
28  * Windows API extension
29  */
30 
31 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)
32 # define _TYPE_ALIGNMENT(type) __alignof(type)
33 #elif defined(__GNUC__)
34 # define _TYPE_ALIGNMENT(type) __alignof__(type)
35 #else
36 /*
37  * FIXME: May not be possible without a compiler extension
38  *        (if type is not just a name that is, otherwise the normal
39  *         TYPE_ALIGNMENT can be used)
40  */
41 #endif
42 
43 #if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)
44 #pragma warning(disable:4116)
45 #endif
46 
47 #if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)
48 # define TYPE_ALIGNMENT _TYPE_ALIGNMENT
49 #endif
50 
51 /***********************************************************************
52  * Test helper macros
53  */
54 
55 #define TEST_TYPE_SIZE(type, size)             C_ASSERT(sizeof(type) == size);
56 
57 #ifdef TYPE_ALIGNMENT
58 # define TEST_TYPE_ALIGN(type, align)          C_ASSERT(TYPE_ALIGNMENT(type) == align);
59 #else
60 # define TEST_TYPE_ALIGN(type, align)
61 #endif
62 
63 #ifdef _TYPE_ALIGNMENT
64 # define TEST_TARGET_ALIGN(type, align)        C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);
65 # define TEST_FIELD_ALIGN(type, field, align)  C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);
66 #else
67 # define TEST_TARGET_ALIGN(type, align)
68 # define TEST_FIELD_ALIGN(type, field, align)
69 #endif
70 
71 #define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);
72 
73 #define TEST_TARGET_SIZE(type, size)            TEST_TYPE_SIZE(*(type)0, size)
74 #define TEST_FIELD_SIZE(type, field, size)      TEST_TYPE_SIZE((((type*)0)->field), size)
75 #define TEST_TYPE_SIGNED(type)                  C_ASSERT((type) -1 < 0);
76 #define TEST_TYPE_UNSIGNED(type)                C_ASSERT((type) -1 > 0);
77 
78 
79 #ifdef _WIN64
80 
81 static void test_pack_ASSOCF(void)
82 {
83     /* ASSOCF */
84     TEST_TYPE_SIZE   (ASSOCF, 4)
85     TEST_TYPE_ALIGN  (ASSOCF, 4)
86     TEST_TYPE_UNSIGNED(ASSOCF)
87 }
88 
89 static void test_pack_DLLGETVERSIONPROC(void)
90 {
91     /* DLLGETVERSIONPROC */
92     TEST_TYPE_SIZE   (DLLGETVERSIONPROC, 8)
93     TEST_TYPE_ALIGN  (DLLGETVERSIONPROC, 8)
94 }
95 
96 static void test_pack_DLLVERSIONINFO(void)
97 {
98     /* DLLVERSIONINFO (pack 8) */
99     TEST_TYPE_SIZE   (DLLVERSIONINFO, 20)
100     TEST_TYPE_ALIGN  (DLLVERSIONINFO, 4)
101     TEST_FIELD_SIZE  (DLLVERSIONINFO, cbSize, 4)
102     TEST_FIELD_ALIGN (DLLVERSIONINFO, cbSize, 4)
103     TEST_FIELD_OFFSET(DLLVERSIONINFO, cbSize, 0)
104     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwMajorVersion, 4)
105     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwMajorVersion, 4)
106     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwMajorVersion, 4)
107     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwMinorVersion, 4)
108     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwMinorVersion, 4)
109     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwMinorVersion, 8)
110     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwBuildNumber, 4)
111     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwBuildNumber, 4)
112     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwBuildNumber, 12)
113     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwPlatformID, 4)
114     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwPlatformID, 4)
115     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwPlatformID, 16)
116 }
117 
118 static void test_pack_DLLVERSIONINFO2(void)
119 {
120     /* DLLVERSIONINFO2 (pack 8) */
121     TEST_TYPE_SIZE   (DLLVERSIONINFO2, 32)
122     TEST_TYPE_ALIGN  (DLLVERSIONINFO2, 8)
123     TEST_FIELD_SIZE  (DLLVERSIONINFO2, info1, 20)
124     TEST_FIELD_ALIGN (DLLVERSIONINFO2, info1, 4)
125     TEST_FIELD_OFFSET(DLLVERSIONINFO2, info1, 0)
126     TEST_FIELD_SIZE  (DLLVERSIONINFO2, dwFlags, 4)
127     TEST_FIELD_ALIGN (DLLVERSIONINFO2, dwFlags, 4)
128     TEST_FIELD_OFFSET(DLLVERSIONINFO2, dwFlags, 20)
129     TEST_FIELD_SIZE  (DLLVERSIONINFO2, ullVersion, 8)
130     TEST_FIELD_ALIGN (DLLVERSIONINFO2, ullVersion, 8)
131     TEST_FIELD_OFFSET(DLLVERSIONINFO2, ullVersion, 24)
132 }
133 
134 static void test_pack_HUSKEY(void)
135 {
136     /* HUSKEY */
137     TEST_TYPE_SIZE   (HUSKEY, 8)
138     TEST_TYPE_ALIGN  (HUSKEY, 8)
139 }
140 
141 static void test_pack_PHUSKEY(void)
142 {
143     /* PHUSKEY */
144     TEST_TYPE_SIZE   (PHUSKEY, 8)
145     TEST_TYPE_ALIGN  (PHUSKEY, 8)
146     TEST_TARGET_SIZE (PHUSKEY, 8)
147     TEST_TARGET_ALIGN(PHUSKEY, 8)
148 }
149 
150 #else /* _WIN64 */
151 
152 static void test_pack_ASSOCF(void)
153 {
154     /* ASSOCF */
155     TEST_TYPE_SIZE   (ASSOCF, 4)
156     TEST_TYPE_ALIGN  (ASSOCF, 4)
157     TEST_TYPE_UNSIGNED(ASSOCF)
158 }
159 
160 static void test_pack_DLLGETVERSIONPROC(void)
161 {
162     /* DLLGETVERSIONPROC */
163     TEST_TYPE_SIZE   (DLLGETVERSIONPROC, 4)
164     TEST_TYPE_ALIGN  (DLLGETVERSIONPROC, 4)
165 }
166 
167 static void test_pack_DLLVERSIONINFO(void)
168 {
169     /* DLLVERSIONINFO (pack 8) */
170     TEST_TYPE_SIZE   (DLLVERSIONINFO, 20)
171     TEST_TYPE_ALIGN  (DLLVERSIONINFO, 4)
172     TEST_FIELD_SIZE  (DLLVERSIONINFO, cbSize, 4)
173     TEST_FIELD_ALIGN (DLLVERSIONINFO, cbSize, 4)
174     TEST_FIELD_OFFSET(DLLVERSIONINFO, cbSize, 0)
175     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwMajorVersion, 4)
176     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwMajorVersion, 4)
177     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwMajorVersion, 4)
178     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwMinorVersion, 4)
179     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwMinorVersion, 4)
180     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwMinorVersion, 8)
181     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwBuildNumber, 4)
182     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwBuildNumber, 4)
183     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwBuildNumber, 12)
184     TEST_FIELD_SIZE  (DLLVERSIONINFO, dwPlatformID, 4)
185     TEST_FIELD_ALIGN (DLLVERSIONINFO, dwPlatformID, 4)
186     TEST_FIELD_OFFSET(DLLVERSIONINFO, dwPlatformID, 16)
187 }
188 
189 static void test_pack_DLLVERSIONINFO2(void)
190 {
191     /* DLLVERSIONINFO2 (pack 8) */
192     TEST_TYPE_SIZE   (DLLVERSIONINFO2, 32)
193     TEST_TYPE_ALIGN  (DLLVERSIONINFO2, 8)
194     TEST_FIELD_SIZE  (DLLVERSIONINFO2, info1, 20)
195     TEST_FIELD_ALIGN (DLLVERSIONINFO2, info1, 4)
196     TEST_FIELD_OFFSET(DLLVERSIONINFO2, info1, 0)
197     TEST_FIELD_SIZE  (DLLVERSIONINFO2, dwFlags, 4)
198     TEST_FIELD_ALIGN (DLLVERSIONINFO2, dwFlags, 4)
199     TEST_FIELD_OFFSET(DLLVERSIONINFO2, dwFlags, 20)
200     TEST_FIELD_SIZE  (DLLVERSIONINFO2, ullVersion, 8)
201     TEST_FIELD_ALIGN (DLLVERSIONINFO2, ullVersion, 8)
202     TEST_FIELD_OFFSET(DLLVERSIONINFO2, ullVersion, 24)
203 }
204 
205 static void test_pack_HUSKEY(void)
206 {
207     /* HUSKEY */
208     TEST_TYPE_SIZE   (HUSKEY, 4)
209     TEST_TYPE_ALIGN  (HUSKEY, 4)
210 }
211 
212 static void test_pack_PHUSKEY(void)
213 {
214     /* PHUSKEY */
215     TEST_TYPE_SIZE   (PHUSKEY, 4)
216     TEST_TYPE_ALIGN  (PHUSKEY, 4)
217     TEST_TARGET_SIZE (PHUSKEY, 4)
218     TEST_TARGET_ALIGN(PHUSKEY, 4)
219 }
220 
221 #endif /* _WIN64 */
222 
223 static void test_pack(void)
224 {
225     test_pack_ASSOCF();
226     test_pack_DLLGETVERSIONPROC();
227     test_pack_DLLVERSIONINFO();
228     test_pack_DLLVERSIONINFO2();
229     test_pack_HUSKEY();
230     test_pack_PHUSKEY();
231 }
232 
233 START_TEST(generated)
234 {
235     test_pack();
236 }
237