mirror of https://github.com/OpenMW/openmw.git
Merge branch 'settings_values_tests' into 'master'
Add tests for Settings::Values (#6876) See merge request OpenMW/openmw!2961use_qt_lockfile
commit
6f246e084a
@ -0,0 +1,85 @@
|
||||
#include "components/misc/strings/conversion.hpp"
|
||||
#include "components/settings/parser.hpp"
|
||||
#include "components/settings/values.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#ifndef OPENMW_PROJECT_SOURCE_DIR
|
||||
#define OPENMW_PROJECT_SOURCE_DIR "."
|
||||
#endif
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
namespace
|
||||
{
|
||||
using namespace testing;
|
||||
|
||||
struct SettingsValuesTest : Test
|
||||
{
|
||||
const std::filesystem::path mSettingsDefaultPath = std::filesystem::path{ OPENMW_PROJECT_SOURCE_DIR }
|
||||
/ "files" / Misc::StringUtils::stringToU8String("settings-default.cfg");
|
||||
|
||||
SettingsValuesTest()
|
||||
{
|
||||
Manager::mDefaultSettings.clear();
|
||||
Manager::mUserSettings.clear();
|
||||
Manager::mChangedSettings.clear();
|
||||
SettingsFileParser parser;
|
||||
parser.loadSettingsFile(mSettingsDefaultPath, Manager::mDefaultSettings);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SettingsValuesTest, shouldLoadFromSettingsManager)
|
||||
{
|
||||
Values values;
|
||||
EXPECT_EQ(values.mCamera.mFieldOfView.get(), 60);
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, constructorShouldThrowExceptionOnMissingSetting)
|
||||
{
|
||||
Manager::mDefaultSettings.erase({ "Camera", "field of view" });
|
||||
EXPECT_THROW([] { Values values; }(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, constructorShouldSanitize)
|
||||
{
|
||||
Manager::mUserSettings[std::make_pair("Camera", "field of view")] = "-1";
|
||||
Values values;
|
||||
EXPECT_EQ(values.mCamera.mFieldOfView.get(), 1);
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, moveConstructorShouldSetDefaults)
|
||||
{
|
||||
Values defaultValues;
|
||||
Manager::mUserSettings.emplace(std::make_pair("Camera", "field of view"), "61");
|
||||
Values values(std::move(defaultValues));
|
||||
EXPECT_EQ(values.mCamera.mFieldOfView.get(), 61);
|
||||
values.mCamera.mFieldOfView.reset();
|
||||
EXPECT_EQ(values.mCamera.mFieldOfView.get(), 60);
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, moveConstructorShouldSanitize)
|
||||
{
|
||||
Values defaultValues;
|
||||
Manager::mUserSettings[std::make_pair("Camera", "field of view")] = "-1";
|
||||
Values values(std::move(defaultValues));
|
||||
EXPECT_EQ(values.mCamera.mFieldOfView.get(), 1);
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, setShouldChangeManagerUserSettings)
|
||||
{
|
||||
Values values;
|
||||
values.mCamera.mFieldOfView.set(42);
|
||||
EXPECT_EQ(Manager::mUserSettings.at({ "Camera", "field of view" }), "42");
|
||||
EXPECT_THAT(Manager::mChangedSettings, ElementsAre(std::make_pair("Camera", "field of view")));
|
||||
}
|
||||
|
||||
TEST_F(SettingsValuesTest, setShouldNotChangeManagerChangedSettingsForNoChange)
|
||||
{
|
||||
Values values;
|
||||
values.mCamera.mFieldOfView.set(values.mCamera.mFieldOfView.get());
|
||||
EXPECT_THAT(Manager::mChangedSettings, ElementsAre());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue