mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / tools / winapi / winapi_test
blob716bb30ac08944f7a7b7963c5b2bed6dec2fdf1a
1 #!/usr/bin/perl
3 # Copyright 2002 Patrik Stridvall
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 use strict;
21 use warnings 'all';
23 BEGIN {
24 $0 =~ m%^(.*?/?tools)/winapi/winapi_test$%;
25 require "$1/winapi/setup.pm";
28 use config qw(
29 file_type files_skip files_filter
30 $current_dir $wine_dir $winapi_dir
32 use output qw($output);
33 use winapi_test_options qw($options);
35 if($options->progress) {
36 $output->enable_progress;
37 } else {
38 $output->disable_progress;
41 use c_parser;
42 use tests qw($tests);
43 use type;
44 use util qw(replace_file);
46 my $pointer_size = 4;
48 my @tests = ();
49 if ($options->pack) {
50 push @tests, "pack";
53 my @files;
55 my %files;
57 foreach my $test (@tests)
59 foreach my $test_dir ($tests->get_test_dirs($test))
61 foreach my $header ($tests->get_section($test_dir, $test, "header"))
63 if (!$files{$header})
65 push @files, "include/$header";
66 $files{$header} = 1;
73 if (0) {
74 my $file = "tests.dat";
76 $file .= "2"; # FIXME: For tests
78 open(OUT, "> $winapi_dir/$file") || die "Error: Can't open $winapi_dir/$file: $!\n";
80 my $x = 0;
81 my @test_dirs = $tests->get_test_dirs();
82 foreach my $test_dir (@test_dirs) {
83 print OUT "\n" if $x++;
84 print OUT "%%%$test_dir\n";
85 print OUT "\n";
87 my $y = 0;
88 my @tests = $tests->get_tests($test_dir);
89 foreach my $test (@tests) {
90 print OUT "\n" if $y++;
91 print OUT "%%$test\n";
92 print OUT "\n";
94 my @types;
96 my $z = 0;
97 my @sections = $tests->get_sections($test_dir, $test);
98 foreach my $section (@sections) {
99 my @lines = $tests->get_section($test_dir, $test, $section);
101 if ($section =~ /^(?:struct|type)$/) {
102 foreach my $line (@lines) {
103 push @types, $line;
105 next;
108 print OUT "\n" if $z++;
109 print OUT "%$section\n";
110 print OUT "\n";
111 foreach my $line (@lines) {
112 print OUT "$line\n";
116 @types = sort { $x = $a; $y = $b; $x =~ s/^!//; $y =~ s/^!//; $x cmp $y } @types;
118 print OUT "\n" if $z++;
119 print OUT "%type\n";
120 print OUT "\n";
121 foreach my $type (@types) {
122 print OUT "$type\n";
127 close(OUT);
128 exit(0);
132 my %file2types;
134 my $progress_output;
135 my $progress_current = 0;
136 my $progress_max = scalar(@files);
138 ########################################################################
139 # find_type
141 my %type_name2type;
143 my %defines = (
144 "ANYSIZE_ARRAY" => 1,
145 "CCHDEVICENAME" => 32,
146 "CCHILDREN_TITLEBAR+1" => 6,
147 "ELF_VENDOR_SIZE" => 4,
148 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
149 "HW_PROFILE_GUIDLEN" => 39,
150 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
151 "IMAGE_SIZEOF_SHORT_NAME" => 8,
152 "LF_FACESIZE" => 32,
153 "LF_FULLFACESIZE" => 64,
154 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
155 "MAX_GOPHER_DISPLAY_TEXT + 1" => 129,
156 "MAX_GOPHER_LOCATOR_LENGTH + 1" => 654,
157 "MAX_PATH" => 260,
158 "MAX_PROFILE_LEN" => 80,
159 "NUM_POINTS" => 3,
160 "OFS_MAXPATHNAME" => 128,
161 "SIZE_OF_80387_REGISTERS" => 80,
162 "TOKEN_SOURCE_LENGTH" => 8,
165 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
166 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
167 my %size_parse_reported;
169 sub _find_align_kind_size($) {
170 my $type_name = shift;
172 local $_ = $type_name;
174 my $align;
175 my $kind;
176 my $size;
177 if (/\*+$/) {
178 $align = $pointer_size;
179 $kind = "pointer";
180 $size = $pointer_size;
181 } elsif (/^(?:void|VOID)$/) {
182 $align = 4;
183 $kind = "signed";
184 $size = 4;
185 } elsif(/^char$/) {
186 $align = 1;
187 $kind = "char";
188 $size = 1;
189 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char)$/) {
190 $align = 1;
191 $kind = defined($1) ? $1 : "signed";
192 $size = 1;
193 } elsif(/^CHAR$/) {
194 $align = 1;
195 $kind = "signed";
196 $size = 1;
197 } elsif(/^(?:byte|BOOLEAN|BYTE|UCHAR)$/) {
198 $align = 1;
199 $kind = "unsigned";
200 $size = 1;
201 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
202 $align = 2;
203 $kind = defined($1) ? $1 : "signed";
204 $size = 2;
205 } elsif (/^SHORT$/) {
206 $align = 2;
207 $kind = "signed";
208 $size = 2;
209 } elsif (/^(?:char16_t|wchar_t|USHORT|WCHAR|WORD)$/) {
210 $align = 2;
211 $kind = "unsigned";
212 $size = 2;
213 } elsif (/^(signed|unsigned)$/) {
214 $align = 4;
215 $kind = $1;
216 $size = 4;
217 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int32|int)$/) {
218 $align = 4;
219 $kind = defined($1) ? $1 : "signed";
220 $size = 4;
221 } elsif (/^(?:BOOL|INT|LONG)$/) {
222 $align = 4;
223 $kind = "signed";
224 $size = 4;
225 } elsif (/^(?:DWORD|FOURCC|LCID|UINT|ULONG)$/) {
226 $align = 4;
227 $kind = "unsigned";
228 $size = 4;
229 } elsif (/^(?:float|FLOAT)$/) {
230 $align = 4;
231 $kind = "float";
232 $size = 4;
233 } elsif (/^(?:(signed|unsigned)\s+)?(?:long(?:\s+int)?)$/) {
234 # 'long' is always 4 bytes on Windows.
235 $align = 4;
236 $kind = defined($1) ? $1 : "signed";
237 $size = 4;
238 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
239 $align = 8;
240 $kind = defined($1) ? $1 : "signed";
241 $size = 8;
242 } elsif (/^(?:INT64|LONG64|LONGLONG)$/) {
243 $align = 8;
244 $kind = "signed";
245 $size = 8;
246 } elsif (/^(?:UINT64|ULONG64|DWORD64|ULONGLONG|DWORDLONG)$/) {
247 $align = 8;
248 $kind = "unsigned";
249 $size = 8;
250 } elsif (/^(?:double|DOUBLE|DATE)$/) {
251 $align = 8;
252 $kind = "float";
253 $size = 8;
254 } elsif (/^(?:long\s+double)$/) {
255 $align = 4;
256 $kind = "float";
257 $size = 12;
258 } elsif (/^(?:INT|LONG)_PTR$/) {
259 $align = $pointer_size;
260 $kind = "signed";
261 $size = $pointer_size;
262 } elsif (/^(?:UINT|MMVERSION|ULONG|DWORD)_PTR$/) {
263 $align = $pointer_size;
264 $kind = "unsigned";
265 $size = $pointer_size;
266 } elsif (/^H(?:ANDLE|DC|BITMAP|BRUSH|ICON|INSTANCE|KEY|MENU|METAFILE|MMIO|TASK|WND)$/) {
267 $align = $pointer_size;
268 $kind = "pointer";
269 $size = $pointer_size;
270 } elsif (/^(?:HPSTR|LP[A-Z0-9_]+|PVOID)$/) {
271 $align = $pointer_size;
272 $kind = "pointer";
273 $size = $pointer_size;
274 } elsif (/^POINTS$/) {
275 $align = 2;
276 $kind = "struct";
277 $size = 4;
278 } elsif (/^(?:FILETIME|LUID|POINT|POINTL)$/) {
279 $align = 4;
280 $kind = "struct";
281 $size = 8;
282 } elsif (/^(?:CLSID|GUID|RECT|RECTL)$/) {
283 $align = 4;
284 $kind = "struct";
285 $size = 16;
286 } elsif (/^(?:LARGE_INTEGER)$/) {
287 $align = 8;
288 $kind = "union";
289 $size = 8;
290 } elsif (/^(struct|union)$/) {
291 $kind = $1;
292 if (!$size_parse_reported{$_}) {
293 $output->write("cannot compute the size and alignment of $type_name types\n");
294 $size_parse_reported{$_} = 1;
296 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
297 $align = $pointer_size;
298 $kind = "pointer";
299 $size = $pointer_size;
302 my $align2;
303 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
304 $align2 = $type->align;
307 if (!defined($align)) {
308 $align = $align2;
309 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
310 $align_kludge_reported{$_} = 1;
311 $output->write("$type_name: type needn't be kludged\n");
314 if (!defined($align)) {
315 # $output->write("$type_name: can't find type\n");
318 my $size2;
319 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
320 $size2 = $type->size;
323 if (!defined($size)) {
324 $size = $size2;
325 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
326 $size_kludge_reported{$_} = 1;
327 $output->write("$type_name: type needn't be kludged\n");
330 return ($align, $kind, $size);
333 sub find_align($) {
334 my $type_name = shift;
335 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
336 return $align;
339 sub find_kind($) {
340 my $type_name = shift;
341 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
343 return $kind;
346 sub find_size($) {
347 my $type_name = shift;
348 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
349 return $size;
352 sub find_count($) {
353 my $count = shift;
354 return $defines{$count};
357 foreach my $file (@files) {
358 $progress_current++;
359 foreach my $ptr (4, 8) {
360 $pointer_size = $ptr;
363 open(IN, "< $wine_dir/$file") || die "Error: Can't open $wine_dir/$file: $!\n";
364 local $/ = undef;
365 $_ = <IN>;
366 close(IN);
369 my $max_line = 0;
371 local $_ = $_;
372 while(s/^.*?\n//) { $max_line++; }
373 if($_) { $max_line++; }
376 my $parser = new c_parser($file);
378 my $line;
379 my $type;
380 my @packs = ();
381 my @ifdefs = ();
383 my $update_output = sub {
384 my $progress = "";
385 my $prefix = "";
387 $progress .= "$file (file $progress_current of $progress_max" . sprintf ", %u-bit)", $pointer_size * 8;
388 $prefix .= "$file: ";
390 if(defined($line)) {
391 $progress .= ": line $line of $max_line";
394 $output->progress($progress);
395 $output->prefix($prefix);
398 &$update_output();
400 my $found_line = sub {
401 $line = shift;
403 &$update_output;
405 $parser->set_found_line_callback($found_line);
407 my $found_preprocessor = sub {
408 my $begin_line = shift;
409 my $begin_column = shift;
410 my $preprocessor = shift;
412 #print "found_preprocessor: $begin_line: [$_]\n";
413 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d)\.h[\">]$/) {
414 push @packs, $1 unless @ifdefs && !$ifdefs[$#ifdefs];
415 #print "found pack $1 on line $begin_line\n";
416 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
417 pop @packs unless @ifdefs && !$ifdefs[$#ifdefs];
418 #print "found poppack on line $begin_line\n";
419 } elsif ($preprocessor =~ /^\#\s*ifdef\s+_WIN64/) {
420 push @ifdefs, ($pointer_size == 8);
421 } elsif ($preprocessor =~ /^\#\s*ifndef\s+_WIN64/) {
422 push @ifdefs, ($pointer_size != 8);
423 } elsif ($preprocessor =~ /^\#\s*elif\s+defined\s*\(\s*_WIN64\s*\)/) {
424 $ifdefs[$#ifdefs] = ($pointer_size == 8);
425 } elsif ($preprocessor =~ /^\#\s*ifdef\s/) {
426 push @ifdefs, 2;
427 } elsif ($preprocessor =~ /^\#\s*ifndef\s/) {
428 push @ifdefs, 2;
429 } elsif ($preprocessor =~ /^\#\s*if/) {
430 push @ifdefs, 2;
431 } elsif ($preprocessor =~ /^\#\s*else/) {
432 $ifdefs[$#ifdefs] = $ifdefs[$#ifdefs] ^ 1;
433 } elsif ($preprocessor =~ /^\#\s*elif/) {
434 $ifdefs[$#ifdefs] = 2;
435 } elsif ($preprocessor =~ /^\#\s*endif/) {
436 pop @ifdefs;
438 return 1;
440 $parser->set_found_preprocessor_callback($found_preprocessor);
442 my $found_type = sub {
443 $type = shift;
444 return if @ifdefs && !$ifdefs[$#ifdefs];
446 &$update_output();
448 my $name = $type->name;
449 $file2types{$pointer_size}{$file}{$name} = $type;
451 $type->set_find_align_callback(\&find_align);
452 $type->set_find_kind_callback(\&find_kind);
453 $type->set_find_size_callback(\&find_size);
454 $type->set_find_count_callback(\&find_count);
456 my $pack = $packs[$#packs];
457 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
458 $type->pack($pack);
460 my $size = $type->size();
461 if (defined($size)) {
462 my $max_field_base_size = 0;
464 foreach my $field ($type->fields()) {
465 my $field_type_name = $field->type_name;
466 my $field_name = $field->name;
467 my $field_size = $field->size;
468 my $field_base_size = $field->base_size;
469 my $field_offset = $field->offset;
470 my $field_align = $field->align;
472 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
474 # $output->write("$name: $size\n");
476 $type_name2type{$pointer_size}{$name} = $type;
477 } else {
478 # $output->write("$name: can't find size\n");
481 return 1;
483 $parser->set_found_type_callback($found_type);
486 my $line = 1;
487 my $column = 0;
488 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
489 $output->write("can't parse file\n");
493 $output->prefix("");
497 ########################################################################
498 # output_header
500 sub output_header($$$) {
501 local *OUT = shift;
503 my $test_dir = shift;
504 my @tests = @{(shift)};
506 print OUT "/* File generated automatically from tools/winapi/tests.dat; do not edit! */\n";
507 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
508 print OUT "\n";
510 print OUT "/*\n";
511 foreach my $test (@tests) {
512 my @description = $tests->get_section($test_dir, $test, "description");
513 foreach my $description (@description) {
514 print OUT " * $description\n";
517 print OUT " */\n";
518 print OUT "\n";
520 print OUT "#define WINE_NOWINSOCK\n";
521 print OUT "\n";
522 foreach my $test (@tests) {
523 my @includes = $tests->get_section($test_dir, $test, "include");
524 foreach my $include (@includes) {
525 print OUT "#include $include\n";
528 print OUT "\n";
529 print OUT "#include \"wine/test.h\"\n";
530 print OUT "\n";
532 print OUT "/***********************************************************************\n";
533 print OUT " * Compatibility macros\n";
534 print OUT " */\n";
535 print OUT "\n";
536 print OUT "#define DWORD_PTR UINT_PTR\n";
537 print OUT "#define LONG_PTR INT_PTR\n";
538 print OUT "#define ULONG_PTR UINT_PTR\n";
539 print OUT "\n";
541 print OUT "/***********************************************************************\n";
542 print OUT " * Windows API extension\n";
543 print OUT " */\n";
544 print OUT "\n";
545 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
546 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
547 print OUT "#elif defined(__GNUC__) || defined(__clang__)\n";
548 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
549 print OUT "#else\n";
550 print OUT "/*\n";
551 print OUT " * FIXME: May not be possible without a compiler extension\n";
552 print OUT " * (if type is not just a name that is, otherwise the normal\n";
553 print OUT " * TYPE_ALIGNMENT can be used)\n";
554 print OUT " */\n";
555 print OUT "#endif\n";
556 print OUT "\n";
557 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
558 print OUT "#pragma warning(disable:4116)\n";
559 print OUT "#endif\n";
560 print OUT "\n";
561 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
562 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
563 print OUT "#endif\n";
564 print OUT "\n";
566 print OUT "/***********************************************************************\n";
567 print OUT " * Test helper macros\n";
568 print OUT " */\n";
569 print OUT "\n";
570 print OUT "#define TEST_TYPE_SIZE(type, size) C_ASSERT(sizeof(type) == size);\n";
571 print OUT "\n";
572 print OUT "#ifdef TYPE_ALIGNMENT\n";
573 print OUT "# define TEST_TYPE_ALIGN(type, align) C_ASSERT(TYPE_ALIGNMENT(type) == align);\n";
574 print OUT "#else\n";
575 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
576 print OUT "#endif\n";
577 print OUT "\n";
578 print OUT "#ifdef _TYPE_ALIGNMENT\n";
579 print OUT "# define TEST_TARGET_ALIGN(type, align) C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);\n";
580 print OUT "# define TEST_FIELD_ALIGN(type, field, align) C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);\n";
581 print OUT "#else\n";
582 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
583 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
584 print OUT "#endif\n";
585 print OUT "\n";
586 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);\n";
587 print OUT "\n";
588 print OUT "#define TEST_TARGET_SIZE(type, size) TEST_TYPE_SIZE(*(type)0, size)\n";
589 print OUT "#define TEST_FIELD_SIZE(type, field, size) TEST_TYPE_SIZE((((type*)0)->field), size)\n";
590 print OUT "#define TEST_TYPE_SIGNED(type) C_ASSERT((type) -1 < 0);\n";
591 print OUT "#define TEST_TYPE_UNSIGNED(type) C_ASSERT((type) -1 > 0);\n";
592 print OUT "\n";
593 print OUT "\n";
596 ########################################################################
597 # output_footer
599 sub output_footer($$$) {
600 local *OUT = shift;
602 my $test_dir = shift;
603 my @tests = @{(shift)};
605 print OUT "START_TEST(generated)\n";
606 print OUT "{\n";
607 foreach my $test (@tests) {
608 print OUT " test_$test();\n";
610 print OUT "}\n";
613 ########################################################################
614 # output_test_pack_type
616 sub output_test_pack_type($$$$$$) {
617 local *OUT = shift;
619 my $type_name2type = shift;
620 my $type_name2optional = shift;
621 my $type_name2optional_fields = shift;
622 my $type_name = shift;
623 my $type = shift;
625 my $optional_fields = $$type_name2optional_fields{$type_name};
627 my $type_align = $type->align;
628 my $type_pack = $type->pack;
629 my $type_size = $type->size;
630 my $type_kind = $type->kind;
632 if (defined($type_pack)) {
633 print OUT " /* $type_name (pack $type_pack) */\n";
634 } else {
635 print OUT " /* $type_name */\n";
638 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
639 print OUT " TEST_TYPE_SIZE ($type_name, $type_size)\n";
640 print OUT " TEST_TYPE_ALIGN ($type_name, $type_align)\n";
643 if ($type_kind eq "float") {
644 # Nothing
645 } elsif ($type_kind eq "pointer") {
646 my $dereference_type;
647 $dereference_type = sub {
648 my $type = shift;
650 my @fields = $type->fields;
651 my $type_name2 =$fields[0]->type_name;
653 if ($type_name2 =~ s/\s*\*$//) {
654 my $type2 = $$type_name2type{$type_name2};
655 if (defined($type2)) {
656 return $type2;
657 } else {
658 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
659 $output->write("$type_name2: warning: type not found 1\n");
661 return undef;
663 } elsif ($type_name2 =~ /^\w+$/) {
664 my $type2 = $$type_name2type{$type_name2};
665 if (defined($type2)) {
666 return &$dereference_type($type2);
667 } else {
668 $output->write("$type_name2: warning: type not found\n");
669 return undef;
671 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
672 return undef;
673 } else {
674 $output->write("$type_name2: warning: type can't be parsed\n");
675 return undef;
679 my $type2 = &$dereference_type($type);
680 if (defined($type2)) {
681 my $type_name2 = $type2->name;
682 my $type_align2 = $type2->align;
683 my $type_size2 = $type2->size;
685 my $optional = $$type_name2optional{$type_name};
686 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
688 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
689 print OUT " TEST_TARGET_SIZE ($type_name, $type_size2)\n";
690 print OUT " TEST_TARGET_ALIGN($type_name, $type_align2)\n";
691 } else {
692 # $output->write("$type_name: warning: type size not found\n");
695 } elsif ($type_kind eq "signed") {
696 print OUT " TEST_TYPE_SIGNED ($type_name)\n";
697 } elsif ($type_kind eq "unsigned") {
698 print OUT " TEST_TYPE_UNSIGNED($type_name)\n";
702 sub output_test_pack_fields($$$$$$$);
703 sub output_test_pack_fields($$$$$$$) {
704 local *OUT = shift;
706 my $type_name2type = shift;
707 my $type_name2optional = shift;
708 my $type_name2optional_fields = shift;
709 my $type_name = shift;
710 my $type = shift;
711 my $offset = shift;
713 my $optional_fields = $$type_name2optional_fields{$type_name};
715 foreach my $field ($type->fields()) {
716 my $field_type_name = $field->type_name;
717 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
718 my $field_name = $field->name;
719 my $field_size = $field->size;
720 my $field_offset = $field->offset;
721 my $field_align = $field->align;
723 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
724 # We cannot take the address of a bitfield with MSVC
725 next if ($field_type_name =~ /:/);
727 if ($$optional_fields{$field_name}) {
728 # Nothing
729 } elsif (defined($field_size) && defined($field_offset)) {
730 $field_offset += $offset;
731 if ($field_name eq "DUMMYSTRUCTNAME") {
732 print OUT "#ifdef NONAMELESSSTRUCT\n";
733 print OUT " TEST_TYPE_SIZE ($type_name.$field_name, $field_size)\n";
734 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
735 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
736 print OUT "#else\n";
737 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
738 $type_name, $$type_name2type{$field_type_name}, $field_offset);
739 print OUT "#endif\n";
740 } else {
741 print OUT " TEST_FIELD_SIZE ($type_name, $field_name, $field_size)\n";
742 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
743 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
745 } else {
746 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
751 ########################################################################
752 # output_test_pack
754 sub output_test_pack($$$$) {
755 local *OUT = shift;
757 my $test_dir = shift;
758 my $test = shift;
760 my $type_names_used = shift;
762 $output->prefix("$test_dir: $test: ");
764 my @headers = $tests->get_section($test_dir, $test, "header");
765 my @type_names = $tests->get_section($test_dir, $test, "type");
767 my %type_name2optional;
768 my %type_name2optional_fields;
770 foreach my $_type_name (@type_names) {
771 my $type_name = $_type_name;
773 if ($type_name =~ s/^!//) {
774 $type_name2optional{$type_name}++;
777 my $optional_fields = {};
778 if ($type_name =~ s/:\s*(.*?)$//) {
779 my @fields = split /\s+/, $1;
780 foreach my $field (@fields) {
781 if ($field =~ s/^!//) {
782 $$optional_fields{$field}++;
787 $type_name2optional_fields{$type_name} = $optional_fields;
790 foreach my $header (@headers) {
791 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
793 foreach my $_type_name (@type_names) {
794 my $type_name = $_type_name;
796 my $skip = ($type_name =~ s/^!//);
797 $type_name =~ s/:.*?$//;
798 my $type = $$type_name2type{$type_name};
799 if (!defined($type)) {
800 next;
802 $$type_names_used{$type_name} = $skip ? -1 : 1;
803 next if $skip;
805 print OUT "static void test_${test}_$type_name(void)\n";
806 print OUT "{\n";
807 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
808 $type_name, $type);
809 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
810 $type_name, $type, 0);
811 print OUT "}\n";
812 print OUT "\n";
818 ########################################################################
819 # output_file
821 sub output_file($$$$) {
822 local *OUT = shift;
824 my $test_dir = shift;
825 my @tests = @{(shift)};
827 my $type_names_used = shift;
829 output_header(\*OUT, $test_dir, \@tests);
831 foreach my $test (@tests) {
832 my %type_names_used2;
834 if ($test eq "pack") {
835 print OUT "#ifdef _WIN64\n\n";
836 $pointer_size = 8;
837 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
838 print OUT "#else /* _WIN64 */\n\n";
839 $pointer_size = 4;
840 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
841 print OUT "#endif /* _WIN64 */\n\n";
842 } else {
843 die "no such test ($test)\n";
846 print OUT "static void test_$test(void)\n";
847 print OUT "{\n";
848 foreach my $type_name (sort(keys(%type_names_used2))) {
849 $$type_names_used{$type_name} = $type_names_used2{$type_name};
850 if ($type_names_used2{$type_name} > 0) {
851 print OUT " test_${test}_$type_name();\n";
854 print OUT "}\n";
855 print OUT "\n";
858 output_footer(\*OUT, $test_dir, \@tests);
860 return 1;
863 ########################################################################
864 # main
866 my %type_names_used = ();
868 my @test_dirs = $tests->get_test_dirs();
869 foreach my $test_dir (@test_dirs) {
870 my $file = "$wine_dir/$test_dir/generated.c";
871 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
874 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
875 $output->prefix("$header: ");
876 my $type_name2type = $file2types{$pointer_size}{$header};
877 foreach my $_type_name (sort(keys(%$type_name2type))) {
878 my $type_name = $_type_name;
880 if (!exists($type_names_used{$type_name})) {
881 $output->write("$type_name: type not used\n");
886 $output->prefix("$winapi_dir/tests.dat: ");
887 foreach my $type_name (sort(keys(%type_names_used))) {
888 my $found = 0;
889 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
890 if (exists($file2types{$pointer_size}{$header}{$type_name})) {
891 $found = 1;
892 last;
896 if (!$found) {
897 $output->write("$type_name: type not used\n");