diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-13 17:33:58 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-13 17:33:58 +0200 |
commit | 879be9db4f7fb285eb42a3f0479eaed457870097 (patch) | |
tree | 88cdcd827f51e80d21701ca71c975f51a079a1c1 /test/driver.c |
Initial packaging, based on SQLite 3.14.1
Diffstat (limited to 'test/driver.c')
-rw-r--r-- | test/driver.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/driver.c b/test/driver.c new file mode 100644 index 0000000..d079a0d --- /dev/null +++ b/test/driver.c @@ -0,0 +1,54 @@ +/* file : test/driver.c + * copyright : not copyrighted - public domain + */ + +/* + * Basic test to make sure the library is usable. + */ + +#ifdef NDEBUG +# undef NDEBUG +#endif + +#include <sqlite3.h> + +#include <stddef.h> /* NULL */ +#include <assert.h> + +static int +sql (sqlite3* db, const char* stmt) +{ + return sqlite3_exec (db, stmt, NULL, NULL, NULL) == SQLITE_OK; +} + +int +main () +{ + sqlite3* db; + int r; + + r = sqlite3_open_v2 (":memory:", + &db, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, + NULL); + assert (r == SQLITE_OK); + + assert (sql (db, "BEGIN")); + assert (sql (db, "CREATE TABLE test (id INTEGER PRIMARY KEY, str TEXT)")); + assert (sql (db, "COMMIT")); + + assert (sql (db, "BEGIN")); + assert (sql (db, "INSERT INTO test VALUES (123, 'abc')")); + assert (sql (db, "COMMIT")); + + assert (sql (db, "BEGIN")); + assert (!sql (db, "INSERT INTO test VALUES (123, 'ABC')")); + assert (sql (db, "ROLLBACK")); + + assert (sql (db, "BEGIN")); + assert (sql (db, "DROP TABLE test")); + assert (sql (db, "COMMIT")); + + r = sqlite3_close (db); + assert (r == SQLITE_OK); +} |