Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
database::testing Namespace Reference

Namespaces

namespace  assertions
 Query assertion helpers.
 
namespace  fixtures
 Test fixture helpers.
 

Classes

class  backend_exception
 Exception thrown by mock when simulating errors. More...
 
class  backend_expectation
 Single query expectation with configurable behavior for database_backend. More...
 
class  backend_expectation_builder
 Fluent builder for backend expectations. More...
 
class  database_exception
 Exception thrown by mock when simulating errors. More...
 
class  expectation
 Single query expectation with configurable behavior. More...
 
class  expectation_builder
 Fluent builder for expectations. More...
 
class  mock_backend
 Configurable mock for database_backend interface. More...
 
class  mock_backend_builder
 Builder for common mock configurations. More...
 
class  mock_connection_pool
 Mock connection pool for testing pool-related functionality. More...
 
class  mock_database
 Configurable mock for database_backend interface. More...
 
class  mock_database_builder
 Builder for common mock configurations. More...
 
class  scoped_connection
 RAII wrapper for pool connections. More...
 
class  scoped_test_database
 RAII wrapper for test database setup/teardown. More...
 
class  test_timer
 Simple timer for performance testing. More...
 

Enumerations

enum class  backend_match_type { EXACT , PATTERN , ANY }
 How to match query strings. More...
 
enum class  match_type { EXACT , PATTERN , ANY }
 How to match query strings. More...
 

Functions

core::database_result make_result (std::initializer_list< core::database_row > rows)
 Helper function to create test data rows.
 
core::database_row make_row (std::initializer_list< std::pair< std::string, core::database_value > > fields)
 Create a single row.
 
template<typename T >
core::database_value make_value (const T &val)
 Create a database_value from common types.
 
core::database_value make_null ()
 Create a NULL value.
 
core::database_result generate_test_data (size_t count, std::function< core::database_row(size_t index)> row_generator)
 Generate test data for a table.
 
core::database_result generate_sequential_ids (size_t count, const std::string &id_column="id")
 Generate sequential integer test data.
 

Enumeration Type Documentation

◆ backend_match_type

How to match query strings.

Enumerator
EXACT 

Exact string match.

PATTERN 

Regex pattern match.

ANY 

Match any query.

Definition at line 24 of file mock_backend_expectations.h.

24 {
25 EXACT,
26 PATTERN,
27 ANY
28};

◆ match_type

enum class database::testing::match_type
strong

How to match query strings.

Enumerator
EXACT 

Exact string match.

PATTERN 

Regex pattern match.

ANY 

Match any query.

Definition at line 24 of file mock_expectations.h.

24 {
25 EXACT,
26 PATTERN,
27 ANY
28};

Function Documentation

◆ generate_sequential_ids()

core::database_result database::testing::generate_sequential_ids ( size_t count,
const std::string & id_column = "id" )
inline

Generate sequential integer test data.

Parameters
countNumber of rows
id_columnName of the ID column
Returns
database_result with sequential IDs

Definition at line 136 of file database_test_utils.h.

136 {
137 return generate_test_data(count, [&](size_t i) {
138 return core::database_row{{id_column, static_cast<int64_t>(i + 1)}};
139 });
140}
std::map< std::string, database_value > database_row
core::database_result generate_test_data(size_t count, std::function< core::database_row(size_t index)> row_generator)
Generate test data for a table.

References generate_test_data().

Here is the call graph for this function:

◆ generate_test_data()

core::database_result database::testing::generate_test_data ( size_t count,
std::function< core::database_row(size_t index)> row_generator )
inline

Generate test data for a table.

Parameters
countNumber of rows to generate
row_generatorFunction to generate each row
Returns
database_result with generated rows

Definition at line 118 of file database_test_utils.h.

121{
123 result.reserve(count);
124 for (size_t i = 0; i < count; ++i) {
125 result.push_back(row_generator(i));
126 }
127 return result;
128}
std::vector< database_row > database_result

Referenced by generate_sequential_ids().

Here is the caller graph for this function:

◆ make_null()

core::database_value database::testing::make_null ( )
inline

Create a NULL value.

Definition at line 54 of file database_test_utils.h.

54 {
55 return core::database_value(nullptr);
56}
std::variant< std::string, int64_t, double, bool, std::nullptr_t > database_value

◆ make_result()

core::database_result database::testing::make_result ( std::initializer_list< core::database_row > rows)
inline

Helper function to create test data rows.

Example:

auto result = make_result({
{{"id", int64_t(1)}, {"name", std::string("Alice")}},
{{"id", int64_t(2)}, {"name", std::string("Bob")}}
});
core::database_result make_result(std::initializer_list< core::database_row > rows)
Helper function to create test data rows.

Definition at line 28 of file database_test_utils.h.

28 {
29 return core::database_result(rows);
30}

Referenced by database::testing::fixtures::products_data(), and database::testing::fixtures::users_data().

Here is the caller graph for this function:

◆ make_row()

core::database_row database::testing::make_row ( std::initializer_list< std::pair< std::string, core::database_value > > fields)
inline

Create a single row.

Definition at line 35 of file database_test_utils.h.

35 {
37 for (const auto& [key, value] : fields) {
38 row[key] = value;
39 }
40 return row;
41}

◆ make_value()

template<typename T >
core::database_value database::testing::make_value ( const T & val)

Create a database_value from common types.

Definition at line 47 of file database_test_utils.h.

47 {
48 return core::database_value(val);
49}