tests.pm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #
  2. # Copyright 2002 Patrik Stridvall
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. #
  18. package tests;
  19. use strict;
  20. use warnings 'all';
  21. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  22. require Exporter;
  23. @ISA = qw(Exporter);
  24. @EXPORT = qw();
  25. @EXPORT_OK = qw($tests);
  26. use vars qw($tests);
  27. use config qw($current_dir $wine_dir $winapi_dir);
  28. use options qw($options);
  29. use output qw($output);
  30. sub import(@) {
  31. $Exporter::ExportLevel++;
  32. Exporter::import(@_);
  33. $Exporter::ExportLevel--;
  34. $tests = 'tests'->new;
  35. }
  36. sub parse_tests_file($);
  37. sub new($) {
  38. my $proto = shift;
  39. my $class = ref($proto) || $proto;
  40. my $self = {};
  41. bless ($self, $class);
  42. $self->parse_tests_file();
  43. return $self;
  44. }
  45. sub parse_tests_file($) {
  46. my $self = shift;
  47. my $file = "tests.dat";
  48. my $tests = \%{$self->{TESTS}};
  49. $output->lazy_progress($file);
  50. my $test_dir;
  51. my $test;
  52. my $section;
  53. open(IN, "< $winapi_dir/$file") || die "$winapi_dir/$file: $!\n";
  54. while(<IN>) {
  55. s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
  56. s/^(.*?)\s*#.*$/$1/; # remove comments
  57. /^$/ && next; # skip empty lines
  58. if (/^%%%\s*(\S+)$/) {
  59. $test_dir = $1;
  60. } elsif (/^%%\s*(\w+)$/) {
  61. $test = $1;
  62. } elsif (/^%\s*(\w+)$/) {
  63. $section = $1;
  64. } elsif (!/^%/) {
  65. if (!exists($$tests{$test_dir}{$test}{$section})) {
  66. $$tests{$test_dir}{$test}{$section} = [];
  67. }
  68. push @{$$tests{$test_dir}{$test}{$section}}, $_;
  69. } else {
  70. $output->write("$file:$.: parse error: '$_'\n");
  71. exit 1;
  72. }
  73. }
  74. close(IN);
  75. }
  76. sub get_tests($$) {
  77. my $self = shift;
  78. my $tests = \%{$self->{TESTS}};
  79. my $test_dir = shift;
  80. my %tests = ();
  81. if (defined($test_dir)) {
  82. foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
  83. $tests{$test}++;
  84. }
  85. } else {
  86. foreach my $test_dir (sort(keys(%$tests))) {
  87. foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
  88. $tests{$test}++;
  89. }
  90. }
  91. }
  92. return sort(keys(%tests));
  93. }
  94. sub get_test_dirs($$) {
  95. my $self = shift;
  96. my $tests = \%{$self->{TESTS}};
  97. my $test = shift;
  98. my %test_dirs = ();
  99. if (defined($test)) {
  100. foreach my $test_dir (sort(keys(%$tests))) {
  101. if (exists($$tests{$test_dir}{$test})) {
  102. $test_dirs{$test_dir}++;
  103. }
  104. }
  105. } else {
  106. foreach my $test_dir (sort(keys(%$tests))) {
  107. $test_dirs{$test_dir}++;
  108. }
  109. }
  110. return sort(keys(%test_dirs));
  111. }
  112. sub get_sections($$$) {
  113. my $self = shift;
  114. my $tests = \%{$self->{TESTS}};
  115. my $test_dir = shift;
  116. my $test = shift;
  117. my %sections = ();
  118. if (defined($test_dir)) {
  119. if (defined($test)) {
  120. foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
  121. $sections{$section}++;
  122. }
  123. } else {
  124. foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
  125. foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
  126. $sections{$section}++;
  127. }
  128. }
  129. }
  130. } elsif (defined($test)) {
  131. foreach my $test_dir (sort(keys(%$tests))) {
  132. foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
  133. $sections{$section}++;
  134. }
  135. }
  136. } else {
  137. foreach my $test_dir (sort(keys(%$tests))) {
  138. foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
  139. foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
  140. $sections{$section}++;
  141. }
  142. }
  143. }
  144. }
  145. return sort(keys(%sections));
  146. }
  147. sub get_section($$$$) {
  148. my $self = shift;
  149. my $tests = \%{$self->{TESTS}};
  150. my $test_dir = shift;
  151. my $test = shift;
  152. my $section = shift;
  153. my $array = $$tests{$test_dir}{$test}{$section};
  154. if (defined($array)) {
  155. return @$array;
  156. } else {
  157. return ();
  158. }
  159. }
  160. 1;