~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/randgen/unit/GrammarTest.pm

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.2.11) (2.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619104649-9ij634mxm4x8pp4l
Tags: 1:7.1.36-stable-1ubuntu1
* Merge from Debian unstable. (LP: #987575)
  Remaining changes:
  - Added upstart script.
* debian/drizzle.upstart: dropped logger since upstart logs job
  output now.

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;