From 59b409892978ccfced8f8f8cc162491c1408f25e Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 14 Jan 2024 22:40:46 +0100 Subject: [PATCH] test cleanup v2 (#57) * remove unused test files * update include/ignore patterns for gcov * fix include paths * add codecov config file * remove unused files, update codecov.yml * test * v4 * a --- .github/workflows/build-linux.yml | 3 +- .gitignore | 2 +- CMakeLists.txt | 4 +- clean-coverage.sh | 2 - codecov.yml | 3 + generate-coverage.sh | 4 - src/test/advanced-array.cpp | 155 ----------- src/test/bad-instance.cpp | 127 --------- src/test/channel.cpp | 25 -- src/test/common.cpp | 82 ------ src/test/default.cpp | 168 ------------ src/test/deserialize.cpp | 166 ------------ src/test/foo.cpp | 46 ---- src/test/listener.cpp | 122 --------- src/test/load.cpp | 87 ------ src/test/main.cpp | 9 - src/test/map.cpp | 66 ----- src/test/misc.cpp | 206 -------------- src/test/remove.cpp | 93 ------- src/test/save.cpp | 235 ---------------- src/test/scope.cpp | 44 --- src/test/serialize.cpp | 252 ------------------ src/test/signal.cpp | 154 ----------- src/test/static.cpp | 117 -------- tests/CMakeLists.txt | 2 + tests/src/advanced-array.cpp | 2 +- tests/src/bad-instance.cpp | 2 +- tests/src/channel.cpp | 10 +- {include/test => tests/src}/channel.hpp | 0 .../test => tests/src}/channelmanager.hpp | 8 +- tests/src/common.cpp | 2 +- {include/test => tests/src}/common.hpp | 0 tests/src/default.cpp | 2 +- tests/src/deserialize.cpp | 2 +- tests/src/foo.cpp | 8 +- {include/test => tests/src}/foo.hpp | 0 tests/src/listener.cpp | 3 +- tests/src/load.cpp | 2 +- tests/src/map.cpp | 2 +- tests/src/misc.cpp | 10 +- tests/src/remove.cpp | 2 +- tests/src/save.cpp | 2 +- tests/src/scope.cpp | 2 +- tests/src/serialize.cpp | 2 +- tests/src/signal.cpp | 2 +- tests/src/static.cpp | 2 +- 46 files changed, 37 insertions(+), 2202 deletions(-) delete mode 100644 clean-coverage.sh create mode 100644 codecov.yml delete mode 100755 generate-coverage.sh delete mode 100644 src/test/advanced-array.cpp delete mode 100644 src/test/bad-instance.cpp delete mode 100644 src/test/channel.cpp delete mode 100644 src/test/common.cpp delete mode 100644 src/test/default.cpp delete mode 100644 src/test/deserialize.cpp delete mode 100644 src/test/foo.cpp delete mode 100644 src/test/listener.cpp delete mode 100644 src/test/load.cpp delete mode 100644 src/test/main.cpp delete mode 100644 src/test/map.cpp delete mode 100644 src/test/misc.cpp delete mode 100644 src/test/remove.cpp delete mode 100644 src/test/save.cpp delete mode 100644 src/test/scope.cpp delete mode 100644 src/test/serialize.cpp delete mode 100644 src/test/signal.cpp delete mode 100644 src/test/static.cpp rename {include/test => tests/src}/channel.hpp (100%) rename {include/test => tests/src}/channelmanager.hpp (93%) rename {include/test => tests/src}/common.hpp (100%) rename {include/test => tests/src}/foo.hpp (100%) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index c43580b..2a77261 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -102,8 +102,7 @@ jobs: - name: Upload coverage reports to Codecov if: matrix.os == 'ubuntu-22.04' - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4-beta with: token: ${{ secrets.CODECOV_TOKEN }} - gcov: true verbose: true diff --git a/.gitignore b/.gitignore index 6560d21..0c8f77a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /*build* compile_commands.json -/.cache +.cache/ CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 94fbfbe..3ddbcf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") project(PajladaSettings) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + option(PAJLADA_SETTINGS_USE_CONAN "Use conan file manager to handle dependencies" OFF) if (PAJLADA_SETTINGS_USE_CONAN) @@ -89,5 +91,3 @@ if(NOT MSVC) target_link_libraries(PajladaSettings INTERFACE $<$,$,9.0>>:stdc++fs>) endif() -set(CMAKE_EXPORT_COMPILE_COMMANDS YES) - diff --git a/clean-coverage.sh b/clean-coverage.sh deleted file mode 100644 index a9795e5..0000000 --- a/clean-coverage.sh +++ /dev/null @@ -1,2 +0,0 @@ -rm *.gcda *.gcno test.info* -rm -rf res/ diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..6d7230b --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +ignore: + - "tests" + - "external" diff --git a/generate-coverage.sh b/generate-coverage.sh deleted file mode 100755 index 02ee2e5..0000000 --- a/generate-coverage.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -lcov -o test.info.base -c -d . && \ -lcov -r test.info.base '/usr/include/*' "$PWD/external/*" "$PWD/include/test*" "$PWD/src/test/*" -o test.info && \ -genhtml --demangle-cpp -o res test.info diff --git a/src/test/advanced-array.cpp b/src/test/advanced-array.cpp deleted file mode 100644 index 3fc497d..0000000 --- a/src/test/advanced-array.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -class MyWindow -{ -public: - int x = 0; - - bool - operator==(const MyWindow &rhs) const - { - return std::tie(this->x) == std::tie(rhs.x); - } -}; - -TEST(AdvancedArray, SingleWindow) -{ - SettingManager::clear(); - Setting myWindow("/a"); - - // EXPECT_TRUE(myWindow->x == 0); - - EXPECT_TRUE(LoadFile("advanced-window.json")); - - // EXPECT_TRUE(myWindow->x == 5); -} - -TEST(AdvancedArray, MultiWindow) -{ - SettingManager::clear(); - Setting> myWindows("/a"); - - // EXPECT_TRUE(myWindows->size() == 0); - - EXPECT_TRUE(LoadFile("advanced-window-multi.json")); - - // EXPECT_TRUE(myWindows->size() == 3); - - std::deque values{5, 10, 15}; - - /* - for (const auto &window : myWindows.getArray()) { - EXPECT_TRUE(window.x == values.front()); - values.pop_front(); - } - */ - - // myWindows.push_back(MyWindow{}); - - // EXPECT_TRUE(myWindows->size() == 4); - - // myWindows.push_back(MyWindow{}); - - // EXPECT_TRUE(myWindows->size() == 5); -} - -TEST(AdvancedArray, MultiFiles) -{ - auto sm1 = std::make_shared(); - auto sm2 = std::make_shared(); - Setting> myWindows("/a", SettingOption::Default, sm1); - - // EXPECT_TRUE(myWindows->size() == 0); - - EXPECT_TRUE(sm1->load("files/advanced-window-multi.json") == - SettingManager::LoadError::NoError); - EXPECT_TRUE(sm2->load("files/advanced-window-multi.json") == - SettingManager::LoadError::NoError); - - // EXPECT_TRUE(myWindows->size() == 3); - - std::deque values{5, 10, 15}; - - /* - for (const auto &window : myWindows.getArray()) { - EXPECT_TRUE(window.x == values.front()); - values.pop_front(); - } - */ - - // myWindows.push_back(MyWindow{}); - - // EXPECT_TRUE(myWindows->size() == 4); - - // myWindows.push_back(MyWindow{}); - - // EXPECT_TRUE(myWindows->size() == 5); - - Setting> myWindows2("/a", SettingOption::Default, - sm2); - - MyWindow test; - test.x = 77; - - // myWindows2.push_back(std::move(test)); - - sm1->setPath("lol.json"); - - sm2->setPath("lol2.json"); -} - -namespace pajlada { - -template <> -struct IsEqual { - static bool - get(const MyWindow &lhs, const MyWindow &rhs) - { - return lhs == rhs; - } -}; - -template <> -struct Serialize { - static rapidjson::Value - get(const MyWindow &value, rapidjson::Document::AllocatorType &a) - { - rapidjson::Value ret(rapidjson::kObjectType); - - ret.AddMember(rapidjson::Value("x", a).Move(), - pajlada::Serialize::get(value.x, a), a); - - return ret; - } -}; - -template <> -struct Deserialize { - static MyWindow - get(const rapidjson::Value &value, bool *error = nullptr) - { - MyWindow ret; - - if (!value.IsObject()) { - PAJLADA_REPORT_ERROR(error) - return ret; - } - - if (value.HasMember("x")) { - bool innerError = false; - auto out = pajlada::Deserialize::get(value["x"], &innerError); - - if (!innerError) { - ret.x = out; - } - } - - return ret; - } -}; - -} // namespace pajlada diff --git a/src/test/bad-instance.cpp b/src/test/bad-instance.cpp deleted file mode 100644 index da4d75b..0000000 --- a/src/test/bad-instance.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; -using namespace pajlada::Signals; - -TEST(BadInstance, MultipleFiles) -{ - auto sm1 = std::make_shared(); - auto sm2 = std::make_shared(); - - Setting a("/multi/a", sm1); - - EXPECT_TRUE(a == 0); - - a = 3; - - EXPECT_TRUE(a == 3); - - sm1.reset(); - - a.getValue(); -} - -TEST(BadInstance, Two) -{ - auto sm1 = std::make_shared(); - - Setting a("/multi/a", sm1); - - EXPECT_TRUE(a == 0); - - a = 3; - - EXPECT_TRUE(a == 3); - - auto lockedData = a.getData().lock(); - - sm1.reset(); - - rapidjson::Value val; - - EXPECT_TRUE(lockedData->marshal(53) == false); - EXPECT_TRUE(lockedData->unmarshalJSON() == nullptr); - EXPECT_TRUE(lockedData->getPath() == "/multi/a"); - EXPECT_TRUE(lockedData->unmarshal() == std::nullopt); - - a.getValue(); -} - -TEST(MultiInstance, Good1) -{ - auto sm = std::make_shared(); - - EXPECT_TRUE(sm->loadFrom("files/in.multi.json") == - SettingManager::LoadError::NoError); - - Setting a("/multi/a", sm); - - bool called = false; - - { - std::vector> - managedConnections; - - const bool autoInvoke = true; - - a.connect( - [&](int value, const SignalArgs &) { - EXPECT_TRUE(value == 50); - called = true; - }, - managedConnections, autoInvoke); - if (autoInvoke) { - EXPECT_TRUE(called); - } - } - - called = false; - a.connect([&](int /*value*/) { - //EXPECT_TRUE(value == 50); // - called = true; - }); - - EXPECT_TRUE(called); - - // EXPECT_TRUE(a == 50); -} - -TEST(MultiInstance, Good2) -{ - auto sm = std::make_shared(); - - EXPECT_TRUE(sm->loadFrom("files/in.multi.json") == - SettingManager::LoadError::NoError); - - Setting a("/multi/a", sm); - - bool called = false; - - { - std::vector> - managedConnections; - - const bool autoInvoke = true; - - a.connectJSON( - [&](const rapidjson::Value &, const SignalArgs &) { - called = true; // - }, - managedConnections, autoInvoke); - if (autoInvoke) { - EXPECT_TRUE(called); - } - } - - called = false; - a.connect([&](int value) { - EXPECT_TRUE(value == 50); // - called = true; - }); - - EXPECT_TRUE(called); - - // EXPECT_TRUE(a == 50); -} diff --git a/src/test/channel.cpp b/src/test/channel.cpp deleted file mode 100644 index a0d5369..0000000 --- a/src/test/channel.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "test/channel.hpp" - -#include "test/channelmanager.hpp" - -namespace pajlada { -namespace test { - -using namespace Settings; - -IndexedChannel::IndexedChannel(const unsigned _index) - : index(_index) - , xDIndex("/channelsArray/" + std::to_string(index) + "/index", _index) - , name("/channelsArray/" + std::to_string(index) + "/name", - "Name not loaded") -{ -} - -Channel::Channel(const std::string &_name) - : name(_name) - , maxMessageLength("/channels/" + this->name + "/maxMessageLength", 240) -{ -} - -} // namespace test -} // namespace pajlada diff --git a/src/test/common.cpp b/src/test/common.cpp deleted file mode 100644 index 78f9e84..0000000 --- a/src/test/common.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "test/common.hpp" - -#include -#include - -using namespace pajlada::Settings; - -namespace { - -std::string initialPath = "files/"; - -} // namespace - -std::string -ReadFile(const std::string &path) -{ - std::ifstream fh(path, std::ios::in | std::ios::binary); - if (!fh) { - return ""; - } - - std::string contents; - fh.seekg(0, std::ios::end); - contents.resize(fh.tellg()); - fh.seekg(0, std::ios::beg); - fh.read(&contents[0], contents.size()); - fh.close(); - - return contents; -} - -bool -FilesMatch(const std::string &fileName1, const std::string &fileName2) -{ - std::string path1 = initialPath + fileName1; - std::string path2 = initialPath + fileName2; - - auto content1 = ReadFile(path1); - auto content2 = ReadFile(path2); - - // cout << path1 << ": " << content1 << '\n'; - // cout << path2 << ": " << content2 << '\n'; - - return content1 == content2; -} - -bool -LoadFile(const std::string &fileName, SettingManager *sm) -{ - if (sm == nullptr) { - sm = SettingManager::getInstance().get(); - } - - std::string path = initialPath + fileName; - - return sm->loadFrom(path.c_str()) == SettingManager::LoadError::NoError; -} - -bool -SaveFile(const std::string &fileName, SettingManager *sm) -{ - if (sm == nullptr) { - sm = SettingManager::getInstance().get(); - } - - std::string path = initialPath + fileName; - - return sm->saveAs(path.c_str()); -} - -bool -RemoveFile(const std::string &path) -{ - std::error_code ec; - auto res = std::filesystem::remove(path, ec); - - if (ec) { - return false; - } - - return res; -} diff --git a/src/test/default.cpp b/src/test/default.cpp deleted file mode 100644 index 512ca49..0000000 --- a/src/test/default.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Default, Reset) -{ - // No custom default value, not available in the settings file - Setting noDefault("/noDefault"); - - // Custom default value, not available in the settings file - Setting customDefault("/customDefault", 5); - - // No custom default value, saved in settings file as the same value - Setting loadedSameNoDefault("/loadedSameNoDefault"); - - // No custom default value, saved in settings file as a different value - Setting loadedDifferentNoDefault("/loadedDifferentNoDefault"); - - // Custom default value, saved in settings file as the same value - Setting loadedSameCustomDefault("/loadedSameCustomDefault", 5); - - // Custom default value, saved in settings file as a different value - Setting loadedDifferentCustomDefault("/loadedDifferentCustomDefault", - 5); - - EXPECT_TRUE(noDefault.getDefaultValue() == 0); - EXPECT_TRUE(customDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedSameNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedDifferentNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedSameCustomDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedDifferentCustomDefault.getDefaultValue() == 5); - - EXPECT_TRUE(noDefault.isDefaultValue()); - EXPECT_TRUE(customDefault.isDefaultValue()); - EXPECT_TRUE(loadedSameNoDefault.isDefaultValue()); - EXPECT_TRUE(loadedDifferentNoDefault.isDefaultValue()); - EXPECT_TRUE(loadedSameCustomDefault.isDefaultValue()); - EXPECT_TRUE(loadedDifferentCustomDefault.isDefaultValue()); - - // Before loading - EXPECT_TRUE(noDefault == 0); - EXPECT_TRUE(customDefault == 5); - EXPECT_TRUE(loadedSameNoDefault == 0); - EXPECT_TRUE(loadedDifferentNoDefault == 0); - EXPECT_TRUE(loadedSameCustomDefault == 5); - EXPECT_TRUE(loadedDifferentCustomDefault == 5); - - // Before loading, after resetting all values to their default value - noDefault.resetToDefaultValue(); - customDefault.resetToDefaultValue(); - loadedSameNoDefault.resetToDefaultValue(); - loadedDifferentNoDefault.resetToDefaultValue(); - loadedSameCustomDefault.resetToDefaultValue(); - loadedDifferentCustomDefault.resetToDefaultValue(); - - EXPECT_TRUE(noDefault.getDefaultValue() == 0); - EXPECT_TRUE(customDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedSameNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedDifferentNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedSameCustomDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedDifferentCustomDefault.getDefaultValue() == 5); - - EXPECT_TRUE(noDefault == 0); - EXPECT_TRUE(customDefault == 5); - EXPECT_TRUE(loadedSameNoDefault == 0); - EXPECT_TRUE(loadedDifferentNoDefault == 0); - EXPECT_TRUE(loadedSameCustomDefault == 5); - EXPECT_TRUE(loadedDifferentCustomDefault == 5); - - EXPECT_TRUE(LoadFile("in.resettodefault.json")); - - // value does not exist in json file, so should still be same as default - EXPECT_TRUE(noDefault.isDefaultValue()); - // value does not exist in json file, so should still be same as default - EXPECT_TRUE(customDefault.isDefaultValue()); - // value exists in json file, and it's the same as the implicit default value - EXPECT_TRUE(loadedSameNoDefault.isDefaultValue()); - // value exists in json file, but it's different from the implicit default value - EXPECT_TRUE(!loadedDifferentNoDefault.isDefaultValue()); - // value exists in json file, and it's the same as the explicit default value - EXPECT_TRUE(loadedSameCustomDefault.isDefaultValue()); - // value exists in json file, but it's different from the explicit default value - EXPECT_TRUE(!loadedDifferentCustomDefault.isDefaultValue()); - - // After loading - EXPECT_TRUE(noDefault == 0); - EXPECT_TRUE(customDefault == 5); - EXPECT_TRUE(loadedSameNoDefault == 0); - EXPECT_TRUE(loadedDifferentNoDefault == 1); - EXPECT_TRUE(loadedSameCustomDefault == 5); - EXPECT_TRUE(loadedDifferentCustomDefault == 6); - - EXPECT_TRUE(noDefault.getDefaultValue() == 0); - EXPECT_TRUE(customDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedSameNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedDifferentNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedSameCustomDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedDifferentCustomDefault.getDefaultValue() == 5); - - // Reset all values to their default values - noDefault.resetToDefaultValue(); - customDefault.resetToDefaultValue(); - loadedSameNoDefault.resetToDefaultValue(); - loadedDifferentNoDefault.resetToDefaultValue(); - loadedSameCustomDefault.resetToDefaultValue(); - loadedDifferentCustomDefault.resetToDefaultValue(); - - EXPECT_TRUE(noDefault.isDefaultValue()); - EXPECT_TRUE(customDefault.isDefaultValue()); - EXPECT_TRUE(loadedSameNoDefault.isDefaultValue()); - EXPECT_TRUE(loadedDifferentNoDefault.isDefaultValue()); - EXPECT_TRUE(loadedSameCustomDefault.isDefaultValue()); - EXPECT_TRUE(loadedDifferentCustomDefault.isDefaultValue()); - - EXPECT_TRUE(noDefault.getDefaultValue() == 0); - EXPECT_TRUE(customDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedSameNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedDifferentNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedSameCustomDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedDifferentCustomDefault.getDefaultValue() == 5); - - // After loading, after resetting all values to their default value - EXPECT_TRUE(noDefault == 0); - EXPECT_TRUE(customDefault == 5); - EXPECT_TRUE(loadedSameNoDefault == 0); - EXPECT_TRUE(loadedDifferentNoDefault == 0); - EXPECT_TRUE(loadedSameCustomDefault == 5); - EXPECT_TRUE(loadedDifferentCustomDefault == 5); - - noDefault.setDefaultValue(1); - - EXPECT_TRUE(noDefault == 0); - - EXPECT_TRUE(!noDefault.isDefaultValue()); - - noDefault.resetToDefaultValue(); - - EXPECT_TRUE(noDefault.isDefaultValue()); - - EXPECT_TRUE(noDefault == 1); - - EXPECT_TRUE(noDefault.getDefaultValue() == 1); - EXPECT_TRUE(customDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedSameNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedDifferentNoDefault.getDefaultValue() == 0); - EXPECT_TRUE(loadedSameCustomDefault.getDefaultValue() == 5); - EXPECT_TRUE(loadedDifferentCustomDefault.getDefaultValue() == 5); -} - -TEST(Default, UpdateUpdateIteration) -{ - SettingManager::clear(); - - Setting setting("/setting", 42); - - EXPECT_EQ(setting.getUpdateIteration(), -1); - - EXPECT_TRUE(LoadFile("empty.json")); - EXPECT_EQ(setting.getUpdateIteration(), -1); - - EXPECT_EQ(setting.getValue(), 42); - EXPECT_EQ(setting.getUpdateIteration(), 0); - - setting = 43; - EXPECT_EQ(setting.getUpdateIteration(), 0); - EXPECT_EQ(setting.getValue(), 43); - EXPECT_EQ(setting.getUpdateIteration(), 1); -} diff --git a/src/test/deserialize.cpp b/src/test/deserialize.cpp deleted file mode 100644 index 413f878..0000000 --- a/src/test/deserialize.cpp +++ /dev/null @@ -1,166 +0,0 @@ -#include "test/common.hpp" - -using namespace pajlada::Settings; -using namespace pajlada; - -const double EPSILON = 1e-6; - -class FDeserialize : public ::testing::Test -{ -protected: - void - SetUp() override - { - EXPECT_TRUE(LoadFile("deserialize-samples.json")); - } - - void - TearDown() override - { - SettingManager::clear(); - } -}; - -TEST_F(FDeserialize, A) -{ -} - -TEST_F(FDeserialize, Int) -{ - Setting a1("/int"); - Setting a2("/float"); - auto a3 = new Setting("/std::string"); - auto a4 = new Setting("/bool"); - - EXPECT_TRUE(a1.getValue() == 5); - EXPECT_TRUE(a2.getValue() == 5); - DD_THROWS(a3->getValue()); - DD_THROWS(a4->getValue()); -} - -TEST_F(FDeserialize, Float) -{ - Setting a1("/int"); - Setting a2("/float"); - auto a3 = new Setting("/std::string"); - auto a4 = new Setting("/bool"); - - EXPECT_NEAR(a1.getValue(), 5.f, EPSILON); - EXPECT_NEAR(a2.getValue(), 5.3f, EPSILON); - DD_THROWS(a3->getValue()); - DD_THROWS(a4->getValue()); -} - -TEST_F(FDeserialize, Double) -{ - Setting a1("/int"); - Setting a2("/float"); - auto a3 = new Setting("/std::string"); - auto a4 = new Setting("/bool"); - - EXPECT_NEAR(a1.getValue(), 5., EPSILON); - EXPECT_NEAR(a2.getValue(), 5.3, EPSILON); - DD_THROWS(a3->getValue()); - DD_THROWS(a4->getValue()); -} - -TEST_F(FDeserialize, Bool) -{ - Setting a1("/int"); - auto a2 = new Setting("/float"); - auto a3 = new Setting("/std::string"); - auto a4 = new Setting("/bool"); - - Setting a5("/int1"); - - EXPECT_TRUE(a1.getValue() == false); - DD_THROWS(a2->getValue()); - DD_THROWS(a3->getValue()); - EXPECT_TRUE(a4->getValue() == true); - EXPECT_TRUE(a5.getValue() == true); -} - -TEST_F(FDeserialize, String) -{ - Setting *a1, *a2, *a3, *a4; - a1 = new Setting("/int"); - a2 = new Setting("/float"); - a3 = new Setting("/string"); - a4 = new Setting("/bool"); - - DD_THROWS(a1->getValue()); - DD_THROWS(a2->getValue()); - EXPECT_TRUE(a3->getValue() == "xd"); - DD_THROWS(a4->getValue()); -} - -class FDeserialize2 : public ::testing::Test -{ -protected: - void - SetUp() override - { - } - - void - TearDown() override - { - } - - rapidjson::Value jString{"asd"}; - rapidjson::Value jInt{5}; - rapidjson::Value jBool{true}; - rapidjson::Value jDouble{6.4}; - - bool error = false; -}; - -TEST_F(FDeserialize2, Int) -{ - int v = 0; - - error = false; - DD_THROWS(v = Deserialize::get(jString, &error)); - EXPECT_TRUE(error == true); - REQUIRE_IF_NOEXCEPT2(v, 0); - - error = false; - v = Deserialize::get(jInt, &error); - EXPECT_TRUE(error == false); - EXPECT_TRUE(v == 5); - - error = false; - DD_THROWS(v = Deserialize::get(jBool, &error)); - EXPECT_TRUE(error == true); - REQUIRE_IF_NOEXCEPT2(v, 0); - - error = false; - v = Deserialize::get(jDouble, &error); - EXPECT_TRUE(error == false); - EXPECT_TRUE(v == 6); -} - -TEST_F(FDeserialize2, String) -{ - std::string v = ""; - - error = false; - v = Deserialize::get(this->jString, &error); - EXPECT_TRUE(error == false); - EXPECT_TRUE(v == "asd"); - - error = false; - DD_THROWS(v = Deserialize::get(jInt, &error)); - EXPECT_TRUE(error == true); - REQUIRE_IF_NOEXCEPT2(v, ""); - - error = false; - DD_THROWS(v = Deserialize::get(jBool, &error)); - EXPECT_TRUE(error == true); - REQUIRE_IF_NOEXCEPT2(v, ""); - - error = false; - DD_THROWS(v = Deserialize::get(this->jDouble, &error)); - EXPECT_TRUE(error == true); - REQUIRE_IF_NOEXCEPT2(v, ""); -} diff --git a/src/test/foo.cpp b/src/test/foo.cpp deleted file mode 100644 index 79741ff..0000000 --- a/src/test/foo.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "test/foo.hpp" - -namespace pajlada { -namespace test { - -using namespace Settings; - -Setting Foo::i1("rootSetting1", 1); -Setting Foo::i2("rootSetting2", 2); -Setting Foo::i3("rootSetting3", 3); -Setting Foo::s1( - "rootSetting4", - "Default string"); // XXX(pajlada): Something is wrong with this - -Setting Foo::f1("float1", 1.0101f); -Setting Foo::f2("float2", 1.0101010101f); -Setting Foo::f3("float3", 1.123456789f); -Setting Foo::f4("float4", 1.f); -Setting Foo::f5("float5", 0.f); -Setting Foo::f6("float6", -.1f); -Setting Foo::f7("float7", 1.0f); - -Setting Foo::d1("double1", 1.0101); -Setting Foo::d2("double2", 1.0101010101); -Setting Foo::d3("double3", 1.123456789); -Setting Foo::d4("double4", 1.); -Setting Foo::d5("double5", 0.); -Setting Foo::d6("double6", -.1); -Setting Foo::d7("double7", 123.456); - -Setting Foo::b1("bool1", true); -Setting Foo::b2("bool2", false); -Setting Foo::b3("bool3", true); -Setting Foo::b4("bool4", false); -Setting Foo::b5("bool5", true); -Setting Foo::b6("bool6", false); -Setting Foo::b7("bool7", true); - -Setting Foo::rootInt1 = Setting("/root/i1", 1); -// the error happens here for some reason -// these lines (i1 and i2) are the reason that the new array thing isn't saved -// properly -Setting Foo::rootInt2 = Setting("/root/i2", 1); - -} // namespace test -} // namespace pajlada diff --git a/src/test/listener.cpp b/src/test/listener.cpp deleted file mode 100644 index d4b70a7..0000000 --- a/src/test/listener.cpp +++ /dev/null @@ -1,122 +0,0 @@ - -#include - -#include "pajlada/settings/settinglistener.hpp" -#include "test/common.hpp" - -using namespace pajlada::Settings; -using namespace pajlada; - -TEST(Listener, simple) -{ - Setting a("/listener/simple/a"); - Setting b("/listener/simple/b"); - - size_t invocations = 0; - SettingListener listener([&] { invocations++; }); - - ASSERT_EQ(invocations, 0); - listener.addSetting(a); - ASSERT_EQ(invocations, 0); - listener.addSetting(b); - ASSERT_EQ(invocations, 0); - - a = 42; - ASSERT_EQ(invocations, 1); - b = 42; - ASSERT_EQ(invocations, 2); - a = 42; - ASSERT_EQ(invocations, 3); - a = 1; - ASSERT_EQ(invocations, 4); -} - -TEST(Listener, autoinvoke) -{ - Setting a("/listener/autoinvoke/a"); - Setting b("/listener/autoinvoke/b"); - - size_t invocations = 0; - SettingListener listener([&] { invocations++; }); - - ASSERT_EQ(invocations, 0); - listener.addSetting(a, true); - ASSERT_EQ(invocations, 1); - listener.addSetting(b); - ASSERT_EQ(invocations, 1); - - a = 42; - ASSERT_EQ(invocations, 2); - b = 42; - ASSERT_EQ(invocations, 3); - a = 42; - ASSERT_EQ(invocations, 4); - a = 1; - ASSERT_EQ(invocations, 5); -} - -TEST(Listener, manualInvoke) -{ - Setting a("/listener/manual-invoke/a"); - Setting b("/listener/manual-invoke/b"); - - size_t invocations = 0; - SettingListener listener([&] { invocations++; }); - - ASSERT_EQ(invocations, 0); - listener.addSetting(a); - ASSERT_EQ(invocations, 0); - listener.addSetting(b); - ASSERT_EQ(invocations, 0); - - a = 42; - ASSERT_EQ(invocations, 1); - listener.invoke(); - ASSERT_EQ(invocations, 2); - b = 42; - ASSERT_EQ(invocations, 3); -} - -TEST(Listener, resetCallback) -{ - Setting a("/listener/reset-callback/a"); - Setting b("/listener/reset-callback/b"); - - size_t invocations = 0; - SettingListener listener([&] { invocations++; }); - - ASSERT_EQ(invocations, 0); - listener.addSetting(a); - ASSERT_EQ(invocations, 0); - listener.addSetting(b); - ASSERT_EQ(invocations, 0); - - a = 42; - ASSERT_EQ(invocations, 1); - listener.resetCB(); - ASSERT_EQ(invocations, 1); - b = 42; - a = 42; - listener.invoke(); - ASSERT_EQ(invocations, 1); -} - -TEST(Listener, emptyCallback) -{ - Setting a("/listener/empty-callback/a"); - Setting b("/listener/empty-callback/b"); - - SettingListener listener; - - listener.addSetting(a); - listener.addSetting(b); - - b = 42; - a = 42; - listener.invoke(); - - listener.resetCB(); - b = 42; - a = 42; - listener.invoke(); -} diff --git a/src/test/load.cpp b/src/test/load.cpp deleted file mode 100644 index 1ad54c2..0000000 --- a/src/test/load.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -namespace fs = std::filesystem; - -TEST(Load, Unicode) -{ - SettingManager::clear(); - - Setting a("/a", 1); - - EXPECT_TRUE(a == 1); - - for (const auto &p : fs::directory_iterator("files/unicode/a")) { - auto sm = SettingManager::getInstance().get(); - EXPECT_TRUE(sm->loadFrom(p) == SettingManager::LoadError::NoError); - } - - EXPECT_TRUE(a == 5); -} - -TEST(Load, Space) -{ - SettingManager::clear(); - - Setting a("/a", 1); - - EXPECT_TRUE(a == 1); - - EXPECT_TRUE(LoadFile("load. .json")); - - EXPECT_TRUE(a == 5); -} - -TEST(Load, Symlink) -{ - std::string bp("in.symlink.json"); - - SettingManager::clear(); - - Setting lol("/lol", 1); - - EXPECT_TRUE(lol == 1); - - EXPECT_TRUE(LoadFile(bp)); - - EXPECT_TRUE(lol == 10); -} - -TEST(Load, RelativeSymlink) -{ - std::string bp("in.relative-symlink.json"); - - SettingManager::clear(); - - Setting lol("/lol", 1); - - EXPECT_TRUE(lol == 1); - - EXPECT_TRUE(LoadFile(bp)); - - EXPECT_TRUE(lol == 10); -} - -TEST(Load, AbsoluteSymlinkSameFolder) -{ - std::string bp("files/in.absolute-symlink-same-folder.json"); - - RemoveFile(bp); - - auto cwd = fs::current_path(); - - fs::create_symlink(cwd / "files" / "correct.save.save_int.json", bp); - - SettingManager::clear(); - - Setting lol("/lol", 1); - - EXPECT_TRUE(lol == 1); - - EXPECT_TRUE(LoadFile("in.absolute-symlink-same-folder.json")); - - EXPECT_TRUE(lol == 10); -} diff --git a/src/test/main.cpp b/src/test/main.cpp deleted file mode 100644 index df0987b..0000000 --- a/src/test/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -int -main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - - return RUN_ALL_TESTS(); -} diff --git a/src/test/map.cpp b/src/test/map.cpp deleted file mode 100644 index 790f058..0000000 --- a/src/test/map.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Map, Simple) -{ - using std::any_cast; - - Setting> test("/map"); - - EXPECT_TRUE(LoadFile("in.simplemap.json")); - - auto myMap = test.getValue(); - EXPECT_TRUE(myMap.size() == 3); - EXPECT_TRUE(any_cast(myMap["a"]) == 1); - EXPECT_TRUE(any_cast(myMap["b"]) == "asd"); - EXPECT_DOUBLE_EQ(any_cast(myMap["c"]), 3.14); - - std::vector keys{"a", "b", "c"}; - - EXPECT_TRUE(keys == SettingManager::getObjectKeys("/map")); - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.simplemap.json")); -} - -TEST(Map, Complex) -{ - using std::any_cast; - - Setting> test("/map"); - - EXPECT_TRUE(LoadFile("in.complexmap.json")); - - auto myMap = test.getValue(); - EXPECT_TRUE(myMap.size() == 3); - EXPECT_TRUE(any_cast(myMap["a"]) == 5); - - auto innerMap = - any_cast>(myMap["innerMap"]); - EXPECT_TRUE(innerMap.size() == 3); - EXPECT_TRUE(any_cast(innerMap["a"]) == 420); - EXPECT_TRUE(any_cast(innerMap["b"]) == 320); - EXPECT_DOUBLE_EQ(any_cast(innerMap["c"]), 13.37); - - auto innerArray = any_cast>(myMap["innerArray"]); - EXPECT_TRUE(innerArray.size() == 9); - EXPECT_TRUE(any_cast(innerArray[0]) == 1); - EXPECT_TRUE(any_cast(innerArray[1]) == 2); - EXPECT_TRUE(any_cast(innerArray[2]) == 3); - EXPECT_TRUE(any_cast(innerArray[3]) == 4); - EXPECT_TRUE(any_cast(innerArray[4]) == "testman"); - EXPECT_TRUE(any_cast(innerArray[5]) == true); - EXPECT_TRUE(any_cast(innerArray[6]) == false); - EXPECT_DOUBLE_EQ(any_cast(innerArray[7]), 4.20); - - auto innerArrayMap = - any_cast>(innerArray[8]); - EXPECT_TRUE(innerArrayMap.size() == 3); - EXPECT_TRUE(any_cast(innerArrayMap["a"]) == 1); - EXPECT_TRUE(any_cast(innerArrayMap["b"]) == 2); - EXPECT_TRUE(any_cast(innerArrayMap["c"]) == 3); - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.complexmap.json")); -} diff --git a/src/test/misc.cpp b/src/test/misc.cpp deleted file mode 100644 index a1aa28a..0000000 --- a/src/test/misc.cpp +++ /dev/null @@ -1,206 +0,0 @@ -// UNSORTED TESTS - -#include -#include -#include -#include -#include -#include -#include - -#include "test/channel.hpp" -#include "test/channelmanager.hpp" -#include "test/common.hpp" -#include "test/foo.hpp" - -using namespace pajlada::Settings; -using namespace pajlada::test; - -TEST(Misc, StdAny) -{ - Setting test("/anyTest"); - auto test2 = new Setting("/anyTest2"); - - auto v1 = test.getValue(); - auto v2 = test2->getValue(); -} - -TEST(Misc, Array) -{ - Setting test1("/array/0/int"); - Setting test2("/array/1/int"); - Setting test3("/array/2/int"); - - test1 = 5; - test2 = 10; - test3 = 15; - - // This below assertation is not always true - // It will only be true if the settings above area created with - // "SaveInitialValue", or if "SaveOnChange" is enabled and the value has - // been changed - EXPECT_TRUE(SettingManager::arraySize("/array") == 3); - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.array_test.json") == true); - - EXPECT_TRUE(SettingManager::arraySize("/array") == 3); -} - -TEST(Misc, ArraySize) -{ - EXPECT_TRUE(LoadFile("in.array_size.json")); - - EXPECT_TRUE(SettingManager::arraySize("/arraySize1") == 1); - EXPECT_TRUE(SettingManager::arraySize("/arraySize2") == 2); - EXPECT_TRUE(SettingManager::arraySize("/arraySize3") == 3); - EXPECT_TRUE(SettingManager::arraySize("/arraySize4") == 4); - - // Not an array - EXPECT_TRUE(SettingManager::arraySize("/arraySize5") == 0); -} - -TEST(Misc, Vector) -{ - Setting> test("/vectorTest"); - - EXPECT_TRUE(LoadFile("in.vector.json")); - - auto vec = test.getValue(); - - EXPECT_TRUE(vec.size() == 3); - - EXPECT_TRUE(vec.at(0) == 5); - EXPECT_TRUE(vec.at(1) == 10); - EXPECT_TRUE(vec.at(2) == 15); - - std::vector x = {1, 2, 3}; - - test = x; - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.vector.json") == true); -} - -TEST(Misc, ChannelManager) -{ - ChannelManager manager; - - EXPECT_TRUE(manager.channels.size() == pajlada::test::NUM_CHANNELS); - - for (size_t i = 0; i < manager.channels.size(); ++i) { - EXPECT_TRUE(manager.channels.at(i).name.getValue() == - "Name not loaded"); - } - - EXPECT_TRUE(LoadFile("channelmanager.json")); - - EXPECT_TRUE(manager.channels.at(0).name.getValue() == "pajlada"); - EXPECT_TRUE(manager.channels.at(1).name.getValue() == "hemirt"); - EXPECT_TRUE(manager.channels.at(2).name.getValue() == "gempir"); - - // Last channel should always be unset - EXPECT_TRUE( - manager.channels.at(pajlada::test::NUM_CHANNELS - 1).name.getValue() == - "Name not loaded"); - - for (auto i = 4; i < pajlada::test::NUM_CHANNELS; ++i) { - manager.channels.at(i).name = "From file FeelsGoodMan"; - } - - EXPECT_TRUE(manager.channels.size() == pajlada::test::NUM_CHANNELS); - EXPECT_TRUE(SettingManager::gSaveAs("files/out.test3.json")); - EXPECT_TRUE(manager.channels.size() == pajlada::test::NUM_CHANNELS); -} - -TEST(Misc, Channel) -{ - Channel chHemirt("hemirt"); - Channel chPajlada("pajlada"); - - // Pre-load - EXPECT_TRUE(chHemirt.maxMessageLength == 240); - EXPECT_TRUE(chPajlada.maxMessageLength == 240); - - // Load default file - EXPECT_TRUE(LoadFile("d.channels.json")); - - // Post defaults load - EXPECT_TRUE(chHemirt.maxMessageLength.getValue() == 200); - EXPECT_TRUE(chPajlada.maxMessageLength == 240); - - // Load custom file - EXPECT_TRUE(LoadFile("channels.json")); - - // Post channels load - EXPECT_TRUE(chHemirt.maxMessageLength == 300); - EXPECT_TRUE(chPajlada.maxMessageLength == 500); -} - -TEST(Misc, LoadFilesInvalidFiles) -{ - EXPECT_TRUE(SettingManager::gLoadFrom("files/bad-1.json") == - SettingManager::LoadError::JSONParseError); - EXPECT_TRUE(SettingManager::gLoadFrom("files/bad-2.json") == - SettingManager::LoadError::JSONParseError); - EXPECT_TRUE(SettingManager::gLoadFrom("files/bad-3.json") == - SettingManager::LoadError::JSONParseError); - EXPECT_TRUE(SettingManager::gLoadFrom("files/empty.json") == - SettingManager::LoadError::NoError); -} - -TEST(Misc, NonExistantFiles) -{ - EXPECT_TRUE( - SettingManager::gLoadFrom("files/test-non-existant-file.json") == - SettingManager::LoadError::CannotOpenFile); -} - -TEST(Misc, ValidFiles) -{ - EXPECT_TRUE(SettingManager::gLoadFrom("files/default.json") == - SettingManager::LoadError::NoError); -} - -TEST(Misc, Misc) -{ - Setting test1("/test"); - EXPECT_TRUE(test1.getPath() == "/test"); - EXPECT_TRUE(test1.getData().lock()->getPath() == "/test"); - EXPECT_TRUE(test1.getData().lock()->getPath() == test1.getPath()); -} - -TEST(Misc, Stringify) -{ - rapidjson::Value test(5); - - EXPECT_TRUE(SettingManager::stringify(test) == "5"); -} - -TEST(Misc, MoveSet) -{ - int v = 69; - Setting test1("/test"); - EXPECT_TRUE(test1 == 0); - test1 = 3; - EXPECT_TRUE(test1 == 3); - test1 = std::move(v); - EXPECT_TRUE(test1 == 69); - - std::string v2("lol"); - Setting test2("/test"); - EXPECT_TRUE(test2 == ""); - EXPECT_TRUE(test2.getValue() == ""); - test2 = "hej"; - EXPECT_TRUE(test2 == "hej"); - EXPECT_TRUE(test2.getValue() == "hej"); - test2 = std::move(v2); - EXPECT_TRUE(test2 == "lol"); - EXPECT_TRUE(test2.getValue() == "lol"); - - const auto &lol = test2; - - const auto &hehe = lol.getValue(); - EXPECT_TRUE(hehe == "lol"); - EXPECT_TRUE(lol.getValue() == "lol"); - EXPECT_TRUE(lol.getValue() == "lol"); - EXPECT_TRUE(lol.getValue() == "lol"); -} diff --git a/src/test/remove.cpp b/src/test/remove.cpp deleted file mode 100644 index fdbcb43..0000000 --- a/src/test/remove.cpp +++ /dev/null @@ -1,93 +0,0 @@ -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Remove, Simple) -{ - Setting a("/rs/a"); - Setting b("/rs/b", 5); - Setting c("/rs/c"); - - // Before loading - EXPECT_TRUE(a == 0); - EXPECT_TRUE(b == 5); - EXPECT_TRUE(c == 0); - - EXPECT_TRUE(LoadFile("in.removesetting.json")); - - // After loading - EXPECT_TRUE(a == 5); - EXPECT_TRUE(b == 10); - EXPECT_TRUE(c == 0); - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.pre.removesetting.json")); - - EXPECT_TRUE(a.remove()); - - EXPECT_TRUE(SettingManager::gSaveAs("files/out.post.removesetting.json")); - - EXPECT_TRUE(!FilesMatch("out.pre.removesetting.json", - "out.post.removesetting.json")); -} - -TEST(Remove, Nested) -{ - Setting a("/root/nested/a", 5); - Setting b("/root/nested/b", 10); - Setting c("/root/nested/c", 15); - Setting d("/root/d"); - Setting e("/root/e", 20); - - // Before loading - EXPECT_TRUE(a == 5); - EXPECT_TRUE(b == 10); - EXPECT_TRUE(c == 15); - EXPECT_TRUE(d == 0); - EXPECT_TRUE(e == 20); - - EXPECT_TRUE(LoadFile("in.removenestedsetting.json")); - - // After loading - EXPECT_TRUE(a == 6); - EXPECT_TRUE(b == 11); - EXPECT_TRUE(c == 15); - EXPECT_TRUE(d == 0); - EXPECT_TRUE(e == 21); - - EXPECT_TRUE(a.isValid()); - EXPECT_TRUE(b.isValid()); - EXPECT_TRUE(c.isValid()); - EXPECT_TRUE(d.isValid()); - EXPECT_TRUE(e.isValid()); - - EXPECT_TRUE( - SettingManager::gSaveAs("files/out.removenestedsetting.state1.json")); - EXPECT_TRUE(FilesMatch("out.removenestedsetting.state1.json", - "in.removenestedsetting.state1.json")); - - EXPECT_TRUE(SettingManager::removeSetting("/root/nested/a")); - - EXPECT_TRUE(!a.isValid()); - EXPECT_TRUE(b.isValid()); - EXPECT_TRUE(c.isValid()); - EXPECT_TRUE(d.isValid()); - EXPECT_TRUE(e.isValid()); - - EXPECT_TRUE( - SettingManager::gSaveAs("files/out.removenestedsetting.state2.json")); - EXPECT_TRUE(FilesMatch("out.removenestedsetting.state2.json", - "in.removenestedsetting.state2.json")); - - EXPECT_TRUE(SettingManager::removeSetting("/root/nested")); - - EXPECT_TRUE(!a.isValid()); - EXPECT_TRUE(!b.isValid()); - EXPECT_TRUE(!c.isValid()); - EXPECT_TRUE(d.isValid()); - EXPECT_TRUE(e.isValid()); - - EXPECT_TRUE( - SettingManager::gSaveAs("files/out.removenestedsetting.state3.json")); - EXPECT_TRUE(FilesMatch("out.removenestedsetting.state3.json", - "in.removenestedsetting.state3.json")); -} diff --git a/src/test/save.cpp b/src/test/save.cpp deleted file mode 100644 index b4b5714..0000000 --- a/src/test/save.cpp +++ /dev/null @@ -1,235 +0,0 @@ -#include - -#include -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -namespace fs = std::filesystem; - -TEST(Save, Int) -{ - SettingManager::clear(); - // This will not be part of the final file, since we clear the settings right afterwards - // Setting::set("/asd", 5); - - // SettingManager::clear(); - - Setting::set("/lol", 10); - - EXPECT_TRUE(SaveFile("out.save.save_int.json")); - - EXPECT_TRUE( - FilesMatch("out.save.save_int.json", "correct.save.save_int.json")); -} - -TEST(Save, DoNotWriteToJSON) -{ - Setting::set("/asd", 5, SettingOption::DoNotWriteToJSON); - - Setting::set("/lol", 10); - - EXPECT_TRUE(SaveFile("out.save.save_int.json")); - - EXPECT_TRUE( - FilesMatch("out.save.save_int.json", "correct.save.save_int.json")); -} - -TEST(Save, NonSymlink) -{ - std::string ps = "files/save.not-a-symlink.json"; - EXPECT_TRUE(!fs::is_symlink(ps)); - - std::error_code ec; - - auto p1 = fs::path(ps); - auto p2 = detail::RealPath(p1, ec); - - EXPECT_TRUE(!ec); - - EXPECT_TRUE(p2 == ps); -} - -TEST(Save, Symlink) -{ - std::string ps = "files/save.symlink.json"; - EXPECT_TRUE(fs::is_symlink(ps)); - - SettingManager::clear(); - auto sm = SettingManager::getInstance().get(); - - Setting::set("/lol", 10); - - EXPECT_TRUE(sm->saveAs(ps.c_str())); - - EXPECT_TRUE(fs::is_symlink(ps)); -} - -TEST(Save, ErrorOnRecursiveSymlink) -{ - std::string ps = "files/save.symlink.recursive1.json"; - EXPECT_TRUE(fs::is_symlink(ps)); - - std::error_code ec; - - auto finalPath = detail::RealPath(ps, ec); - - EXPECT_TRUE(ec); - - EXPECT_TRUE(ec.value() == - static_cast(std::errc::too_many_symbolic_link_levels)); -} - -TEST(Save, ErrorOnSymlinkPointingToNonexistantFile) -{ - std::string ps = "files/save.symlink.nonexistant.json"; - EXPECT_TRUE(fs::is_symlink(ps)); - - std::error_code ec; - - auto finalPath = detail::RealPath(ps, ec); - - EXPECT_TRUE(!ec); -} - -TEST(Save, Backup) -{ - auto sm = std::make_shared(); - - sm->setPath("files/out.backup.json"); - - sm->saveMethod = SettingManager::SaveMethod::SaveManually; - - RemoveFile("files/out.backup.json"); - RemoveFile("files/out.backup.json.bkp-1"); - RemoveFile("files/out.backup.json.bkp-2"); - RemoveFile("files/out.backup.json.bkp-3"); - - sm->setBackupEnabled(true); - sm->setBackupSlots(3); - - { - Setting setting("/lol", SettingOption::Default, sm); - - setting.setValue(13); - } - - EXPECT_TRUE(!fs::exists("files/out.backup.json")); - - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists("files/out.backup.json")); - EXPECT_TRUE(!fs::exists("files/out.backup.json.bkp-1")); - - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists("files/out.backup.json")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-1")); - EXPECT_TRUE(!fs::exists("files/out.backup.json.bkp-2")); - - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists("files/out.backup.json")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-1")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-2")); - EXPECT_TRUE(!fs::exists("files/out.backup.json.bkp-3")); - - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists("files/out.backup.json")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-1")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-2")); - EXPECT_TRUE(fs::exists("files/out.backup.json.bkp-3")); -} - -TEST(Save, SaveSymlink) -{ - auto sm = std::make_shared(); - sm->saveMethod = SettingManager::SaveMethod::SaveManually; - - std::string bp("files/save.symlink-normal.json"); - std::string tp("files/out.symlink-normal.target.json"); - - sm->setPath(bp); - - RemoveFile(tp); - - EXPECT_TRUE(fs::is_symlink(bp)); - EXPECT_TRUE(!fs::exists(tp)); - - { - Setting setting("/lol", SettingOption::Default, sm); - - setting.setValue(13); - } - - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists(bp)); - EXPECT_TRUE(fs::is_symlink(bp)); - EXPECT_TRUE(fs::exists(tp)); -} - -TEST(Save, SaveBackupSymlink) -{ - // In this scenario: - // The base file is a symlink - // bkp-1 is not a symlink - // bkp-2 is a symlink - std::string bp("files/save.symlink-backup.json"); - std::string tp("files/out.symlink-backup.target.json"); - - std::string tp1("files/save.symlink-backup.json.bkp-1"); - - std::string bp2("files/save.symlink-backup.json.bkp-2"); - std::string tp2("files/out.symlink-backup.target.json.bkp-2"); - - // Start from a clean slate - we should only have symlinks at the start - RemoveFile(tp); - RemoveFile(tp1); - RemoveFile(tp2); - - EXPECT_TRUE(!fs::exists(tp)); - EXPECT_TRUE(!fs::exists(tp1)); - EXPECT_TRUE(!fs::exists(tp2)); - - auto sm = std::make_shared(); - - sm->setPath(bp); - sm->setBackupEnabled(true); - sm->setBackupSlots(2); - sm->saveMethod = SettingManager::SaveMethod::SaveManually; - - { - Setting setting("/lol", SettingOption::Default, sm); - - setting.setValue(13); - } - - EXPECT_TRUE(fs::is_symlink(bp)); - EXPECT_TRUE(!fs::exists(tp)); - - // Save to base file (following the symlink) - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::is_symlink(bp)); - EXPECT_TRUE(fs::exists(tp)); - - EXPECT_TRUE(!fs::exists(tp1)); - - // Save to base file, should create bkp-1 - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::exists(tp1)); - - EXPECT_TRUE(fs::is_symlink(bp2)); - EXPECT_TRUE(!fs::exists(tp2)); - - // Save to base file, should follow bkp-2 and save a file there - EXPECT_TRUE(sm->save()); - - EXPECT_TRUE(fs::is_symlink(bp2)); - EXPECT_TRUE(fs::exists(tp2)); -} diff --git a/src/test/scope.cpp b/src/test/scope.cpp deleted file mode 100644 index 1a2a948..0000000 --- a/src/test/scope.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Scope, Simple) -{ - Setting a1("/a", 1); - - EXPECT_TRUE(a1 == 1); - EXPECT_TRUE(a1.getDefaultValue() == 1); - - { - Setting a2("/a"); - // Because /a is already initialized, we should just load the same - // shared_ptr that a1 uses - - EXPECT_TRUE(a2 == 0); - EXPECT_TRUE(a2.getDefaultValue() == 0); - - a2 = 8; - - EXPECT_TRUE(a2 == 8); - EXPECT_TRUE(a1 == 8); - } - - EXPECT_TRUE(a1 == 8); - - Setting::set("/a", 10); - - EXPECT_TRUE(a1 == 10); - - { - Setting a2("/a"); - - EXPECT_TRUE(a2 == 10); - - Setting::set("/a", 20); - - EXPECT_TRUE(a2 == 20); - EXPECT_TRUE(a1 == 20); - } - - EXPECT_TRUE(a1 == 20); -} diff --git a/src/test/serialize.cpp b/src/test/serialize.cpp deleted file mode 100644 index 0caa1ce..0000000 --- a/src/test/serialize.cpp +++ /dev/null @@ -1,252 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Serialize, VectorBeforeLoading) -{ - std::vector data{"a", "b", "c"}; - Setting> a("/a"); - auto vec = a.getValue(); - - EXPECT_TRUE(vec.size() == 0); -} - -TEST(Serialize, VectorAfterSetting) -{ - std::vector data{"a", "b", "c"}; - Setting> a("/a"); - a = data; - - auto vec = a.getValue(); - - EXPECT_TRUE(vec.size() == data.size()); -} - -TEST(Serialize, VectorAfterLoading) -{ - std::vector data{"a", "b", "c"}; - Setting> a("/a"); - EXPECT_TRUE(LoadFile("in.serialize.vector.str.json")); - auto vec = a.getValue(); - - EXPECT_TRUE(vec.size() == 2); - EXPECT_TRUE(vec[0] == "x"); - EXPECT_TRUE(vec[1] == "D"); -} - -TEST(Serialize, VectorMisc) -{ - std::vector data{"a", "b", "c"}; - Setting> a("/a"); - std::vector newData{"l", "o", "l", "4HEad"}; - - a = newData; - - EXPECT_TRUE(SaveFile("out.serialize.vector.str.json")); - - EXPECT_TRUE(FilesMatch("in.serialize.vector.str.state1.json", - "out.serialize.vector.str.json")); -} - -TEST(Serialize, StdAnyVectorString) -{ - using std::any_cast; - - SettingManager::clear(); - - std::vector data{"a", "b", "c"}; - - Setting a("/a"); - - auto rawAny = a.getValue(); - EXPECT_FALSE(rawAny.has_value()); - - a = data; - - rawAny = a.getValue(); - - EXPECT_TRUE(rawAny.has_value()); - - auto vec = any_cast>(rawAny); - - EXPECT_TRUE(vec.size() == data.size()); - - EXPECT_TRUE(LoadFile("in.serialize.any.vector.str.json")); - - rawAny = a.getValue(); - vec = any_cast>(rawAny); - - EXPECT_TRUE(vec.size() == 2); - EXPECT_TRUE(any_cast(vec[0]) == "x"); - EXPECT_TRUE(any_cast(vec[1]) == "D"); - - std::vector newData{"l", "o", "l", "4HEad"}; - - a = newData; - - EXPECT_TRUE(SaveFile("out.serialize.any.vector.str.json")); - - EXPECT_TRUE(FilesMatch("in.serialize.vector.str.state1.json", - "out.serialize.any.vector.str.json")); -} - -TEST(Serialize, StdAnyVectorAny) -{ - using std::any_cast; - - SettingManager::clear(); - - std::vector data{"test", 5, 13.37}; - - Setting a("/a"); - - auto rawAny = a.getValue(); - EXPECT_FALSE(rawAny.has_value()); - - a = data; - - rawAny = a.getValue(); - auto vec = any_cast>(rawAny); - - EXPECT_TRUE(vec.size() == data.size()); - - EXPECT_TRUE(vec[0].type().name() == typeid(std::string).name()); - EXPECT_TRUE(any_cast(vec[0]) == "test"); - EXPECT_TRUE(any_cast(vec[1]) == 5); - EXPECT_DOUBLE_EQ(any_cast(vec[2]), 13.37); - - EXPECT_TRUE(LoadFile("in.serialize.any.vector.str.json")); - - rawAny = a.getValue(); - vec = any_cast>(rawAny); - - EXPECT_TRUE(vec.size() == 2); - EXPECT_TRUE(any_cast(vec[0]) == "x"); - EXPECT_TRUE(any_cast(vec[1]) == "D"); - - std::vector newData{"l", "o", "l", "4HEad"}; - - a = newData; - - EXPECT_TRUE(SaveFile("out.serialize.any.vector.str.json")); - - EXPECT_TRUE(FilesMatch("in.serialize.vector.str.state1.json", - "out.serialize.any.vector.str.json")); -} - -TEST(Serialize, Int1) -{ - SettingManager::clear(); - Setting a("/a"); - EXPECT_TRUE(a == 0); - EXPECT_TRUE(a.getValue() == 0); - int val = a; - EXPECT_TRUE(val == 0); -} - -TEST(Serialize, Int2) -{ - SettingManager::clear(); - int data = 8; - Setting a("/a"); - a = data; - - EXPECT_TRUE(a == data); - EXPECT_TRUE(a.getValue() == data); - int val = a; - EXPECT_TRUE(val == data); -} - -TEST(Serialize, Int3) -{ - SettingManager::clear(); - Setting a("/a"); - EXPECT_TRUE(LoadFile("in.serialize.int.json")); - EXPECT_TRUE(a == 10); - EXPECT_TRUE(a.getValue() == 10); - int val = a; - EXPECT_TRUE(val == 10); -} - -TEST(Serialize, Int4) -{ - SettingManager::clear(); - Setting a("/a"); - EXPECT_TRUE(LoadFile("in.serialize.int.json")); - EXPECT_TRUE(SaveFile("out.serialize.int.json")); - - EXPECT_TRUE(FilesMatch("in.serialize.int.json", "out.serialize.int.json")); -} - -TEST(Serialize, Bool) -{ - SettingManager::clear(); - - bool data = true; - bool val; - - Setting a("/a"); - - EXPECT_TRUE(a == false); - EXPECT_TRUE(a.getValue() == false); - val = a; - EXPECT_TRUE(val == false); - - a = data; - - EXPECT_TRUE(a == data); - EXPECT_TRUE(a.getValue() == data); - val = a; - EXPECT_TRUE(val == data); - - a = false; - - EXPECT_TRUE(a == false); - EXPECT_TRUE(a.getValue() == false); - val = a; - EXPECT_TRUE(val == false); - - EXPECT_TRUE(LoadFile("in.serialize.bool.json")); - EXPECT_TRUE(a == true); - EXPECT_TRUE(a.getValue() == true); - val = a; - EXPECT_TRUE(val == true); - - EXPECT_TRUE(LoadFile("in.serialize.bool2.json")); - EXPECT_TRUE(a == false); - EXPECT_TRUE(a.getValue() == false); - val = a; - EXPECT_TRUE(val == false); - - EXPECT_TRUE(LoadFile("in.serialize.bool3.json")); - EXPECT_TRUE(a == true); - EXPECT_TRUE(a.getValue() == true); - val = a; - EXPECT_TRUE(val == true); - - EXPECT_TRUE(LoadFile("in.serialize.bool4.json")); - EXPECT_TRUE(a == false); - EXPECT_TRUE(a.getValue() == false); - val = a; - EXPECT_TRUE(val == false); - - a = true; - EXPECT_TRUE(a == true); - EXPECT_TRUE(a.getValue() == true); - val = a; - EXPECT_TRUE(val == true); - EXPECT_TRUE(SaveFile("out.serialize.bool.json")); - EXPECT_TRUE( - FilesMatch("in.serialize.bool.json", "out.serialize.bool.json")); - - a = false; - EXPECT_TRUE(a == false); - EXPECT_TRUE(a.getValue() == false); - val = a; - EXPECT_TRUE(val == false); - EXPECT_TRUE(SaveFile("out.serialize.bool.json")); - EXPECT_TRUE( - FilesMatch("in.serialize.bool.false.json", "out.serialize.bool.json")); -} diff --git a/src/test/signal.cpp b/src/test/signal.cpp deleted file mode 100644 index d5353aa..0000000 --- a/src/test/signal.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "test/common.hpp" - -using namespace pajlada::Settings; - -TEST(Signal, Simple) -{ - int count = 0; - int currentValue = 0; - auto cb = [&count, ¤tValue](const int &newValue, auto) { - ++count; - currentValue = newValue; - }; - - Setting a("/simple_signal/a"); - - EXPECT_TRUE(count == 0); - EXPECT_TRUE(currentValue == 0); - - a.connect(cb, false); - - EXPECT_TRUE(count == 0); - EXPECT_TRUE(currentValue == 0); - - a = 5; - - EXPECT_TRUE(count == 1); - EXPECT_TRUE(currentValue == 5); -} - -TEST(Signal, LoadFromFile) -{ - int count = 0; - int currentValue = 0; - auto cb = [&count, ¤tValue](const int &newValue, auto) { - ++count; - currentValue = newValue; - }; - - Setting a("/signal/a"); - Setting b("/signal/b"); - - EXPECT_TRUE(a.getValue() == 0); - - EXPECT_TRUE(count == 0); - EXPECT_TRUE(currentValue == 0); - - a.connect(cb, false); - b.connect(cb, false); - - EXPECT_TRUE(count == 0); - EXPECT_TRUE(currentValue == 0); - - a = 5; - - EXPECT_TRUE(count == 1); - EXPECT_TRUE(currentValue == 5); - - EXPECT_TRUE(LoadFile("in.signal.json")); - - EXPECT_TRUE(count == 2); - EXPECT_TRUE(currentValue == 3); -} - -TEST(Signal, ScopedConnection) -{ - int count = 0; - int currentValue = 0; - auto cb = [&count, ¤tValue](const int &newValue, auto) { - ++count; - currentValue = newValue; - }; - - std::vector> - connections; - - { - Setting c("/advancedSignals/c"); - - EXPECT_TRUE(count == 0); - - c.connect(cb, connections, false); - c.connect(cb, connections, false); - c.connect(cb, connections, false); - - EXPECT_TRUE(count == 0); - - // c1, c2, and c3 are active - c = 1; - - EXPECT_TRUE(count == 3); - - connections.pop_back(); - - // c1 and c2 are active - c = 2; - - EXPECT_TRUE(count == 5); - - connections.clear(); - - // No connection is active - c = 3; - - EXPECT_TRUE(count == 5); - } -} - -TEST(Signal, ScopedConnection2) -{ - int count = 0; - int currentValue = 0; - auto cb = [&count, ¤tValue](const int &newValue, auto) { - ++count; - currentValue = newValue; - }; - - std::vector> - connections; - - { - Setting c("/advancedSignals/c"); - - EXPECT_TRUE(count == 0); - - c.connect(cb, connections, false); - c.connect(cb, connections, false); - c.connect(cb, connections, false); - - EXPECT_TRUE(count == 0); - - // c1, c2, and c3 are active - c = 1; - - EXPECT_TRUE(count == 3); - - connections.pop_back(); - - { - Setting c2("/advancedSignals/c"); - } - - // c1 and c2 are active - c = 2; - - EXPECT_TRUE(count == 5); - - connections.clear(); - - // No connection is active - c = 3; - - EXPECT_TRUE(count == 5); - } -} diff --git a/src/test/static.cpp b/src/test/static.cpp deleted file mode 100644 index 4a8b2bc..0000000 --- a/src/test/static.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include - -#include "test/common.hpp" - -using namespace pajlada::Settings; - -namespace { - -// The static settings have been delegated to their own setting manager to not mess up other tests -auto ssm = std::make_shared(); - -Setting iNoDefault("/iNoDefault", ssm); -Setting iDefault("/iDefault", 5, ssm); - -Setting f1("/float1", 1.0101f, ssm); -Setting f2("/float2", 1.0101010101f, ssm); -Setting f3("/float3", 1.123456789f, ssm); -Setting f4("/float4", 1.f, ssm); -Setting f5("/float5", 0.f, ssm); -Setting f6("/float6", -.1f, ssm); -Setting f7("/float7", 1.0f, ssm); - -Setting d1("/double1", 1.0101, ssm); -Setting d2("/double2", 1.0101010101, ssm); -Setting d3("/double3", 1.123456789, ssm); -Setting d4("/double4", 1., ssm); -Setting d5("/double5", 0., ssm); -Setting d6("/double6", -.1, ssm); -Setting d7("/double7", 123.456, ssm); - -Setting b1("/bool1", true, ssm); -Setting b2("/bool2", false, ssm); -Setting b3("/bool3", true, ssm); -Setting b4("/bool4", false, ssm); -Setting b5("/bool5", true, ssm); -Setting b6("/bool6", false, ssm); -Setting b7("/bool7", true, ssm); - -} // namespace - -TEST(Static, Static) -{ - ssm->setBackupEnabled(true); - EXPECT_TRUE(iNoDefault.getValue() == 0); - EXPECT_TRUE(iDefault.getValue() == 5); - - EXPECT_TRUE(f1.getValue() == 1.0101f); - EXPECT_TRUE(f2.getValue() == 1.0101010101f); - EXPECT_TRUE(f3.getValue() == 1.123456789f); - EXPECT_TRUE(f4.getValue() == 1.f); - EXPECT_TRUE(f5.getValue() == 0.f); - EXPECT_TRUE(f6.getValue() == -.1f); - EXPECT_TRUE(f7.getValue() == 1.f); - - EXPECT_TRUE(d1.getValue() == 1.0101); - EXPECT_TRUE(d2.getValue() == 1.0101010101); - EXPECT_TRUE(d3.getValue() == 1.123456789); - EXPECT_TRUE(d4.getValue() == 1.); - EXPECT_TRUE(d5.getValue() == 0.); - EXPECT_TRUE(d6.getValue() == -.1); - EXPECT_TRUE(d7.getValue() == 123.456); - - EXPECT_TRUE(b1.getValue() == true); - EXPECT_TRUE(b2.getValue() == false); - EXPECT_TRUE(b3.getValue() == true); - EXPECT_TRUE(b4.getValue() == false); - EXPECT_TRUE(b5.getValue() == true); - EXPECT_TRUE(b6.getValue() == false); - EXPECT_TRUE(b7.getValue() == true); - - EXPECT_TRUE(LoadFile("test.json", ssm.get())); - - // Floats post-load - EXPECT_TRUE(f1.getValue() == 1.f); - EXPECT_TRUE(f2.getValue() == -1.f); - EXPECT_TRUE(f3.getValue() == 500.987654321f); - EXPECT_TRUE(f4.getValue() == 5.1f); - EXPECT_TRUE(f5.getValue() == 5.321f); - EXPECT_TRUE(f6.getValue() == 500000.1f); - - // Doubles post-load - EXPECT_TRUE(d1.getValue() == 1.); - EXPECT_TRUE(d2.getValue() == -1.); - EXPECT_TRUE(d3.getValue() == 500.987654321); - EXPECT_TRUE(d4.getValue() == 5.1); - EXPECT_TRUE(d5.getValue() == 5.321); - EXPECT_TRUE(d6.getValue() == 500000.1); - EXPECT_TRUE(d7.getValue() == 123.456); - - // Booleans post-load - EXPECT_TRUE(b1.getValue() == false); // false - EXPECT_TRUE(b2.getValue() == true); // true - EXPECT_TRUE(b3.getValue() == false); // 0 - EXPECT_TRUE(b4.getValue() == true); // 1 - EXPECT_TRUE(b5.getValue() == false); // 50291 (anything but 1) - EXPECT_TRUE(b6.getValue() == false); // nothing loaded - EXPECT_TRUE(b7.getValue() == true); // nothing loaded - - EXPECT_TRUE(iNoDefault.getValue() == 2); - EXPECT_TRUE(iDefault.getValue() == 3); - - // Class2::i1.signalValueChanged.connect([](const int &newValue) { - // std::cout << "new value for i1: " << newValue << std::endl; - // }); - - iNoDefault.setValue(3); - - EXPECT_TRUE(iNoDefault.getValue() == 3); - - iNoDefault = 4; - - EXPECT_TRUE(iNoDefault.getValue() == 4); - - f7 = 0.f; - - EXPECT_TRUE(SaveFile("out.test2.json", ssm.get())); -} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1feac8c..15f4784 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake") project(PajladaSettingsTest) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + option(BUILD_COVERAGE "Enable code coverage output" OFF) add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/.." PajladaSettings) diff --git a/tests/src/advanced-array.cpp b/tests/src/advanced-array.cpp index 3fc497d..4c454f9 100644 --- a/tests/src/advanced-array.cpp +++ b/tests/src/advanced-array.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/bad-instance.cpp b/tests/src/bad-instance.cpp index da4d75b..16f92fe 100644 --- a/tests/src/bad-instance.cpp +++ b/tests/src/bad-instance.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; using namespace pajlada::Signals; diff --git a/tests/src/channel.cpp b/tests/src/channel.cpp index a0d5369..c65d1ec 100644 --- a/tests/src/channel.cpp +++ b/tests/src/channel.cpp @@ -1,9 +1,8 @@ -#include "test/channel.hpp" +#include "channel.hpp" -#include "test/channelmanager.hpp" +#include "channelmanager.hpp" -namespace pajlada { -namespace test { +namespace pajlada::test { using namespace Settings; @@ -21,5 +20,4 @@ Channel::Channel(const std::string &_name) { } -} // namespace test -} // namespace pajlada +} // namespace pajlada::test diff --git a/include/test/channel.hpp b/tests/src/channel.hpp similarity index 100% rename from include/test/channel.hpp rename to tests/src/channel.hpp diff --git a/include/test/channelmanager.hpp b/tests/src/channelmanager.hpp similarity index 93% rename from include/test/channelmanager.hpp rename to tests/src/channelmanager.hpp index bb2cac0..194cc55 100644 --- a/include/test/channelmanager.hpp +++ b/tests/src/channelmanager.hpp @@ -2,10 +2,9 @@ #include -#include "test/channel.hpp" +#include "channel.hpp" -namespace pajlada { -namespace test { +namespace pajlada::test { constexpr int NUM_CHANNELS = 5; @@ -72,5 +71,4 @@ class ChannelManager std::array channels; }; -} // namespace test -} // namespace pajlada +} // namespace pajlada::test diff --git a/tests/src/common.cpp b/tests/src/common.cpp index 78f9e84..c76680f 100644 --- a/tests/src/common.cpp +++ b/tests/src/common.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" #include #include diff --git a/include/test/common.hpp b/tests/src/common.hpp similarity index 100% rename from include/test/common.hpp rename to tests/src/common.hpp diff --git a/tests/src/default.cpp b/tests/src/default.cpp index 512ca49..a824df1 100644 --- a/tests/src/default.cpp +++ b/tests/src/default.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/deserialize.cpp b/tests/src/deserialize.cpp index 413f878..4a38611 100644 --- a/tests/src/deserialize.cpp +++ b/tests/src/deserialize.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; using namespace pajlada; diff --git a/tests/src/foo.cpp b/tests/src/foo.cpp index 79741ff..e4d21f0 100644 --- a/tests/src/foo.cpp +++ b/tests/src/foo.cpp @@ -1,7 +1,6 @@ -#include "test/foo.hpp" +#include "foo.hpp" -namespace pajlada { -namespace test { +namespace pajlada::test { using namespace Settings; @@ -42,5 +41,4 @@ Setting Foo::rootInt1 = Setting("/root/i1", 1); // properly Setting Foo::rootInt2 = Setting("/root/i2", 1); -} // namespace test -} // namespace pajlada +} // namespace pajlada::test diff --git a/include/test/foo.hpp b/tests/src/foo.hpp similarity index 100% rename from include/test/foo.hpp rename to tests/src/foo.hpp diff --git a/tests/src/listener.cpp b/tests/src/listener.cpp index d4b70a7..bdaf759 100644 --- a/tests/src/listener.cpp +++ b/tests/src/listener.cpp @@ -1,8 +1,7 @@ - #include +#include "common.hpp" #include "pajlada/settings/settinglistener.hpp" -#include "test/common.hpp" using namespace pajlada::Settings; using namespace pajlada; diff --git a/tests/src/load.cpp b/tests/src/load.cpp index 1ad54c2..25e10e1 100644 --- a/tests/src/load.cpp +++ b/tests/src/load.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/map.cpp b/tests/src/map.cpp index 790f058..64cb58e 100644 --- a/tests/src/map.cpp +++ b/tests/src/map.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/misc.cpp b/tests/src/misc.cpp index a1aa28a..0a91f58 100644 --- a/tests/src/misc.cpp +++ b/tests/src/misc.cpp @@ -1,5 +1,3 @@ -// UNSORTED TESTS - #include #include #include @@ -8,10 +6,10 @@ #include #include -#include "test/channel.hpp" -#include "test/channelmanager.hpp" -#include "test/common.hpp" -#include "test/foo.hpp" +#include "channel.hpp" +#include "channelmanager.hpp" +#include "common.hpp" +#include "foo.hpp" using namespace pajlada::Settings; using namespace pajlada::test; diff --git a/tests/src/remove.cpp b/tests/src/remove.cpp index fdbcb43..34729af 100644 --- a/tests/src/remove.cpp +++ b/tests/src/remove.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/save.cpp b/tests/src/save.cpp index b4b5714..e44955c 100644 --- a/tests/src/save.cpp +++ b/tests/src/save.cpp @@ -3,7 +3,7 @@ #include #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/scope.cpp b/tests/src/scope.cpp index 1a2a948..a19a978 100644 --- a/tests/src/scope.cpp +++ b/tests/src/scope.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/serialize.cpp b/tests/src/serialize.cpp index 0caa1ce..952b2d6 100644 --- a/tests/src/serialize.cpp +++ b/tests/src/serialize.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/signal.cpp b/tests/src/signal.cpp index d5353aa..ce796d6 100644 --- a/tests/src/signal.cpp +++ b/tests/src/signal.cpp @@ -1,4 +1,4 @@ -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings; diff --git a/tests/src/static.cpp b/tests/src/static.cpp index 4a8b2bc..f584de7 100644 --- a/tests/src/static.cpp +++ b/tests/src/static.cpp @@ -1,6 +1,6 @@ #include -#include "test/common.hpp" +#include "common.hpp" using namespace pajlada::Settings;