#include #include "csp/db/sqlite_db.h" #include namespace { int CountTable(sqlite3* db, const char* table_name) { sqlite3_stmt* stmt = nullptr; const char* sql = "SELECT COUNT(1) FROM sqlite_master WHERE type='table' AND name=?"; REQUIRE(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr) == SQLITE_OK); REQUIRE(sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT) == SQLITE_OK); REQUIRE(sqlite3_step(stmt) == SQLITE_ROW); const int v = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); return v; } } // namespace TEST_CASE("migrations create core tables") { auto db = csp::db::SqliteDb::OpenMemory(); csp::db::ApplyMigrations(db); REQUIRE(CountTable(db.raw(), "users") == 1); REQUIRE(CountTable(db.raw(), "sessions") == 1); REQUIRE(CountTable(db.raw(), "problems") == 1); REQUIRE(CountTable(db.raw(), "submissions") == 1); REQUIRE(CountTable(db.raw(), "wrong_book") == 1); }