tests.pm 4.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#
# Copyright 2002 Patrik Stridvall
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#

package tests;

use strict;

use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;

@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw($tests);

use vars qw($tests);

use config qw($current_dir $wine_dir $winapi_dir);
use options qw($options);
use output qw($output);

36
sub import(@) {
37
    $Exporter::ExportLevel++;
38
    Exporter::import(@_);
39 40 41 42 43
    $Exporter::ExportLevel--;

    $tests = 'tests'->new;
}

44 45 46
sub parse_tests_file($);

sub new($) {
47 48 49 50 51 52 53 54 55 56
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self  = {};
    bless ($self, $class);

    $self->parse_tests_file();

    return $self;
}

57
sub parse_tests_file($) {
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    my $self = shift;

    my $file = "tests.dat";

    my $tests = \%{$self->{TESTS}};

    $output->lazy_progress($file);

    my $test_dir;
    my $test;
    my $section;

    open(IN, "< $winapi_dir/$file") || die "$winapi_dir/$file: $!\n";
    while(<IN>) {
	s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
	s/^(.*?)\s*#.*$/$1/;  # remove comments
	/^$/ && next;         # skip empty lines

	if (/^%%%\s*(\S+)$/) {
	    $test_dir = $1;
	} elsif (/^%%\s*(\w+)$/) {
	    $test = $1;
	} elsif (/^%\s*(\w+)$/) {
	    $section = $1;
	} elsif (!/^%/) {
	    if (!exists($$tests{$test_dir}{$test}{$section})) {
		$$tests{$test_dir}{$test}{$section} = [];
	    }
	    push @{$$tests{$test_dir}{$test}{$section}}, $_;
	} else {
	    $output->write("$file:$.: parse error: '$_'\n");
	    exit 1;
	}
    }
    close(IN);
}

95
sub get_tests($$) {
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    my $self = shift;

    my $tests = \%{$self->{TESTS}};

    my $test_dir = shift;

    my %tests = ();
    if (defined($test_dir)) {
	foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
	    $tests{$test}++;
	}
    } else {
	foreach my $test_dir (sort(keys(%$tests))) {
	    foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
		$tests{$test}++;
	    }
	}
    }
    return sort(keys(%tests));
}

117
sub get_test_dirs($$) {
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
    my $self = shift;

    my $tests = \%{$self->{TESTS}};

    my $test = shift;

    my %test_dirs = ();    
    if (defined($test)) {
	foreach my $test_dir (sort(keys(%$tests))) {
	    if (exists($$tests{$test_dir}{$test})) {
		$test_dirs{$test_dir}++;
	    }
	}
    } else {
	foreach my $test_dir (sort(keys(%$tests))) {
	    $test_dirs{$test_dir}++;
	}
    }

    return sort(keys(%test_dirs));
}

140
sub get_sections($$$) {
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    my $self = shift;

    my $tests = \%{$self->{TESTS}};

    my $test_dir = shift;
    my $test = shift;

    my %sections = ();   
    if (defined($test_dir)) { 
	if (defined($test)) {
	    foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
		$sections{$section}++;
	    }
	} else {
	    foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
		foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
		    $sections{$section}++;
		}
	    }
	}
    } elsif (defined($test)) {
	foreach my $test_dir (sort(keys(%$tests))) {
	    foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
		$sections{$section}++;
	    }
	}
    } else {
	foreach my $test_dir (sort(keys(%$tests))) {
	    foreach my $test (sort(keys(%{$$tests{$test_dir}}))) {
		foreach my $section (sort(keys(%{$$tests{$test_dir}{$test}}))) {
		    $sections{$section}++;
		}
	    }
	}
    }

    return sort(keys(%sections));
}

180
sub get_section($$$$) {
181 182 183 184 185 186 187 188
    my $self = shift;

    my $tests = \%{$self->{TESTS}};

    my $test_dir = shift;
    my $test = shift;
    my $section = shift;

189 190 191 192 193 194
    my $array = $$tests{$test_dir}{$test}{$section};
    if (defined($array)) {
	return @$array;
    } else {
	return ();
    }
195 196 197
}

1;