wintrust: Added stubbed CryptCATAdminEnumCatalogFromHash.
[wine/wine64.git] / tools / winapi / winapi_test
blobdb95c36df86fa1292092d2f6a436a0b1d7bb7ebf
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 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 "Error: Can't open $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 "CCHILDREN_TITLEBAR+1" => 6,
153 "ELF_VENDOR_SIZE" => 4,
154 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
155 "HW_PROFILE_GUIDLEN" => 39,
156 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
157 "IMAGE_SIZEOF_SHORT_NAME" => 8,
158 "LF_FACESIZE" => 32,
159 "LF_FULLFACESIZE" => 64,
160 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
161 "MAX_GOPHER_DISPLAY_TEXT + 1" => 129,
162 "MAX_GOPHER_LOCATOR_LENGTH + 1" => 654,
163 "MAX_PATH" => 260,
164 "MAX_PROFILE_LEN" => 80,
165 "NUM_POINTS" => 3,
166 "OFS_MAXPATHNAME" => 128,
167 "SIZE_OF_80387_REGISTERS" => 80,
168 "TOKEN_SOURCE_LENGTH" => 8,
171 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
172 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
173 my %size_parse_reported;
175 sub _find_align_kind_size($) {
176 my $type_name = shift;
178 local $_ = $type_name;
180 my $align;
181 my $kind;
182 my $size;
183 if (0) {
184 # Nothing
185 } elsif (/\*+$/) {
186 $align = 4;
187 $kind = "pointer";
188 $size = 4;
189 } elsif(/^(?:(signed|unsigned)\s+)?(?:__int8|char|byte)$/) {
190 $align = 1;
191 $kind = defined($1) ? $1 : "signed";
192 $size = 1;
193 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int16|short(?:\s+int)?)$/) {
194 $align = 2;
195 $kind = defined($1) ? $1 : "signed";
196 $size = 2;
197 } elsif (/^(?:wchar_t)$/) {
198 $align = 2;
199 $kind = "signed";
200 $size = 2;
201 } elsif (/^(signed|unsigned)$/) {
202 $align = 4;
203 $kind = defined($1) ? $1 : "signed";
204 $size = 4;
205 } elsif (/^(?:(signed|unsigned)\s+)?(?:__int32|int|long(?:\s+int)?)$/) {
206 $align = 4;
207 $kind = defined($1) ? $1 : "signed";
208 $size = 4;
209 } elsif (/^(?:float)$/) {
210 $align = 4;
211 $kind = "float";
212 $size = 4;
213 } elsif (/^(?:(signed|unsigned)\s+)?__int64$/) {
214 $align = 8;
215 $kind = defined($1) ? $1 : "signed";
216 $size = 8;
217 } elsif (/^(?:double|DOUBLE|DATE)$/) {
218 $align = 8;
219 $kind = "float";
220 $size = 8;
221 } elsif (/^(?:long\s+double)$/) {
222 $align = 4;
223 $kind = "float";
224 $size = 12;
225 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|KEY|MENU|METAFILE|RESULT|WND)$/) {
226 $align = 4;
227 $kind = "unsigned";
228 $size = 4;
229 } elsif (/^LP(?:BYTE|CSTR|CWSTR|DWORD|STR|VOID|WSTR)$/) {
230 $align = 4;
231 $kind = "pointer";
232 $size = 4;
233 } elsif (/^(?:FILETIME)$/) {
234 $align = 4;
235 $kind = "struct";
236 $size = 8;
237 } elsif (/^(?:VOID)$/) {
238 $align = 4;
239 $kind = "signed";
240 $size = 4;
241 } elsif (/^(?:SHORT)$/) {
242 $align = 2;
243 $kind = "unsigned";
244 $size = 2;
245 } elsif (/^(?:BYTE)$/) {
246 $align = 1;
247 $kind = "unsigned";
248 $size = 1;
249 } elsif (/^(?:DWORD)$/) {
250 $align = 4;
251 $kind = "unsigned";
252 $size = 4;
253 } elsif (/^(?:WORD)$/) {
254 $align = 2;
255 $kind = "unsigned";
256 $size = 2;
257 } elsif (/^(?:INT64|LONG64|LONGLONG)$/) {
258 $align = 8;
259 $kind = "signed";
260 $size = 8;
261 } elsif (/^(?:UINT64|ULONG64|DWORD64|ULONGLONG|DWORDLONG)$/) {
262 $align = 8;
263 $kind = "unsigned";
264 $size = 8;
265 } elsif (/^(?:LARGE_INTEGER)$/) {
266 $align = 8;
267 $kind = "union";
268 $size = 8;
269 } elsif (/^(struct|union)$/) {
270 $kind = $1;
271 if (!$size_parse_reported{$_}) {
272 $output->write("$type_name: can't parse type\n");
273 $size_parse_reported{$_} = 1;
275 } elsif (/^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
276 $align = 4;
277 $kind = "pointer";
278 $size = 4;
281 my $align2;
282 if (defined(my $type = $type_name2type{$_})) {
283 $align2 = $type->align;
286 if (!defined($align)) {
287 $align = $align2;
288 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
289 $align_kludge_reported{$_} = 1;
290 $output->write("$type_name: type needn't be kludged\n");
293 if (!defined($align)) {
294 # $output->write("$type_name: can't find type\n");
297 my $size2;
298 if (defined(my $type = $type_name2type{$_})) {
299 $size2 = $type->size;
302 if (!defined($size)) {
303 $size = $size2;
304 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
305 $size_kludge_reported{$_} = 1;
306 $output->write("$type_name: type needn't be kludged\n");
309 return ($align, $kind, $size);
312 sub find_align($) {
313 my $type_name = shift;
314 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
315 return $align;
318 sub find_kind($) {
319 my $type_name = shift;
320 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
322 return $kind;
325 sub find_size($) {
326 my $type_name = shift;
327 (my $align, my $kind, my $size) = _find_align_kind_size($type_name);
328 return $size;
331 sub find_count($) {
332 my $count = shift;
333 return $defines{$count};
336 foreach my $file (@files) {
337 $progress_current++;
340 open(IN, "< $wine_dir/$file") || die "Error: Can't open $wine_dir/$file: $!\n";
341 local $/ = undef;
342 $_ = <IN>;
343 close(IN);
346 my $max_line = 0;
348 local $_ = $_;
349 while(s/^.*?\n//) { $max_line++; }
350 if($_) { $max_line++; }
353 my $parser = new c_parser($file);
355 my $line;
356 my $type;
357 my @packs = (4);
359 my $update_output = sub {
360 my $progress = "";
361 my $prefix = "";
363 $progress .= "$file (file $progress_current of $progress_max)";
364 $prefix .= "$file: ";
366 if(defined($line)) {
367 $progress .= ": line $line of $max_line";
370 $output->progress($progress);
371 $output->prefix($prefix);
374 &$update_output();
376 my $found_line = sub {
377 $line = shift;
379 &$update_output;
381 $parser->set_found_line_callback($found_line);
383 my $found_preprocessor = sub {
384 my $begin_line = shift;
385 my $begin_column = shift;
386 my $preprocessor = shift;
388 #print "found_preprocessor: $begin_line: [$_]\n";
389 if ($preprocessor =~ /^\#\s*include\s+[\"<]pshpack(\d+)\.h[\">]$/) {
390 push @packs, $1;
391 #print "found pack $1 on line $begin_line\n";
392 } elsif($preprocessor =~ /^\#\s*include\s+[\"<]poppack\.h[\">]$/) {
393 pop @packs;
394 #print "found poppack on line $begin_line\n";
397 return 1;
399 $parser->set_found_preprocessor_callback($found_preprocessor);
401 my $found_type = sub {
402 $type = shift;
404 &$update_output();
406 my $name = $type->name;
407 $file2types{$file}{$name} = $type;
409 $type->set_find_align_callback(\&find_align);
410 $type->set_find_kind_callback(\&find_kind);
411 $type->set_find_size_callback(\&find_size);
412 $type->set_find_count_callback(\&find_count);
414 my $pack = $packs[$#packs];
415 if (!defined($type->pack) && $type->kind =~ /^(?:struct|union)$/) {
416 $type->pack($pack);
418 my $size = $type->size();
419 if (defined($size)) {
420 my $max_field_base_size = 0;
422 foreach my $field ($type->fields()) {
423 my $field_type_name = $field->type_name;
424 my $field_name = $field->name;
425 my $field_size = $field->size;
426 my $field_base_size = $field->base_size;
427 my $field_offset = $field->offset;
428 my $field_align = $field->align;
430 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
432 # $output->write("$name: $size\n");
434 $type_name2type{$name} = $type;
435 } else {
436 # $output->write("$name: can't find size\n");
439 return 1;
441 $parser->set_found_type_callback($found_type);
444 my $line = 1;
445 my $column = 0;
446 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
447 $output->write("can't parse file\n");
451 $output->prefix("");
454 ########################################################################
455 # output_header
457 sub output_header($$$) {
458 local *OUT = shift;
460 my $test_dir = shift;
461 my @tests = @{(shift)};
463 print OUT "/* File generated automatically from tools/winapi/test.dat; do not edit! */\n";
464 print OUT "/* This file can be copied, modified and distributed without restriction. */\n";
465 print OUT "\n";
467 print OUT "/*\n";
468 foreach my $test (@tests) {
469 my @description = $tests->get_section($test_dir, $test, "description");
470 foreach my $description (@description) {
471 print OUT " * $description\n";
474 print OUT " */\n";
475 print OUT "\n";
477 print OUT "#define WINVER 0x0501\n";
478 print OUT "#define _WIN32_IE 0x0501\n";
479 print OUT "#define _WIN32_WINNT 0x0501\n";
480 print OUT "\n";
481 print OUT "#define WINE_NOWINSOCK\n";
482 print OUT "\n";
483 foreach my $test (@tests) {
484 my @includes = $tests->get_section($test_dir, $test, "include");
485 foreach my $include (@includes) {
486 print OUT "#include $include\n";
489 print OUT "\n";
490 print OUT "#include \"wine/test.h\"\n";
491 print OUT "\n";
493 print OUT "/***********************************************************************\n";
494 print OUT " * Compability macros\n";
495 print OUT " */\n";
496 print OUT "\n";
497 print OUT "#define DWORD_PTR UINT_PTR\n";
498 print OUT "#define LONG_PTR INT_PTR\n";
499 print OUT "#define ULONG_PTR UINT_PTR\n";
500 print OUT "\n";
502 print OUT "/***********************************************************************\n";
503 print OUT " * Windows API extension\n";
504 print OUT " */\n";
505 print OUT "\n";
506 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
507 print OUT "# define FIELD_ALIGNMENT(type, field) __alignof(((type*)0)->field)\n";
508 print OUT "#elif defined(__GNUC__)\n";
509 print OUT "# define FIELD_ALIGNMENT(type, field) __alignof__(((type*)0)->field)\n";
510 print OUT "#else\n";
511 print OUT "/* FIXME: Not sure if is possible to do without compiler extension */\n";
512 print OUT "#endif\n";
513 print OUT "\n";
514 print OUT "#if defined(_MSC_VER) && (_MSC_VER >= 1300) && defined(__cplusplus)\n";
515 print OUT "# define _TYPE_ALIGNMENT(type) __alignof(type)\n";
516 print OUT "#elif defined(__GNUC__)\n";
517 print OUT "# define _TYPE_ALIGNMENT(type) __alignof__(type)\n";
518 print OUT "#else\n";
519 print OUT "/*\n";
520 print OUT " * FIXME: Not sure if is possible to do without compiler extension\n";
521 print OUT " * (if type is not just a name that is, if so the normal)\n";
522 print OUT " * TYPE_ALIGNMENT can be used)\n";
523 print OUT " */\n";
524 print OUT "#endif\n";
525 print OUT "\n";
526 print OUT "#if defined(TYPE_ALIGNMENT) && defined(_MSC_VER) && _MSC_VER >= 800 && !defined(__cplusplus)\n";
527 print OUT "#pragma warning(disable:4116)\n";
528 print OUT "#endif\n";
529 print OUT "\n";
530 print OUT "#if !defined(TYPE_ALIGNMENT) && defined(_TYPE_ALIGNMENT)\n";
531 print OUT "# define TYPE_ALIGNMENT _TYPE_ALIGNMENT\n";
532 print OUT "#endif\n";
533 print OUT "\n";
535 print OUT "/***********************************************************************\n";
536 print OUT " * Test helper macros\n";
537 print OUT " */\n";
538 print OUT "\n";
539 print OUT "#ifdef FIELD_ALIGNMENT\n";
540 print OUT "# define TEST_FIELD_ALIGNMENT(type, field, align) \\\n";
541 print OUT " ok(FIELD_ALIGNMENT(type, field) == align, \\\n";
542 print OUT " \"FIELD_ALIGNMENT(\" #type \", \" #field \") == %d (expected \" #align \")\\n\", \\\n";
543 print OUT " (int)FIELD_ALIGNMENT(type, field))\n";
544 print OUT "#else\n";
545 print OUT "# define TEST_FIELD_ALIGNMENT(type, field, align) do { } while (0)\n";
546 print OUT "#endif\n";
547 print OUT "\n";
548 print OUT "#define TEST_FIELD_OFFSET(type, field, offset) \\\n";
549 print OUT " ok(FIELD_OFFSET(type, field) == offset, \\\n";
550 print OUT " \"FIELD_OFFSET(\" #type \", \" #field \") == %ld (expected \" #offset \")\\n\", \\\n";
551 print OUT " (long int)FIELD_OFFSET(type, field))\n";
552 print OUT "\n";
553 print OUT "#ifdef _TYPE_ALIGNMENT\n";
554 print OUT "#define TEST__TYPE_ALIGNMENT(type, align) \\\n";
555 print OUT " ok(_TYPE_ALIGNMENT(type) == align, \"TYPE_ALIGNMENT(\" #type \") == %d (expected \" #align \")\\n\", (int)_TYPE_ALIGNMENT(type))\n";
556 print OUT "#else\n";
557 print OUT "# define TEST__TYPE_ALIGNMENT(type, align) do { } while (0)\n";
558 print OUT "#endif\n";
559 print OUT "\n";
560 print OUT "#ifdef TYPE_ALIGNMENT\n";
561 print OUT "#define TEST_TYPE_ALIGNMENT(type, align) \\\n";
562 print OUT " ok(TYPE_ALIGNMENT(type) == align, \"TYPE_ALIGNMENT(\" #type \") == %d (expected \" #align \")\\n\", (int)TYPE_ALIGNMENT(type))\n";
563 print OUT "#else\n";
564 print OUT "# define TEST_TYPE_ALIGNMENT(type, align) do { } while (0)\n";
565 print OUT "#endif\n";
566 print OUT "\n";
567 print OUT "#define TEST_TYPE_SIZE(type, size) \\\n";
568 print OUT " ok(sizeof(type) == size, \"sizeof(\" #type \") == %d (expected \" #size \")\\n\", ((int) sizeof(type)))\n";
569 print OUT "\n";
570 print OUT "/***********************************************************************\n";
571 print OUT " * Test macros\n";
572 print OUT " */\n";
573 print OUT "\n";
574 print OUT "#define TEST_FIELD(type, field_type, field_name, field_offset, field_size, field_align) \\\n";
575 print OUT " TEST_TYPE_SIZE(field_type, field_size); \\\n";
576 print OUT " TEST_FIELD_ALIGNMENT(type, field_name, field_align); \\\n";
577 print OUT " TEST_FIELD_OFFSET(type, field_name, field_offset); \\\n";
578 print OUT "\n";
579 print OUT "#define TEST_TYPE(type, size, align) \\\n";
580 print OUT " TEST_TYPE_ALIGNMENT(type, align); \\\n";
581 print OUT " TEST_TYPE_SIZE(type, size)\n";
582 print OUT "\n";
583 print OUT "#define TEST_TYPE_POINTER(type, size, align) \\\n";
584 print OUT " TEST__TYPE_ALIGNMENT(*(type)0, align); \\\n";
585 print OUT " TEST_TYPE_SIZE(*(type)0, size)\n";
586 print OUT "\n";
587 print OUT "#define TEST_TYPE_SIGNED(type) \\\n";
588 print OUT " ok((type) -1 < 0, \"(\" #type \") -1 < 0\\n\");\n";
589 print OUT "\n";
590 print OUT "#define TEST_TYPE_UNSIGNED(type) \\\n";
591 print OUT " ok((type) -1 > 0, \"(\" #type \") -1 > 0\\n\");\n";
592 print OUT "\n";
595 ########################################################################
596 # output_footer
598 sub output_footer($$$) {
599 local *OUT = shift;
601 my $test_dir = shift;
602 my @tests = @{(shift)};
604 print OUT "START_TEST(generated)\n";
605 print OUT "{\n";
606 foreach my $test (@tests) {
607 print OUT " test_$test();\n";
609 print OUT "}\n";
612 ########################################################################
613 # output_test_pack_type
615 sub output_test_pack_type($$$$$$) {
616 local *OUT = shift;
618 my $type_name2type = shift;
619 my $type_name2optional = shift;
620 my $type_name2optional_fields = shift;
621 my $type_name = shift;
622 my $type = shift;
624 my $optional_fields = $$type_name2optional_fields{$type_name};
626 my $type_align = $type->align;
627 my $type_pack = $type->pack;
628 my $type_size = $type->size;
629 my $type_kind = $type->kind;
631 if (defined($type_pack)) {
632 print OUT " /* $type_name (pack $type_pack) */\n";
633 } else {
634 print OUT " /* $type_name */\n";
637 if (!scalar(keys(%$optional_fields)) && defined($type_align) && defined($type_size)) {
638 print OUT " TEST_TYPE($type_name, $type_size, $type_align);\n";
641 if ($type_kind eq "float") {
642 # Nothing
643 } elsif ($type_kind eq "pointer") {
644 my $dereference_type;
645 $dereference_type = sub {
646 my $type = shift;
648 my @fields = $type->fields;
649 my $type_name2 =$fields[0]->type_name;
651 if ($type_name2 =~ s/\s*\*$//) {
652 my $type2 = $$type_name2type{$type_name2};
653 if (defined($type2)) {
654 return $type2;
655 } else {
656 if ($type_name2 !~ /^(?:PVOID|VOID|void)$/) {
657 $output->write("$type_name2: warning: type not found 1\n");
659 return undef;
661 } elsif ($type_name2 =~ /^\w+$/) {
662 my $type2 = $$type_name2type{$type_name2};
663 if (defined($type2)) {
664 return &$dereference_type($type2);
665 } else {
666 $output->write("$type_name2: warning: type not found\n");
667 return undef;
669 } elsif ($type_name2 =~ /^\w+\s*\((?:\s*CALLBACK|\s*NTAPI|\s*WINAPI)?\s*\*\s*\)\s*\(.*?\)$/) {
670 return undef;
671 } else {
672 $output->write("$type_name2: warning: type can't be parsed\n");
673 return undef;
677 my $type2 = &$dereference_type($type);
678 if (defined($type2)) {
679 my $type_name2 = $type2->name;
680 my $type_align2 = $type2->align;
681 my $type_size2 = $type2->size;
683 my $optional = $$type_name2optional{$type_name};
684 my $optional_fields2 = $$type_name2optional_fields{$type_name2};
686 if (!$optional && !scalar(keys(%$optional_fields2)) && defined($type_align2) && defined($type_size2)) {
687 print OUT " TEST_TYPE_POINTER($type_name, $type_size2, $type_align2);\n";
688 } else {
689 # $output->write("$type_name: warning: type size not found\n");
692 } elsif ($type_kind eq "signed") {
693 print OUT " TEST_TYPE_SIGNED($type_name);\n";
694 } elsif ($type_kind eq "unsigned") {
695 print OUT " TEST_TYPE_UNSIGNED($type_name);\n";
699 sub output_test_pack_fields($$$$$$$);
700 sub output_test_pack_fields($$$$$$$) {
701 local *OUT = shift;
703 my $type_name2type = shift;
704 my $type_name2optional = shift;
705 my $type_name2optional_fields = shift;
706 my $type_name = shift;
707 my $type = shift;
708 my $offset = shift;
710 my $optional_fields = $$type_name2optional_fields{$type_name};
712 foreach my $field ($type->fields()) {
713 my $field_type_name = $field->type_name;
714 $field_type_name =~ s/\s+DECLSPEC_ALIGN\(\d+\)//;
715 my $field_name = $field->name;
716 my $field_size = $field->size;
717 my $field_offset = $field->offset;
718 my $field_align = $field->align;
720 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
721 # We cannot take the address of a bitfield with MSVC
722 next if ($field_type_name =~ /:/);
724 if ($$optional_fields{$field_name}) {
725 # Nothing
726 } elsif (defined($field_size) && defined($field_offset)) {
727 $field_offset += $offset;
728 if ($field_name eq "DUMMYSTRUCTNAME") {
729 print OUT "#ifdef NONAMELESSSTRUCT\n";
730 print OUT " TEST_FIELD($type_name, $field_type_name, $field_name, ";
731 print OUT "$field_offset, $field_size, $field_align);\n";
732 print OUT "#else\n";
733 output_test_pack_fields(\*OUT, $type_name2type, $type_name2optional, $type_name2optional_fields,
734 $type_name, $$type_name2type{$field_type_name}, $field_offset);
735 print OUT "#endif\n";
736 } else {
737 print OUT " TEST_FIELD($type_name, $field_type_name, $field_name, ";
738 print OUT "$field_offset, $field_size, $field_align);\n";
740 } else {
741 # $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
746 ########################################################################
747 # output_test_pack
749 sub output_test_pack($$$$) {
750 local *OUT = shift;
752 my $test_dir = shift;
753 my $test = shift;
755 my $type_names_used = shift;
757 $output->prefix("$test_dir: $test: ");
759 my @headers = $tests->get_section($test_dir, $test, "header");
760 my @type_names = $tests->get_section($test_dir, $test, "type");
762 my %type_name2optional;
763 my %type_name2optional_fields;
765 foreach my $_type_name (@type_names) {
766 my $type_name = $_type_name;
768 if ($type_name =~ s/^!//) {
769 $type_name2optional{$type_name}++;
772 my $optional_fields = {};
773 if ($type_name =~ s/:\s*(.*?)$//) {
774 my @fields = split /\s+/, $1;
775 foreach my $field (@fields) {
776 if ($field =~ s/^!//) {
777 $$optional_fields{$field}++;
782 $type_name2optional_fields{$type_name} = $optional_fields;
785 foreach my $header (@headers) {
786 my $type_name2type = $file2types{"include/$header"};
788 foreach my $_type_name (@type_names) {
789 my $type_name = $_type_name;
791 my $skip = ($type_name =~ s/^!//);
792 $type_name =~ s/:.*?$//;
793 my $type = $$type_name2type{$type_name};
794 if (!defined($type)) {
795 next;
797 $$type_names_used{$type_name} = $skip ? -1 : 1;
798 next if $skip;
800 print OUT "static void test_${test}_$type_name(void)\n";
801 print OUT "{\n";
802 output_test_pack_type(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
803 $type_name, $type);
804 output_test_pack_fields(\*OUT, $type_name2type, \%type_name2optional, \%type_name2optional_fields,
805 $type_name, $type, 0);
806 print OUT "}\n";
807 print OUT "\n";
813 ########################################################################
814 # output_file
816 sub output_file($$$$) {
817 local *OUT = shift;
819 my $test_dir = shift;
820 my @tests = @{(shift)};
822 my $type_names_used = shift;
824 output_header(\*OUT, $test_dir, \@tests);
826 foreach my $test (@tests) {
827 my %type_names_used2;
829 if ($test eq "pack") {
830 output_test_pack(\*OUT, $test_dir, $test, \%type_names_used2);
831 } else {
832 die "no such test ($test)\n";
835 print OUT "static void test_$test(void)\n";
836 print OUT "{\n";
837 foreach my $type_name (sort(keys(%type_names_used2))) {
838 $$type_names_used{$type_name} = $type_names_used2{$type_name};
839 if ($type_names_used2{$type_name} > 0) {
840 print OUT " test_${test}_$type_name();\n";
843 print OUT "}\n";
844 print OUT "\n";
847 output_footer(\*OUT, $test_dir, \@tests);
849 return 1;
852 ########################################################################
853 # main
855 my %type_names_used = ();
857 my @test_dirs = $tests->get_test_dirs();
858 foreach my $test_dir (@test_dirs) {
859 my $file = "$wine_dir/$test_dir/generated.c";
860 replace_file($file, \&output_file, $test_dir, \@tests, \%type_names_used);
863 foreach my $header (sort(keys(%file2types))) {
864 $output->prefix("$header: ");
865 $header =~ s%^include/%%;
866 my $type_name2type = $file2types{"include/$header"};
867 foreach my $_type_name (sort(keys(%$type_name2type))) {
868 my $type_name = $_type_name;
870 if (!exists($type_names_used{$type_name})) {
871 $output->write("$type_name: type not used\n");
876 $output->prefix("$winapi_dir/tests.dat: ");
877 foreach my $type_name (sort(keys(%type_names_used))) {
878 my $found = 0;
879 foreach my $header (sort(keys(%file2types))) {
880 my $type_name2type = $file2types{"include/$header"};
881 if (exists($type_name2type{$type_name})) {
882 $found = 1;
886 if (!$found) {
887 $output->write("$type_name: type not used\n");