File: namazu-5

package info (click to toggle)
namazu2 2.0.21-22
  • links: PTS
  • area: main
  • in suites: buster
  • size: 7,032 kB
  • sloc: ansic: 14,161; perl: 10,789; sh: 9,355; lisp: 1,147; makefile: 914
file content (65 lines) | stat: -rwxr-xr-x 2,005 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /bin/sh
#
# Test for namazu. Attack namazu with nasty cases.
#
LOG=`pwd`/test-log
echo '  *** starting ' $0 >>$LOG
docnum=`perl -lne 'print $1 if /^files (\d+)/' idx1/NMZ.status`

cd ../src

# No query, no results.
# FIXME: Is it a good behavior?
test "`./namazu -c ''   ../tests/idx1`" != ''  && exit 1

# Should never match any documents.
test `./namazu -c '"'     ../tests/idx1` != '0' && exit 1
test `./namazu -c '/'     ../tests/idx1` != '0' && exit 1
test `./namazu -c '{'     ../tests/idx1` != '0' && exit 1
test `./namazu -c '}'     ../tests/idx1` != '0' && exit 1
test `./namazu -c '""'    ../tests/idx1` != '0' && exit 1
test `./namazu -c '{}'    ../tests/idx1` != '0' && exit 1
test `./namazu -c '" "'   ../tests/idx1` != '0' && exit 1
test `./namazu -c '{ }'   ../tests/idx1` != '0' && exit 1
test `./namazu -c '"  "'  ../tests/idx1` != '0' && exit 1
test `./namazu -c '{  }'  ../tests/idx1` != '0' && exit 1
test `./namazu -c ' " " ' ../tests/idx1` != '0' && exit 1
test `./namazu -c ' { } ' ../tests/idx1` != '0' && exit 1

# Match all documents.
test `./namazu -c '//'       ../tests/idx1` != $docnum && exit 1
test `./namazu -c 'namazu'   ../tests/idx1` != $docnum && exit 1
test `./namazu -c '"namazu"' ../tests/idx1` != $docnum && exit 1
test `./namazu -c '{namazu}' ../tests/idx1` != $docnum && exit 1

# Boundary testing.
perl << 'TEST'  >> $LOG
	my $QUERY_MAX = 256;
	my $BUFSIZE   = 1024;
	for my $num (0 .. 3, $QUERY_MAX - 5 .. $QUERY_MAX + 5,
			     $BUFSIZE   - 5 .. $BUFSIZE   + 5, 
			     10000) # Huge query
        {
		my $query  = "x" x $num;
		my $cmd    = "./namazu -c '$query' ../tests/idx1";
		my $result = `$cmd 2>&1`;
		print "$num: $?\n";
		print "$result\n";

		my $assert = sub {
		    my ($code) = @_;
		    die "assert failed: $code" if ! eval $code;
		};

		if ($num == 0) {
			&$assert('$result eq ""');
		} elsif ($num <= 256) {
			&$assert('$result eq "0\n"');
		} elsif ($num > 256) {
			&$assert('$result =~ /^namazu: /');
		}
	}
	exit 0;
TEST
exit $?