Update tests.dat to include the various #include fixes.
[wine/multimedia.git] / tools / winapi / winapi_test
blobf726b7c77264639c00a8ad07d795475a4d46d529
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 $winapi_check_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 @tests = ();
46 if ($options->pack) {
47 push @tests, "pack";
50 my @files = ();
52 my %files;
54 my %test_dirs;
55 foreach my $test (@tests) {
56 my @test_dirs = $tests->get_test_dirs($test);
57 foreach my $test_dir (@test_dirs) {
58 my @headers = $tests->get_section($test_dir, $test, "header");
59 foreach my $header (@headers) {
60 $files{"include/$header"} = 1;
65 foreach my $test (@tests) {
66 my @test_dirs = $tests->get_test_dirs($test);
67 foreach my $test_dir (@test_dirs) {
68 my @headers = $tests->get_section($test_dir, $test, "header");
69 foreach my $header (@headers) {
70 if($files{"include/$header"}) {
71 push @files, "include/$header";
72 $files{"include/$header"} = 0;
79 if (0) {
80 my $file = "tests.dat";
82 $file .= "2"; # FIXME: For tests
84 open(OUT, "> $winapi_dir/$file") || die "$winapi_dir/$file: $!\n";
86 my $x = 0;
87 my @test_dirs = $tests->get_test_dirs();
88 foreach my $test_dir (@test_dirs) {
89 print OUT "\n" if $x++;
90 print OUT "%%%$test_dir\n";
91 print OUT "\n";
93 my $y = 0;
94 my @tests = $tests->get_tests($test_dir);
95 foreach my $test (@tests) {
96 print OUT "\n" if $y++;
97 print OUT "%%$test\n";
98 print OUT "\n";
100 my @types;
102 my $z = 0;
103 my @sections = $tests->get_sections($test_dir, $test);
104 foreach my $section (@sections) {
105 my @lines = $tests->get_section($test_dir, $test, $section);
107 if ($section =~ /^(?:struct|type)$/) {
108 foreach my $line (@lines) {
109 push @types, $line;
111 next;
114 print OUT "\n" if $z++;
115 print OUT "%$section\n";
116 print OUT "\n";
117 foreach my $line (@lines) {
118 print OUT "$line\n";
122 @types = sort { $x = $a; $y = $b; $x =~ s/^!//; $y =~ s/^!//; $x cmp $y } @types;
124 print OUT "\n" if $z++;
125 print OUT "%type\n";
126 print OUT "\n";
127 foreach my $type (@types) {
128 print OUT "$type\n";
133 close(OUT);
134 exit(0);
138 my %file2types;
140 my $progress_output;
141 my $progress_current = 0;
142 my $progress_max = scalar(@files);
144 ########################################################################
145 # find_type
147 my %type_name2type;
149 my %defines = (
150 "ANYSIZE_ARRAY" => 1,
151 "CCHDEVICENAME" => 32,
152 "ELF_VENDOR_SIZE" => 4,
153 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
154 "HW_PROFILE_GUIDLEN" => 39,
155 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
156 "IMAGE_SIZEOF_SHORT_NAME" => 8,
157 "LF_FACESIZE" => 32,
158 "LF_FULLFACESIZE" => 64,
159 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
160 "MAX_GOPHER_DISPLAY_TEXT + 1" => 129,
161 "MAX_GOPHER_LOCATOR_LENGTH + 1" => 654,
162 "MAX_PATH" => 260,
163 "MAX_PROFILE_LEN" => 80,
164 "OFS_MAXPATHNAME" => 128,
165 "SIZE_OF_80387_REGISTERS" => 80,
166 "TOKEN_SOURCE_LENGTH" => 8,
169 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
170 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
171 my %size_parse_reported;
173 sub _find_align_kind_size {
174 my $type_name = shift;
176 local $_ = $type_name;
178 my $count;
179 my $bits;
180 if (s/^(.*?)\s*(?:\[\s*(.*?)\s*\]|:(\d+))?$/$1/) {
181 $count = $2;
182 $bits = $3;
185 my $align;
186 my $kind;
187 my $size;
188 if (0) {
189 # Nothing
190 } elsif (/\*+$/) {
191 $align = 4;
192 $kind = "pointer";
193 $size = 4;
194 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char)$/) {
195 $align = 1;
196 $kind = defined($1) ? $1 : "signed";
197 $size = 1;
198 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
199 $align = 2;
200 $kind = defined($1) ? $1 : "signed";
201 $size = 2;
202 } elsif (/^(?:wchar_t)$/) {
203 $align = 2;
204 $kind = "signed";
205 $size = 2;
206 } elsif (!/^$/ && /^(?:(signed|unsigned)\s+)?(?:__int32|int|long(?:\s+int)?)?$/) {
207 $align = 4;
208 $kind = defined($1) ? $1 : "signed";
209 $size = 4;
210 } elsif (/^(?:float)$/) {
211 $align = 4;
212 $kind = "float";
213 $size = 4;
214 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
215 $align = 8;
216 $kind = defined($1) ? $1 : "signed";
217 $size = 8;
218 } elsif (/^(?:double)$/) {
219 $align = 4;
220 $kind = "float";
221 $size = 8;
222 } elsif (/^(?:long\s+double)$/) {
223 $align = 4;
224 $kind = "float";
225 $size = 12;
226 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|MENU|METAFILE|WND)$/) {
227 $align = 4;
228 $kind = "unsigned";
229 $size = 4;
230 } elsif (/^LP(?:CSTR|CWSTR|DWORD|VOID|WSTR)$/) {
231 $align = 4;
232 $kind = "pointer";
233 $size = 4;
234 } elsif (/^(?:FILETIME)$/) {
235 $align = 4;
236 $kind = "struct";
237 $size = 8;
238 } elsif (/^(?:LARGE_INTEGER)$/) {
239 $align = 4;
240 $kind = "signed";
241 $size = 8;
242 } elsif (/^(struct|union)$/) {
243 $kind = $1;
244 if (!$size_parse_reported{$_}) {
245 $output->write("$type_name: can't parse type\n");
246 $size_parse_reported{$_} = 1;
248 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
249 $align = 4;
250 $kind = "pointer";
251 $size = 4;
254 my $align2;
255 if (defined(my $type = $type_name2type{$_})) {
256 $align2 = $type->align;
259 if (!defined($align)) {
260 $align = $align2;
261 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
262 $align_kludge_reported{$_} = 1;
263 $output->write("$type_name: type needn't be kludged\n");
266 if (!defined($align)) {
267 # $output->write("$type_name: can't find type\n");
270 my $size2;
271 if (defined(my $type = $type_name2type{$_})) {
272 $size2 = $type->size;
275 if (!defined($size)) {
276 $size = $size2;
277 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
278 $size_kludge_reported{$_} = 1;
279 $output->write("$type_name: type needn't be kludged\n");
282 if (!defined($size)) {
283 # $output->write("$type_name: can't find type\n");
284 } elsif (defined($count)) {
285 if ($count =~ /^\d+$/) {
286 $size *= int($count);
287 } elsif (defined(my $count2 = $defines{$count})) {
288 $size *= int($count2);
289 } else {
290 $output->write("$type_name: can't parse type ('$_') ('$count')\n");
291 $size = undef;
293 } elsif (defined($bits)) {
294 $size = -$bits;
297 return ($align, $kind, $size);
300 sub find_align {
301 my $type_name = shift;
302 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
303 return $align;
306 sub find_kind {
307 my $type_name = shift;
308 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
310 return $kind;
313 sub find_size {
314 my $type_name = shift;
315 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
316 return $size;
319 foreach my $file (@files) {
320 $progress_current++;
323 open(IN, "< $wine_dir/$file");
324 local $/ = undef;
325 $_ = <IN>;
326 close(IN);
329 my $max_line = 0;
331 local $_ = $_;
332 while(s/^.*?\n//) { $max_line++; }
333 if($_) { $max_line++; }
336 my $parser = new c_parser($file);
338 my $line;
339 my $type;
340 my @packs = (4);
342 my $update_output = sub {
343 my $progress = "";
344 my $prefix = "";
346 $progress .= "$file (file $progress_current of $progress_max)";
347 $prefix .= "$file: ";
349 if(defined($line)) {
350 $progress .= ": line $line of $max_line";
353 $output->progress($progress);
354 $output->prefix($prefix);
357 &$update_output();
359 my $found_line = sub {
360 $line = shift;
362 &$update_output;
364 $parser->set_found_line_callback($found_line);
366 my $found_preprocessor = sub {
367 my $begin_line = shift;
368 my $begin_column = shift;
369 my $preprocessor = shift;
371 #print "found_preprocessor: $begin_line: [$_]\n";
372 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d+)\.h[\">]$/) {
373 push @packs, $1;
374 #print "found pack $1 on line $begin_line\n";
375 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
376 pop @packs;
377 #print "found poppack on line $begin_line\n";
380 return 1;
382 $parser->set_found_preprocessor_callback($found_preprocessor);
384 my $found_type = sub {
385 $type = shift;
387 &$update_output();
389 my $name = $type->name;
390 $file2types{$file}{$name} = $type;
392 $type->set_find_align_callback(\&find_align);
393 $type->set_find_kind_callback(\&find_kind);
394 $type->set_find_size_callback(\&find_size);
396 my $pack = $packs[$#packs];
397 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
398 $type->pack($pack);
400 my $size = $type->size();
401 if (defined($size)) {
402 my $max_field_base_size = 0;
404 foreach my $field ($type->fields()) {
405 my $field_type_name = $field->type_name;
406 my $field_name = $field->name;
407 my $field_size = $field->size;
408 my $field_base_size = $field->base_size;
409 my $field_offset = $field->offset;
410 my $field_align = $field->align;
412 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
414 # $output->write("$name: $size\n");
416 $type_name2type{$name} = $type;
417 } else {
418 # $output->write("$name: can't find size\n");
421 return 1;
423 $parser->set_found_type_callback($found_type);
426 my $line = 1;
427 my $column = 0;
428 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
429 $output->write("can't parse file\n");
433 $output->prefix("");
436 ########################################################################
437 # output_header
439 sub output_header {
440 local *OUT = shift;
442 my $test_dir = shift;
443 my @tests = @{(shift)};
445 print OUT "/* File generated automatically from tools/winapi/test.dat; do not edit! */\n";
446 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
447 print OUT "\n";
449 print OUT "/*\n";
450 foreach my $test (@tests) {
451 my @description = $tests->get_section($test_dir, $test, "description");
452 foreach my $description (@description) {
453 print OUT " * $description\n";
456 print OUT " */\n";
457 print OUT "\n";
459 print OUT "#define WINVER 0x0501\n";
460 print OUT "#define _WIN32_IE 0x0501\n";
461 print OUT "#define _WIN32_WINNT 0x0501\n";
462 print OUT "\n";
463 print OUT "#define WINE_NOWINSOCK\n";
464 print OUT "\n";
465 foreach my $test (@tests) {
466 my @includes = $tests->get_section($test_dir, $test, "include");
467 foreach my $include (@includes) {
468 print OUT "#include \"$include\"\n";
471 print OUT "\n";
472 print OUT "#include \"wine/test.h\"\n";
473 print OUT "\n";
475 print OUT "/***********************************************************************\n";
476 print OUT " * Compability macros\n";
477 print OUT " */\n";
478 print OUT "\n";
479 print OUT "#define DWORD_PTR UINT_PTR\n";
480 print OUT "#define LONG_PTR INT_PTR\n";
481 print OUT "#define ULONG_PTR UINT_PTR\n";
482 print OUT "\n";
484 print OUT "/***********************************************************************\n";
485 print OUT " * Windows API extension\n";
486 print OUT " */\n";
487 print OUT "\n";
488 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
489 print OUT "# define FIELD_ALIGNMENT(type, field) __alignof(((type*)0)->field)\n";
490 print OUT "#elif defined(__GNUC__)\n";
491 print OUT "# define FIELD_ALIGNMENT(type, field) __alignof__(((type*)0)->field)\n";
492 print OUT "#else\n";
493 print OUT "/* FIXME: Not sure if is possible to do without compiler extension */\n";
494 print OUT "#endif\n";
495 print OUT "\n";
496 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
497 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
498 print OUT "#elif defined(__GNUC__)\n";
499 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
500 print OUT "#else\n";
501 print OUT "/*\n";
502 print OUT " * FIXME: Not sure if is possible to do without compiler extension\n";
503 print OUT " * (if type is not just a name that is, if so the normal)\n";
504 print OUT " * TYPE_ALIGNMENT can be used)\n";
505 print OUT " */\n";
506 print OUT "#endif\n";
507 print OUT "\n";
508 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
509 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
510 print OUT "#endif\n";
511 print OUT "\n";
513 print OUT "/***********************************************************************\n";
514 print OUT " * Test helper macros\n";
515 print OUT " */\n";
516 print OUT "\n";
517 print OUT "#ifdef FIELD_ALIGNMENT\n";
518 print OUT "# define TEST_FIELD_ALIGNMENT(type, field, align) \\\n";
519 print OUT " ok(FIELD_ALIGNMENT(type, field) == align, \\\n";
520 print OUT " \"FIELD_ALIGNMENT(\" #type \", \" #field \") == %d (expected \" #align \")\\n\", \\\n";
521 print OUT " FIELD_ALIGNMENT(type, field))\n";
522 print OUT "#else\n";
523 print OUT "# define TEST_FIELD_ALIGNMENT(type, field, align) do { } while (0)\n";
524 print OUT "#endif\n";
525 print OUT "\n";
526 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) \\\n";
527 print OUT " ok(FIELD_OFFSET(type, field) == offset, \\\n";
528 print OUT " \"FIELD_OFFSET(\" #type \", \" #field \") == %ld (expected \" #offset \")\\n\", \\\n";
529 print OUT " FIELD_OFFSET(type, field))\n";
530 print OUT "\n";
531 print OUT "#ifdef _TYPE_ALIGNMENT\n";
532 print OUT "#define TEST__TYPE_ALIGNMENT(type, align) \\\n";
533 print OUT " ok(_TYPE_ALIGNMENT(type) == align, \"TYPE_ALIGNMENT(\" #type \") == %d (expected \" #align \")\", _TYPE_ALIGNMENT(type))\n";
534 print OUT "#else\n";
535 print OUT "# define TEST__TYPE_ALIGNMENT(type, align) do { } while (0)\n";
536 print OUT "#endif\n";
537 print OUT "\n";
538 print OUT "#ifdef TYPE_ALIGNMENT\n";
539 print OUT "#define TEST_TYPE_ALIGNMENT(type, align) \\\n";
540 print OUT " ok(TYPE_ALIGNMENT(type) == align, \"TYPE_ALIGNMENT(\" #type \") == %d (expected \" #align \")\\n\", TYPE_ALIGNMENT(type))\n";
541 print OUT "#else\n";
542 print OUT "# define TEST_TYPE_ALIGNMENT(type, align) do { } while (0)\n";
543 print OUT "#endif\n";
544 print OUT "\n";
545 print OUT "#define TEST_TYPE_SIZE(type, size) \\\n";
546 print OUT " ok(sizeof(type) == size, \"sizeof(\" #type \") == %d (expected \" #size \")\\n\", sizeof(type))\n";
547 print OUT "\n";
548 print OUT "/***********************************************************************\n";
549 print OUT " * Test macros\n";
550 print OUT " */\n";
551 print OUT "\n";
552 print OUT "#define TEST_FIELD(type, field_type, field_name, field_offset, field_size, field_align) \\\n";
553 print OUT " TEST_TYPE_SIZE(field_type, field_size); \\\n";
554 print OUT " TEST_FIELD_ALIGNMENT(type, field_name, field_align); \\\n";
555 print OUT " TEST_FIELD_OFFSET(type, field_name, field_offset); \\\n";
556 print OUT "\n";
557 print OUT "#define TEST_TYPE(type, size, align) \\\n";
558 print OUT " TEST_TYPE_ALIGNMENT(type, align); \\\n";
559 print OUT " TEST_TYPE_SIZE(type, size)\n";
560 print OUT "\n";
561 print OUT "#define TEST_TYPE_POINTER(type, size, align) \\\n";
562 print OUT " TEST__TYPE_ALIGNMENT(*(type)0, align); \\\n";
563 print OUT " TEST_TYPE_SIZE(*(type)0, size)\n";
564 print OUT "\n";
565 print OUT "#define TEST_TYPE_SIGNED(type) \\\n";
566 print OUT " ok((type) -1 < 0, \"(\" #type \") -1 < 0\\n\");\n";
567 print OUT "\n";
568 print OUT "#define TEST_TYPE_UNSIGNED(type) \\\n";
569 print OUT " ok((type) -1 > 0, \"(\" #type \") -1 > 0\\n\");\n";
570 print OUT "\n";
573 ########################################################################
574 # output_footer
576 sub output_footer {
577 local *OUT = shift;
579 my $test_dir = shift;
580 my @tests = @{(shift)};
582 print OUT "START_TEST(generated)\n";
583 print OUT "{\n";
584 foreach my $test (@tests) {
585 print OUT " test_$test();\n";
587 print OUT "}\n";
590 ########################################################################
591 # output_test_pack_type
593 sub output_test_pack_type {
594 local *OUT = shift;
596 my $type_name2type = shift;
597 my $type_name2optional = shift;
598 my $type_name2optional_fields = shift;
599 my $type_name = shift;
600 my $type = shift;
602 my $optional_fields = $$type_name2optional_fields{$type_name};
604 my $type_align = $type->align;
605 my $type_pack = $type->pack;
606 my $type_size = $type->size;
607 my $type_kind = $type->kind;
609 if (defined($type_pack)) {
610 print OUT " /* $type_name (pack $type_pack) */\n";
611 } else {
612 print OUT " /* $type_name */\n";
615 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
616 print OUT " TEST_TYPE($type_name, $type_size, $type_align);\n";
619 if ($type_kind eq "float") {
620 # Nothing
621 } elsif ($type_kind eq "pointer") {
622 my $dereference_type;
623 $dereference_type = sub {
624 my $type = shift;
626 my @fields = $type->fields;
627 my $type_name2 =$fields[0]->type_name;
629 if ($type_name2 =~ s/\s*\*$//) {
630 my $type2 = $$type_name2type{$type_name2};
631 if (defined($type2)) {
632 return $type2;
633 } else {
634 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
635 $output->write("$type_name2: warning: type not found 1\n");
637 return undef;
639 } elsif ($type_name2 =~ /^\w+$/) {
640 my $type2 = $$type_name2type{$type_name2};
641 if (defined($type2)) {
642 return &$dereference_type($type2);
643 } else {
644 $output->write("$type_name2: warning: type not found\n");
645 return undef;
647 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
648 return undef;
649 } else {
650 $output->write("$type_name2: warning: type can't be parsed\n");
651 return undef;
655 my $type2 = &$dereference_type($type);
656 if (defined($type2)) {
657 my $type_name2 = $type2->name;
658 my $type_align2 = $type2->align;
659 my $type_size2 = $type2->size;
661 my $optional = $$type_name2optional{$type_name};
662 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
664 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
665 print OUT " TEST_TYPE_POINTER($type_name, $type_size2, $type_align2);\n";
666 } else {
667 # $output->write("$type_name: warning: type size not found\n");
670 } elsif ($type_kind eq "signed") {
671 print OUT " TEST_TYPE_SIGNED($type_name);\n";
672 } elsif ($type_kind eq "unsigned") {
673 print OUT " TEST_TYPE_UNSIGNED($type_name);\n";
677 sub output_test_pack_fields {
678 local *OUT = shift;
680 my $type_name2type = shift;
681 my $type_name2optional = shift;
682 my $type_name2optional_fields = shift;
683 my $type_name = shift;
684 my $type = shift;
685 my $offset = shift;
687 my $optional_fields = $$type_name2optional_fields{$type_name};
689 foreach my $field ($type->fields()) {
690 my $field_type_name = $field->type_name;
691 my $field_name = $field->name;
692 my $field_size = $field->size;
693 my $field_offset = $field->offset;
694 my $field_align = $field->align;
696 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
698 if ($$optional_fields{$field_name}) {
699 # Nothing
700 } elsif (defined($field_size) && defined($field_offset)) {
701 $field_offset += $offset;
702 if ($field_name eq "DUMMYSTRUCTNAME") {
703 print OUT "#ifdef NONAMELESSSTRUCT\n";
704 print OUT " TEST_FIELD($type_name, $field_type_name, $field_name, ";
705 print OUT "$field_offset, $field_size, $field_align);\n";
706 print OUT "#else\n";
707 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
708 $type_name, $$type_name2type{$field_type_name}, $field_offset);
709 print OUT "#endif\n";
710 } else {
711 print OUT " TEST_FIELD($type_name, $field_type_name, $field_name, ";
712 print OUT "$field_offset, $field_size, $field_align);\n";
714 } else {
715 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
720 ########################################################################
721 # output_test_pack
723 sub output_test_pack {
724 local *OUT = shift;
726 my $test_dir = shift;
727 my $test = shift;
729 my $type_names_used = shift;
731 $output->prefix("$test_dir: $test: ");
733 my @headers = $tests->get_section($test_dir, $test, "header");
734 my @type_names = $tests->get_section($test_dir, $test, "type");
736 my %type_name2optional;
737 my %type_name2optional_fields;
739 foreach my $_type_name (@type_names) {
740 my $type_name = $_type_name;
742 if ($type_name =~ s/^!//) {
743 $type_name2optional{$type_name}++;
746 my $optional_fields = {};
747 if ($type_name =~ s/:\s*(.*?)$//) {
748 my @fields = split /\s+/, $1;
749 foreach my $field (@fields) {
750 if ($field =~ s/^!//) {
751 $$optional_fields{$field}++;
756 $type_name2optional_fields{$type_name} = $optional_fields;
759 foreach my $header (@headers) {
760 my $type_name2type = $file2types{"include/$header"};
762 foreach my $_type_name (@type_names) {
763 my $type_name = $_type_name;
765 my $skip = ($type_name =~ s/^!//);
766 $type_name =~ s/:.*?$//;
767 my $type = $$type_name2type{$type_name};
768 if (!defined($type)) {
769 next;
771 $$type_names_used{$type_name} = $skip ? -1 : 1;
772 next if $skip;
774 print OUT "static void test_${test}_$type_name(void)\n";
775 print OUT "{\n";
776 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
777 $type_name, $type);
778 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
779 $type_name, $type, 0);
780 print OUT "}\n";
781 print OUT "\n";
787 ########################################################################
788 # output_file
790 sub output_file {
791 local *OUT = shift;
793 my $test_dir = shift;
794 my @tests = @{(shift)};
796 my $type_names_used = shift;
798 output_header(\*OUT, $test_dir, \@tests);
800 foreach my $test (@tests) {
801 my %type_names_used2;
803 if ($test eq "pack") {
804 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
805 } else {
806 die "no such test ($test)\n";
809 print OUT "static void test_$test(void)\n";
810 print OUT "{\n";
811 foreach my $type_name (sort(keys(%type_names_used2))) {
812 $$type_names_used{$type_name} = $type_names_used2{$type_name};
813 if ($type_names_used2{$type_name} > 0) {
814 print OUT " test_${test}_$type_name();\n";
817 print OUT "}\n";
818 print OUT "\n";
821 output_footer(\*OUT, $test_dir, \@tests);
823 return 1;
826 ########################################################################
827 # main
829 my %type_names_used = ();
831 my @test_dirs = $tests->get_test_dirs();
832 foreach my $test_dir (@test_dirs) {
833 my $file = "$wine_dir/$test_dir/generated.c";
834 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
837 foreach my $header (sort(keys(%file2types))) {
838 $output->prefix("$header: ");
839 $header =~ s%^include/%%;
840 my $type_name2type = $file2types{"include/$header"};
841 foreach my $_type_name (sort(keys(%$type_name2type))) {
842 my $type_name = $_type_name;
844 if (!exists($type_names_used{$type_name})) {
845 $output->write("$type_name: type not used\n");
850 $output->prefix("$winapi_dir/tests.dat: ");
851 foreach my $type_name (sort(keys(%type_names_used))) {
852 my $found = 0;
853 foreach my $header (sort(keys(%file2types))) {
854 my $type_name2type = $file2types{"include/$header"};
855 if (exists($type_name2type{$type_name})) {
856 $found = 1;
860 if (!$found) {
861 $output->write("$type_name: type not used\n");