summaryrefslogtreecommitdiff
path: root/lib/tdb2/test
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:32:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:32:13 +0930
commite613effeae7c9373c9e635fc708ec2ce29661d4c (patch)
treed8cdb019f54302de6aa813a62a34e036cf9c7faf /lib/tdb2/test
parent50484d4bede6b59706457e44a32cbe2d3e9c28d2 (diff)
downloadsamba-e613effeae7c9373c9e635fc708ec2ce29661d4c.tar.gz
samba-e613effeae7c9373c9e635fc708ec2ce29661d4c.tar.bz2
samba-e613effeae7c9373c9e635fc708ec2ce29661d4c.zip
tdb2: make TDB1 code use tdb2's TDB_ERROR and tdb_logerr()
To do this, we make sure that the first few fields of tdb1_context and tdb_context are the same. This sweep also fixes up a few paths where we weren't setting tdb->ecode before our old logging function. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 919937354a331bb964564a11b5a5b80403ff8db9)
Diffstat (limited to 'lib/tdb2/test')
-rw-r--r--lib/tdb2/test/run-tdb1-3G-file.c8
-rw-r--r--lib/tdb2/test/run-tdb1-check.c2
-rw-r--r--lib/tdb2/test/run-tdb1-endian.c4
-rw-r--r--lib/tdb2/test/run-tdb1-incompatible.c7
-rw-r--r--lib/tdb2/test/run-tdb1-nested-transactions.c2
-rw-r--r--lib/tdb2/test/run-tdb1-readonly-check.c2
-rw-r--r--lib/tdb2/test/run-tdb1-rwlock-check.c7
-rw-r--r--lib/tdb2/test/run-tdb1-wronghash-fail.c7
-rw-r--r--lib/tdb2/test/run-tdb1.c4
-rw-r--r--lib/tdb2/test/tdb1-external-agent.c2
-rw-r--r--lib/tdb2/test/tdb1-logging.c19
11 files changed, 32 insertions, 32 deletions
diff --git a/lib/tdb2/test/run-tdb1-3G-file.c b/lib/tdb2/test/run-tdb1-3G-file.c
index 6509ca3ab7..fd66c047b1 100644
--- a/lib/tdb2/test/run-tdb1-3G-file.c
+++ b/lib/tdb2/test/run-tdb1-3G-file.c
@@ -11,7 +11,7 @@ static int tdb1_expand_file_sparse(struct tdb1_context *tdb,
tdb1_off_t addition)
{
if (tdb->read_only || tdb->traverse_read) {
- tdb->ecode = TDB1_ERR_RDONLY;
+ tdb->last_error = TDB_ERR_RDONLY;
return -1;
}
@@ -27,8 +27,10 @@ static int tdb1_expand_file_sparse(struct tdb1_context *tdb,
errno = ENOSPC;
}
if (written != 1) {
- TDB1_LOG((tdb, TDB1_DEBUG_FATAL, "expand_file to %d failed (%s)\n",
- size+addition, strerror(errno)));
+ tdb->last_error = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+ "expand_file to %d failed (%s)",
+ size+addition,
+ strerror(errno));
return -1;
}
}
diff --git a/lib/tdb2/test/run-tdb1-check.c b/lib/tdb2/test/run-tdb1-check.c
index 03b0191a17..b3b240e002 100644
--- a/lib/tdb2/test/run-tdb1-check.c
+++ b/lib/tdb2/test/run-tdb1-check.c
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
&taplogctx, NULL);
ok1(tdb);
ok1(tdb1_check(tdb, NULL, NULL) == -1);
- ok1(tdb1_error(tdb) == TDB1_ERR_CORRUPT);
+ ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
tdb1_close(tdb);
/* Big and little endian should work! */
diff --git a/lib/tdb2/test/run-tdb1-endian.c b/lib/tdb2/test/run-tdb1-endian.c
index 1a01de17ab..7691260606 100644
--- a/lib/tdb2/test/run-tdb1-endian.c
+++ b/lib/tdb2/test/run-tdb1-endian.c
@@ -21,10 +21,10 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0);
- ok1(tdb1_error(tdb) == TDB1_ERR_NOEXIST);
+ ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0);
- ok1(tdb1_error(tdb) == TDB1_ERR_EXISTS);
+ ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0);
data = tdb1_fetch(tdb, key);
diff --git a/lib/tdb2/test/run-tdb1-incompatible.c b/lib/tdb2/test/run-tdb1-incompatible.c
index 5a4a61af33..13ba810169 100644
--- a/lib/tdb2/test/run-tdb1-incompatible.c
+++ b/lib/tdb2/test/run-tdb1-incompatible.c
@@ -8,10 +8,11 @@ static unsigned int tdb1_dumb_hash(TDB1_DATA *key)
return key->dsize;
}
-static void log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
+static void log_fn(struct tdb1_context *tdb, enum tdb_log_level level,
+ enum TDB_ERROR ecode, const char *message, void *priv)
{
- unsigned int *count = tdb->log.log_private;
- if (strstr(fmt, "hash"))
+ unsigned int *count = priv;
+ if (strstr(message, "hash"))
(*count)++;
}
diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c
index 2518003c63..e9640990e0 100644
--- a/lib/tdb2/test/run-tdb1-nested-transactions.c
+++ b/lib/tdb2/test/run-tdb1-nested-transactions.c
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
free(data.dptr);
ok1(tdb1_transaction_start(tdb) != 0);
- ok1(tdb1_error(tdb) == TDB1_ERR_NESTING);
+ ok1(tdb_error(tdb) == TDB_ERR_EINVAL);
data = tdb1_fetch(tdb, key);
ok1(data.dsize == strlen("world"));
diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c
index 2c06ca92ee..6bfa0dc3f5 100644
--- a/lib/tdb2/test/run-tdb1-readonly-check.c
+++ b/lib/tdb2/test/run-tdb1-readonly-check.c
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
ok1(tdb);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == -1);
- ok1(tdb1_error(tdb) == TDB1_ERR_RDONLY);
+ ok1(tdb_error(tdb) == TDB_ERR_RDONLY);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
ok1(tdb1_close(tdb) == 0);
diff --git a/lib/tdb2/test/run-tdb1-rwlock-check.c b/lib/tdb2/test/run-tdb1-rwlock-check.c
index f40a6fe13e..ec2a66a5bf 100644
--- a/lib/tdb2/test/run-tdb1-rwlock-check.c
+++ b/lib/tdb2/test/run-tdb1-rwlock-check.c
@@ -3,10 +3,11 @@
#include <stdlib.h>
#include <err.h>
-static void log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
+static void log_fn(struct tdb1_context *tdb, enum tdb_log_level level,
+ enum TDB_ERROR ecode, const char *message, void *priv)
{
- unsigned int *count = tdb->log.log_private;
- if (strstr(fmt, "spinlocks"))
+ unsigned int *count = priv;
+ if (strstr(message, "spinlocks"))
(*count)++;
}
diff --git a/lib/tdb2/test/run-tdb1-wronghash-fail.c b/lib/tdb2/test/run-tdb1-wronghash-fail.c
index 15047677a2..59bfbbeccb 100644
--- a/lib/tdb2/test/run-tdb1-wronghash-fail.c
+++ b/lib/tdb2/test/run-tdb1-wronghash-fail.c
@@ -3,10 +3,11 @@
#include <stdlib.h>
#include <err.h>
-static void log_fn(struct tdb1_context *tdb, enum tdb1_debug_level level, const char *fmt, ...)
+static void log_fn(struct tdb1_context *tdb, enum tdb_log_level level,
+ enum TDB_ERROR ecode, const char *message, void *priv)
{
- unsigned int *count = tdb->log.log_private;
- if (strstr(fmt, "hash"))
+ unsigned int *count = priv;
+ if (strstr(message, "hash"))
(*count)++;
}
diff --git a/lib/tdb2/test/run-tdb1.c b/lib/tdb2/test/run-tdb1.c
index ebbfd77bb2..30de924cd2 100644
--- a/lib/tdb2/test/run-tdb1.c
+++ b/lib/tdb2/test/run-tdb1.c
@@ -20,10 +20,10 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0);
- ok1(tdb1_error(tdb) == TDB1_ERR_NOEXIST);
+ ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0);
- ok1(tdb1_error(tdb) == TDB1_ERR_EXISTS);
+ ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0);
data = tdb1_fetch(tdb, key);
diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c
index da9d709468..7ccbd9ca37 100644
--- a/lib/tdb2/test/tdb1-external-agent.c
+++ b/lib/tdb2/test/tdb1-external-agent.c
@@ -61,7 +61,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
case FETCH:
data = tdb1_fetch(tdb, k);
if (data.dptr == NULL) {
- if (tdb->ecode == TDB1_ERR_NOEXIST)
+ if (tdb->last_error == TDB_ERR_NOEXIST)
ret = FAILED;
else
ret = OTHER_FAILURE;
diff --git a/lib/tdb2/test/tdb1-logging.c b/lib/tdb2/test/tdb1-logging.c
index 43ce07b27c..3424296b91 100644
--- a/lib/tdb2/test/tdb1-logging.c
+++ b/lib/tdb2/test/tdb1-logging.c
@@ -7,24 +7,19 @@
/* Turn log messages into tap diag messages. */
static void taplog(struct tdb1_context *tdb,
- enum tdb1_debug_level level,
- const char *fmt, ...)
+ enum tdb_log_level level,
+ enum TDB_ERROR ecode,
+ const char *message,
+ void *data)
{
- va_list ap;
- char line[200];
-
if (suppress_logging)
return;
- va_start(ap, fmt);
- vsprintf(line, fmt, ap);
- va_end(ap);
-
/* Strip trailing \n: diag adds it. */
- if (line[0] && line[strlen(line)-1] == '\n')
- diag("%s%.*s", log_prefix, (unsigned)strlen(line)-1, line);
+ if (message[0] && message[strlen(message)-1] == '\n')
+ diag("%s%.*s", log_prefix, (unsigned)strlen(message)-1, message);
else
- diag("%s%s", log_prefix, line);
+ diag("%s%s", log_prefix, message);
}
struct tdb1_logging_context taplogctx = { taplog, NULL };