1
# Copyright (C) 2009 Sun Microsystems, Inc. All rights reserved. Use
2
# is subject to license terms.
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.
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.
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
19
use base qw(Test::Unit::TestCase);
22
use GenTest::Executor;
23
use GenTest::Executor::Dummy;
24
use GenTest::Generator::FromGrammar;
30
my $self = shift()->SUPER::new(@_);
31
# your state for fixture here
37
$grammar = GenTest::Grammar->new(grammar_file => "unit/testGrammar.yy");
44
sub test_create_grammar {
47
$self->assert_not_null($grammar);
49
$self->assert_not_null($grammar->rule("item1"));
50
$self->assert_null($grammar->rule("item2"));
53
sub test_patch_grammar {
56
my $newGrammar = GenTest::Grammar->new(grammar_string => "item1 : foobar ;\nitem2: barfoo ;\n");
58
my $patchedGrammar = $grammar->patch($newGrammar);
60
$self->assert_not_null($patchedGrammar);
61
$self->assert_not_null($patchedGrammar->rule('item2'));
64
my $item1= $patchedGrammar->rule('item1');
65
$self->assert_not_null($item1);
66
$self->assert_matches(qr/foobar/, $item1->toString());
69
sub test_top_grammar {
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'));
78
sub test_mask_grammar {
81
my $maskedGrammar = $grammar->mask(0xaaaa);
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());
90
sub test_grammar_speed {
93
my $grammar = GenTest::Grammar->new(grammar_file => 'conf/examples/example.yy');
95
my $generator = GenTest::Generator::FromGrammar->new(grammar => $grammar,
98
my $executor = GenTest::Executor->newFromDSN("dummy");
100
$executor->cacheMetaData();
102
my $start = Time::HiRes::time();
103
foreach $i (0.. 10000) {
104
$generator->next([$executor,undef]);
106
my $stop = Time::HiRes::time();
107
open TM,">unit/grammar.dat";
108
print TM "YVALUE = ".($stop - $start)."\n";