mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:10:05 +00:00
Settings manager test
This commit is contained in:
parent
1c0140fc98
commit
fd0a148d3e
4 changed files with 113 additions and 4 deletions
97
test/source/scwx/qt/manager/settings_manager.test.cpp
Normal file
97
test/source/scwx/qt/manager/settings_manager.test.cpp
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
#include <scwx/qt/manager/settings_manager.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace manager
|
||||
{
|
||||
|
||||
static const std::string DEFAULT_SETTINGS_FILE =
|
||||
std::string(SCWX_TEST_DATA_DIR) + "/json/settings/settings-default.json";
|
||||
static const std::string TEMP_SETTINGS_FILE =
|
||||
std::string(SCWX_TEST_DATA_DIR) + "/json/settings/settings-temp.json";
|
||||
|
||||
class DefaultSettingsTest : public testing::TestWithParam<std::string>
|
||||
{
|
||||
};
|
||||
|
||||
void VerifyDefaults()
|
||||
{
|
||||
std::shared_ptr<settings::GeneralSettings> defaultGeneralSettings =
|
||||
settings::GeneralSettings::Create();
|
||||
|
||||
EXPECT_EQ(*defaultGeneralSettings, *SettingsManager::general_settings());
|
||||
}
|
||||
|
||||
void CompareFiles(const std::string& file1, const std::string& file2)
|
||||
{
|
||||
std::ifstream ifs1 {file1};
|
||||
std::stringstream buffer1;
|
||||
buffer1 << buffer1.rdbuf();
|
||||
|
||||
std::ifstream ifs2 {file2};
|
||||
std::stringstream buffer2;
|
||||
buffer2 << buffer2.rdbuf();
|
||||
|
||||
EXPECT_EQ(buffer1.str(), buffer2.str());
|
||||
}
|
||||
|
||||
TEST(SettingsManager, CreateJson)
|
||||
{
|
||||
std::string filename {TEMP_SETTINGS_FILE};
|
||||
|
||||
// Verify file doesn't exist prior to test start
|
||||
EXPECT_EQ(std::filesystem::exists(filename), false);
|
||||
|
||||
SettingsManager::ReadSettings(filename);
|
||||
|
||||
EXPECT_EQ(std::filesystem::exists(filename), true);
|
||||
|
||||
VerifyDefaults();
|
||||
CompareFiles(filename, DEFAULT_SETTINGS_FILE);
|
||||
|
||||
std::filesystem::remove(filename);
|
||||
EXPECT_EQ(std::filesystem::exists(filename), false);
|
||||
}
|
||||
|
||||
TEST(SettingsManager, SettingsKeax)
|
||||
{
|
||||
std::string filename(std::string(SCWX_TEST_DATA_DIR) +
|
||||
"/json/settings/settings-keax.json");
|
||||
|
||||
SettingsManager::ReadSettings(filename);
|
||||
|
||||
EXPECT_EQ(SettingsManager::general_settings()->default_radar_site(), "KEAX");
|
||||
}
|
||||
|
||||
TEST_P(DefaultSettingsTest, DefaultSettings)
|
||||
{
|
||||
std::string sourceFile(std::string(SCWX_TEST_DATA_DIR) + "/json/settings/" +
|
||||
GetParam());
|
||||
std::string filename {TEMP_SETTINGS_FILE};
|
||||
|
||||
std::filesystem::copy_file(sourceFile, filename);
|
||||
|
||||
SettingsManager::ReadSettings(filename);
|
||||
|
||||
VerifyDefaults();
|
||||
CompareFiles(filename, DEFAULT_SETTINGS_FILE);
|
||||
|
||||
std::filesystem::remove(filename);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(SettingsManager,
|
||||
DefaultSettingsTest,
|
||||
testing::Values("settings-bad-types.json",
|
||||
"settings-empty-groups.json",
|
||||
"settings-empty-object.json"));
|
||||
|
||||
} // namespace manager
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue