-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathself_test.cpp
215 lines (171 loc) · 6.26 KB
/
self_test.cpp
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright © 2018 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alan Griffiths <[email protected]>
*/
#include "data_device.h"
#include "helpers.h"
#include "gtest_helpers.h"
#include "in_process_server.h"
#include "version_specifier.h"
#include <gmock/gmock.h>
#include <memory>
using namespace testing;
using namespace wlcs;
namespace
{
struct SelfTest : StartedInProcessServer
{
Client client1{the_server()};
};
auto static const any_width = 100;
auto static const any_height = 100;
}
TEST_F(SelfTest, when_creating_second_client_nothing_bad_happens)
{
Client client2{the_server()};
}
TEST_F(SelfTest, given_second_client_when_roundtripping_first_client_nothing_bad_happens)
{
Client client2{the_server()};
client1.roundtrip();
}
TEST_F(SelfTest, given_second_client_when_roundtripping_both_clients_nothing_bad_happens)
{
Client client2{the_server()};
for (auto i = 0; i != 10; ++i)
{
client1.roundtrip();
client2.roundtrip();
}
}
TEST_F(SelfTest, when_a_client_creates_a_surface_nothing_bad_happens)
{
Surface const surface1{client1.create_visible_surface(any_width, any_height)};
client1.roundtrip();
}
TEST_F(SelfTest, given_second_client_when_first_creates_a_surface_nothing_bad_happens)
{
Client client2{the_server()};
Surface const surface1{client1.create_visible_surface(any_width, any_height)};
for (auto i = 0; i != 10; ++i)
{
client1.roundtrip();
client2.roundtrip();
}
}
TEST_F(SelfTest, given_second_client_when_both_create_a_surface_nothing_bad_happens)
{
Client client2{the_server()};
Surface const surface1{client1.create_visible_surface(any_width, any_height)};
Surface const surface2{client2.create_visible_surface(any_width, any_height)};
for (auto i = 0; i != 10; ++i)
{
client1.roundtrip();
client2.roundtrip();
}
}
TEST_F(SelfTest, xfail_failure_is_noted)
{
::testing::Test::RecordProperty("wlcs-skip-test", "Reason goes here");
FAIL() << "This message shouldn't be seen";
}
TEST_F(SelfTest, expected_missing_extension_is_xfail)
{
throw wlcs::ExtensionExpectedlyNotSupported("xdg_not_really_an_extension", wlcs::AtLeastVersion{1});
}
TEST_F(SelfTest, acquiring_unsupported_extension_is_xfail)
{
auto const extension_list = the_server().supported_extensions();
if (!extension_list)
{
::testing::Test::RecordProperty("wlcs-skip-test", "Compositor Integration module is too old for expected extension failures");
FAIL() << "Requires unsupported feature from module under test";
}
Client client{the_server()};
wl_interface unsupported_interface = wl_shell_interface;
unsupported_interface.name = "wlcs_non_existent_extension";
client.bind_if_supported(unsupported_interface, AnyVersion);
FAIL() << "We should have (x)failed at acquiring the interface";
}
TEST_F(SelfTest, acquiring_unsupported_extension_version_is_xfail)
{
auto const extension_list = the_server().supported_extensions();
if (!extension_list)
{
::testing::Test::RecordProperty("wlcs-skip-test", "Compositor Integration module is too old for expected extension failures");
FAIL() << "Requires unsupported feature from module under test";
}
Client client{the_server()};
wl_interface interface_with_unsupported_version = wl_shell_interface;
interface_with_unsupported_version.version += 1;
client.bind_if_supported(
interface_with_unsupported_version,
AtLeastVersion{static_cast<uint32_t>(interface_with_unsupported_version.version)});
FAIL() << "We should have (x)failed at acquiring the interface";
}
TEST_F(SelfTest, does_not_acquire_version_newer_than_wlcs_supports)
{
auto const extension_list = the_server().supported_extensions();
if (!extension_list)
{
::testing::Test::RecordProperty("wlcs-skip-test", "Compositor Integration module is too old for expected extension failures");
FAIL() << "Requires unsupported feature from module under test";
}
Client client{the_server()};
auto const proxy_latest = static_cast<wl_seat*>(client.bind_if_supported(wl_seat_interface, AnyVersion));
ASSERT_THAT(wl_seat_get_version(proxy_latest), Gt(1));
wl_interface interface_with_old_version = wl_seat_interface;
interface_with_old_version.version = wl_seat_get_version(proxy_latest) - 1;
auto const proxy_old = static_cast<wl_seat*>(client.bind_if_supported(interface_with_old_version, AnyVersion));
EXPECT_THAT(wl_seat_get_version(proxy_old), Eq(interface_with_old_version.version));
wl_seat_destroy(proxy_latest);
wl_seat_destroy(proxy_old);
}
TEST_F(SelfTest, dispatch_until_times_out_on_failure)
{
Client client{the_server()};
// Ensure that there's some events happening on the Wayland socket
auto dummy = client.create_visible_surface(300, 300);
dummy.attach_buffer(300, 300);
wl_surface_commit(dummy);
try
{
client.dispatch_until([]() { return false; }, std::chrono::seconds{1});
}
catch (wlcs::Timeout const&)
{
return;
}
FAIL() << "Dispatch did not raise a wlcs::Timeout exception";
}
TEST_F(SelfTest, dispatch_until_times_out_at_the_right_time)
{
using namespace std::literals::chrono_literals;
Client client{the_server()};
auto const timeout = 5s;
auto const expected_end = std::chrono::steady_clock::now() + timeout;
try
{
client.dispatch_until([]() { return false; }, timeout);
}
catch (wlcs::Timeout const&)
{
EXPECT_THAT(std::chrono::steady_clock::now(), Gt(expected_end));
EXPECT_THAT(std::chrono::steady_clock::now(), Lt(expected_end + 5s));
return;
}
FAIL() << "Dispatch did not raise a wlcs::Timeout exception";
}