diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 17:46:14 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 17:46:14 +0300 |
commit | fd87ed4d17dd8fc6fb7fbc936861393c6455815d (patch) | |
tree | 0d95ec29b6e6d5948c07ee59c5c9a94653d5ea6b /lib/configuration/test | |
parent | Added poi resources to sources (diff) | |
download | smolbote-fd87ed4d17dd8fc6fb7fbc936861393c6455815d.tar.xz |
Added libConfiguration unit test
Diffstat (limited to 'lib/configuration/test')
-rw-r--r-- | lib/configuration/test/configuration.cpp | 57 |
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"); +} |