]> git.sur5r.net Git - openldap/blob - tests/scripts/test003-search
Add infrastructure for reindex testing
[openldap] / tests / scripts / test003-search
1 #! /bin/sh
2 # $OpenLDAP$
3
4 if test $# -eq 0 ; then
5         SRCDIR="."
6 else
7         SRCDIR=$1; shift
8 fi
9 if test $# -eq 1 ; then
10         BACKEND=$1; shift
11 fi
12
13 echo "running defines.sh $SRCDIR $BACKEND"
14 . $SRCDIR/scripts/defines.sh
15
16 echo "Cleaning up in $DBDIR..."
17
18 rm -f $DBDIR/[!C]*
19
20 echo "Running slapadd to build slapd database..."
21 # $SLAPADD -f $MCONF -l $LDIF
22 $SLAPADD -f $CONF -l $LDIF
23 RC=$?
24 if test $RC != 0 ; then
25         echo "slapadd failed ($RC)!"
26         exit $RC
27 fi
28
29 # echo "Running slapindex to index slapd database..."
30 # $SLAPINDEX -f $CONF
31 # RC=$?
32 # if test $RC != 0 ; then
33 #       echo "slapindex failed ($RC)!"
34 #       exit $RC
35 # fi
36
37 echo "Starting slapd on TCP/IP port $PORT..."
38 $SLAPD -f $CONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
39 PID=$!
40
41 echo "Testing slapd searching..."
42 for i in 0 1 2 3 4 5; do
43         $LDAPSEARCH -s base -b "$MONITOR" -h localhost -p $PORT \
44                 'objectclass=*' > /dev/null 2>&1
45         RC=$?
46         if test $RC = 1 ; then
47                 echo "Waiting 5 seconds for slapd to start..."
48                 sleep 5
49         fi
50 done
51
52 if test $RC != 0 ; then
53         echo "ldapsearch failed ($RC)!"
54         kill -HUP $PID
55         exit $RC
56 fi
57
58 cat /dev/null > $SEARCHOUT
59
60 echo "Testing exact searching..."
61 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
62         'sn=jensen' >> $SEARCHOUT 2>&1
63 if test $RC != 0 ; then
64         echo "ldapsearch failed ($RC)!"
65         kill -HUP $PID
66         exit $RC
67 fi
68
69 echo "Testing OR searching..."
70 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
71         '(|(objectclass=groupofnames)(sn=jones))' >> $SEARCHOUT 2>&1
72 if test $RC != 0 ; then
73         echo "ldapsearch failed ($RC)!"
74         kill -HUP $PID
75         exit $RC
76 fi
77
78 echo "Testing AND matching and ends-with searching..."
79 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
80         '(&(objectclass=groupofnames)(cn=A*))' >> $SEARCHOUT 2>&1
81 if test $RC != 0 ; then
82         echo "ldapsearch failed ($RC)!"
83         kill -HUP $PID
84         exit $RC
85 fi
86
87 echo "Testing NOT searching..."
88 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
89         '(!(objectclass=person))' >> $SEARCHOUT 2>&1
90 if test $RC != 0 ; then
91         echo "ldapsearch failed ($RC)!"
92         kill -HUP $PID
93         exit $RC
94 fi
95
96 kill -HUP $PID
97
98 LDIF=$SEARCHOUTMASTER
99
100 echo "Filtering ldapsearch results..."
101 . $SRCDIR/scripts/acfilter.sh < $SEARCHOUT > $SEARCHFLT
102 echo "Filtering original ldif used to create database..."
103 . $SRCDIR/scripts/acfilter.sh < $LDIF > $LDIFFLT
104 echo "Comparing filter output..."
105 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
106
107 if test $? != 0 ; then
108         echo "Comparison failed"
109         exit 1
110 fi
111
112 echo ">>>>> Test succeeded"
113
114
115 exit 0