From fd87ed4d17dd8fc6fb7fbc936861393c6455815d Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 28 Apr 2024 17:46:14 +0300 Subject: Added libConfiguration unit test --- lib/configuration/test/configuration.cpp | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 lib/configuration/test/configuration.cpp (limited to 'lib/configuration/test') diff --git a/lib/configuration/test/configuration.cpp b/lib/configuration/test/configuration.cpp new file mode 100644 index 0000000..0796c11 --- /dev/null +++ b/lib/configuration/test/configuration.cpp @@ -0,0 +1,57 @@ +#include "configuration.h" +#include + +TEST(Configuration, ctor_empty_initializer_list) +{ + Configuration conf({}); + + std::cout << conf; +} + +TEST(Configuration, ctor_initializer_list) +{ + Configuration conf({ + { "some_string", "value1" }, + { "some_bool", true }, + { "some_int", 42 }, + }); + + // operator<< should not throw exceptions + std::cout << conf; + + EXPECT_EQ(*conf.value("some_string"), "value1"); + EXPECT_EQ(*conf.value("some_bool"), true); + EXPECT_EQ(*conf.value("some_int"), 42); + + EXPECT_FALSE(conf.value("no_int")); +} + +TEST(Configuration, read_file) +{ + // because the init_list is empty, all types are strings + Configuration conf({}); + + EXPECT_TRUE(conf.read_file("defaultrc.ini")); + + std::cout << "---------\n"; + std::cout << conf; + std::cout << "---------\n"; + + // defaultrc.ini contents + EXPECT_EQ(*conf.value("name"), "Top level"); + EXPECT_FALSE(conf.value("comment")); + + EXPECT_EQ(*conf.value("main/name"), "Section Testing"); + + // casting a string to an integer + EXPECT_EQ(*conf.value("number"), 12); + + // casting a string to a boolean + EXPECT_EQ(*conf.value("toggle"), "true"); + EXPECT_EQ(*conf.value("toggle"), true); + EXPECT_EQ(*conf.value("main/toggle"), false); + + // extrarc.ini contents + EXPECT_EQ(*conf.value("over"), "extra"); + EXPECT_EQ(*conf.value("extra/name"), "extra section"); +} -- cgit v1.2.1