~ubuntu-branches/ubuntu/vivid/drizzle/vivid

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/unit/ParseAllGrammars.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (20.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131029154340-j36v7gxq9tm1gi5f
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Sun Microsystems, Inc. All rights reserved.  Use
 
2
# is subject to license terms.
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
#
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
11
# General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
16
# USA
 
17
 
 
18
# Basic grammar test
 
19
# Walk through all the grammars and feed them to the Grammar
 
20
# constructor. 
 
21
#
 
22
package ParseAllGrammars;
 
23
use base qw(Test::Unit::TestCase);
 
24
use lib 'lib';
 
25
use GenTest::Grammar;
 
26
use GenTest::Executor;
 
27
use GenTest::Executor::Dummy;
 
28
use GenTest::Generator::FromGrammar;
 
29
use File::Find;
 
30
use Digest::SHA1  qw(sha1_base64);
 
31
 
 
32
use Data::Dumper;
 
33
 
 
34
sub new {
 
35
    my $self = shift()->SUPER::new(@_);
 
36
    # your state for fixture here
 
37
    return $self;
 
38
}
 
39
 
 
40
my $generator;
 
41
sub set_up {
 
42
}
 
43
 
 
44
sub tear_down {
 
45
    # clean up after test
 
46
}
 
47
 
 
48
my @files;
 
49
sub isGrammar {
 
50
    if ($File::Find::name =~ m/\.yy$/) {
 
51
        push(@files, $File::Find::name);
 
52
    }
 
53
}
 
54
 
 
55
sub test_parse {
 
56
    my $self = shift;
 
57
    @files = ();
 
58
    find(\&isGrammar, ("conf"));
 
59
    my @filesToTest = sort(@files);
 
60
    if (defined $ENV{RQG_OTHER_GRAMMAR_DIR}) {
 
61
        @files = ();
 
62
        find(\&isGrammar, ($ENV{RQG_OTHER_GRAMMAR_DIR}));
 
63
        @filesToTest = (@filesToTest, sort(@files));
 
64
    }
 
65
    #@files = sort((@files));
 
66
 
 
67
    foreach $f (@filesToTest) {
 
68
        my $grammar = new GenTest::Grammar(grammar_file => $f);
 
69
        $self->assert_not_null($grammar, "Grammar was null: $f");
 
70
 
 
71
        # Skip further checks of redefine files, recognized by "_redefine." in 
 
72
        # file name. These files can contain just a subset of a grammar, so 
 
73
        # there is no point looking for a specific grammar rule.
 
74
        my $redefine_file = undef;
 
75
        if ($f =~ m{_redefine\.}) {
 
76
            $redefine_file = 1;
 
77
        }
 
78
 
 
79
        if (!defined $redefine_file) {
 
80
            print "... $f\n";
 
81
            my $startRule = $grammar->firstMatchingRule("query");
 
82
            $self->assert_not_null($startRule, '"query" rule was null in '.$f);
 
83
            my $executor = GenTest::Executor->newFromDSN("dummy");
 
84
            $self->assert_not_null($executor);
 
85
            $executor->init();
 
86
            $executor->cacheMetaData();
 
87
            my $generator = GenTest::Generator::FromGrammar->new(
 
88
                grammar_file => $f,
 
89
                seed => 0
 
90
                );
 
91
            $self->assert_not_null($generator);
 
92
            foreach $i (1..100) {
 
93
                $generator->next([$executor,undef]);
 
94
            }
 
95
 
 
96
        } else {
 
97
            print ".*. $f\n";
 
98
        }
 
99
    }
 
100
 
 
101
    sub isStable {
 
102
        my ($self, $file, $hash) = @_;
 
103
        my $executor = GenTest::Executor->newFromDSN("dummy");
 
104
        $self->assert_not_null($executor);
 
105
        $executor->init();
 
106
        $executor->cacheMetaData();
 
107
        my $generator = GenTest::Generator::FromGrammar->new(
 
108
            grammar_file => $file,
 
109
            seed => 2
 
110
            );
 
111
        
 
112
        $self->assert_not_null($generator);
 
113
        my $data;
 
114
        foreach $i (1..1000) {
 
115
            $data .= $generator->next([$executor,undef])->[0];
 
116
        }
 
117
        my $newhash =sha1_base64($data);
 
118
        $self->assert_str_equals($newhash,$hash,"'$newhash' different from '$hash'. Generator or grammar changed for $file");
 
119
        
 
120
    }
 
121
    
 
122
    sub test_stability {
 
123
        ## Test stability of selected grammars
 
124
        my ($self) = @_;
 
125
        $self->isStable("conf/examples/example.yy", 
 
126
                        "GVRJcbOKijEUdJQjuor4upMdzDo");
 
127
   } 
 
128
}
 
129
 
 
130
 
 
131
1;