File: shadermanager.cpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (69 lines) | stat: -rw-r--r-- 2,155 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <components/settings/shadermanager.hpp>
#include <components/testing/util.hpp>

#include <filesystem>
#include <fstream>

#include <gtest/gtest.h>

namespace
{
    using namespace testing;
    using namespace Settings;

    struct ShaderSettingsTest : Test
    {
        template <typename F>
        void withSettingsFile(const std::string& content, F&& f)
        {
            auto path = TestingOpenMW::outputFilePath(
                std::string(UnitTest::GetInstance()->current_test_info()->name()) + ".yaml");

            {
                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";

        withSettingsFile(content, [](const auto& path) {
            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";

        withSettingsFile(content, [](const auto& path) {
            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());
        });
    }
}