r4477: expanded the test suite to increase code coverage a lot
authorAndrew Tridgell <tridge@samba.org>
Sun, 2 Jan 2005 09:46:59 +0000 (09:46 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:07:56 +0000 (13:07 -0500)
source/lib/ldb/Makefile.ldb
source/lib/ldb/common/util.c
source/lib/ldb/include/ldb_private.h
source/lib/ldb/ldb_tdb/ldb_index.c
source/lib/ldb/ldb_tdb/ldb_pack.c
source/lib/ldb/tests/test-generic.sh
source/lib/ldb/tests/test-index.ldif
source/lib/ldb/tests/test.ldif
source/lib/ldb/tools/ldbsearch.c

index a472f949af7cec773e300da97a9bd1c38225d8bc..75c298241d289fa043aeb2ca0169cfe867b7bc71 100644 (file)
@@ -15,6 +15,8 @@ TALLOCDIR=../talloc
 CFLAGS1=-Wall -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith \
        -Wcast-qual -Wcast-align -Wwrite-strings -g -Iinclude -I. -I.. \
        -I$(TDBDIR)/include -I$(TALLOCDIR) -DUSE_MMAP=1 $(LDAP_FLAGS)
+
+# enable the following two lines to build with gcov code coverage support
 #GCOV_FLAGS = -ftest-coverage -fprofile-arcs 
 #GCOV_LIBS = -lgcov
 
@@ -99,6 +101,6 @@ test: test-tdb test-ldap
 gcov:
        gcov -po ldb_ldap ldb_ldap/*.c 2| tee ldb_ldap.report.gcov
        gcov -po ldb_tdb ldb_tdb/*.c 2| tee ldb_tdb.report.gcov
-       gcov -po common common/*.c 2| tee ldb_common.report.gcov
-       gcov -po modules modules/*.c 2| tee ldb_modules.report.gcov
-       gcov -po tools tools/*.c 2| tee ldb_tools.report.gcov
+       gcov -po common common/*.c 2| tee common.report.gcov
+       gcov -po modules modules/*.c 2| tee modules.report.gcov
+       gcov -po tools tools/*.c 2| tee tools.report.gcov
index 0c9cf297c144b64e45b05cad194ba63d3574f1ae..c2fd72acd1fdf14a40ce54f10108633c1e4072c7 100644 (file)
 #include "ldb/include/ldb_private.h"
 
 
-/*
-  find an element in a list, using the given comparison function and
-  assuming that the list is already sorted using comp_fn
-
-  return -1 if not found, or the index of the first occurance of needle if found
-*/
-int ldb_list_find(const void *needle, 
-             const void *base, size_t nmemb, size_t size, comparison_fn_t comp_fn)
-{
-       const char *base_p = base;
-       size_t min_i, max_i, test_i;
-
-       if (nmemb == 0) {
-               return -1;
-       }
-
-       min_i = 0;
-       max_i = nmemb-1;
-
-       while (min_i < max_i) {
-               int r;
-
-               test_i = (min_i + max_i) / 2;
-               r = comp_fn(needle, *(void * const *)(base_p + (size * test_i)));
-               if (r == 0) {
-                       /* scan back for first element */
-                       while (test_i > 0 &&
-                              comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) {
-                               test_i--;
-                       }
-                       return test_i;
-               }
-               if (r < 0) {
-                       if (test_i == 0) {
-                               return -1;
-                       }
-                       max_i = test_i - 1;
-               }
-               if (r > 0) {
-                       min_i = test_i + 1;
-               }
-       }
-
-       if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) {
-               return min_i;
-       }
-
-       return -1;
-}
-
-
 /*
   common code for parsing -o options in ldb tools
 */
index 3d3b1ec0ebb54f2897e2dea3b7825a7b4388d17f..426da5ccaef887f2b1369ec8a09adc5157b167f4 100644 (file)
@@ -100,10 +100,6 @@ int ldb_next_named_lock(struct ldb_module *module, const char *lockname);
 int ldb_next_named_unlock(struct ldb_module *module, const char *lockname);
 const char *ldb_next_errstring(struct ldb_module *module);
 
-/* The following definitions come from lib/ldb/common/util.c  */
-int ldb_list_find(const void *needle, 
-             const void *base, size_t nmemb, size_t size, comparison_fn_t comp_fn);
-
 /* The following definitions come from lib/ldb/common/ldb_debug.c  */
 void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
 
index ff0cabb0d670d44be87c8ff52bc53cd3e185891a..88ef997a0364466fbf78edbd768cdca044b780b2 100644 (file)
 #include "ldb/ldb_tdb/ldb_tdb.h"
 #include "ldb/include/ldb_parse.h"
 
