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
23 $0 =~ m
%^(.*?
/?tools)/winapi
/winapi_test
$%;
24 require "$1/winapi/setup.pm";
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;
37 $output->disable_progress;
43 use util qw(replace_file);
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;
82 my $progress_current = 0;
83 my $progress_max = scalar(@files);
85 ########################################################################
92 "CCHDEVICENAME" => 32,
93 "ELF_VENDOR_SIZE" => 4,
94 "EXCEPTION_MAXIMUM_PARAMETERS" => 15,
95 "HW_PROFILE_GUIDLEN" => 39,
96 "IMAGE_NUMBEROF_DIRECTORY_ENTRIES" => 16,
97 "IMAGE_SIZEOF_SHORT_NAME" => 8,
99 "LF_FULLFACESIZE" => 64,
100 "MAXIMUM_SUPPORTED_EXTENSION" => 512,
102 "MAX_PROFILE_LEN" => 80,
103 "OFS_MAXPATHNAME" => 128,
104 "SIZE_OF_80387_REGISTERS" => 80,
105 "TOKEN_SOURCE_LENGTH" => 8,
108 my %align_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
111 my $type_name = shift;
113 local $_ = $type_name;
115 # Remove "count" and "bits"
116 s/^(.*?)\s*(?:\[\s*(.*?)\s*\]|:(\d+))?$/$1/;
123 } elsif(/^(?:(?:signed\s+|unsigned\s+)?char)$/) {
125 } elsif (/^(?:(?:signed\s+|unsigned\s+)?short)$/) {
127 } elsif (/^(?:wchar_t)$/) {
129 } elsif (/^(?:(?:signed\s+|unsigned\s+)?(?:__int32|int|long(?:\s+int)?)|unsigned|signed)$/) {
131 } elsif (/^(?:float)$/) {
133 } elsif (/^(?:signed\s+|unsigned\s+)?__int64$/) {
135 } elsif (/^(?:double)$/) {
137 } elsif (/^(?:long\s+double)$/) {
139 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|MENU|METAFILE|WND)$/) {
141 } elsif (/^LP(?:CSTR|CWSTR|DWORD|STR|VOID|THREAD_START_ROUTINE|WSTR)$/) {
143 } elsif (/^(?:(?:MSGBOX)CALLBACK[AW]?|(?:FAR|WND)PROC[AW]?)$/) {
145 } elsif (/^(?:FILETIME|LARGE_INTEGER|LONGLONG)$/) {
152 if (defined(my $type = $type_name2type{$_})) {
153 $align2 = $type->align;
156 if (!defined($align)) {
158 } elsif (defined($align2) && !$align_kludge_reported{$_}) {
159 $align_kludge_reported{$_} = 1;
160 $output->write("$type_name: type needn't be kludged\n");
163 if (!defined($align)) {
164 # $output->write("$type_name: can't find type\n");
170 my %size_kludge_reported = ("FILETIME" => 1, "LARGE_INTEGER" => 1);
171 my %size_parse_reported;
174 my $type_name = shift;
176 local $_ = $type_name;
180 if (s/^(.*?)\s*(?:\[\s*(.*?)\s*\]|:(\d+))?$/$1/) {
190 } elsif(/^(?:(?:signed\s+|unsigned\s+)?char)$/) {
192 } elsif (/^(?:(?:signed\s+|unsigned\s+)?short)$/) {
194 } elsif (/^(?:wchar_t)$/) {
196 } elsif (/^(?:(?:signed\s+|unsigned\s+)?(?:__int32|int|long(?:\s+int)?)|unsigned|signed)$/) {
198 } elsif (/^(?:float)$/) {
200 } elsif (/^(?:signed\s+|unsigned\s+)?__int64$/) {
202 } elsif (/^(?:double)$/) {
204 } elsif (/^(?:long\s+double)$/) {
206 } elsif (/^H(?:DC|BITMAP|BRUSH|ICON|INSTANCE|MENU|METAFILE|WND)$/) {
208 } elsif (/^LP(?:CSTR|CWSTR|DWORD|STR|VOID|THREAD_START_ROUTINE|WSTR)$/) {
210 } elsif (/^(?:(?:MSGBOX)CALLBACK[AW]?|(?:FAR|WND)PROC[AW]?)$/) {
212 } elsif (/^(?:FILETIME|LARGE_INTEGER|LONGLONG)$/) {
214 } elsif (/^(?:struct|union)$/) {
215 if (!$size_parse_reported{$_}) {
216 $output->write("$type_name: can't parse type\n");
217 $size_parse_reported{$_} = 1;
225 if (defined(my $type = $type_name2type{$_})) {
226 $size2 = $type->size;
229 if (!defined($size)) {
231 } elsif (defined($size2) && !$size_kludge_reported{$_}) {
232 $size_kludge_reported{$_} = 1;
233 $output->write("$type_name: type needn't be kludged\n");
236 if (!defined($size)) {
237 # $output->write("$type_name: can't find type\n");
238 } elsif (defined($count)) {
239 if ($count =~ /^\d+$/) {
240 $size *= int($count);
241 } elsif (defined($count = $defines{$count})) {
242 $size *= int($count);
244 $output->write("$type_name: can't parse type\n");
247 } elsif (defined($bits)) {
254 foreach my $file (@files) {
258 open(IN
, "< $wine_dir/$file");
267 while(s/^.*?\n//) { $max_line++; }
268 if($_) { $max_line++; }
271 my $parser = new c_parser
($file);
277 my $update_output = sub {
281 $progress .= "$file (file $progress_current of $progress_max)";
282 $prefix .= "$file: ";
285 $progress .= ": line $line of $max_line";
288 $output->progress($progress);
289 $output->prefix($prefix);
294 my $found_line = sub {
299 $parser->set_found_line_callback($found_line);
301 my $found_preprocessor = sub {
302 my $begin_line = shift;
303 my $begin_column = shift;
304 my $preprocessor = shift;
306 local $_ = $preprocessor;
307 if (/^\#\s*include\s+\"pshpack(\d+)\.h\"$/) {
309 } elsif(/^\#\s*include\s+\"poppack\.h\"$/) {
315 $parser->set_found_preprocessor_callback($found_preprocessor);
317 my $found_type = sub {
322 my $name = $type->name;
323 $file2types{$file}{$name} = $type;
325 $type->set_find_align_callback(\
&find_align
);
326 $type->set_find_size_callback(\
&find_size
);
328 my $pack = $packs[$#packs];
329 if (!defined($type->pack)) {
332 my $size = $type->size();
333 if (defined($size)) {
334 my $max_field_base_size = 0;
336 foreach my $field ($type->fields()) {
337 my $field_type_name = $field->type_name;
338 my $field_name = $field->name;
339 my $field_size = $field->size;
340 my $field_base_size = $field->base_size;
341 my $field_offset = $field->offset;
342 my $field_align = $field->align;
344 # $output->write("$name: $field_type_name: $field_name: $field_offset: $field_size($field_base_size): $field_align\n");
346 # $output->write("$name: $size\n");
348 $type_name2type{$name} = $type;
350 # $output->write("$name: can't find size\n");
355 $parser->set_found_type_callback($found_type);
360 if(!$parser->parse_c_file(\
$_, \
$line, \
$column)) {
361 $output->write("can't parse file\n");
368 ########################################################################
374 my $test_dir = shift;
375 my @tests = @
{(shift)};
377 print OUT
"/* File generated automatically from tools/winapi/test.dat; do not edit! */\n";
378 print OUT
"/* This file can be copied, modified and distributed without restriction. */\n";
382 foreach my $test (@tests) {
383 my @description = $tests->get_section($test_dir, $test, "description");
384 foreach my $description (@description) {
385 print OUT
" * $description\n";
391 print OUT
"#define WINVER 0x0501\n";
392 print OUT
"#define _WIN32_WINNT 0x0501\n";
394 print OUT
"#define WINE_NOWINSOCK\n";
396 foreach my $test (@tests) {
397 my @includes = $tests->get_section($test_dir, $test, "include");
398 foreach my $include (@includes) {
399 print OUT
"#include \"$include\"\n";
403 print OUT
"#include \"wine/test.h\"\n";
406 print OUT
"/***********************************************************************\n";
407 print OUT
" * Compability macros\n";
410 print OUT
"#define DWORD_PTR UINT_PTR\n";
411 print OUT
"#define LONG_PTR INT_PTR\n";
412 print OUT
"#define ULONG_PTR UINT_PTR\n";
415 print OUT
"/***********************************************************************\n";
416 print OUT
" * Windows API extension\n";
419 print OUT
"#if (_MSC_VER >= 1300) && defined(__cplusplus)\n";
420 print OUT
"# define FIELD_ALIGNMENT(type, field) __alignof(((type*)0)->field)\n";
421 print OUT
"#elif defined(__GNUC__)\n";
422 print OUT
"# define FIELD_ALIGNMENT(type, field) __alignof__(((type*)0)->field)\n";
424 print OUT
"/* FIXME: Not sure if is possible to do without compiler extension */\n";
425 print OUT
"#endif\n";
427 print OUT
"/***********************************************************************\n";
428 print OUT
" * Test helper macros\n";
431 print OUT
"#ifdef FIELD_ALIGNMENT\n";
432 print OUT
"# define TEST_FIELD_ALIGNMENT(type, field, align) \\\n";
433 print OUT
" ok(FIELD_ALIGNMENT(type, field) == align, \\\n";
434 print OUT
" \"FIELD_ALIGNMENT(\" #type \", \" #field \") == %d (expected \" #align \")\", \\\n";
435 print OUT
" FIELD_ALIGNMENT(type, field))\n";
437 print OUT
"# define TEST_FIELD_ALIGNMENT(type, field, align) do { } while (0)\n";
438 print OUT
"#endif\n";
440 print OUT
"#define TEST_FIELD_OFFSET(type, field, offset) \\\n";
441 print OUT
" ok(FIELD_OFFSET(type, field) == offset, \\\n";
442 print OUT
" \"FIELD_OFFSET(\" #type \", \" #field \") == %ld (expected \" #offset \")\", \\\n";
443 print OUT
" FIELD_OFFSET(type, field))\n";
445 print OUT
"#define TEST_TYPE_ALIGNMENT(type, align) \\\n";
446 print OUT
" ok(TYPE_ALIGNMENT(type) == align, \"TYPE_ALIGNMENT(\" #type \") == %d (expected \" #align \")\", TYPE_ALIGNMENT(type))\n";
448 print OUT
"#define TEST_TYPE_SIZE(type, size) \\\n";
449 print OUT
" ok(sizeof(type) == size, \"sizeof(\" #type \") == %d (expected \" #size \")\", sizeof(type))\n";
451 print OUT
"/***********************************************************************\n";
452 print OUT
" * Test macros\n";
455 print OUT
"#define TEST_FIELD(type, field_type, field_name, field_offset, field_size, field_align) \\\n";
456 print OUT
" TEST_TYPE_SIZE(field_type, field_size); \\\n";
457 print OUT
" TEST_FIELD_ALIGNMENT(type, field_name, field_align); \\\n";
458 print OUT
" TEST_FIELD_OFFSET(type, field_name, field_offset); \\\n";
460 print OUT
"#define TEST_TYPE(type, size, align) \\\n";
461 print OUT
" TEST_TYPE_ALIGNMENT(type, align); \\\n";
462 print OUT
" TEST_TYPE_SIZE(type, size)\n";
466 ########################################################################
472 my $test_dir = shift;
473 my @tests = @
{(shift)};
475 print OUT
"START_TEST(generated)\n";
477 foreach my $test (@tests) {
478 print OUT
" test_$test();\n";
483 ########################################################################
484 # output_test_pack_type
486 sub output_test_pack_type
{
490 my $type_name = shift;
493 my $type_align = $type->align;
494 my $type_pack = $type->pack;
495 my $type_size = $type->size;
497 print OUT
" /* $type_name (pack $type_pack) */\n";
498 if (defined($type_align) && defined($type_size)) {
499 print OUT
" TEST_TYPE($type_name, $type_size, $type_align);\n";
503 sub output_test_pack_fields
{
507 my $type_name = shift;
510 my $optional_field = shift;
512 foreach my $field ($type->fields()) {
513 my $field_type_name = $field->type_name;
514 my $field_name = $field->name;
515 my $field_size = $field->size;
516 my $field_offset = $field->offset;
517 my $field_align = $field->align;
519 next if $field_name eq "" || (defined($field_size) && $field_size < 0);
521 if ($$optional_field{$field_name}) {
523 } elsif (defined($field_size) && defined($field_offset)) {
524 $field_offset += $offset;
525 if ($field_name eq "DUMMYSTRUCTNAME") {
526 print OUT
"#ifdef NONAMELESSSTRUCT\n";
527 print OUT
" TEST_FIELD($type_name, $field_type_name, $field_name, ";
528 print OUT
"$field_offset, $field_size, $field_align);\n";
530 output_test_pack_fields
(\
*OUT
, $types, $type_name, $$types{$field_type_name}, $field_offset, $optional_field);
531 print OUT
"#endif\n";
533 print OUT
" TEST_FIELD($type_name, $field_type_name, $field_name, ";
534 print OUT
"$field_offset, $field_size, $field_align);\n";
537 $output->write("$type_name: $field_type_name: $field_name: test not generated (offset not defined)\n");
542 ########################################################################
545 sub output_test_pack
{
548 my $test_dir = shift;
551 my @headers = $tests->get_section($test_dir, $test, "header");
552 my @type_names = $tests->get_section($test_dir, $test, "struct");
554 my %type_name_not_used;
556 foreach my $_type_name (@type_names) {
557 my $type_name = $_type_name;
559 $type_name =~ s/:.*?$//;
560 $type_name_not_used{$type_name} = 1;
563 foreach my $header (@headers) {
564 my $types = $file2types{"include/$header"};
566 foreach my $_type_name (@type_names) {
567 my $type_name = $_type_name;
569 my %optional_field = ();
570 if ($type_name =~ s/:\s*(.*?)$//) {
571 my @fields = split /\s+/, $1;
572 foreach my $field (@fields) {
573 if ($field =~ s/^!//) {
574 $optional_field{$field}++;
579 my $type = $$types{$type_name};
580 if (!defined($type)) {
583 $type_name_not_used{$type_name} = 0;
585 if (!scalar(keys(%optional_field))) {
586 output_test_pack_type
(\
*OUT
, $types, $type_name, $type);
588 print OUT
" /* $type_name */\n";
590 output_test_pack_fields
(\
*OUT
, $types, $type_name, $type, 0, \
%optional_field);
595 foreach my $_type_name (@type_names) {
596 my $type_name = $_type_name;
597 $type_name =~ s/:.*?$//;
598 if ($type_name_not_used{$type_name}) {
599 # $output->write("$test_dir: $test: $type_name: type not found (ignored)\n");
605 ########################################################################
611 my $test_dir = shift;
612 my @tests = @
{(shift)};
614 output_header
(\
*OUT
, $test_dir, \
@tests);
616 foreach my $test (@tests) {
617 print OUT
"void test_$test(void)\n";
620 if ($test eq "pack") {
621 output_test_pack
(\
*OUT
, $test_dir, $test);
623 die "no such test ($test)\n";
630 output_footer
(\
*OUT
, $test_dir, \
@tests);
635 ########################################################################
638 my @test_dirs = $tests->get_test_dirs();
639 foreach my $test_dir (@test_dirs) {
640 my $file = "$wine_dir/$test_dir/generated.c";
641 replace_file
($file, \
&output_file
, $test_dir, \
@tests);