cppfig 0.1.0
Modern C++20 compile-time type-safe configuration library
Loading...
Searching...
No Matches
cppfig::testing::MockConfiguration< Schema > Class Template Reference

Mock implementation of configuration for testing. More...

#include <mock.h>

Public Types

using schema_type = Schema
 

Public Member Functions

 MockConfiguration ()
 
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto Get () const -> typename S::value_type
 Gets the value for a setting type.
 
template<IsSetting S>
requires (Schema::template has_setting<S>)
void SetValue (typename S::value_type value)
 Sets the value for a setting type (bypasses validation for testing).
 
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto Set (typename S::value_type value) -> Status
 Sets the value with validation.
 
auto Load () -> Status
 Simulates loading (no-op for mock).
 
auto Save () const -> Status
 Simulates saving (no-op for mock).
 
void Reset ()
 Resets all values to defaults.
 
void SetRawValue (std::string_view path, Value value)
 Sets a raw Value for testing parse failure scenarios.
 
void ClearValue (std::string_view path)
 Clears a value by path for testing scenarios where key is not found.
 

Detailed Description

template<typename Schema>
class cppfig::testing::MockConfiguration< Schema >

Mock implementation of configuration for testing.

This class provides a simple in-memory configuration that can be used in unit tests. It stores values in a map and doesn't require file I/O.

Usage:

// Define settings
struct AppName {
static constexpr std::string_view path = "app.name";
using value_type = std::string;
static auto default_value() -> std::string { return "MyApp"; }
};
struct AppPort {
static constexpr std::string_view path = "app.port";
using value_type = int;
static auto default_value() -> int { return 8080; }
};
using Schema = ConfigSchema<AppName, AppPort>;
MockConfiguration<Schema> config;
// Set values for testing
config.SetValue<AppPort>(9000);
// Use in tests
EXPECT_EQ(config.Get<AppPort>(), 9000);

Member Typedef Documentation

◆ schema_type

template<typename Schema >
using cppfig::testing::MockConfiguration< Schema >::schema_type = Schema

Constructor & Destructor Documentation

◆ MockConfiguration()

template<typename Schema >
cppfig::testing::MockConfiguration< Schema >::MockConfiguration ( )
inline

Member Function Documentation

◆ ClearValue()

template<typename Schema >
void cppfig::testing::MockConfiguration< Schema >::ClearValue ( std::string_view  path)
inline

Clears a value by path for testing scenarios where key is not found.

This method removes a value from the internal map, allowing tests to verify the behavior when a setting key is not present.

Parameters
pathThe setting path to clear.

◆ Get()

template<typename Schema >
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto cppfig::testing::MockConfiguration< Schema >::Get ( ) const -> typename S::value_type
inline

Gets the value for a setting type.

◆ Load()

template<typename Schema >
auto cppfig::testing::MockConfiguration< Schema >::Load ( ) -> Status
inline

Simulates loading (no-op for mock).

◆ Reset()

template<typename Schema >
void cppfig::testing::MockConfiguration< Schema >::Reset ( )
inline

Resets all values to defaults.

◆ Save()

template<typename Schema >
auto cppfig::testing::MockConfiguration< Schema >::Save ( ) const -> Status
inline

Simulates saving (no-op for mock).

◆ Set()

template<typename Schema >
template<IsSetting S>
requires (Schema::template has_setting<S>)
auto cppfig::testing::MockConfiguration< Schema >::Set ( typename S::value_type  value) -> Status
inline

Sets the value with validation.

◆ SetRawValue()

template<typename Schema >
void cppfig::testing::MockConfiguration< Schema >::SetRawValue ( std::string_view  path,
Value  value 
)
inline

Sets a raw Value for testing parse failure scenarios.

This method allows tests to inject invalid values that will cause Deserialize to fail, triggering the default value fallback path.

Parameters
pathThe setting path (e.g., "app.name").
valueThe raw Value to set.

◆ SetValue()

template<typename Schema >
template<IsSetting S>
requires (Schema::template has_setting<S>)
void cppfig::testing::MockConfiguration< Schema >::SetValue ( typename S::value_type  value)
inline

Sets the value for a setting type (bypasses validation for testing).


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