#include "ut.hpp"
#include "config/fields.hpp"
#include "config/manager.hpp"
+#include <boost/filesystem.hpp>
+namespace fs = boost::filesystem;
using namespace config;
BOOST_AUTO_TEST_SUITE(ConfigurationSuite)
struct TestConfig {
// subtree class
struct SubConfig {
+
+ struct SubSubConfig {
+ int intVal;
+
+ CONFIG_REGISTER
+ (
+ intVal
+ )
+ };
+
int intVal;
+ SubSubConfig subSubObj;
CONFIG_REGISTER
(
- intVal
+ intVal,
+ subSubObj
)
};
"\"intVector\": [ 1, 2, 3 ], "
"\"stringVector\": [ \"a\", \"b\" ], "
"\"doubleVector\": [ 0.000000, 1.000000, 2.000000 ], "
- "\"subObj\": { \"intVal\": 54321 }, "
- "\"subVector\": [ { \"intVal\": 123 }, { \"intVal\": 456 } ] }";
+ "\"subObj\": { \"intVal\": 54321, \"subSubObj\": { \"intVal\": 234 } }, "
+ "\"subVector\": [ { \"intVal\": 123, \"subSubObj\": { \"intVal\": 345 } }, "
+ "{ \"intVal\": 456, \"subSubObj\": { \"intVal\": 567 } } ] }";
// Floating point tolerance as a number of rounding errors
const int TOLERANCE = 1;
BOOST_REQUIRE_EQUAL(2, testConfig.subVector.size());
BOOST_CHECK_EQUAL(123, testConfig.subVector[0].intVal);
BOOST_CHECK_EQUAL(456, testConfig.subVector[1].intVal);
+ BOOST_CHECK_EQUAL(345, testConfig.subVector[0].subSubObj.intVal);
+ BOOST_CHECK_EQUAL(567, testConfig.subVector[1].subSubObj.intVal);
}
namespace loadErrorsTest {
#define DECLARE_CONFIG(name, type) \
-struct name { \
- type field; \
- CONFIG_REGISTER(field) \
-};
+ struct name { \
+ type field; \
+ CONFIG_REGISTER(field) \
+ };
DECLARE_CONFIG(IntConfig, int)
DECLARE_CONFIG(StringConfig, std::string)
DECLARE_CONFIG(DoubleConfig, double)
BOOST_CHECK(isVisitable<Visitable>());
}
+namespace saveLoadKVStoreTest {
+
+// This struct is like TestConfig, but without a list of structures.
+struct PoorTestConfig {
+ // subtree class
+ struct SubConfig {
+
+ struct SubSubConfig {
+ int intVal;
+
+ CONFIG_REGISTER
+ (
+ intVal
+ )
+ };
+
+ int intVal;
+ SubSubConfig subSubObj;
+
+ CONFIG_REGISTER
+ (
+ intVal,
+ subSubObj
+ )
+ };
+
+ int intVal;
+ std::int64_t int64Val;
+ std::string stringVal;
+ double doubleVal;
+ bool boolVal;
+
+ std::vector<int> intVector;
+ std::vector<std::string> stringVector;
+ std::vector<double> doubleVector;
+
+ SubConfig subObj;
+
+ CONFIG_REGISTER
+ (
+ intVal,
+ int64Val,
+ stringVal,
+ doubleVal,
+ boolVal,
+
+ intVector,
+ stringVector,
+ doubleVector,
+
+ subObj
+ )
+};
+} // saveLoadKVStoreTest
+
+
+BOOST_AUTO_TEST_CASE(FromToKVStoreTest)
+{
+ using namespace saveLoadKVStoreTest;
+
+ // TODO: Change this to TestConfig and delete PoorTestConfig when serialization is implemented
+ PoorTestConfig config;
+ loadFromString(jsonTestString, config);
+
+ std::string dbPath = fs::unique_path("/tmp/kvstore-%%%%.db3").string();
+
+ saveToKVStore(dbPath, config);
+ loadFromKVStore(dbPath, config);
+ saveToKVStore(dbPath, config, "some_config");
+ loadFromKVStore(dbPath, config, "some_config");
+
+ fs::remove(dbPath);
+}
+
BOOST_AUTO_TEST_SUITE_END()