File: Window.test.cpp

package info (click to toggle)
libsfml 3.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 13,704 kB
  • sloc: cpp: 52,754; ansic: 24,944; objc: 668; sh: 172; xml: 25; makefile: 18
file content (178 lines) | stat: -rw-r--r-- 7,822 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <SFML/Window/Window.hpp>

// Other 1st party headers
#include <SFML/Window/VideoMode.hpp>

#include <SFML/System/String.hpp>

#include <catch2/catch_test_macros.hpp>

#include <WindowUtil.hpp>
#include <type_traits>

TEST_CASE("[Window] sf::Window", runDisplayTests())
{
    SECTION("Type traits")
    {
        STATIC_CHECK(std::has_virtual_destructor_v<sf::Window>);
        STATIC_CHECK(!std::is_copy_constructible_v<sf::Window>);
        STATIC_CHECK(!std::is_copy_assignable_v<sf::Window>);
        STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Window>);
        STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Window>);
    }

    SECTION("Construction")
    {
        SECTION("Default constructor")
        {
            const sf::Window window;
            CHECK(!window.isOpen());
            CHECK(window.getPosition() == sf::Vector2i());
            CHECK(window.getSize() == sf::Vector2u());
            CHECK(!window.hasFocus());
            CHECK(window.getNativeHandle() == sf::WindowHandle());
            CHECK(window.getSettings().depthBits == 0);
            CHECK(window.getSettings().stencilBits == 0);
            CHECK(window.getSettings().antiAliasingLevel == 0);
            CHECK(window.getSettings().majorVersion == 1);
            CHECK(window.getSettings().minorVersion == 1);
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
            CHECK(!window.getSettings().sRgbCapable);
        }

        SECTION("Mode and title constructor")
        {
            const sf::Window window(sf::VideoMode({360, 240}), "Window Tests");
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, and style constructor")
        {
            const sf::Window window(sf::VideoMode({360, 240}), "Window Tests", sf::Style::Resize);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, style, and state constructor")
        {
            const sf::Window window(sf::VideoMode({360, 240}), "Window Tests", sf::Style::Resize, sf::State::Windowed);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, style, state, and context settings constructor")
        {
            const sf::Window window(sf::VideoMode({360, 240}),
                                    "Window Tests",
                                    sf::Style::Resize,
                                    sf::State::Windowed,
                                    sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antiAliasingLevel */ 1});
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().depthBits >= 1);
            CHECK(window.getSettings().stencilBits >= 1);
            CHECK(window.getSettings().antiAliasingLevel >= 1);
        }

        SECTION("Mode, title, and state")
        {
            const sf::Window window(sf::VideoMode({360, 240}), "Window Tests", sf::State::Windowed);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, state, and context settings constructor")
        {
            const sf::Window window(sf::VideoMode({360, 240}),
                                    "Window Tests",
                                    sf::State::Windowed,
                                    sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antiAliasingLevel */ 1});
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(360, 240));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().depthBits >= 1);
            CHECK(window.getSettings().stencilBits >= 1);
            CHECK(window.getSettings().antiAliasingLevel >= 1);
        }
    }

    SECTION("create()")
    {
        sf::Window window;

        SECTION("Mode and title")
        {
            window.create(sf::VideoMode({240, 360}), "Window Tests");
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, and style")
        {
            window.create(sf::VideoMode({240, 360}), "Window Tests", sf::Style::Resize);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, style, and state")
        {
            window.create(sf::VideoMode({240, 360}), "Window Tests", sf::Style::Resize, sf::State::Windowed);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, style, state, and context settings")
        {
            window.create(sf::VideoMode({240, 360}),
                          "Window Tests",
                          sf::Style::Resize,
                          sf::State::Windowed,
                          sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antiAliasingLevel */ 1});
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().depthBits >= 1);
            CHECK(window.getSettings().stencilBits >= 1);
            CHECK(window.getSettings().antiAliasingLevel >= 1);
        }

        SECTION("Mode, title, and state")
        {
            window.create(sf::VideoMode({240, 360}), "Window Tests", sf::State::Windowed);
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default);
        }

        SECTION("Mode, title, state, and context settings")
        {
            window.create(sf::VideoMode({240, 360}),
                          "Window Tests",
                          sf::State::Windowed,
                          sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antiAliasingLevel */ 1});
            CHECK(window.isOpen());
            CHECK(window.getSize() == sf::Vector2u(240, 360));
            CHECK(window.getNativeHandle() != sf::WindowHandle());
            CHECK(window.getSettings().depthBits >= 1);
            CHECK(window.getSettings().stencilBits >= 1);
            CHECK(window.getSettings().antiAliasingLevel >= 1);
        }
    }
}