1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-15 23:24:37 +03:00

r2485: - add a test case in ldbtest for a bug pointed out by Jon Haswell.

- fixed the bug shown with the above test, by initialising the
  sequence number to something different from the value used in
  ltdb_cache_free()
(This used to be commit 856cdf82f24aada074ee5c605cccb2e8ceeea487)
This commit is contained in:
Andrew Tridgell 2004-09-22 02:05:02 +00:00 committed by Gerald (Jerry) Carter
parent a2a97238f5
commit 4b09c0e5d9
2 changed files with 88 additions and 3 deletions

View File

@ -45,8 +45,12 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb)
struct ldb_message_element el;
struct ldb_val val;
int ret;
/* the initial sequence number must be different from the one
set in ltdb_cache_free(). Thanks to Jon for pointing this
out. */
const char *initial_sequence_number = "1";
ltdb->sequence_number = 0;
ltdb->sequence_number = atof(initial_sequence_number);
msg.num_elements = 1;
msg.elements = ⪙
@ -64,7 +68,7 @@ static int ltdb_baseinfo_init(struct ldb_context *ldb)
el.values = &val;
el.num_values = 1;
el.flags = 0;
val.data = ldb_strdup(ldb, "0");
val.data = ldb_strdup(ldb, initial_sequence_number);
if (!val.data) {
ldb_free(ldb, el.name);
ldb_free(ldb, msg.dn);

View File

@ -34,6 +34,8 @@
#include "includes.h"
static const char *ldb_url;
static struct timeval tp1,tp2;
static void start_timer(void)
@ -270,6 +272,84 @@ static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
}
/*
2) Store an @indexlist record
3) Store a record that contains fields that should be index according
to @index
4) disconnection from database
5) connect to same database
6) search for record added in step 3 using a search key that should
be indexed
*/
static void start_test_index(struct ldb_context **ldb)
{
struct ldb_message msg;
struct ldb_message_element el[1];
struct ldb_val val[1];
struct ldb_message **res;
int ret;
printf("Starting index test\n");
msg.dn = strdup("@INDEXLIST");
msg.num_elements = 1;
msg.elements = el;
el[0].flags = 0;
el[0].name = strdup("@IDXATTR");
el[0].num_values = 1;
el[0].values = val;
val[0].data = strdup("test");
val[0].length = strlen(val[0].data);
if (ldb_add(*ldb, &msg) != 0) {
printf("Add of %s failed - %s\n", msg.dn, ldb_errstring(*ldb));
exit(1);
}
msg.dn = strdup("test1");
el[0].name = strdup("test");
val[0].data = strdup("foo");
val[0].length = strlen(val[0].data);
if (ldb_add(*ldb, &msg) != 0) {
printf("Add of %s failed - %s\n", msg.dn, ldb_errstring(*ldb));
exit(1);
}
if (ldb_close(*ldb) != 0) {
printf("ldb_close failed - %s\n", ldb_errstring(*ldb));
exit(1);
}
*ldb = ldb_connect(ldb_url, 0, NULL);
if (!*ldb) {
perror("ldb_connect");
exit(1);
}
ret = ldb_search(*ldb, NULL, LDB_SCOPE_SUBTREE, "test=foo", NULL, &res);
if (ret != 1) {
printf("Should have found 1 record - found %d\n", ret);
exit(1);
}
if (ldb_delete(*ldb, "test1") != 0 ||
ldb_delete(*ldb, "@INDEXLIST") != 0) {
printf("cleanup failed - %s\n", ldb_errstring(*ldb));
exit(1);
}
printf("Finished index test\n");
}
static void usage(void)
{
printf("Usage: ldbtest <options>\n");
@ -285,7 +365,6 @@ static void usage(void)
int main(int argc, char * const argv[])
{
struct ldb_context *ldb;
const char *ldb_url;
int opt;
int nrecords = 5000;
int nsearches = 2000;
@ -332,6 +411,8 @@ static void usage(void)
srandom(1);
start_test_index(&ldb);
start_test(ldb, nrecords, nsearches);
ldb_close(ldb);