]> git.sur5r.net Git - openldap/blob - tests/scripts/test042-valsort
Delete unused idl_cache_entry rwlock field
[openldap] / tests / scripts / test042-valsort
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2007 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $VALSORT = valsortno; then 
20         echo "Valsort overlay not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1
25
26 echo "Running slapadd to build slapd database..."
27 . $CONFFILTER $BACKEND $MONITORDB < $VALSORTCONF > $CONF1
28 $SLAPADD -f $CONF1 -l $LDIFVALSORT
29 RC=$?
30 if test $RC != 0 ; then
31         echo "slapadd failed ($RC)!"
32         exit $RC
33 fi
34
35 echo "Starting slapd on TCP/IP port $PORT1..."
36 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
37 PID=$!
38 if test $WAIT != 0 ; then
39     echo PID $PID
40     read foo
41 fi
42 KILLPIDS="$PID"
43
44 sleep 1
45
46 echo "Testing slapd sorted values operations..."
47 for i in 0 1 2 3 4 5; do
48         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49                 'objectclass=*' > /dev/null 2>&1
50         RC=$?
51         if test $RC = 0 ; then
52                 break
53         fi
54         echo "Waiting 5 seconds for slapd to start..."
55         sleep 5
56 done
57
58 if test $RC != 0 ; then
59         echo "ldapsearch failed ($RC)!"
60         test $KILLSERVERS != no && kill -HUP $KILLPIDS
61         exit $RC
62 fi
63
64 echo "Testing ascending and weighted sort"
65
66 FILTER="objectClass=*"
67 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
68         "$FILTER" > $SEARCHOUT 2>&1
69
70 RC=$?
71 if test $RC != 0 ; then
72         echo "ldapsearch failed ($RC)!"
73         test $KILLSERVERS != no && kill -HUP $KILLPIDS
74         exit $RC
75 fi
76
77 echo "Filtering ldapsearch results..."
78 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
79 echo "Comparing filter output..."
80 $CMP $SEARCHFLT $VALSORTOUT1 > $CMPOUT
81
82 if test $? != 0 ; then
83         echo "Comparison failed"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit 1
86 fi
87
88 echo "Reconfiguring slapd to test valsort descending"
89
90 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF > \
91         $TESTOUT 2>&1 << EOMODS
92 version: 1
93 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config
94 changetype: modify
95 replace: olcValSortAttr
96 olcValSortAttr: employeeType "ou=users,o=valsort" weighted alpha-descend
97 olcValSortAttr: ou "ou=users,o=valsort" weighted
98 olcValSortAttr: mailPreferenceOption "ou=users,o=valsort" numeric-descend
99 olcValSortAttr: departmentNumber "ou=users,o=valsort" alpha-descend
100 olcValSortAttr: sn "ou=users,o=valsort" alpha-descend
101
102 EOMODS
103
104 RC=$?
105 if test $RC != 0 ; then
106     echo "ldapmodify failed ($RC)!"
107     test $KILLSERVERS != no && kill -HUP $KILLPIDS
108     exit $RC
109 fi
110
111 echo "Testing descending and weighted sort"
112
113 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
114         "$FILTER" > $SEARCHOUT 2>&1
115
116 RC=$?
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Filtering ldapsearch results..."
124 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
125 echo "Comparing filter output..."
126 $CMP $SEARCHFLT $VALSORTOUT2 > $CMPOUT
127
128 if test $? != 0 ; then
129         echo "Comparison failed"
130         test $KILLSERVERS != no && kill -HUP $KILLPIDS
131         exit 1
132 fi
133
134 echo "Adding a valsort record with weighted ou..."
135
136 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
137         > /dev/null << EOTVALSORT1
138 dn: uid=dave,ou=users,o=valsort
139 objectClass: OpenLDAPperson
140 uid: dave
141 sn: nothere
142 cn: dave
143 businessCategory: otest
144 carLicense: TEST
145 departmentNumber: 42
146 displayName: Dave
147 employeeNumber: 69
148 employeeType: {1}contractor
149 givenName: Dave
150 ou: {1}Test
151 ou: {3}Okay
152 ou: {2}Is
153 EOTVALSORT1
154
155 RC=$?
156 if test $RC != 0 ; then
157         echo "ldapadd failed ($RC)!"
158         test $KILLSERVERS != no && kill -HUP $KILLPIDS
159         exit $RC
160 fi
161
162 #echo ----------------------
163 #$LDAPSEARCH -b "o=valsort" -h $LOCALHOST -p $PORT1
164
165 echo "Adding a non-weighted valsort record with ou..."
166
167 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
168          $TESTOUT 2>&1 << EOTVALSORT2
169 dn: uid=bill,ou=users,o=valsort
170 objectClass: OpenLDAPperson
171 uid: bill
172 sn: johnson
173 cn: bill
174 businessCategory: rtest
175 carLicense: ABC123
176 departmentNumber: 42
177 displayName: Bill
178 employeeNumber: 5150
179 employeeType: {1}contractor
180 givenName: Bill
181 ou: Test
182 ou: Okay
183 ou: Is
184 EOTVALSORT2
185
186 RC=$?
187 if test $RC != 19 ; then
188         echo "valsort check failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit -1
191 fi
192
193 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
194         "$FILTER" > $SEARCHOUT 2>&1
195
196 RC=$?
197 if test $RC != 0 ; then
198         echo "ldapsearch failed ($RC)!"
199         test $KILLSERVERS != no && kill -HUP $KILLPIDS
200         exit $RC
201 fi
202
203 echo "Filtering ldapsearch results..."
204 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
205 echo "Comparing filter output..."
206 $CMP $SEARCHFLT $VALSORTOUT3 > $CMPOUT
207
208 if test $? != 0 ; then
209         echo "Comparison failed"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit 1
212 fi
213
214 test $KILLSERVERS != no && kill -HUP $KILLPIDS
215
216 test $KILLSERVERS != no && wait
217
218 echo ">>>>> Test succeeded"
219
220 exit 0