documentation: Remove all occurrence of bugs.sgml.
[wine.git] / tools / winapi / winapi_test
blobcf3a2b614b35f6533f83aaa7adbd620d42625b29
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 @tests = ();
46 if ($options->pack) {
47 push @tests, "pack";
50 my @files;
52 my %files;
54 foreach my $test (@tests)
56 foreach my $test_dir ($tests->get_test_dirs($test))
58 foreach my $header ($tests->get_section($test_dir, $test, "header"))
60 if (!$files{$header})
62 push @files, "include/$header";
63 $files{$header} = 1;
70 if (0) {
71 my $file = "tests.dat";
73 $file .= "2"; # FIXME: For tests
75 open(OUT, "> $winapi_dir/$file") || die "Error: Can't open $winapi_dir/$file: $!\n";
77 my $x = 0;
78 my @test_dirs = $tests->get_test_dirs();
79 foreach my $test_dir (@test_dirs) {
80 print OUT "\n" if $x++;
81 print OUT "%%%$test_dir\n";
82 print OUT "\n";
84 my $y = 0;
85 my @tests = $tests->get_tests($test_dir);
86 foreach my $test (@tests) {
87 print OUT "\n" if $y++;
88 print OUT "%%$test\n";
89 print OUT "\n";
91 my @types;
93 my $z = 0;
94 my @sections = $tests->get_sections($test_dir, $test);
95 foreach my $section (@sections) {
96 my @lines = $tests->get_section($test_dir, $test, $section);
98 if ($section =~ /^(?:struct|type)$/) {
99 foreach my $line (@lines) {
100 push @types, $line;
102 next;
105 print OUT "\n" if $z++;
106 print OUT "%$section\n";
107 print OUT "\n";
108 foreach my $line (@lines) {
109 print OUT "$line\n";
113 @types = sort { $x = $a; $y = $b; $x =~ s/^!//; $y =~ s/^!//; $x cmp $y } @types;
115 print OUT "\n" if $z++;
116 print OUT "%type\n";
117 print OUT "\n";
118 foreach my $type (@types) {
119 print OUT "$type\n";
124 close(OUT);
125 exit(0);
129 my %file2types;
131 my $progress_output;
132 my $progress_current = 0;
133 my $progress_max = scalar(@files);
135 ########################################################################
136 # find_type
138 my %type_name2type;
140 my %defines = (
141 "ANYSIZE_ARRAY" => 1,
142 "CCHDEVICENAME" => 32,
143 "CCHILDREN_TITLEBAR+1" => 6,
144 "ELF_VENDOR_SIZE" => 4,
145 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
146 "HW_PROFILE_GUIDLEN" => 39,
147 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
148 "IMAGE_SIZEOF_SHORT_NAME" => 8,
149 "LF_FACESIZE" => 32,
150 "LF_FULLFACESIZE" => 64,
151 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
152 "MAX_GOPHER_DISPLAY_TEXT + 1" => 129,
153 "MAX_GOPHER_LOCATOR_LENGTH + 1" => 654,
154 "MAX_PATH" => 260,
155 "MAX_PROFILE_LEN" => 80,
156 "NUM_POINTS" => 3,
157 "OFS_MAXPATHNAME" => 128,
158 "SIZE_OF_80387_REGISTERS" => 80,
159 "TOKEN_SOURCE_LENGTH" => 8,
162 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
163 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
164 my %size_parse_reported;
166 sub _find_align_kind_size($) {
167 my $type_name = shift;
169 local $_ = $type_name;
171 my $align;
172 my $kind;
173 my $size;
174 if (/\*+$/) {
175 $align = 4;
176 $kind = "pointer";
177 $size = 4;
178 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char|byte)$/) {
179 $align = 1;
180 $kind = defined($1) ? $1 : "signed";
181 $size = 1;
182 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
183 $align = 2;
184 $kind = defined($1) ? $1 : "signed";
185 $size = 2;
186 } elsif (/^(?:wchar_t)$/) {
187 $align = 2;
188 $kind = "signed";
189 $size = 2;
190 } elsif (/^(signed|unsigned)$/) {
191 $align = 4;
192 $kind = defined($1) ? $1 : "signed";
193 $size = 4;
194 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int32|int|long(?:\s+int)?)$/) {
195 $align = 4;
196 $kind = defined($1) ? $1 : "signed";
197 $size = 4;
198 } elsif (/^(?:float)$/) {
199 $align = 4;
200 $kind = "float";
201 $size = 4;
202 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
203 $align = 8;
204 $kind = defined($1) ? $1 : "signed";
205 $size = 8;
206 } elsif (/^(?:double|DOUBLE|DATE)$/) {
207 $align = 8;
208 $kind = "float";
209 $size = 8;
210 } elsif (/^(?:long\s+double)$/) {
211 $align = 4;
212 $kind = "float";
213 $size = 12;
214 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|KEY|MENU|METAFILE|WND)$/) {
215 $align = 4;
216 $kind = "pointer";
217 $size = 4;
218 } elsif (/^LP(?:BYTE|CSTR|CWSTR|DWORD|STR|VOID|WSTR)$/) {
219 $align = 4;
220 $kind = "pointer";
221 $size = 4;
222 } elsif (/^(?:FILETIME)$/) {
223 $align = 4;
224 $kind = "struct";
225 $size = 8;
226 } elsif (/^GUID$/) {
227 $align = 4;
228 $kind = "struct";
229 $size = 16;
230 } elsif (/^(?:VOID)$/) {
231 $align = 4;
232 $kind = "signed";
233 $size = 4;
234 } elsif (/^(?:SHORT)$/) {
235 $align = 2;
236 $kind = "unsigned";
237 $size = 2;
238 } elsif (/^(?:BYTE)$/) {
239 $align = 1;
240 $kind = "unsigned";
241 $size = 1;
242 } elsif (/^(?:DWORD)$/) {
243 $align = 4;
244 $kind = "unsigned";
245 $size = 4;
246 } elsif (/^(?:WORD)$/) {
247 $align = 2;
248 $kind = "unsigned";
249 $size = 2;
250 } elsif (/^(?:INT64|LONG64|LONGLONG)$/) {
251 $align = 8;
252 $kind = "signed";
253 $size = 8;
254 } elsif (/^(?:UINT64|ULONG64|DWORD64|ULONGLONG|DWORDLONG)$/) {
255 $align = 8;
256 $kind = "unsigned";
257 $size = 8;
258 } elsif (/^(?:LARGE_INTEGER)$/) {
259 $align = 8;
260 $kind = "union";
261 $size = 8;
262 } elsif (/^(?:POINTS)$/) {
263 $align = 2;
264 $kind = "struct";
265 $size = 4;
266 } elsif (/^(struct|union)$/) {
267 $kind = $1;
268 if (!$size_parse_reported{$_}) {
269 $output->write("$type_name: can't parse type\n");
270 $size_parse_reported{$_} = 1;
272 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
273 $align = 4;
274 $kind = "pointer";
275 $size = 4;
278 my $align2;
279 if (defined(my $type = $type_name2type{$_})) {
280 $align2 = $type->align;
283 if (!defined($align)) {
284 $align = $align2;
285 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
286 $align_kludge_reported{$_} = 1;
287 $output->write("$type_name: type needn't be kludged\n");
290 if (!defined($align)) {
291 # $output->write("$type_name: can't find type\n");
294 my $size2;
295 if (defined(my $type = $type_name2type{$_})) {
296 $size2 = $type->size;
299 if (!defined($size)) {
300 $size = $size2;
301 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
302 $size_kludge_reported{$_} = 1;
303 $output->write("$type_name: type needn't be kludged\n");
306 return ($align, $kind, $size);
309 sub find_align($) {
310 my $type_name = shift;
311 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
312 return $align;
315 sub find_kind($) {
316 my $type_name = shift;
317 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
319 return $kind;
322 sub find_size($) {
323 my $type_name = shift;
324 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
325 return $size;
328 sub find_count($) {
329 my $count = shift;
330 return $defines{$count};
333 foreach my $file (@files) {
334 $progress_current++;
337 open(IN, "< $wine_dir/$file") || die "Error: Can't open $wine_dir/$file: $!\n";
338 local $/ = undef;
339 $_ = <IN>;
340 close(IN);
343 my $max_line = 0;
345 local $_ = $_;
346 while(s/^.*?\n//) { $max_line++; }
347 if($_) { $max_line++; }
350 my $parser = new c_parser($file);
352 my $line;
353 my $type;
354 my @packs = (4);
356 my $update_output = sub {
357 my $progress = "";
358 my $prefix = "";
360 $progress .= "$file (file $progress_current of $progress_max)";
361 $prefix .= "$file: ";
363 if(defined($line)) {
364 $progress .= ": line $line of $max_line";
367 $output->progress($progress);
368 $output->prefix($prefix);
371 &$update_output();
373 my $found_line = sub {
374 $line = shift;
376 &$update_output;
378 $parser->set_found_line_callback($found_line);
380 my $found_preprocessor = sub {
381 my $begin_line = shift;
382 my $begin_column = shift;
383 my $preprocessor = shift;
385 #print "found_preprocessor: $begin_line: [$_]\n";
386 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d+)\.h[\">]$/) {
387 push @packs, $1;
388 #print "found pack $1 on line $begin_line\n";
389 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
390 pop @packs;
391 #print "found poppack on line $begin_line\n";
394 return 1;
396 $parser->set_found_preprocessor_callback($found_preprocessor);
398 my $found_type = sub {
399 $type = shift;
401 &$update_output();
403 my $name = $type->name;
404 $file2types{$file}{$name} = $type;
406 $type->set_find_align_callback(\&find_align);
407 $type->set_find_kind_callback(\&find_kind);
408 $type->set_find_size_callback(\&find_size);
409 $type->set_find_count_callback(\&find_count);
411 my $pack = $packs[$#packs];
412 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
413 $type->pack($pack);
415 my $size = $type->size();
416 if (defined($size)) {
417 my $max_field_base_size = 0;
419 foreach my $field ($type->fields()) {
420 my $field_type_name = $field->type_name;
421 my $field_name = $field->name;
422 my $field_size = $field->size;
423 my $field_base_size = $field->base_size;
424 my $field_offset = $field->offset;
425 my $field_align = $field->align;
427 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
429 # $output->write("$name: $size\n");
431 $type_name2type{$name} = $type;
432 } else {
433 # $output->write("$name: can't find size\n");
436 return 1;
438 $parser->set_found_type_callback($found_type);
441 my $line = 1;
442 my $column = 0;
443 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
444 $output->write("can't parse file\n");
448 $output->prefix("");
451 ########################################################################
452 # output_header
454 sub output_header($$$) {
455 local *OUT = shift;
457 my $test_dir = shift;
458 my @tests = @{(shift)};
460 print OUT "/* File generated automatically from tools/winapi/tests.dat; do not edit! */\n";
461 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
462 print OUT "\n";
464 print OUT "/*\n";
465 foreach my $test (@tests) {
466 my @description = $tests->get_section($test_dir, $test, "description");
467 foreach my $description (@description) {
468 print OUT " * $description\n";
471 print OUT " */\n";
472 print OUT "\n";
474 print OUT "#define WINVER 0x0501\n";
475 print OUT "#define _WIN32_IE 0x0501\n";
476 print OUT "#define _WIN32_WINNT 0x0501\n";
477 print OUT "\n";
478 print OUT "#define WINE_NOWINSOCK\n";
479 print OUT "\n";
480 foreach my $test (@tests) {
481 my @includes = $tests->get_section($test_dir, $test, "include");
482 foreach my $include (@includes) {
483 print OUT "#include $include\n";
486 print OUT "\n";
487 print OUT "#include \"wine/test.h\"\n";
488 print OUT "\n";
490 print OUT "/***********************************************************************\n";
491 print OUT " * Compatibility macros\n";
492 print OUT " */\n";
493 print OUT "\n";
494 print OUT "#define DWORD_PTR UINT_PTR\n";
495 print OUT "#define LONG_PTR INT_PTR\n";
496 print OUT "#define ULONG_PTR UINT_PTR\n";
497 print OUT "\n";
499 print OUT "/***********************************************************************\n";
500 print OUT " * Windows API extension\n";
501 print OUT " */\n";
502 print OUT "\n";
503 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
504 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
505 print OUT "#elif defined(__GNUC__)\n";
506 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
507 print OUT "#else\n";
508 print OUT "/*\n";
509 print OUT " * FIXME: May not be possible without a compiler extension\n";
510 print OUT " * (if type is not just a name that is, otherwise the normal\n";
511 print OUT " * TYPE_ALIGNMENT can be used)\n";
512 print OUT " */\n";
513 print OUT "#endif\n";
514 print OUT "\n";
515 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
516 print OUT "#pragma warning(disable:4116)\n";
517 print OUT "#endif\n";
518 print OUT "\n";
519 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
520 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
521 print OUT "#endif\n";
522 print OUT "\n";
524 print OUT "/***********************************************************************\n";
525 print OUT " * Test helper macros\n";
526 print OUT " */\n";
527 print OUT "\n";
528 print OUT "#ifdef _WIN64\n";
529 print OUT "\n";
530 print OUT "# define TEST_TYPE_SIZE(type, size)\n";
531 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
532 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
533 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
534 print OUT "# define TEST_FIELD_OFFSET(type, field, offset)\n";
535 print OUT "\n";
536 print OUT "#else\n";
537 print OUT "\n";
538 print OUT "# define TEST_TYPE_SIZE(type, size) C_ASSERT(sizeof(type) == size);\n";
539 print OUT "\n";
540 print OUT "# ifdef TYPE_ALIGNMENT\n";
541 print OUT "# define TEST_TYPE_ALIGN(type, align) C_ASSERT(TYPE_ALIGNMENT(type) == align);\n";
542 print OUT "# else\n";
543 print OUT "# define TEST_TYPE_ALIGN(type, align)\n";
544 print OUT "# endif\n";
545 print OUT "\n";
546 print OUT "# ifdef _TYPE_ALIGNMENT\n";
547 print OUT "# define TEST_TARGET_ALIGN(type, align) C_ASSERT(_TYPE_ALIGNMENT(*(type)0) == align);\n";
548 print OUT "# define TEST_FIELD_ALIGN(type, field, align) C_ASSERT(_TYPE_ALIGNMENT(((type*)0)->field) == align);\n";
549 print OUT "# else\n";
550 print OUT "# define TEST_TARGET_ALIGN(type, align)\n";
551 print OUT "# define TEST_FIELD_ALIGN(type, field, align)\n";
552 print OUT "# endif\n";
553 print OUT "\n";
554 print OUT "# define TEST_FIELD_OFFSET(type, field, offset) C_ASSERT(FIELD_OFFSET(type, field) == offset);\n";
555 print OUT "\n";
556 print OUT "#endif\n";
557 print OUT "\n";
558 print OUT "#define TEST_TARGET_SIZE(type, size) TEST_TYPE_SIZE(*(type)0, size)\n";
559 print OUT "#define TEST_FIELD_SIZE(type, field, size) TEST_TYPE_SIZE((((type*)0)->field), size)\n";
560 print OUT "#define TEST_TYPE_SIGNED(type) C_ASSERT((type) -1 < 0);\n";
561 print OUT "#define TEST_TYPE_UNSIGNED(type) C_ASSERT((type) -1 > 0);\n";
562 print OUT "\n";
563 print OUT "\n";
566 ########################################################################
567 # output_footer
569 sub output_footer($$$) {
570 local *OUT = shift;
572 my $test_dir = shift;
573 my @tests = @{(shift)};
575 print OUT "START_TEST(generated)\n";
576 print OUT "{\n";
577 foreach my $test (@tests) {
578 print OUT "#ifdef _WIN64\n";
579 print OUT " ok(0, \"The type size / alignment tests don't support Win64 yet\\n\");\n";
580 print OUT "#else\n";
581 print OUT " test_$test();\n";
582 print OUT "#endif\n";
584 print OUT "}\n";
587 ########################################################################
588 # output_test_pack_type
590 sub output_test_pack_type($$$$$$) {
591 local *OUT = shift;
593 my $type_name2type = shift;
594 my $type_name2optional = shift;
595 my $type_name2optional_fields = shift;
596 my $type_name = shift;
597 my $type = shift;
599 my $optional_fields = $$type_name2optional_fields{$type_name};
601 my $type_align = $type->align;
602 my $type_pack = $type->pack;
603 my $type_size = $type->size;
604 my $type_kind = $type->kind;
606 if (defined($type_pack)) {
607 print OUT " /* $type_name (pack $type_pack) */\n";
608 } else {
609 print OUT " /* $type_name */\n";
612 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
613 print OUT " TEST_TYPE_SIZE ($type_name, $type_size)\n";
614 print OUT " TEST_TYPE_ALIGN ($type_name, $type_align)\n";
617 if ($type_kind eq "float") {
618 # Nothing
619 } elsif ($type_kind eq "pointer") {
620 my $dereference_type;
621 $dereference_type = sub {
622 my $type = shift;
624 my @fields = $type->fields;
625 my $type_name2 =$fields[0]->type_name;
627 if ($type_name2 =~ s/\s*\*$//) {
628 my $type2 = $$type_name2type{$type_name2};
629 if (defined($type2)) {
630 return $type2;
631 } else {
632 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
633 $output->write("$type_name2: warning: type not found 1\n");
635 return undef;
637 } elsif ($type_name2 =~ /^\w+$/) {
638 my $type2 = $$type_name2type{$type_name2};
639 if (defined($type2)) {
640 return &$dereference_type($type2);
641 } else {
642 $output->write("$type_name2: warning: type not found\n");
643 return undef;
645 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
646 return undef;
647 } else {
648 $output->write("$type_name2: warning: type can't be parsed\n");
649 return undef;
653 my $type2 = &$dereference_type($type);
654 if (defined($type2)) {
655 my $type_name2 = $type2->name;
656 my $type_align2 = $type2->align;
657 my $type_size2 = $type2->size;
659 my $optional = $$type_name2optional{$type_name};
660 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
662 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
663 print OUT " TEST_TARGET_SIZE ($type_name, $type_size2)\n";
664 print OUT " TEST_TARGET_ALIGN($type_name, $type_align2)\n";
665 } else {
666 # $output->write("$type_name: warning: type size not found\n");
669 } elsif ($type_kind eq "signed") {
670 print OUT " TEST_TYPE_SIGNED($type_name)\n";
671 } elsif ($type_kind eq "unsigned") {
672 print OUT " TEST_TYPE_UNSIGNED($type_name)\n";
676 sub output_test_pack_fields($$$$$$$);
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 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
692 my $field_name = $field->name;
693 my $field_size = $field->size;
694 my $field_offset = $field->offset;
695 my $field_align = $field->align;
697 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
698 # We cannot take the address of a bitfield with MSVC
699 next if ($field_type_name =~ /:/);
701 if ($$optional_fields{$field_name}) {
702 # Nothing
703 } elsif (defined($field_size) && defined($field_offset)) {
704 $field_offset += $offset;
705 if ($field_name eq "DUMMYSTRUCTNAME") {
706 print OUT "#ifdef NONAMELESSSTRUCT\n";
707 print OUT " TEST_TYPE_SIZE ($type_name.$field_name, $field_size)\n";
708 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
709 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
710 print OUT "#else\n";
711 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
712 $type_name, $$type_name2type{$field_type_name}, $field_offset);
713 print OUT "#endif\n";
714 } else {
715 print OUT " TEST_FIELD_SIZE ($type_name, $field_name, $field_size)\n";
716 print OUT " TEST_FIELD_ALIGN ($type_name, $field_name, $field_align)\n";
717 print OUT " TEST_FIELD_OFFSET($type_name, $field_name, $field_offset)\n";
719 } else {
720 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
725 ########################################################################
726 # output_test_pack
728 sub output_test_pack($$$$) {
729 local *OUT = shift;
731 my $test_dir = shift;
732 my $test = shift;
734 my $type_names_used = shift;
736 $output->prefix("$test_dir: $test: ");
738 my @headers = $tests->get_section($test_dir, $test, "header");
739 my @type_names = $tests->get_section($test_dir, $test, "type");
741 my %type_name2optional;
742 my %type_name2optional_fields;
744 foreach my $_type_name (@type_names) {
745 my $type_name = $_type_name;
747 if ($type_name =~ s/^!//) {
748 $type_name2optional{$type_name}++;
751 my $optional_fields = {};
752 if ($type_name =~ s/:\s*(.*?)$//) {
753 my @fields = split /\s+/, $1;
754 foreach my $field (@fields) {
755 if ($field =~ s/^!//) {
756 $$optional_fields{$field}++;
761 $type_name2optional_fields{$type_name} = $optional_fields;
764 foreach my $header (@headers) {
765 my $type_name2type = $file2types{"include/$header"};
767 foreach my $_type_name (@type_names) {
768 my $type_name = $_type_name;
770 my $skip = ($type_name =~ s/^!//);
771 $type_name =~ s/:.*?$//;
772 my $type = $$type_name2type{$type_name};
773 if (!defined($type)) {
774 next;
776 $$type_names_used{$type_name} = $skip ? -1 : 1;
777 next if $skip;
779 print OUT "static void test_${test}_$type_name(void)\n";
780 print OUT "{\n";
781 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
782 $type_name, $type);
783 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
784 $type_name, $type, 0);
785 print OUT "}\n";
786 print OUT "\n";
792 ########################################################################
793 # output_file
795 sub output_file($$$$) {
796 local *OUT = shift;
798 my $test_dir = shift;
799 my @tests = @{(shift)};
801 my $type_names_used = shift;
803 output_header(\*OUT, $test_dir, \@tests);
805 foreach my $test (@tests) {
806 my %type_names_used2;
808 if ($test eq "pack") {
809 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
810 } else {
811 die "no such test ($test)\n";
814 print OUT "static void test_$test(void)\n";
815 print OUT "{\n";
816 foreach my $type_name (sort(keys(%type_names_used2))) {
817 $$type_names_used{$type_name} = $type_names_used2{$type_name};
818 if ($type_names_used2{$type_name} > 0) {
819 print OUT " test_${test}_$type_name();\n";
822 print OUT "}\n";
823 print OUT "\n";
826 output_footer(\*OUT, $test_dir, \@tests);
828 return 1;
831 ########################################################################
832 # main
834 my %type_names_used = ();
836 my @test_dirs = $tests->get_test_dirs();
837 foreach my $test_dir (@test_dirs) {
838 my $file = "$wine_dir/$test_dir/generated.c";
839 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
842 foreach my $header (sort(keys(%file2types))) {
843 $output->prefix("$header: ");
844 $header =~ s%^include/%%;
845 my $type_name2type = $file2types{"include/$header"};
846 foreach my $_type_name (sort(keys(%$type_name2type))) {
847 my $type_name = $_type_name;
849 if (!exists($type_names_used{$type_name})) {
850 $output->write("$type_name: type not used\n");
855 $output->prefix("$winapi_dir/tests.dat: ");
856 foreach my $type_name (sort(keys(%type_names_used))) {
857 my $found = 0;
858 foreach my $header (sort(keys(%file2types))) {
859 my $type_name2type = $file2types{"include/$header"};
860 if (exists($type_name2type{$type_name})) {
861 $found = 1;
865 if (!$found) {
866 $output->write("$type_name: type not used\n");