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

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/unit/GrammarTest.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
 
package GrammarTest;
19
 
use base qw(Test::Unit::TestCase);
20
 
use lib 'lib';
21
 
use GenTest::Grammar;
22
 
use GenTest::Executor;
23
 
use GenTest::Executor::Dummy;
24
 
use GenTest::Generator::FromGrammar;
25
 
 
26
 
use Data::Dumper;
27
 
use Time::HiRes;
28
 
 
29
 
sub new {
30
 
    my $self = shift()->SUPER::new(@_);
31
 
    # your state for fixture here
32
 
    return $self;
33
 
}
34
 
 
35
 
my $grammar;
36
 
sub set_up {
37
 
    $grammar = GenTest::Grammar->new(grammar_file => "unit/testGrammar.yy");
38
 
}
39
 
 
40
 
sub tear_down {
41
 
    # clean up after test
42
 
}
43
 
 
44
 
sub test_create_grammar {
45
 
    my $self = shift;
46
 
    
47
 
    $self->assert_not_null($grammar);
48
 
    
49
 
    $self->assert_not_null($grammar->rule("item1"));
50
 
    $self->assert_null($grammar->rule("item2"));
51
 
}
52
 
 
53
 
sub test_patch_grammar {
54
 
    my $self = shift;
55
 
 
56
 
    my $newGrammar = GenTest::Grammar->new(grammar_string => "item1 : foobar ;\nitem2: barfoo ;\n");
57
 
 
58
 
    my $patchedGrammar = $grammar->patch($newGrammar);
59
 
 
60
 
    $self->assert_not_null($patchedGrammar);
61
 
    $self->assert_not_null($patchedGrammar->rule('item2'));
62
 
 
63
 
 
64
 
    my $item1= $patchedGrammar->rule('item1');
65
 
    $self->assert_not_null($item1);
66
 
    $self->assert_matches(qr/foobar/, $item1->toString());
67
 
}
68
 
 
69
 
sub test_top_grammar {
70
 
    my $self =shift;
71
 
 
72
 
    my $topGrammar = $grammar->topGrammar(1,'foobar','query');
73
 
    $self->assert_not_null($topGrammar);
74
 
    $self->assert_not_null($topGrammar->rule('query'));
75
 
    $self->assert_null($topGrammar->rule('itme1'));
76
 
}
77
 
 
78
 
sub test_mask_grammar {
79
 
    my $self =shift;
80
 
 
81
 
    my $maskedGrammar = $grammar->mask(0xaaaa);
82
 
 
83
 
    $self->assert_not_null($maskedGrammar);
84
 
    my $query = $maskedGrammar->rule('query');
85
 
    $self->assert_not_null($query);
86
 
    $self->assert_does_not_match(qr/item1/,$query->toString());
87
 
 
88
 
}
89
 
 
90
 
sub test_grammar_speed {
91
 
    my $self = shift;
92
 
 
93
 
    my $grammar = GenTest::Grammar->new(grammar_file => 'conf/examples/example.yy');
94
 
 
95
 
    my $generator = GenTest::Generator::FromGrammar->new(grammar => $grammar,
96
 
                                                         seed => 0);
97
 
 
98
 
    my $executor = GenTest::Executor->newFromDSN("dummy");
99
 
    $executor->init();
100
 
    $executor->cacheMetaData();
101
 
 
102
 
    my $start = Time::HiRes::time();
103
 
    foreach $i (0.. 10000) {
104
 
        $generator->next([$executor,undef]);
105
 
    }
106
 
    my $stop = Time::HiRes::time();
107
 
    open TM,">unit/grammar.dat";
108
 
    print TM "YVALUE = ".($stop - $start)."\n";
109
 
    close TM;
110
 
 
111
 
    
112
 
}
113
 
 
114
 
1;