This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsommelier-output-test.cc
259 lines (214 loc) · 7.78 KB
/
sommelier-output-test.cc
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/x11-test-base.h"
namespace vm_tools {
namespace sommelier {
using X11Test = X11TestBase;
TEST_F(X11Test, OutputScaleAndTransformAreApplied) {
// Arrange/Act: Advertise a fake output with no scaling.
AdvertiseOutputs(xwayland.get(),
{{.width_pixels = 1920, .height_pixels = 1080}});
struct sl_host_output* output = nullptr;
// Assert: Dimensions are unchanged.
output = ctx.host_outputs[0];
EXPECT_EQ(output->virt_rotated_width, 1920);
EXPECT_EQ(output->virt_rotated_height, 1080);
// Act: Change the user defined zoom factor to be 150%.
ConfigureOutput(output, {.output_scale = 1500});
// Assert: Dimensions scaled up.
EXPECT_EQ(output->virt_rotated_width, 1280);
EXPECT_EQ(output->virt_rotated_height, 720);
// Act: Change zoom factor to be 80% and rotate.
ConfigureOutput(output,
{.transform = WL_OUTPUT_TRANSFORM_90, .output_scale = 800});
// Assert: Dimensions are scaled down and rotated dimensions are set.
EXPECT_EQ(output->virt_rotated_width, 1350);
EXPECT_EQ(output->virt_rotated_height, 2400);
}
TEST_F(X11DirectScaleTest,
AddingMultipleOutputsPositionsCorrectlyInDirectScale) {
// Act: Advertise two outputs together.
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920,
.y = 0,
.width_pixels = 1920,
.height_pixels = 1080,
.output_scale = 1250},
};
AdvertiseOutputs(xwayland.get(), configs);
struct sl_host_output* output = nullptr;
// Assert: Outputs are positioned correctly in logical space.
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 1920);
EXPECT_EQ(output->virt_x, 1920);
// Advertise another output to the left.
AdvertiseOutputs(xwayland.get(), {{.x = -800,
.y = 1080,
.width_pixels = 1920,
.height_pixels = 1080,
.transform = WL_OUTPUT_TRANSFORM_90}});
// Assert: Outputs are positioned correctly in logical space.
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, -800);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 1080);
output = ctx.host_outputs[2];
EXPECT_EQ(output->x, 1920);
EXPECT_EQ(output->virt_x, 3000);
}
TEST_F(X11Test, AddingMultipleOutputsPositionsCorrectly) {
// Act: Advertise outputs.
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920,
.y = 0,
.width_pixels = 1920,
.height_pixels = 1080,
.output_scale = 1250},
};
AdvertiseOutputs(xwayland.get(), configs);
struct sl_host_output* output = nullptr;
// Assert: Outputs are positioned correctly in logical space.
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 1920);
EXPECT_EQ(output->virt_x, 1920);
// Act
AdvertiseOutputs(xwayland.get(), {{
.x = -800,
.y = 1080,
.width_pixels = 1920,
.height_pixels = 1080,
.transform = WL_OUTPUT_TRANSFORM_90,
.output_scale = 750,
}});
// Assert
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, -800);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 1440);
output = ctx.host_outputs[2];
EXPECT_EQ(output->x, 1920);
EXPECT_EQ(output->virt_x, 3360);
}
TEST_F(X11Test, OutputsPositionedCorrectlyAfterRemovingLeftOutput) {
// Arrange: Add 3 outputs.
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920,
.y = 0,
.width_pixels = 1920,
.height_pixels = 1080,
.transform = WL_OUTPUT_TRANSFORM_90,
.output_scale = 2000},
{.x = 2000, .y = 1080, .width_pixels = 1920, .height_pixels = 1080},
};
AdvertiseOutputs(xwayland.get(), configs);
// Act: remove the leftmost output.
struct sl_host_output* output = nullptr;
output = ctx.host_outputs[0];
RemoveOutput(output);
// Assert: Output is removed and others are shifted left.
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, 1920);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 2000);
EXPECT_EQ(output->virt_x, 540);
// outputs has length 2.
EXPECT_EQ(ctx.host_outputs.size(), 2u);
}
TEST_F(X11Test, OutputsPositionedCorrectlyAfterRemovingMiddleOutput) {
// Arrange: Add 3 outputs.
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920,
.y = 0,
.width_pixels = 1920,
.height_pixels = 1080,
.transform = WL_OUTPUT_TRANSFORM_90,
.output_scale = 2000},
{.x = 2000, .y = 1080, .width_pixels = 1920, .height_pixels = 1080},
};
AdvertiseOutputs(xwayland.get(), configs);
// Act: Remove the middle output;
struct sl_host_output* output = nullptr;
output = ctx.host_outputs[1];
RemoveOutput(output);
// Assert
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 2000);
EXPECT_EQ(output->virt_x, 1920);
// outputs has length 2.
EXPECT_EQ(ctx.host_outputs.size(), 2u);
}
TEST_F(X11Test, OtherOutputUnchangedAfterRemovingRightOutput) {
// Arrange: Add 2 outputs.
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920, .y = 0}};
AdvertiseOutputs(xwayland.get(), configs);
// Act: Remove the rightmost output.
struct sl_host_output* output = nullptr;
output = ctx.host_outputs[1];
RemoveOutput(output);
// Assert
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 0);
// outputs has length 1.
EXPECT_EQ(ctx.host_outputs.size(), 1u);
}
TEST_F(X11Test, RotatingOutputsShiftsNeighbouringOutputs) {
// Arrange
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920},
};
AdvertiseOutputs(xwayland.get(), configs);
struct sl_host_output* output = nullptr;
output = ctx.host_outputs[0];
// Act: Rotate output by 270 degrees.
ConfigureOutput(output, {.transform = WL_OUTPUT_TRANSFORM_270});
// Assert: Output is rotated and next output is shifted left.
EXPECT_EQ(output->virt_x, 0);
EXPECT_EQ(output->virt_rotated_width, 1080);
EXPECT_EQ(output->virt_rotated_height, 1920);
output = ctx.host_outputs[1];
EXPECT_EQ(output->virt_x, 1080);
}
TEST_F(X11Test, MovingOutputsShiftsOutputs) {
// Arrange
std::vector<OutputConfig> configs = {
{.x = 0, .y = 0, .width_pixels = 1920, .height_pixels = 1080},
{.x = 1920, .width_pixels = 1920, .height_pixels = 1080},
};
AdvertiseOutputs(xwayland.get(), configs);
struct sl_host_output* output = nullptr;
output = ctx.host_outputs[1];
// Act: Move output on the right to be on the left of other output.
ConfigureOutput(output, {.x = -1920, .y = 700});
// Assert
output = ctx.host_outputs[0];
EXPECT_EQ(output->x, -1920);
EXPECT_EQ(output->virt_x, 0);
output = ctx.host_outputs[1];
EXPECT_EQ(output->x, 0);
EXPECT_EQ(output->virt_x, 1920);
}
} // namespace sommelier
} // namespace vm_tools