2022-05-14 01:58:00 +00:00
|
|
|
#include <components/settings/shadermanager.hpp>
|
|
|
|
|
2022-05-24 20:31:29 +00:00
|
|
|
#include <filesystem>
|
2022-05-14 01:58:00 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2022-05-24 20:31:29 +00:00
|
|
|
#include "../testing_util.hpp"
|
|
|
|
|
2022-05-14 01:58:00 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using namespace testing;
|
|
|
|
using namespace Settings;
|
|
|
|
|
|
|
|
struct ShaderSettingsTest : Test
|
|
|
|
{
|
|
|
|
template <typename F>
|
|
|
|
void withSettingsFile(const std::string& content, F&& f)
|
|
|
|
{
|
2022-06-19 11:28:33 +00:00
|
|
|
auto path = TestingOpenMW::outputFilePath(
|
2022-05-24 20:31:29 +00:00
|
|
|
std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".yaml");
|
2022-05-14 01:58:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream stream;
|
|
|
|
stream.open(path);
|
|
|
|
stream << content;
|
|
|
|
stream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
f(path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ShaderSettingsTest, fail_to_fetch_then_set_and_succeed)
|
|
|
|
{
|
|
|
|
const std::string content =
|
|
|
|
R"YAML(
|
|
|
|
config:
|
|
|
|
shader:
|
|
|
|
vec3_uniform: [1.0, 2.0]
|
|
|
|
)YAML";
|
|
|
|
|
2022-05-21 18:17:36 +00:00
|
|
|
withSettingsFile(content, [](const auto& path) {
|
2022-05-14 01:58:00 +00:00
|
|
|
EXPECT_TRUE(ShaderManager::get().load(path));
|
|
|
|
EXPECT_FALSE(ShaderManager::get().getValue<osg::Vec3f>("shader", "vec3_uniform").has_value());
|
|
|
|
EXPECT_TRUE(ShaderManager::get().setValue<osg::Vec3f>("shader", "vec3_uniform", osg::Vec3f(1, 2, 3)));
|
|
|
|
EXPECT_TRUE(ShaderManager::get().getValue<osg::Vec3f>("shader", "vec3_uniform").has_value());
|
|
|
|
EXPECT_EQ(ShaderManager::get().getValue<osg::Vec3f>("shader", "vec3_uniform").value(), osg::Vec3f(1, 2, 3));
|
|
|
|
EXPECT_TRUE(ShaderManager::get().save());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ShaderSettingsTest, fail_to_load_file_then_fail_to_set_and_get)
|
|
|
|
{
|
|
|
|
const std::string content =
|
|
|
|
R"YAML(
|
|
|
|
config:
|
|
|
|
shader:
|
|
|
|
uniform: 12.0
|
|
|
|
>Defeated by a sideways carrot
|
|
|
|
)YAML";
|
|
|
|
|
2022-05-21 18:17:36 +00:00
|
|
|
withSettingsFile(content, [](const auto& path) {
|
2022-05-14 01:58:00 +00:00
|
|
|
EXPECT_FALSE(ShaderManager::get().load(path));
|
|
|
|
EXPECT_FALSE(ShaderManager::get().setValue("shader", "uniform", 12.0));
|
|
|
|
EXPECT_FALSE(ShaderManager::get().getValue<float>("shader", "uniform").has_value());
|
|
|
|
EXPECT_FALSE(ShaderManager::get().save());
|
|
|
|
});
|
|
|
|
}
|
2022-06-19 11:28:33 +00:00
|
|
|
}
|