+/*
+  find an element in a list, using the given comparison function and
+  assuming that the list is already sorted using comp_fn
+
+  return -1 if not found, or the index of the first occurance of needle if found
+*/
+static int ldb_list_find(const void *needle, 
+                        const void *base, size_t nmemb, size_t size, 
+                        comparison_fn_t comp_fn)
+{
+       const char *base_p = base;
+       size_t min_i, max_i, test_i;
+
+       if (nmemb == 0) {
+               return -1;
+       }
+
+       min_i = 0;
+       max_i = nmemb-1;
+
+       while (min_i < max_i) {
+               int r;
+
+               test_i = (min_i + max_i) / 2;
+               r = comp_fn(needle, *(void * const *)(base_p + (size * test_i)));
+               if (r == 0) {
+                       /* scan back for first element */
+                       while (test_i > 0 &&
+                              comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) {
+                               test_i--;
+                       }
+                       return test_i;
+               }
+               if (r < 0) {
+                       if (test_i == 0) {
+                               return -1;
+                       }
+                       max_i = test_i - 1;
+               }
+               if (r > 0) {
+                       min_i = test_i + 1;
+               }
+       }
+
+       if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) {
+               return min_i;
+       }
+
+       return -1;
+}
+
 struct dn_list {
        unsigned int count;
        char **dn;
index a548a4189b473cf1ca15ec7bc8acaf44084d2f9d..4c1241d0bd87916f22b14031fb9640978ada009a 100644 (file)
@@ -138,16 +138,6 @@ int ltdb_pack_data(struct ldb_module *module,
        return 0;
 }
 
-/*
-  free the memory allocated from a ltdb_unpack_data()
-*/
-void ltdb_unpack_data_free(struct ldb_module *module,
-                          struct ldb_message *message)
-{
-       talloc_free(message->elements);
-}
-
-
 /*
   unpack a ldb message from a linear buffer in TDB_DATA
 
@@ -267,7 +257,6 @@ int ltdb_unpack_data(struct ldb_module *module,
        return 0;
 
 failed:
-       ltdb_unpack_data_free(module, message);
-
+       talloc_free(message->elements);
        return -1;
 }
index 4fb54b6c3b4b438894a764fdafec6935c3b77587..2b2ab2e78a860e5b2746bea4b177157b17f9e515 100755 (executable)
@@ -27,11 +27,15 @@ $VALGRIND bin/ldbadd tests/test-index.ldif  || exit 1
 
 echo "testing indexed search"
 $VALGRIND bin/ldbsearch '(uid=uham)'  || exit 1
+$VALGRIND bin/ldbsearch '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1
 $VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uham))'  || exit 1
 $VALGRIND bin/ldbsearch '(|(uid=uham)(uid=uham))'  || exit 1
 $VALGRIND bin/ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))'  || exit 1
 $VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))'  || exit 1
-$VALGRIND bin/ldbsearch '(&(uid=uham)(!(uid=uhamxx)))'  || exit 1
+$VALGRIND bin/ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn  || exit 1
+$VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1
+$VALGRIND bin/ldbsearch '((' uid && exit 1
+$VALGRIND bin/ldbsearch 'dn=cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=US' uid || exit 1
 
 echo "Starting ldbtest indexed"
 time $VALGRIND bin/ldbtest -r 1000 -s 5000  || exit 1
index 6b2e921ebd5d35ef7336674275e40631fa30eb9e..24ac4087641fea68ca293841b399d9fb90fbddd3 100644 (file)
@@ -1,6 +1,11 @@
 dn: @INDEXLIST
 @IDXATTR: uid
-# it is much better not to index on objectclass if nearly
-# all the records are the same class (the index is expensive
-# to maintain, and doesn't really gain anything)
-# @IDXATTR: objectclass
+@IDXATTR: objectclass
+
+dn: @ATTRIBUTES
+uid: CASE_INSENSITIVE WILDCARD
+
+dn: @SUBCLASSES
+top: person
+person: organizationalPerson
+organizationalPerson: OpenLDAPperson
index 8d6c0c750e3e4ad486696812f93dc77d873aa23b..7fe3a8ffd7c5002c6b43d78c0a4937b8cfc35afc 100644 (file)
@@ -212,7 +212,7 @@ objectclass: OpenLDAPperson
 cn: Barbara Jensen
 cn: Babs Jensen
 sn:: IEplbnNlbiA=
-uid: bjensen
+uid:: YmplCW5zZW4
 title: Mythical Manager, Research Systems
 postaladdress: ITD Prod Dev & Deployment $ 535 W. William St. Room 4212 $ Ann 
  Arbor, MI 48103-4943
index 9041231faf02f0988e3557db3e4e92024dcc8aea..5e0246d7a93d246356cee4b3a43c0c3f27684f80 100644 (file)
@@ -153,7 +153,7 @@ static int do_search(struct ldb_context *ldb,
                attrs = (const char * const *)(argv+1);
        }
 
-       ldb = ldb_connect(ldb_url, 0, options);
+       ldb = ldb_connect(ldb_url, LDB_FLG_RDONLY, options);
        if (!ldb) {
                perror("ldb_connect");
                exit(1);