Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test042-valsort
blob924772a53e961d9cd05e096d12629fd93c14c151
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test042-valsort,v 1.4.2.5 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2008 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.
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $VALSORT = valsortno; then
20 echo "Valsort overlay not available, test skipped"
21 exit 0
22 fi
24 mkdir -p $TESTDIR $DBDIR1
26 $SLAPPASSWD -g -n >$CONFIGPWF
27 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $VALSORTCONF > $CONF1
31 $SLAPADD -f $CONF1 -l $LDIFVALSORT
32 RC=$?
33 if test $RC != 0 ; then
34 echo "slapadd failed ($RC)!"
35 exit $RC
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42 echo PID $PID
43 read foo
45 KILLPIDS="$PID"
47 sleep 1
49 echo "Testing slapd sorted values operations..."
50 for i in 0 1 2 3 4 5; do
51 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
52 'objectclass=*' > /dev/null 2>&1
53 RC=$?
54 if test $RC = 0 ; then
55 break
57 echo "Waiting 5 seconds for slapd to start..."
58 sleep 5
59 done
61 if test $RC != 0 ; then
62 echo "ldapsearch failed ($RC)!"
63 test $KILLSERVERS != no && kill -HUP $KILLPIDS
64 exit $RC
67 echo "Testing ascending and weighted sort"
69 FILTER="objectClass=*"
70 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
71 "$FILTER" > $SEARCHOUT 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75 echo "ldapsearch failed ($RC)!"
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 exit $RC
80 echo "Filtering ldapsearch results..."
81 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
82 echo "Comparing filter output..."
83 $CMP $SEARCHFLT $VALSORTOUT1 > $CMPOUT
85 if test $? != 0 ; then
86 echo "Comparison failed"
87 test $KILLSERVERS != no && kill -HUP $KILLPIDS
88 exit 1
91 echo "Reconfiguring slapd to test valsort descending"
93 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF > \
94 $TESTOUT 2>&1 << EOMODS
95 version: 1
96 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config
97 changetype: modify
98 replace: olcValSortAttr
99 olcValSortAttr: employeeType "ou=users,o=valsort" weighted alpha-descend
100 olcValSortAttr: ou "ou=users,o=valsort" weighted
101 olcValSortAttr: mailPreferenceOption "ou=users,o=valsort" numeric-descend
102 olcValSortAttr: departmentNumber "ou=users,o=valsort" alpha-descend
103 olcValSortAttr: sn "ou=users,o=valsort" alpha-descend
105 EOMODS
107 RC=$?
108 if test $RC != 0 ; then
109 echo "ldapmodify failed ($RC)!"
110 test $KILLSERVERS != no && kill -HUP $KILLPIDS
111 exit $RC
114 echo "Testing descending and weighted sort"
116 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
117 "$FILTER" > $SEARCHOUT 2>&1
119 RC=$?
120 if test $RC != 0 ; then
121 echo "ldapsearch failed ($RC)!"
122 test $KILLSERVERS != no && kill -HUP $KILLPIDS
123 exit $RC
126 echo "Filtering ldapsearch results..."
127 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
128 echo "Comparing filter output..."
129 $CMP $SEARCHFLT $VALSORTOUT2 > $CMPOUT
131 if test $? != 0 ; then
132 echo "Comparison failed"
133 test $KILLSERVERS != no && kill -HUP $KILLPIDS
134 exit 1
137 echo "Adding a valsort record with weighted ou..."
139 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
140 > /dev/null << EOTVALSORT1
141 dn: uid=dave,ou=users,o=valsort
142 objectClass: OpenLDAPperson
143 uid: dave
144 sn: nothere
145 cn: dave
146 businessCategory: otest
147 carLicense: TEST
148 departmentNumber: 42
149 displayName: Dave
150 employeeNumber: 69
151 employeeType: {1}contractor
152 givenName: Dave
153 ou: {1}Test
154 ou: {3}Okay
155 ou: {2}Is
156 EOTVALSORT1
158 RC=$?
159 if test $RC != 0 ; then
160 echo "ldapadd failed ($RC)!"
161 test $KILLSERVERS != no && kill -HUP $KILLPIDS
162 exit $RC
165 #echo ----------------------
166 #$LDAPSEARCH -b "o=valsort" -h $LOCALHOST -p $PORT1
168 echo "Adding a non-weighted valsort record with ou..."
170 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
171 $TESTOUT 2>&1 << EOTVALSORT2
172 dn: uid=bill,ou=users,o=valsort
173 objectClass: OpenLDAPperson
174 uid: bill
175 sn: johnson
176 cn: bill
177 businessCategory: rtest
178 carLicense: ABC123
179 departmentNumber: 42
180 displayName: Bill
181 employeeNumber: 5150
182 employeeType: {1}contractor
183 givenName: Bill
184 ou: Test
185 ou: Okay
186 ou: Is
187 EOTVALSORT2
189 RC=$?
190 if test $RC != 19 ; then
191 echo "valsort check failed ($RC)!"
192 test $KILLSERVERS != no && kill -HUP $KILLPIDS
193 exit -1
196 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
197 "$FILTER" > $SEARCHOUT 2>&1
199 RC=$?
200 if test $RC != 0 ; then
201 echo "ldapsearch failed ($RC)!"
202 test $KILLSERVERS != no && kill -HUP $KILLPIDS
203 exit $RC
206 echo "Filtering ldapsearch results..."
207 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
208 echo "Comparing filter output..."
209 $CMP $SEARCHFLT $VALSORTOUT3 > $CMPOUT
211 if test $? != 0 ; then
212 echo "Comparison failed"
213 test $KILLSERVERS != no && kill -HUP $KILLPIDS
214 exit 1
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
219 test $KILLSERVERS != no && wait
221 echo ">>>>> Test succeeded"
223 exit 0