Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
SQLiteBackendTest Class Reference

Test fixture for SQLite backend tests. More...

Inheritance diagram for SQLiteBackendTest:
Inheritance graph
Collaboration diagram for SQLiteBackendTest:
Collaboration graph

Protected Member Functions

void SetUp () override
 
void TearDown () override
 
bool connectToMemory ()
 
bool connectToFile ()
 
bool createTestTable ()
 

Protected Attributes

std::unique_ptr< sqlite_backendbackend_
 
std::string test_db_path_
 

Detailed Description

Test fixture for SQLite backend tests.

Definition at line 35 of file sqlite_backend_test.cpp.

Member Function Documentation

◆ connectToFile()

bool SQLiteBackendTest::connectToFile ( )
inlineprotected

Definition at line 60 of file sqlite_backend_test.cpp.

60 {
61 connection_config config;
62 config.database = test_db_path_;
63 return backend_->initialize(config).is_ok();
64 }
std::unique_ptr< sqlite_backend > backend_
Configuration for database connection.

References backend_, database::core::connection_config::database, and test_db_path_.

◆ connectToMemory()

bool SQLiteBackendTest::connectToMemory ( )
inlineprotected

Definition at line 54 of file sqlite_backend_test.cpp.

54 {
55 connection_config config;
56 config.database = ":memory:";
57 return backend_->initialize(config).is_ok();
58 }

References backend_, and database::core::connection_config::database.

◆ createTestTable()

bool SQLiteBackendTest::createTestTable ( )
inlineprotected

Definition at line 66 of file sqlite_backend_test.cpp.

66 {
67 return backend_->execute_query("CREATE TABLE IF NOT EXISTS test_table ("
68 " id INTEGER PRIMARY KEY AUTOINCREMENT,"
69 " name TEXT NOT NULL,"
70 " value REAL,"
71 " active INTEGER DEFAULT 1"
72 ")").is_ok();
73 }

References backend_.

◆ SetUp()

void SQLiteBackendTest::SetUp ( )
inlineoverrideprotected

Definition at line 40 of file sqlite_backend_test.cpp.

40 {
41 backend_ = std::make_unique<sqlite_backend>();
42 test_db_path_ = "test_sqlite_" + std::to_string(std::time(nullptr)) + ".db";
43 }

References backend_, and test_db_path_.

◆ TearDown()

void SQLiteBackendTest::TearDown ( )
inlineoverrideprotected

Definition at line 45 of file sqlite_backend_test.cpp.

45 {
46 if (backend_ && backend_->is_initialized()) {
47 backend_->shutdown();
48 }
49 if (std::filesystem::exists(test_db_path_)) {
50 std::filesystem::remove(test_db_path_);
51 }
52 }

References backend_, and test_db_path_.

Member Data Documentation

◆ backend_

std::unique_ptr<sqlite_backend> SQLiteBackendTest::backend_
protected

◆ test_db_path_

std::string SQLiteBackendTest::test_db_path_
protected

Definition at line 38 of file sqlite_backend_test.cpp.

Referenced by connectToFile(), SetUp(), and TearDown().


The documentation for this class was generated from the following file: