aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration/test
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration/test')
-rw-r--r--lib/configuration/test/configuration.cpp57
1 files changed, 57 insertions, 0 deletions
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 <gtest/gtest.h>
+
+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<std::string>("some_string"), "value1");
+ EXPECT_EQ(*conf.value<bool>("some_bool"), true);
+ EXPECT_EQ(*conf.value<int>("some_int"), 42);
+
+ EXPECT_FALSE(conf.value<int>("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<std::string>("name"), "Top level");
+ EXPECT_FALSE(conf.value<std::string>("comment"));
+
+ EXPECT_EQ(*conf.value<std::string>("main/name"), "Section Testing");
+
+ // casting a string to an integer
+ EXPECT_EQ(*conf.value<int>("number"), 12);
+
+ // casting a string to a boolean
+ EXPECT_EQ(*conf.value<std::string>("toggle"), "true");
+ EXPECT_EQ(*conf.value<bool>("toggle"), true);
+ EXPECT_EQ(*conf.value<bool>("main/toggle"), false);
+
+ // extrarc.ini contents
+ EXPECT_EQ(*conf.value<std::string>("over"), "extra");
+ EXPECT_EQ(*conf.value<std::string>("extra/name"), "extra section");
+}