sane.ds: Update Portuguese (Brazilian) translation.
[wine/multimedia.git] / tools / winapi / winapi_test
blob878b1ebf478767385c45dc58e5fc03ed299b4237
1 #!/usr/bin/perl -w
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;
22 BEGIN {
23 $0 =~ m%^(.*?/?tools)/winapi/winapi_test$%;
24 require "$1/winapi/setup.pm";
27 use config qw(
28 file_type files_skip files_filter
29 $current_dir $wine_dir $winapi_dir
31 use output qw($output);
32 use winapi_test_options qw($options);
34 if($options->progress) {
35 $output->enable_progress;
36 } else {
37 $output->disable_progress;
40 use c_parser;
41 use tests qw($tests);
42 use type;
43 use util qw(replace_file);
45 my $pointer_size = 4;
47 my @tests = ();
48 if ($options->pack) {
49 push @tests, "pack";
52 my @files;
54 my %files;
56 foreach my $test (@tests)
58 foreach my $test_dir ($tests->get_test_dirs($test))
60 foreach my $header ($tests->get_section($test_dir, $test, "header"))
62 if (!$files{$header})
64 push @files, "include/$header";
65 $files{$header} = 1;
72 if (0) {
73 my $file = "tests.dat";
75 $file .= "2"; # FIXME: For tests
77 open(OUT, "> $winapi_dir/$file") || die "Error: Can't open $winapi_dir/$file: $!\n";
79 my $x = 0;
80 my @test_dirs = $tests->get_test_dirs();
81 foreach my $test_dir (@test_dirs) {
82 print OUT "\n" if $x++;
83 print OUT "%%%$test_dir\n";
84 print OUT "\n";
86 my $y = 0;
87 my @tests = $tests->get_tests($test_dir);
88 foreach my $test (@tests) {
89 print OUT "\n" if $y++;
90 print OUT "%%$test\n";
91 print OUT "\n";
93 my @types;
95 my $z = 0;
96 my @sections = $tests->get_sections($test_dir, $test);
97 foreach my $section (@sections) {
98 my @lines = $tests->get_section($test_dir, $test, $section);
100 if ($section =~ /^(?:struct|type)$/) {
101 foreach my $line (@lines) {
102 push @types, $line;
104 next;
107 print OUT "\n" if $z++;
108 print OUT "%$section\n";
109 print OUT "\n";
110 foreach my $line (@lines) {
111 print OUT "$line\n";
115 @types = sort { $x = $a; $y = $b; $x =~ s/^!//; $y =~ s/^!//; $x cmp $y } @types;
117 print OUT "\n" if $z++;
118 print OUT "%type\n";
119 print OUT "\n";
120 foreach my $type (@types) {
121 print OUT "$type\n";
126 close(OUT);
127 exit(0);
131 my %file2types;
133 my $progress_output;
134 my $progress_current = 0;
135 my $progress_max = scalar(@files);
137 ########################################################################
138 # find_type
140 my %type_name2type;
142 my %defines = (
143 "ANYSIZE_ARRAY" => 1,
144 "CCHDEVICENAME" => 32,
145 "CCHILDREN_TITLEBAR+1" => 6,
146 "ELF_VENDOR_SIZE" => 4,
147 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
148 "HW_PROFILE_GUIDLEN" => 39,
149 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
150 "IMAGE_SIZEOF_SHORT_NAME" => 8,
151 "LF_FACESIZE" => 32,
152 "LF_FULLFACESIZE" => 64,
153 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
154 "MAX_GOPHER_DISPLAY_TEXT + 1" => 129,
155 "MAX_GOPHER_LOCATOR_LENGTH + 1" => 654,
156 "MAX_PATH" => 260,
157 "MAX_PROFILE_LEN" => 80,
158 "NUM_POINTS" => 3,
159 "OFS_MAXPATHNAME" => 128,
160 "SIZE_OF_80387_REGISTERS" => 80,
161 "TOKEN_SOURCE_LENGTH" => 8,
164 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
165 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
166 my %size_parse_reported;
168 sub _find_align_kind_size($) {
169 my $type_name = shift;
171 local $_ = $type_name;
173 my $align;
174 my $kind;
175 my $size;
176 if (/\*+$/) {
177 $align = $pointer_size;
178 $kind = "pointer";
179 $size = $pointer_size;
180 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char|byte)$/) {
181 $align = 1;
182 $kind = defined($1) ? $1 : "signed";
183 $size = 1;
184 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
185 $align = 2;
186 $kind = defined($1) ? $1 : "signed";
187 $size = 2;
188 } elsif (/^(?:wchar_t)$/) {
189 $align = 2;
190 $kind = "signed";
191 $size = 2;
192 } elsif (/^(signed|unsigned)$/) {
193 $align = 4;
194 $kind = defined($1) ? $1 : "signed";
195 $size = 4;
196 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int32|int)$/) {
197 $align = 4;
198 $kind = defined($1) ? $1 : "signed";
199 $size = 4;
200 } elsif (/^(?:(signed|unsigned)\s+)?(?:long(?:\s+int)?)$/) {
201 $align = $pointer_size;
202 $kind = defined($1) ? $1 : "signed";
203 $size = $pointer_size;
204 } elsif (/^(?:float)$/) {
205 $align = 4;
206 $kind = "float";
207 $size = 4;
208 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
209 $align = 8;
210 $kind = defined($1) ? $1 : "signed";
211 $size = 8;
212 } elsif (/^(?:double|DOUBLE|DATE)$/) {
213 $align = 8;
214 $kind = "float";
215 $size = 8;
216 } elsif (/^(?:long\s+double)$/) {
217 $align = 4;
218 $kind = "float";
219 $size = 12;
220 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|KEY|MENU|METAFILE|WND)$/) {
221 $align = $pointer_size;
222 $kind = "pointer";
223 $size = $pointer_size;
224 } elsif (/^LP(?:BYTE|CSTR|CWSTR|DWORD|STR|VOID|WSTR)$/) {
225 $align = $pointer_size;
226 $kind = "pointer";
227 $size = $pointer_size;
228 } elsif (/^(?:FILETIME)$/) {
229 $align = 4;
230 $kind = "struct";
231 $size = 8;
232 } elsif (/^GUID$/) {
233 $align = 4;
234 $kind = "struct";
235 $size = 16;
236 } elsif (/^(?:VOID)$/) {
237 $align = 4;
238 $kind = "signed";
239 $size = 4;
240 } elsif (/^(?:SHORT)$/) {
241 $align = 2;
242 $kind = "unsigned";
243 $size = 2;
244 } elsif (/^(?:BYTE)$/) {
245 $align = 1;
246 $kind = "unsigned";
247 $size = 1;
248 } elsif (/^(?:DWORD)$/) {
249 $align = 4;
250 $kind = "unsigned";
251 $size = 4;
252 } elsif (/^(?:WORD)$/) {
253 $align = 2;
254 $kind = "unsigned";
255 $size = 2;
256 } elsif (/^(?:INT64|LONG64|LONGLONG)$/) {
257 $align = 8;
258 $kind = "signed";
259 $size = 8;
260 } elsif (/^(?:UINT64|ULONG64|DWORD64|ULONGLONG|DWORDLONG)$/) {
261 $align = 8;
262 $kind = "unsigned";
263 $size = 8;
264 } elsif (/^(?:LARGE_INTEGER)$/) {
265 $align = 8;
266 $kind = "union";
267 $size = 8;
268 } elsif (/^(?:POINTS)$/) {
269 $align = 2;
270 $kind = "struct";
271 $size = 4;
272 } elsif (/^(struct|union)$/) {
273 $kind = $1;
274 if (!$size_parse_reported{$_}) {
275 $output->write("$type_name: can't parse type\n");
276 $size_parse_reported{$_} = 1;
278 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
279 $align = $pointer_size;
280 $kind = "pointer";
281 $size = $pointer_size;
284 my $align2;
285 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
286 $align2 = $type->align;
289 if (!defined($align)) {
290 $align = $align2;
291 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
292 $align_kludge_reported{$_} = 1;
293 $output->write("$type_name: type needn't be kludged\n");
296 if (!defined($align)) {
297 # $output->write("$type_name: can't find type\n");
300 my $size2;
301 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
302 $size2 = $type->size;
305 if (!defined($size)) {
306 $size = $size2;
307 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
308 $size_kludge_reported{$_} = 1;
309 $output->write("$type_name: type needn't be kludged\n");
312 return ($align, $kind, $size);
315 sub find_align($) {
316 my $type_name = shift;
317 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
318 return $align;
321 sub find_kind($) {
322 my $type_name = shift;
323 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
325 return $kind;
328 sub find_size($) {
329 my $type_name = shift;
330 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
331 return $size;
334 sub find_count($) {
335 my $count = shift;
336 return $defines{$count};
339 foreach my $file (@files) {
340 $progress_current++;
341 foreach my $ptr (4, 8) {
342 $pointer_size = $ptr;
345 open(IN, "< $wine_dir/$file") || die "Error: Can't open $wine_dir/$file: $!\n";
346 local $/ = undef;
347 $_ = <IN>;
348 close(IN);
351 my $max_line = 0;
353 local $_ = $_;
354 while(s/^.*?\n//) { $max_line++; }
355 if($_) { $max_line++; }
358 my $parser = new c_parser($file);
360 my $line;
361 my $type;
362 my @packs = ();
363 my @ifdefs = ();
365 my $update_output = sub {
366 my $progress = "";
367 my $prefix = "";
369 $progress .= "$file (file $progress_current of $progress_max" . sprintf ", %u-bit)", $pointer_size * 8;
370 $prefix .= "$file: ";
372 if(defined($line)) {
373 $progress .= ": line $line of $max_line";
376 $output->progress($progress);
377 $output->prefix($prefix);
380 &$update_output();
382 my $found_line = sub {
383 $line = shift;
385 &$update_output;
387 $parser->set_found_line_callback($found_line);
389 my $found_preprocessor = sub {
390 my $begin_line = shift;
391 my $begin_column = shift;
392 my $preprocessor = shift;
394 #print "found_preprocessor: $begin_line: [$_]\n";
395 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d+)\.h[\">]$/) {
396 push @packs, $1 unless @ifdefs && !$ifdefs[$#ifdefs];
397 #print "found pack $1 on line $begin_line\n";
398 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
399 pop @packs unless @ifdefs && !$ifdefs[$#ifdefs];
400 #print "found poppack on line $begin_line\n";
401 } elsif ($preprocessor =~ /^\#\s*ifdef\s+_WIN64/) {
402 push @ifdefs, ($pointer_size == 8);
403 } elsif ($preprocessor =~ /^\#\s*ifndef\s+_WIN64/) {
404 push @ifdefs, ($pointer_size == 4);
405 } elsif ($preprocessor =~ /^\#\s*elif\s+defined(_WIN64)/) {
406 $ifdefs[$#ifdefs] = ($pointer_size == 8);
407 } elsif ($preprocessor =~ /^\#\s*ifdef\s/) {
408 push @ifdefs, 2;
409 } elsif ($preprocessor =~ /^\#\s*ifndef\s/) {
410 push @ifdefs, 2;
411 } elsif ($preprocessor =~ /^\#\s*if/) {
412 push @ifdefs, 2;
413 } elsif ($preprocessor =~ /^\#\s*else/) {
414 $ifdefs[$#ifdefs] = $ifdefs[$#ifdefs] ^ 1;
415 } elsif ($preprocessor =~ /^\#\s*elif/) {
416 $ifdefs[$#ifdefs] = 2;
417 } elsif ($preprocessor =~ /^\#\s*endif/) {
418 pop @ifdefs;
420 return 1;
422 $parser->set_found_preprocessor_callback($found_preprocessor);
424 my $found_type = sub {
425 $type = shift;
426 return if @ifdefs && !$ifdefs[$#ifdefs];
428 &$update_output();
430 my $name = $type->name;
431 $file2types{$pointer_size}{$file}{$name} = $type;
433 $type->set_find_align_callback(\&find_align);
434 $type->set_find_kind_callback(\&find_kind);
435 $type->set_find_size_callback(\&find_size);
436 $type->set_find_count_callback(\&find_count);
438 my $pack = $packs[$#packs];
439 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
440 $type->pack($pack);
442 my $size = $type->size();
443 if (defined($size)) {
444 my $max_field_base_size = 0;
446 foreach my $field ($type->fields()) {
447 my $field_type_name = $field->type_name;
448 my $field_name = $field->name;
449 my $field_size = $field->size;
450 my $field_base_size = $field->base_size;
451 my $field_offset = $field->offset;
452 my $field_align = $field->align;
454 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
456 # $output->write("$name: $size\n");
458 $type_name2type{$pointer_size}{$name} = $type;
459 } else {
460 # $output->write("$name: can't find size\n");
463 return 1;
465 $parser->set_found_type_callback($found_type);
468 my $line = 1;
469 my $column = 0;
470 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
471 $output->write("can't parse file\n");
475 $output->prefix("");
479 ########################################################################
480 # output_header
482 sub output_header($$$) {
483 local *OUT = shift;
485 my $test_dir = shift;
486 my @tests = @{(shift)};
488 print OUT "/* File generated automatically from tools/winapi/tests.dat; do not edit! */\n";
489 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
490 print OUT "\n";
492 print OUT "/*\n";
493 foreach my $test (@tests) {
494 my @description = $tests->get_section($test_dir, $test, "description");
495 foreach my $description (@description) {
496 print OUT " * $description\n";
499 print OUT " */\n";
500 print OUT "\n";
502 print OUT "#define WINVER 0x0501\n";
503 print OUT "#define _WIN32_IE 0x0501\n";
504 print OUT "#define _WIN32_WINNT 0x0501\n";
505 print OUT "\n";
506 print OUT "#define WINE_NOWINSOCK\n";
507 print OUT "\n";
508 foreach my $test (@tests) {
509 my @includes = $tests->get_section($test_dir, $test, "include");
510 foreach my $include (@includes) {
511 print OUT "#include $include\n";
514 print OUT "\n";
515 print OUT "#include \"wine/test.h\"\n";
516 print OUT "\n";
518 print OUT "/***********************************************************************\n";
519 print OUT " * Compatibility macros\n";
520 print OUT " */\n";
521 print OUT "\n";
522 print OUT "#define DWORD_PTR UINT_PTR\n";
523 print OUT "#define LONG_PTR INT_PTR\n";
524 print OUT "#define ULONG_PTR UINT_PTR\n";
525 print OUT "\n";
527 print OUT "/***********************************************************************\n";
528 print OUT " * Windows API extension\n";
529 print OUT " */\n";
530 print OUT "\n";
531 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
532 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
533 print OUT "#elif defined(__GNUC__)\n";
534 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
535 print OUT "#else\n";
536 print OUT "/*\n";
537 print OUT " * FIXME: May not be possible without a compiler extension\n";
538 print OUT " * (if type is not just a name that is, otherwise the normal\n";
539 print OUT " * TYPE_ALIGNMENT can be used)\n";
540 print OUT " */\n";
541 print OUT "#endif\n";
542 print OUT "\n";
543 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
544 print OUT "#pragma warning(disable:4116)\n";
545 print OUT "#endif\n";
546 print OUT "\n";
547 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
548 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
549 print OUT "#endif\n";
550 print OUT "\n";
552 print OUT "/***********************************************************************\n";
553 print OUT " * Test helper macros\n";
554 print OUT " */\n";
555 print OUT "\n";
556 print OUT "#define TEST_TYPE_SIZE(type, size) C_ASSERT(sizeof(type) == size);\n";
557 print OUT "\n";
558 print OUT "#ifdef TYPE_ALIGNMENT\n";
559 print OUT "# define TEST_TYPE_ALIGN(type, align) C_ASSERT(TYPE_ALIGNMENT(type) == align);\n";
560 print OUT "#else\n";
561 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
562 print OUT "#endif\n";
563 print OUT "\n";
564 print OUT "#ifdef _TYPE_ALIGNMENT\n";
565 print OUT "# define TEST_TARGET_ALIGN(type, align) C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);\n";
566 print OUT "# define TEST_FIELD_ALIGN(type, field, align) C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);\n";
567 print OUT "#else\n";
568 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
569 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
570 print OUT "#endif\n";
571 print OUT "\n";
572 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);\n";
573 print OUT "\n";
574 print OUT "#define TEST_TARGET_SIZE(type, size) TEST_TYPE_SIZE(*(type)0, size)\n";
575 print OUT "#define TEST_FIELD_SIZE(type, field, size) TEST_TYPE_SIZE((((type*)0)->field), size)\n";
576 print OUT "#define TEST_TYPE_SIGNED(type) C_ASSERT((type) -1 < 0);\n";
577 print OUT "#define TEST_TYPE_UNSIGNED(type) C_ASSERT((type) -1 > 0);\n";
578 print OUT "\n";
579 print OUT "\n";
582 ########################################################################
583 # output_footer
585 sub output_footer($$$) {
586 local *OUT = shift;
588 my $test_dir = shift;
589 my @tests = @{(shift)};
591 print OUT "START_TEST(generated)\n";
592 print OUT "{\n";
593 foreach my $test (@tests) {
594 print OUT " test_$test();\n";
596 print OUT "}\n";
599 ########################################################################
600 # output_test_pack_type
602 sub output_test_pack_type($$$$$$) {
603 local *OUT = shift;
605 my $type_name2type = shift;
606 my $type_name2optional = shift;
607 my $type_name2optional_fields = shift;
608 my $type_name = shift;
609 my $type = shift;
611 my $optional_fields = $$type_name2optional_fields{$type_name};
613 my $type_align = $type->align;
614 my $type_pack = $type->pack;
615 my $type_size = $type->size;
616 my $type_kind = $type->kind;
618 if (defined($type_pack)) {
619 print OUT " /* $type_name (pack $type_pack) */\n";
620 } else {
621 print OUT " /* $type_name */\n";
624 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
625 print OUT " TEST_TYPE_SIZE ($type_name, $type_size)\n";
626 print OUT " TEST_TYPE_ALIGN ($type_name, $type_align)\n";
629 if ($type_kind eq "float") {
630 # Nothing
631 } elsif ($type_kind eq "pointer") {
632 my $dereference_type;
633 $dereference_type = sub {
634 my $type = shift;
636 my @fields = $type->fields;
637 my $type_name2 =$fields[0]->type_name;
639 if ($type_name2 =~ s/\s*\*$//) {
640 my $type2 = $$type_name2type{$type_name2};
641 if (defined($type2)) {
642 return $type2;
643 } else {
644 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
645 $output->write("$type_name2: warning: type not found 1\n");
647 return undef;
649 } elsif ($type_name2 =~ /^\w+$/) {
650 my $type2 = $$type_name2type{$type_name2};
651 if (defined($type2)) {
652 return &$dereference_type($type2);
653 } else {
654 $output->write("$type_name2: warning: type not found\n");
655 return undef;
657 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
658 return undef;
659 } else {
660 $output->write("$type_name2: warning: type can't be parsed\n");
661 return undef;
665 my $type2 = &$dereference_type($type);
666 if (defined($type2)) {
667 my $type_name2 = $type2->name;
668 my $type_align2 = $type2->align;
669 my $type_size2 = $type2->size;
671 my $optional = $$type_name2optional{$type_name};
672 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
674 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
675 print OUT " TEST_TARGET_SIZE ($type_name, $type_size2)\n";
676 print OUT " TEST_TARGET_ALIGN($type_name, $type_align2)\n";
677 } else {
678 # $output->write("$type_name: warning: type size not found\n");
681 } elsif ($type_kind eq "signed") {
682 print OUT " TEST_TYPE_SIGNED($type_name)\n";
683 } elsif ($type_kind eq "unsigned") {
684 print OUT " TEST_TYPE_UNSIGNED($type_name)\n";
688 sub output_test_pack_fields($$$$$$$);
689 sub output_test_pack_fields($$$$$$$) {
690 local *OUT = shift;
692 my $type_name2type = shift;
693 my $type_name2optional = shift;
694 my $type_name2optional_fields = shift;
695 my $type_name = shift;
696 my $type = shift;
697 my $offset = shift;
699 my $optional_fields = $$type_name2optional_fields{$type_name};
701 foreach my $field ($type->fields()) {
702 my $field_type_name = $field->type_name;
703 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
704 my $field_name = $field->name;
705 my $field_size = $field->size;
706 my $field_offset = $field->offset;
707 my $field_align = $field->align;
709 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
710 # We cannot take the address of a bitfield with MSVC
711 next if ($field_type_name =~ /:/);
713 if ($$optional_fields{$field_name}) {
714 # Nothing
715 } elsif (defined($field_size) && defined($field_offset)) {
716 $field_offset += $offset;
717 if ($field_name eq "DUMMYSTRUCTNAME") {
718 print OUT "#ifdef NONAMELESSSTRUCT\n";
719 print OUT " TEST_TYPE_SIZE ($type_name.$field_name, $field_size)\n";
720 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
721 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
722 print OUT "#else\n";
723 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
724 $type_name, $$type_name2type{$field_type_name}, $field_offset);
725 print OUT "#endif\n";
726 } else {
727 print OUT " TEST_FIELD_SIZE ($type_name, $field_name, $field_size)\n";
728 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
729 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
731 } else {
732 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
737 ########################################################################
738 # output_test_pack
740 sub output_test_pack($$$$) {
741 local *OUT = shift;
743 my $test_dir = shift;
744 my $test = shift;
746 my $type_names_used = shift;
748 $output->prefix("$test_dir: $test: ");
750 my @headers = $tests->get_section($test_dir, $test, "header");
751 my @type_names = $tests->get_section($test_dir, $test, "type");
753 my %type_name2optional;
754 my %type_name2optional_fields;
756 foreach my $_type_name (@type_names) {
757 my $type_name = $_type_name;
759 if ($type_name =~ s/^!//) {
760 $type_name2optional{$type_name}++;
763 my $optional_fields = {};
764 if ($type_name =~ s/:\s*(.*?)$//) {
765 my @fields = split /\s+/, $1;
766 foreach my $field (@fields) {
767 if ($field =~ s/^!//) {
768 $$optional_fields{$field}++;
773 $type_name2optional_fields{$type_name} = $optional_fields;
776 foreach my $header (@headers) {
777 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
779 foreach my $_type_name (@type_names) {
780 my $type_name = $_type_name;
782 my $skip = ($type_name =~ s/^!//);
783 $type_name =~ s/:.*?$//;
784 my $type = $$type_name2type{$type_name};
785 if (!defined($type)) {
786 next;
788 $$type_names_used{$type_name} = $skip ? -1 : 1;
789 next if $skip;
791 print OUT "static void test_${test}_$type_name(void)\n";
792 print OUT "{\n";
793 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
794 $type_name, $type);
795 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
796 $type_name, $type, 0);
797 print OUT "}\n";
798 print OUT "\n";
804 ########################################################################
805 # output_file
807 sub output_file($$$$) {
808 local *OUT = shift;
810 my $test_dir = shift;
811 my @tests = @{(shift)};
813 my $type_names_used = shift;
815 output_header(\*OUT, $test_dir, \@tests);
817 foreach my $test (@tests) {
818 my %type_names_used2;
820 if ($test eq "pack") {
821 print OUT "#ifdef _WIN64\n\n";
822 $pointer_size = 8;
823 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
824 print OUT "#else /* _WIN64 */\n\n";
825 $pointer_size = 4;
826 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
827 print OUT "#endif /* _WIN64 */\n\n";
828 } else {
829 die "no such test ($test)\n";
832 print OUT "static void test_$test(void)\n";
833 print OUT "{\n";
834 foreach my $type_name (sort(keys(%type_names_used2))) {
835 $$type_names_used{$type_name} = $type_names_used2{$type_name};
836 if ($type_names_used2{$type_name} > 0) {
837 print OUT " test_${test}_$type_name();\n";
840 print OUT "}\n";
841 print OUT "\n";
844 output_footer(\*OUT, $test_dir, \@tests);
846 return 1;
849 ########################################################################
850 # main
852 my %type_names_used = ();
854 my @test_dirs = $tests->get_test_dirs();
855 foreach my $test_dir (@test_dirs) {
856 my $file = "$wine_dir/$test_dir/generated.c";
857 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
860 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
861 $output->prefix("$header: ");
862 $header =~ s%^include/%%;
863 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
864 foreach my $_type_name (sort(keys(%$type_name2type))) {
865 my $type_name = $_type_name;
867 if (!exists($type_names_used{$type_name})) {
868 $output->write("$type_name: type not used\n");
873 $output->prefix("$winapi_dir/tests.dat: ");
874 foreach my $type_name (sort(keys(%type_names_used))) {
875 my $found = 0;
876 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
877 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
878 if (exists($type_name2type{$type_name})) {
879 $found = 1;
883 if (!$found) {
884 $output->write("$type_name: type not used\n");