Release 1.6-rc2.
[wine/testsucceed.git] / tools / winapi / winapi_test
blob92f4ae366af9ed4653edfcdad83e28d13bdf49a8
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(/^char$/) {
181 $align = 1;
182 $kind = "char";
183 $size = 1;
184 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char|byte)$/) {
185 $align = 1;
186 $kind = defined($1) ? $1 : "signed";
187 $size = 1;
188 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
189 $align = 2;
190 $kind = defined($1) ? $1 : "signed";
191 $size = 2;
192 } elsif (/^(?:wchar_t)$/) {
193 $align = 2;
194 $kind = "signed";
195 $size = 2;
196 } elsif (/^(signed|unsigned)$/) {
197 $align = 4;
198 $kind = defined($1) ? $1 : "signed";
199 $size = 4;
200 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int32|int)$/) {
201 $align = 4;
202 $kind = defined($1) ? $1 : "signed";
203 $size = 4;
204 } elsif (/^(?:(signed|unsigned)\s+)?(?:long(?:\s+int)?)$/) {
205 $align = $pointer_size;
206 $kind = defined($1) ? $1 : "signed";
207 $size = $pointer_size;
208 } elsif (/^(?:float)$/) {
209 $align = 4;
210 $kind = "float";
211 $size = 4;
212 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
213 $align = 8;
214 $kind = defined($1) ? $1 : "signed";
215 $size = 8;
216 } elsif (/^(?:double|DOUBLE|DATE)$/) {
217 $align = 8;
218 $kind = "float";
219 $size = 8;
220 } elsif (/^(?:long\s+double)$/) {
221 $align = 4;
222 $kind = "float";
223 $size = 12;
224 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|KEY|MENU|METAFILE|WND)$/) {
225 $align = $pointer_size;
226 $kind = "pointer";
227 $size = $pointer_size;
228 } elsif (/^LP(?:BYTE|CSTR|CWSTR|DWORD|STR|VOID|WSTR)$/) {
229 $align = $pointer_size;
230 $kind = "pointer";
231 $size = $pointer_size;
232 } elsif (/^(?:FILETIME)$/) {
233 $align = 4;
234 $kind = "struct";
235 $size = 8;
236 } elsif (/^GUID$/) {
237 $align = 4;
238 $kind = "struct";
239 $size = 16;
240 } elsif (/^(?:VOID)$/) {
241 $align = 4;
242 $kind = "signed";
243 $size = 4;
244 } elsif (/^(?:SHORT)$/) {
245 $align = 2;
246 $kind = "unsigned";
247 $size = 2;
248 } elsif (/^(?:BYTE)$/) {
249 $align = 1;
250 $kind = "unsigned";
251 $size = 1;
252 } elsif (/^(?:DWORD)$/) {
253 $align = 4;
254 $kind = "unsigned";
255 $size = 4;
256 } elsif (/^(?:WORD)$/) {
257 $align = 2;
258 $kind = "unsigned";
259 $size = 2;
260 } elsif (/^(?:INT64|LONG64|LONGLONG)$/) {
261 $align = 8;
262 $kind = "signed";
263 $size = 8;
264 } elsif (/^(?:UINT64|ULONG64|DWORD64|ULONGLONG|DWORDLONG)$/) {
265 $align = 8;
266 $kind = "unsigned";
267 $size = 8;
268 } elsif (/^(?:LARGE_INTEGER)$/) {
269 $align = 8;
270 $kind = "union";
271 $size = 8;
272 } elsif (/^(?:POINTS)$/) {
273 $align = 2;
274 $kind = "struct";
275 $size = 4;
276 } elsif (/^(struct|union)$/) {
277 $kind = $1;
278 if (!$size_parse_reported{$_}) {
279 $output->write("$type_name: can't parse type\n");
280 $size_parse_reported{$_} = 1;
282 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
283 $align = $pointer_size;
284 $kind = "pointer";
285 $size = $pointer_size;
288 my $align2;
289 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
290 $align2 = $type->align;
293 if (!defined($align)) {
294 $align = $align2;
295 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
296 $align_kludge_reported{$_} = 1;
297 $output->write("$type_name: type needn't be kludged\n");
300 if (!defined($align)) {
301 # $output->write("$type_name: can't find type\n");
304 my $size2;
305 if (defined(my $type = $type_name2type{$pointer_size}{$_})) {
306 $size2 = $type->size;
309 if (!defined($size)) {
310 $size = $size2;
311 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
312 $size_kludge_reported{$_} = 1;
313 $output->write("$type_name: type needn't be kludged\n");
316 return ($align, $kind, $size);
319 sub find_align($) {
320 my $type_name = shift;
321 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
322 return $align;
325 sub find_kind($) {
326 my $type_name = shift;
327 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
329 return $kind;
332 sub find_size($) {
333 my $type_name = shift;
334 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
335 return $size;
338 sub find_count($) {
339 my $count = shift;
340 return $defines{$count};
343 foreach my $file (@files) {
344 $progress_current++;
345 foreach my $ptr (4, 8) {
346 $pointer_size = $ptr;
349 open(IN, "< $wine_dir/$file") || die "Error: Can't open $wine_dir/$file: $!\n";
350 local $/ = undef;
351 $_ = <IN>;
352 close(IN);
355 my $max_line = 0;
357 local $_ = $_;
358 while(s/^.*?\n//) { $max_line++; }
359 if($_) { $max_line++; }
362 my $parser = new c_parser($file);
364 my $line;
365 my $type;
366 my @packs = ();
367 my @ifdefs = ();
369 my $update_output = sub {
370 my $progress = "";
371 my $prefix = "";
373 $progress .= "$file (file $progress_current of $progress_max" . sprintf ", %u-bit)", $pointer_size * 8;
374 $prefix .= "$file: ";
376 if(defined($line)) {
377 $progress .= ": line $line of $max_line";
380 $output->progress($progress);
381 $output->prefix($prefix);
384 &$update_output();
386 my $found_line = sub {
387 $line = shift;
389 &$update_output;
391 $parser->set_found_line_callback($found_line);
393 my $found_preprocessor = sub {
394 my $begin_line = shift;
395 my $begin_column = shift;
396 my $preprocessor = shift;
398 #print "found_preprocessor: $begin_line: [$_]\n";
399 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d+)\.h[\">]$/) {
400 push @packs, $1 unless @ifdefs && !$ifdefs[$#ifdefs];
401 #print "found pack $1 on line $begin_line\n";
402 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
403 pop @packs unless @ifdefs && !$ifdefs[$#ifdefs];
404 #print "found poppack on line $begin_line\n";
405 } elsif ($preprocessor =~ /^\#\s*ifdef\s+_WIN64/) {
406 push @ifdefs, ($pointer_size == 8);
407 } elsif ($preprocessor =~ /^\#\s*ifndef\s+_WIN64/) {
408 push @ifdefs, ($pointer_size == 4);
409 } elsif ($preprocessor =~ /^\#\s*elif\s+defined(_WIN64)/) {
410 $ifdefs[$#ifdefs] = ($pointer_size == 8);
411 } elsif ($preprocessor =~ /^\#\s*ifdef\s/) {
412 push @ifdefs, 2;
413 } elsif ($preprocessor =~ /^\#\s*ifndef\s/) {
414 push @ifdefs, 2;
415 } elsif ($preprocessor =~ /^\#\s*if/) {
416 push @ifdefs, 2;
417 } elsif ($preprocessor =~ /^\#\s*else/) {
418 $ifdefs[$#ifdefs] = $ifdefs[$#ifdefs] ^ 1;
419 } elsif ($preprocessor =~ /^\#\s*elif/) {
420 $ifdefs[$#ifdefs] = 2;
421 } elsif ($preprocessor =~ /^\#\s*endif/) {
422 pop @ifdefs;
424 return 1;
426 $parser->set_found_preprocessor_callback($found_preprocessor);
428 my $found_type = sub {
429 $type = shift;
430 return if @ifdefs && !$ifdefs[$#ifdefs];
432 &$update_output();
434 my $name = $type->name;
435 $file2types{$pointer_size}{$file}{$name} = $type;
437 $type->set_find_align_callback(\&find_align);
438 $type->set_find_kind_callback(\&find_kind);
439 $type->set_find_size_callback(\&find_size);
440 $type->set_find_count_callback(\&find_count);
442 my $pack = $packs[$#packs];
443 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
444 $type->pack($pack);
446 my $size = $type->size();
447 if (defined($size)) {
448 my $max_field_base_size = 0;
450 foreach my $field ($type->fields()) {
451 my $field_type_name = $field->type_name;
452 my $field_name = $field->name;
453 my $field_size = $field->size;
454 my $field_base_size = $field->base_size;
455 my $field_offset = $field->offset;
456 my $field_align = $field->align;
458 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
460 # $output->write("$name: $size\n");
462 $type_name2type{$pointer_size}{$name} = $type;
463 } else {
464 # $output->write("$name: can't find size\n");
467 return 1;
469 $parser->set_found_type_callback($found_type);
472 my $line = 1;
473 my $column = 0;
474 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
475 $output->write("can't parse file\n");
479 $output->prefix("");
483 ########################################################################
484 # output_header
486 sub output_header($$$) {
487 local *OUT = shift;
489 my $test_dir = shift;
490 my @tests = @{(shift)};
492 print OUT "/* File generated automatically from tools/winapi/tests.dat; do not edit! */\n";
493 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
494 print OUT "\n";
496 print OUT "/*\n";
497 foreach my $test (@tests) {
498 my @description = $tests->get_section($test_dir, $test, "description");
499 foreach my $description (@description) {
500 print OUT " * $description\n";
503 print OUT " */\n";
504 print OUT "\n";
506 print OUT "#define WINVER 0x0501\n";
507 print OUT "#define _WIN32_IE 0x0501\n";
508 print OUT "#define _WIN32_WINNT 0x0501\n";
509 print OUT "\n";
510 print OUT "#define WINE_NOWINSOCK\n";
511 print OUT "\n";
512 foreach my $test (@tests) {
513 my @includes = $tests->get_section($test_dir, $test, "include");
514 foreach my $include (@includes) {
515 print OUT "#include $include\n";
518 print OUT "\n";
519 print OUT "#include \"wine/test.h\"\n";
520 print OUT "\n";
522 print OUT "/***********************************************************************\n";
523 print OUT " * Compatibility macros\n";
524 print OUT " */\n";
525 print OUT "\n";
526 print OUT "#define DWORD_PTR UINT_PTR\n";
527 print OUT "#define LONG_PTR INT_PTR\n";
528 print OUT "#define ULONG_PTR UINT_PTR\n";
529 print OUT "\n";
531 print OUT "/***********************************************************************\n";
532 print OUT " * Windows API extension\n";
533 print OUT " */\n";
534 print OUT "\n";
535 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
536 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
537 print OUT "#elif defined(__GNUC__)\n";
538 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
539 print OUT "#else\n";
540 print OUT "/*\n";
541 print OUT " * FIXME: May not be possible without a compiler extension\n";
542 print OUT " * (if type is not just a name that is, otherwise the normal\n";
543 print OUT " * TYPE_ALIGNMENT can be used)\n";
544 print OUT " */\n";
545 print OUT "#endif\n";
546 print OUT "\n";
547 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
548 print OUT "#pragma warning(disable:4116)\n";
549 print OUT "#endif\n";
550 print OUT "\n";
551 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
552 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
553 print OUT "#endif\n";
554 print OUT "\n";
556 print OUT "/***********************************************************************\n";
557 print OUT " * Test helper macros\n";
558 print OUT " */\n";
559 print OUT "\n";
560 print OUT "#define TEST_TYPE_SIZE(type, size) C_ASSERT(sizeof(type) == size);\n";
561 print OUT "\n";
562 print OUT "#ifdef TYPE_ALIGNMENT\n";
563 print OUT "# define TEST_TYPE_ALIGN(type, align) C_ASSERT(TYPE_ALIGNMENT(type) == align);\n";
564 print OUT "#else\n";
565 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
566 print OUT "#endif\n";
567 print OUT "\n";
568 print OUT "#ifdef _TYPE_ALIGNMENT\n";
569 print OUT "# define TEST_TARGET_ALIGN(type, align) C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);\n";
570 print OUT "# define TEST_FIELD_ALIGN(type, field, align) C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);\n";
571 print OUT "#else\n";
572 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
573 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
574 print OUT "#endif\n";
575 print OUT "\n";
576 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);\n";
577 print OUT "\n";
578 print OUT "#define TEST_TARGET_SIZE(type, size) TEST_TYPE_SIZE(*(type)0, size)\n";
579 print OUT "#define TEST_FIELD_SIZE(type, field, size) TEST_TYPE_SIZE((((type*)0)->field), size)\n";
580 print OUT "#define TEST_TYPE_SIGNED(type) C_ASSERT((type) -1 < 0);\n";
581 print OUT "#define TEST_TYPE_UNSIGNED(type) C_ASSERT((type) -1 > 0);\n";
582 print OUT "\n";
583 print OUT "\n";
586 ########################################################################
587 # output_footer
589 sub output_footer($$$) {
590 local *OUT = shift;
592 my $test_dir = shift;
593 my @tests = @{(shift)};
595 print OUT "START_TEST(generated)\n";
596 print OUT "{\n";
597 foreach my $test (@tests) {
598 print OUT " test_$test();\n";
600 print OUT "}\n";
603 ########################################################################
604 # output_test_pack_type
606 sub output_test_pack_type($$$$$$) {
607 local *OUT = shift;
609 my $type_name2type = shift;
610 my $type_name2optional = shift;
611 my $type_name2optional_fields = shift;
612 my $type_name = shift;
613 my $type = shift;
615 my $optional_fields = $$type_name2optional_fields{$type_name};
617 my $type_align = $type->align;
618 my $type_pack = $type->pack;
619 my $type_size = $type->size;
620 my $type_kind = $type->kind;
622 if (defined($type_pack)) {
623 print OUT " /* $type_name (pack $type_pack) */\n";
624 } else {
625 print OUT " /* $type_name */\n";
628 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
629 print OUT " TEST_TYPE_SIZE ($type_name, $type_size)\n";
630 print OUT " TEST_TYPE_ALIGN ($type_name, $type_align)\n";
633 if ($type_kind eq "float") {
634 # Nothing
635 } elsif ($type_kind eq "pointer") {
636 my $dereference_type;
637 $dereference_type = sub {
638 my $type = shift;
640 my @fields = $type->fields;
641 my $type_name2 =$fields[0]->type_name;
643 if ($type_name2 =~ s/\s*\*$//) {
644 my $type2 = $$type_name2type{$type_name2};
645 if (defined($type2)) {
646 return $type2;
647 } else {
648 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
649 $output->write("$type_name2: warning: type not found 1\n");
651 return undef;
653 } elsif ($type_name2 =~ /^\w+$/) {
654 my $type2 = $$type_name2type{$type_name2};
655 if (defined($type2)) {
656 return &$dereference_type($type2);
657 } else {
658 $output->write("$type_name2: warning: type not found\n");
659 return undef;
661 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
662 return undef;
663 } else {
664 $output->write("$type_name2: warning: type can't be parsed\n");
665 return undef;
669 my $type2 = &$dereference_type($type);
670 if (defined($type2)) {
671 my $type_name2 = $type2->name;
672 my $type_align2 = $type2->align;
673 my $type_size2 = $type2->size;
675 my $optional = $$type_name2optional{$type_name};
676 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
678 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
679 print OUT " TEST_TARGET_SIZE ($type_name, $type_size2)\n";
680 print OUT " TEST_TARGET_ALIGN($type_name, $type_align2)\n";
681 } else {
682 # $output->write("$type_name: warning: type size not found\n");
685 } elsif ($type_kind eq "signed") {
686 print OUT " TEST_TYPE_SIGNED($type_name)\n";
687 } elsif ($type_kind eq "unsigned") {
688 print OUT " TEST_TYPE_UNSIGNED($type_name)\n";
692 sub output_test_pack_fields($$$$$$$);
693 sub output_test_pack_fields($$$$$$$) {
694 local *OUT = shift;
696 my $type_name2type = shift;
697 my $type_name2optional = shift;
698 my $type_name2optional_fields = shift;
699 my $type_name = shift;
700 my $type = shift;
701 my $offset = shift;
703 my $optional_fields = $$type_name2optional_fields{$type_name};
705 foreach my $field ($type->fields()) {
706 my $field_type_name = $field->type_name;
707 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
708 my $field_name = $field->name;
709 my $field_size = $field->size;
710 my $field_offset = $field->offset;
711 my $field_align = $field->align;
713 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
714 # We cannot take the address of a bitfield with MSVC
715 next if ($field_type_name =~ /:/);
717 if ($$optional_fields{$field_name}) {
718 # Nothing
719 } elsif (defined($field_size) && defined($field_offset)) {
720 $field_offset += $offset;
721 if ($field_name eq "DUMMYSTRUCTNAME") {
722 print OUT "#ifdef NONAMELESSSTRUCT\n";
723 print OUT " TEST_TYPE_SIZE ($type_name.$field_name, $field_size)\n";
724 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
725 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
726 print OUT "#else\n";
727 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
728 $type_name, $$type_name2type{$field_type_name}, $field_offset);
729 print OUT "#endif\n";
730 } else {
731 print OUT " TEST_FIELD_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";
735 } else {
736 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
741 ########################################################################
742 # output_test_pack
744 sub output_test_pack($$$$) {
745 local *OUT = shift;
747 my $test_dir = shift;
748 my $test = shift;
750 my $type_names_used = shift;
752 $output->prefix("$test_dir: $test: ");
754 my @headers = $tests->get_section($test_dir, $test, "header");
755 my @type_names = $tests->get_section($test_dir, $test, "type");
757 my %type_name2optional;
758 my %type_name2optional_fields;
760 foreach my $_type_name (@type_names) {
761 my $type_name = $_type_name;
763 if ($type_name =~ s/^!//) {
764 $type_name2optional{$type_name}++;
767 my $optional_fields = {};
768 if ($type_name =~ s/:\s*(.*?)$//) {
769 my @fields = split /\s+/, $1;
770 foreach my $field (@fields) {
771 if ($field =~ s/^!//) {
772 $$optional_fields{$field}++;
777 $type_name2optional_fields{$type_name} = $optional_fields;
780 foreach my $header (@headers) {
781 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
783 foreach my $_type_name (@type_names) {
784 my $type_name = $_type_name;
786 my $skip = ($type_name =~ s/^!//);
787 $type_name =~ s/:.*?$//;
788 my $type = $$type_name2type{$type_name};
789 if (!defined($type)) {
790 next;
792 $$type_names_used{$type_name} = $skip ? -1 : 1;
793 next if $skip;
795 print OUT "static void test_${test}_$type_name(void)\n";
796 print OUT "{\n";
797 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
798 $type_name, $type);
799 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
800 $type_name, $type, 0);
801 print OUT "}\n";
802 print OUT "\n";
808 ########################################################################
809 # output_file
811 sub output_file($$$$) {
812 local *OUT = shift;
814 my $test_dir = shift;
815 my @tests = @{(shift)};
817 my $type_names_used = shift;
819 output_header(\*OUT, $test_dir, \@tests);
821 foreach my $test (@tests) {
822 my %type_names_used2;
824 if ($test eq "pack") {
825 print OUT "#ifdef _WIN64\n\n";
826 $pointer_size = 8;
827 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
828 print OUT "#else /* _WIN64 */\n\n";
829 $pointer_size = 4;
830 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
831 print OUT "#endif /* _WIN64 */\n\n";
832 } else {
833 die "no such test ($test)\n";
836 print OUT "static void test_$test(void)\n";
837 print OUT "{\n";
838 foreach my $type_name (sort(keys(%type_names_used2))) {
839 $$type_names_used{$type_name} = $type_names_used2{$type_name};
840 if ($type_names_used2{$type_name} > 0) {
841 print OUT " test_${test}_$type_name();\n";
844 print OUT "}\n";
845 print OUT "\n";
848 output_footer(\*OUT, $test_dir, \@tests);
850 return 1;
853 ########################################################################
854 # main
856 my %type_names_used = ();
858 my @test_dirs = $tests->get_test_dirs();
859 foreach my $test_dir (@test_dirs) {
860 my $file = "$wine_dir/$test_dir/generated.c";
861 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
864 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
865 $output->prefix("$header: ");
866 $header =~ s%^include/%%;
867 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
868 foreach my $_type_name (sort(keys(%$type_name2type))) {
869 my $type_name = $_type_name;
871 if (!exists($type_names_used{$type_name})) {
872 $output->write("$type_name: type not used\n");
877 $output->prefix("$winapi_dir/tests.dat: ");
878 foreach my $type_name (sort(keys(%type_names_used))) {
879 my $found = 0;
880 foreach my $header (sort(keys(%{$file2types{$pointer_size}}))) {
881 my $type_name2type = $file2types{$pointer_size}{"include/$header"};
882 if (exists($type_name2type{$type_name})) {
883 $found = 1;
887 if (!$found) {
888 $output->write("$type_name: type not used\n");