wined3d: Avoid uploading deferred context maps more than once.
[wine.git] / tools / winapi / winapi_test
blobb9628e85154faddaadb875681f39c29b2223dfe1
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 foreach my $test (@tests) {
521 my @includes = $tests->get_section($test_dir, $test, "include");
522 foreach my $include (@includes) {
523 print OUT "#include $include\n";
526 print OUT "\n";
527 print OUT "#include \"wine/test.h\"\n";
528 print OUT "\n";
530 print OUT "/***********************************************************************\n";
531 print OUT " * Compatibility macros\n";
532 print OUT " */\n";
533 print OUT "\n";
534 print OUT "#define DWORD_PTR UINT_PTR\n";
535 print OUT "#define LONG_PTR INT_PTR\n";
536 print OUT "#define ULONG_PTR UINT_PTR\n";
537 print OUT "\n";
539 print OUT "/***********************************************************************\n";
540 print OUT " * Windows API extension\n";
541 print OUT " */\n";
542 print OUT "\n";
543 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
544 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
545 print OUT "#elif defined(__GNUC__) || defined(__clang__)\n";
546 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
547 print OUT "#else\n";
548 print OUT "/*\n";
549 print OUT " * FIXME: May not be possible without a compiler extension\n";
550 print OUT " * (if type is not just a name that is, otherwise the normal\n";
551 print OUT " * TYPE_ALIGNMENT can be used)\n";
552 print OUT " */\n";
553 print OUT "#endif\n";
554 print OUT "\n";
555 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
556 print OUT "#pragma warning(disable:4116)\n";
557 print OUT "#endif\n";
558 print OUT "\n";
559 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
560 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
561 print OUT "#endif\n";
562 print OUT "\n";
564 print OUT "/***********************************************************************\n";
565 print OUT " * Test helper macros\n";
566 print OUT " */\n";
567 print OUT "\n";
568 print OUT "#define TEST_TYPE_SIZE(type, size) C_ASSERT(sizeof(type) == size);\n";
569 print OUT "\n";
570 print OUT "#ifdef TYPE_ALIGNMENT\n";
571 print OUT "# define TEST_TYPE_ALIGN(type, align) C_ASSERT(TYPE_ALIGNMENT(type) == align);\n";
572 print OUT "#else\n";
573 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
574 print OUT "#endif\n";
575 print OUT "\n";
576 print OUT "#ifdef _TYPE_ALIGNMENT\n";
577 print OUT "# define TEST_TARGET_ALIGN(type, align) C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);\n";
578 print OUT "# define TEST_FIELD_ALIGN(type, field, align) C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);\n";
579 print OUT "#else\n";
580 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
581 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
582 print OUT "#endif\n";
583 print OUT "\n";
584 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);\n";
585 print OUT "\n";
586 print OUT "#define TEST_TARGET_SIZE(type, size) TEST_TYPE_SIZE(*(type)0, size)\n";
587 print OUT "#define TEST_FIELD_SIZE(type, field, size) TEST_TYPE_SIZE((((type*)0)->field), size)\n";
588 print OUT "#define TEST_TYPE_SIGNED(type) C_ASSERT((type) -1 < 0);\n";
589 print OUT "#define TEST_TYPE_UNSIGNED(type) C_ASSERT((type) -1 > 0);\n";
590 print OUT "\n";
591 print OUT "\n";
594 ########################################################################
595 # output_footer
597 sub output_footer($$$) {
598 local *OUT = shift;
600 my $test_dir = shift;
601 my @tests = @{(shift)};
603 print OUT "START_TEST(generated)\n";
604 print OUT "{\n";
605 foreach my $test (@tests) {
606 print OUT " test_$test();\n";
608 print OUT "}\n";
611 ########################################################################
612 # output_test_pack_type
614 sub output_test_pack_type($$$$$$) {
615 local *OUT = shift;
617 my $type_name2type = shift;
618 my $type_name2optional = shift;
619 my $type_name2optional_fields = shift;
620 my $type_name = shift;
621 my $type = shift;
623 my $optional_fields = $$type_name2optional_fields{$type_name};
625 my $type_align = $type->align;
626 my $type_pack = $type->pack;
627 my $type_size = $type->size;
628 my $type_kind = $type->kind;
630 if (defined($type_pack)) {
631 print OUT " /* $type_name (pack $type_pack) */\n";
632 } else {
633 print OUT " /* $type_name */\n";
636 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
637 print OUT " TEST_TYPE_SIZE ($type_name, $type_size)\n";
638 print OUT " TEST_TYPE_ALIGN ($type_name, $type_align)\n";
641 if ($type_kind eq "float") {
642 # Nothing
643 } elsif ($type_kind eq "pointer") {
644 my $dereference_type;
645 $dereference_type = sub {
646 my $type = shift;
648 my @fields = $type->fields;
649 my $type_name2 =$fields[0]->type_name;
651 if ($type_name2 =~ s/\s*\*$//) {
652 my $type2 = $$type_name2type{$type_name2};
653 if (defined($type2)) {
654 return $type2;
655 } else {
656 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
657 $output->write("$type_name2: warning: type not found 1\n");
659 return undef;
661 } elsif ($type_name2 =~ /^\w+$/) {
662 my $type2 = $$type_name2type{$type_name2};
663 if (defined($type2)) {
664 return &$dereference_type($type2);
665 } else {
666 $output->write("$type_name2: warning: type not found\n");
667 return undef;
669 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
670 return undef;
671 } else {
672 $output->write("$type_name2: warning: type can't be parsed\n");
673 return undef;
677 my $type2 = &$dereference_type($type);
678 if (defined($type2)) {
679 my $type_name2 = $type2->name;
680 my $type_align2 = $type2->align;
681 my $type_size2 = $type2->size;
683 my $optional = $$type_name2optional{$type_name};
684 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
686 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
687 print OUT " TEST_TARGET_SIZE ($type_name, $type_size2)\n";
688 print OUT " TEST_TARGET_ALIGN($type_name, $type_align2)\n";
689 } else {
690 # $output->write("$type_name: warning: type size not found\n");
693 } elsif ($type_kind eq "signed") {
694 print OUT " TEST_TYPE_SIGNED ($type_name)\n";
695 } elsif ($type_kind eq "unsigned") {
696 print OUT " TEST_TYPE_UNSIGNED($type_name)\n";
700 sub output_test_pack_fields($$$$$$$);
701 sub output_test_pack_fields($$$$$$$) {
702 local *OUT = shift;
704 my $type_name2type = shift;
705 my $type_name2optional = shift;
706 my $type_name2optional_fields = shift;
707 my $type_name = shift;
708 my $type = shift;
709 my $offset = shift;
711 my $optional_fields = $$type_name2optional_fields{$type_name};
713 foreach my $field ($type->fields()) {
714 my $field_type_name = $field->type_name;
715 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
716 my $field_name = $field->name;
717 my $field_size = $field->size;
718 my $field_offset = $field->offset;
719 my $field_align = $field->align;
721 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
722 # We cannot take the address of a bitfield with MSVC
723 next if ($field_type_name =~ /:/);
725 if ($$optional_fields{$field_name}) {
726 # Nothing
727 } elsif (defined($field_size) && defined($field_offset)) {
728 $field_offset += $offset;
729 if ($field_name eq "DUMMYSTRUCTNAME") {
730 print OUT "#ifdef NONAMELESSSTRUCT\n";
731 print OUT " TEST_TYPE_SIZE ($type_name.$field_name, $field_size)\n";
732 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
733 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
734 print OUT "#else\n";
735 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
736 $type_name, $$type_name2type{$field_type_name}, $field_offset);
737 print OUT "#endif\n";
738 } else {
739 print OUT " TEST_FIELD_SIZE ($type_name, $field_name, $field_size)\n";
740 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
741 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
743 } else {
744 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
749 ########################################################################
750 # output_test_pack
752 sub output_test_pack($$$$) {
753 local *OUT = shift;
755 my $test_dir = shift;
756 my $test = shift;
758 my $type_names_used = shift;
760 $output->prefix("$test_dir: $test: ");
762 my @headers = $tests->get_section($test_dir, $test, "header");
763 my @type_names = $tests->get_section($test_dir, $test, "type");
765 my %type_name2optional;
766 my %type_name2optional_fields;
768 foreach my $_type_name (@type_names) {
769 my $type_name = $_type_name;
771 if ($type_name =~ s/^!//) {
772 $type_name2optional{$type_name}++;
775 my $optional_fields = {};
776 if ($type_name =~ s/:\s*(.*?)$//) {
777 my @fields = split /\s+/, $1;
778 foreach my $field (@fields) {
779 if ($field =~ s/^!//) {
780 $$optional_fields{$field}++;
785 $type_name2optional_fields{$type_name} = $optional_fields;
788 foreach my $header (@headers) {
789 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
791 foreach my $_type_name (@type_names) {
792 my $type_name = $_type_name;
794 my $skip = ($type_name =~ s/^!//);
795 $type_name =~ s/:.*?$//;
796 my $type = $$type_name2type{$type_name};
797 if (!defined($type)) {
798 next;
800 $$type_names_used{$type_name} = $skip ? -1 : 1;
801 next if $skip;
803 print OUT "static void test_${test}_$type_name(void)\n";
804 print OUT "{\n";
805 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
806 $type_name, $type);
807 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
808 $type_name, $type, 0);
809 print OUT "}\n";
810 print OUT "\n";
816 ########################################################################
817 # output_file
819 sub output_file($$$$) {
820 local *OUT = shift;
822 my $test_dir = shift;
823 my @tests = @{(shift)};
825 my $type_names_used = shift;
827 output_header(\*OUT, $test_dir, \@tests);
829 foreach my $test (@tests) {
830 my %type_names_used2;
832 if ($test eq "pack") {
833 print OUT "#ifdef _WIN64\n\n";
834 $pointer_size = 8;
835 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
836 print OUT "#else /* _WIN64 */\n\n";
837 $pointer_size = 4;
838 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
839 print OUT "#endif /* _WIN64 */\n\n";
840 } else {
841 die "no such test ($test)\n";
844 print OUT "static void test_$test(void)\n";
845 print OUT "{\n";
846 foreach my $type_name (sort(keys(%type_names_used2))) {
847 $$type_names_used{$type_name} = $type_names_used2{$type_name};
848 if ($type_names_used2{$type_name} > 0) {
849 print OUT " test_${test}_$type_name();\n";
852 print OUT "}\n";
853 print OUT "\n";
856 output_footer(\*OUT, $test_dir, \@tests);
858 return 1;
861 ########################################################################
862 # main
864 my %type_names_used = ();
866 my @test_dirs = $tests->get_test_dirs();
867 foreach my $test_dir (@test_dirs) {
868 my $file = "$wine_dir/$test_dir/generated.c";
869 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
872 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
873 $output->prefix("$header: ");
874 my $type_name2type = $file2types{$pointer_size}{$header};
875 foreach my $_type_name (sort(keys(%$type_name2type))) {
876 my $type_name = $_type_name;
878 if (!exists($type_names_used{$type_name})) {
879 $output->write("$type_name: type not used\n");
884 $output->prefix("$winapi_dir/tests.dat: ");
885 foreach my $type_name (sort(keys(%type_names_used))) {
886 my $found = 0;
887 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
888 if (exists($file2types{$pointer_size}{$header}{$type_name})) {
889 $found = 1;
890 last;
894 if (!$found) {
895 $output->write("$type_name: type not used\n");