Browse Source

unittests: Test some more of the db primitives.

ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
1522eee528
  1. 2
      wallet/db.c
  2. 20
      wallet/db_tests.c

2
wallet/db.c

@ -44,6 +44,7 @@ bool PRINTF_FMT(3, 4)
err = sqlite3_exec(db->sql, cmd, NULL, NULL, &errmsg);
if (err != SQLITE_OK) {
db->in_transaction = false;
tal_free(db->err);
db->err = tal_fmt(db, "%s:%s:%s:%s", caller,
sqlite3_errstr(err), cmd, errmsg);
@ -72,6 +73,7 @@ sqlite3_stmt *PRINTF_FMT(3, 4)
err = sqlite3_prepare_v2(db->sql, query, -1, &stmt, NULL);
if (err != SQLITE_OK) {
db->in_transaction = false;
db->err = tal_fmt(db, "%s:%s:%s:%s", caller,
sqlite3_errstr(err), query, sqlite3_errmsg(db->sql));
}

20
wallet/db_tests.c

@ -31,6 +31,25 @@ static bool test_empty_db_migrate(void)
return true;
}
static bool test_primitives(void)
{
struct db *db = create_test_db(__func__);
CHECK_MSG(db_begin_transaction(db), "Starting a new transaction");
CHECK(db->in_transaction);
CHECK_MSG(db_commit_transaction(db), "Committing a transaction");
CHECK(!db->in_transaction);
CHECK_MSG(db_begin_transaction(db), "Starting a transaction after commit");
CHECK(db_rollback_transaction(db));
CHECK_MSG(db_exec(__func__, db, "SELECT name FROM sqlite_master WHERE type='table';"), "Simple correct SQL command");
CHECK_MSG(!db_exec(__func__, db, "not a valid SQL statement"), "Failing SQL command");
CHECK(!db->in_transaction);
CHECK_MSG(db_begin_transaction(db), "Starting a transaction after a failed transaction");
tal_free(db);
return true;
}
static bool test_vars(void)
{
struct db *db = create_test_db(__func__);
@ -59,6 +78,7 @@ int main(void)
ok &= test_empty_db_migrate();
ok &= test_vars();
ok &= test_primitives();
return !ok;
}

Loading…
Cancel
Save