1 | /*
|
---|
2 | * Copyright (c) 2022 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <disp_srv.h>
|
---|
30 | #include <errno.h>
|
---|
31 | #include <gfx/context.h>
|
---|
32 | #include <pcut/pcut.h>
|
---|
33 | #include <stdio.h>
|
---|
34 | #include <str.h>
|
---|
35 |
|
---|
36 | #include "../client.h"
|
---|
37 | #include "../display.h"
|
---|
38 | #include "../seat.h"
|
---|
39 | #include "../window.h"
|
---|
40 |
|
---|
41 | PCUT_INIT;
|
---|
42 |
|
---|
43 | PCUT_TEST_SUITE(window);
|
---|
44 |
|
---|
45 | static errno_t dummy_set_color(void *, gfx_color_t *);
|
---|
46 | static errno_t dummy_fill_rect(void *, gfx_rect_t *);
|
---|
47 |
|
---|
48 | static gfx_context_ops_t dummy_ops = {
|
---|
49 | .set_color = dummy_set_color,
|
---|
50 | .fill_rect = dummy_fill_rect
|
---|
51 | };
|
---|
52 |
|
---|
53 | /** Test creating and destroying window */
|
---|
54 | PCUT_TEST(create_destroy)
|
---|
55 | {
|
---|
56 | ds_display_t *disp;
|
---|
57 | ds_client_t *client;
|
---|
58 | ds_seat_t *seat;
|
---|
59 | ds_window_t *wnd;
|
---|
60 | display_wnd_params_t params;
|
---|
61 | errno_t rc;
|
---|
62 |
|
---|
63 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
64 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
65 |
|
---|
66 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
67 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
68 |
|
---|
69 | rc = ds_seat_create(disp, &seat);
|
---|
70 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
71 |
|
---|
72 | display_wnd_params_init(¶ms);
|
---|
73 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
74 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
75 |
|
---|
76 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
77 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
78 |
|
---|
79 | ds_window_destroy(wnd);
|
---|
80 | ds_seat_destroy(seat);
|
---|
81 | ds_client_destroy(client);
|
---|
82 | ds_display_destroy(disp);
|
---|
83 | }
|
---|
84 |
|
---|
85 | /** Test ds_window_bring_to_top() brings window to top */
|
---|
86 | PCUT_TEST(bring_to_top)
|
---|
87 | {
|
---|
88 | ds_display_t *disp;
|
---|
89 | ds_client_t *client;
|
---|
90 | ds_seat_t *seat;
|
---|
91 | ds_window_t *w1;
|
---|
92 | ds_window_t *w2;
|
---|
93 | display_wnd_params_t params;
|
---|
94 | errno_t rc;
|
---|
95 |
|
---|
96 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
97 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
98 |
|
---|
99 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
100 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
101 |
|
---|
102 | rc = ds_seat_create(disp, &seat);
|
---|
103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
104 |
|
---|
105 | display_wnd_params_init(¶ms);
|
---|
106 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
107 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
108 |
|
---|
109 | rc = ds_window_create(client, ¶ms, &w1);
|
---|
110 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
111 |
|
---|
112 | rc = ds_window_create(client, ¶ms, &w2);
|
---|
113 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
114 |
|
---|
115 | /* w2 should be on the top */
|
---|
116 | PCUT_ASSERT_EQUALS(w2, ds_display_first_window(disp));
|
---|
117 |
|
---|
118 | /* Bring w1 to top */
|
---|
119 | ds_window_bring_to_top(w1);
|
---|
120 |
|
---|
121 | /* Now w1 should be on the top */
|
---|
122 | PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
|
---|
123 |
|
---|
124 | ds_window_destroy(w1);
|
---|
125 | ds_window_destroy(w2);
|
---|
126 | ds_seat_destroy(seat);
|
---|
127 | ds_client_destroy(client);
|
---|
128 | ds_display_destroy(disp);
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Test ds_window_resize(). */
|
---|
132 | PCUT_TEST(window_resize)
|
---|
133 | {
|
---|
134 | ds_display_t *disp;
|
---|
135 | ds_client_t *client;
|
---|
136 | ds_seat_t *seat;
|
---|
137 | ds_window_t *wnd;
|
---|
138 | display_wnd_params_t params;
|
---|
139 | gfx_coord2_t offs;
|
---|
140 | gfx_rect_t nrect;
|
---|
141 | errno_t rc;
|
---|
142 |
|
---|
143 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
144 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
145 |
|
---|
146 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
147 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
148 |
|
---|
149 | rc = ds_seat_create(disp, &seat);
|
---|
150 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
151 |
|
---|
152 | display_wnd_params_init(¶ms);
|
---|
153 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
154 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
155 |
|
---|
156 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
157 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
158 |
|
---|
159 | wnd->dpos.x = 100;
|
---|
160 | wnd->dpos.y = 100;
|
---|
161 |
|
---|
162 | offs.x = -2;
|
---|
163 | offs.y = -3;
|
---|
164 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
165 | params.rect.p1.x = 12;
|
---|
166 | params.rect.p1.y = 13;
|
---|
167 | rc = ds_window_resize(wnd, &offs, &nrect);
|
---|
168 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
169 |
|
---|
170 | PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
|
---|
171 | PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
|
---|
172 |
|
---|
173 | ds_window_destroy(wnd);
|
---|
174 | ds_seat_destroy(seat);
|
---|
175 | ds_client_destroy(client);
|
---|
176 | ds_display_destroy(disp);
|
---|
177 | }
|
---|
178 |
|
---|
179 | /** Test ds_window_get_pos(). */
|
---|
180 | PCUT_TEST(get_pos)
|
---|
181 | {
|
---|
182 | ds_display_t *disp;
|
---|
183 | ds_client_t *client;
|
---|
184 | ds_seat_t *seat;
|
---|
185 | ds_window_t *wnd;
|
---|
186 | display_wnd_params_t params;
|
---|
187 | gfx_coord2_t pos;
|
---|
188 | errno_t rc;
|
---|
189 |
|
---|
190 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
191 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
192 |
|
---|
193 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
194 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
195 |
|
---|
196 | rc = ds_seat_create(disp, &seat);
|
---|
197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
198 |
|
---|
199 | display_wnd_params_init(¶ms);
|
---|
200 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
201 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
202 |
|
---|
203 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
204 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
205 |
|
---|
206 | wnd->dpos.x = 100;
|
---|
207 | wnd->dpos.y = 100;
|
---|
208 |
|
---|
209 | ds_window_get_pos(wnd, &pos);
|
---|
210 |
|
---|
211 | PCUT_ASSERT_INT_EQUALS(100, pos.x);
|
---|
212 | PCUT_ASSERT_INT_EQUALS(100, pos.y);
|
---|
213 |
|
---|
214 | ds_window_destroy(wnd);
|
---|
215 | ds_seat_destroy(seat);
|
---|
216 | ds_client_destroy(client);
|
---|
217 | ds_display_destroy(disp);
|
---|
218 | }
|
---|
219 |
|
---|
220 | /** Test ds_window_get_max_rect(). */
|
---|
221 | PCUT_TEST(get_max_rect)
|
---|
222 | {
|
---|
223 | ds_display_t *disp;
|
---|
224 | ds_client_t *client;
|
---|
225 | ds_seat_t *seat;
|
---|
226 | ds_window_t *wnd;
|
---|
227 | display_wnd_params_t params;
|
---|
228 | gfx_rect_t rect;
|
---|
229 | errno_t rc;
|
---|
230 |
|
---|
231 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
232 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
233 |
|
---|
234 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
235 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
236 |
|
---|
237 | rc = ds_seat_create(disp, &seat);
|
---|
238 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
239 |
|
---|
240 | display_wnd_params_init(¶ms);
|
---|
241 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
242 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
243 |
|
---|
244 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
245 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
246 |
|
---|
247 | wnd->dpos.x = 100;
|
---|
248 | wnd->dpos.y = 100;
|
---|
249 |
|
---|
250 | ds_window_get_max_rect(wnd, &rect);
|
---|
251 |
|
---|
252 | PCUT_ASSERT_INT_EQUALS(disp->rect.p0.x, rect.p0.x);
|
---|
253 | PCUT_ASSERT_INT_EQUALS(disp->rect.p0.y, rect.p0.y);
|
---|
254 | PCUT_ASSERT_INT_EQUALS(disp->rect.p1.x, rect.p1.x);
|
---|
255 | PCUT_ASSERT_INT_EQUALS(disp->rect.p1.y, rect.p1.y);
|
---|
256 |
|
---|
257 | ds_window_destroy(wnd);
|
---|
258 | ds_seat_destroy(seat);
|
---|
259 | ds_client_destroy(client);
|
---|
260 | ds_display_destroy(disp);
|
---|
261 | }
|
---|
262 |
|
---|
263 | /** Test ds_window_maximize(). */
|
---|
264 | PCUT_TEST(window_maximize)
|
---|
265 | {
|
---|
266 | ds_display_t *disp;
|
---|
267 | ds_client_t *client;
|
---|
268 | ds_seat_t *seat;
|
---|
269 | ds_window_t *wnd;
|
---|
270 | display_wnd_params_t params;
|
---|
271 | errno_t rc;
|
---|
272 |
|
---|
273 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
274 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
275 |
|
---|
276 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
277 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
278 |
|
---|
279 | rc = ds_seat_create(disp, &seat);
|
---|
280 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
281 |
|
---|
282 | display_wnd_params_init(¶ms);
|
---|
283 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
284 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
285 |
|
---|
286 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
287 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
288 |
|
---|
289 | wnd->dpos.x = 100;
|
---|
290 | wnd->dpos.y = 100;
|
---|
291 |
|
---|
292 | rc = ds_window_maximize(wnd);
|
---|
293 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
294 |
|
---|
295 | PCUT_ASSERT_INT_EQUALS(wndf_maximized, wnd->flags & wndf_maximized);
|
---|
296 |
|
---|
297 | ds_window_destroy(wnd);
|
---|
298 | ds_seat_destroy(seat);
|
---|
299 | ds_client_destroy(client);
|
---|
300 | ds_display_destroy(disp);
|
---|
301 | }
|
---|
302 |
|
---|
303 | /** Test ds_window_unmaximize(). */
|
---|
304 | PCUT_TEST(window_unmaximize)
|
---|
305 | {
|
---|
306 | ds_display_t *disp;
|
---|
307 | ds_client_t *client;
|
---|
308 | ds_seat_t *seat;
|
---|
309 | ds_window_t *wnd;
|
---|
310 | display_wnd_params_t params;
|
---|
311 | errno_t rc;
|
---|
312 |
|
---|
313 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
314 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
315 |
|
---|
316 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
317 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
318 |
|
---|
319 | rc = ds_seat_create(disp, &seat);
|
---|
320 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
321 |
|
---|
322 | display_wnd_params_init(¶ms);
|
---|
323 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
324 | params.rect.p1.x = params.rect.p1.y = 10;
|
---|
325 |
|
---|
326 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
327 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
328 |
|
---|
329 | wnd->dpos.x = 100;
|
---|
330 | wnd->dpos.y = 100;
|
---|
331 |
|
---|
332 | rc = ds_window_maximize(wnd);
|
---|
333 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
334 |
|
---|
335 | rc = ds_window_unmaximize(wnd);
|
---|
336 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
337 |
|
---|
338 | PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_maximized);
|
---|
339 |
|
---|
340 | ds_window_destroy(wnd);
|
---|
341 | ds_seat_destroy(seat);
|
---|
342 | ds_client_destroy(client);
|
---|
343 | ds_display_destroy(disp);
|
---|
344 | }
|
---|
345 |
|
---|
346 | /** Test ds_window_get_ctx(). */
|
---|
347 | PCUT_TEST(window_get_ctx)
|
---|
348 | {
|
---|
349 | ds_display_t *disp;
|
---|
350 | ds_client_t *client;
|
---|
351 | ds_seat_t *seat;
|
---|
352 | ds_window_t *wnd;
|
---|
353 | display_wnd_params_t params;
|
---|
354 | gfx_context_t *gc;
|
---|
355 | errno_t rc;
|
---|
356 |
|
---|
357 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
358 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
359 |
|
---|
360 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
361 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
362 |
|
---|
363 | rc = ds_seat_create(disp, &seat);
|
---|
364 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
365 |
|
---|
366 | display_wnd_params_init(¶ms);
|
---|
367 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
368 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
369 |
|
---|
370 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
371 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
372 |
|
---|
373 | gc = ds_window_get_ctx(wnd);
|
---|
374 | PCUT_ASSERT_NOT_NULL(gc);
|
---|
375 |
|
---|
376 | ds_window_destroy(wnd);
|
---|
377 | ds_seat_destroy(seat);
|
---|
378 | ds_client_destroy(client);
|
---|
379 | ds_display_destroy(disp);
|
---|
380 | }
|
---|
381 |
|
---|
382 | /** Test ds_window_post_kbd_event() with Alt-F4 sends close event */
|
---|
383 | PCUT_TEST(window_post_kbd_event_alt_f4)
|
---|
384 | {
|
---|
385 | gfx_context_t *gc;
|
---|
386 | ds_display_t *disp;
|
---|
387 | ds_client_t *client;
|
---|
388 | ds_seat_t *seat;
|
---|
389 | ds_window_t *wnd;
|
---|
390 | ds_window_t *rwindow;
|
---|
391 | display_wnd_ev_t revent;
|
---|
392 | display_wnd_params_t params;
|
---|
393 | kbd_event_t event;
|
---|
394 | errno_t rc;
|
---|
395 |
|
---|
396 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
397 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
398 |
|
---|
399 | rc = ds_display_create(gc, df_none, &disp);
|
---|
400 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
401 |
|
---|
402 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
403 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
404 |
|
---|
405 | rc = ds_seat_create(disp, &seat);
|
---|
406 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
407 |
|
---|
408 | display_wnd_params_init(¶ms);
|
---|
409 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
410 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
411 |
|
---|
412 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
413 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
414 |
|
---|
415 | /* New window gets focused event */
|
---|
416 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
417 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
418 |
|
---|
419 | event.type = KEY_PRESS;
|
---|
420 | event.mods = KM_ALT;
|
---|
421 | event.key = KC_F4;
|
---|
422 | rc = ds_window_post_kbd_event(wnd, &event);
|
---|
423 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
424 |
|
---|
425 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
426 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
427 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
---|
428 | PCUT_ASSERT_EQUALS(wev_close, revent.etype);
|
---|
429 |
|
---|
430 | rc = ds_client_get_event(client, &rwindow, &revent);
|
---|
431 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
---|
432 |
|
---|
433 | ds_window_destroy(wnd);
|
---|
434 | ds_seat_destroy(seat);
|
---|
435 | ds_client_destroy(client);
|
---|
436 | ds_display_destroy(disp);
|
---|
437 | }
|
---|
438 |
|
---|
439 | /** Test ds_window_post_pos_event() */
|
---|
440 | PCUT_TEST(window_post_pos_event)
|
---|
441 | {
|
---|
442 | gfx_context_t *gc;
|
---|
443 | ds_display_t *disp;
|
---|
444 | ds_client_t *client;
|
---|
445 | ds_seat_t *seat;
|
---|
446 | ds_window_t *wnd;
|
---|
447 | display_wnd_params_t params;
|
---|
448 | pos_event_t event;
|
---|
449 | errno_t rc;
|
---|
450 |
|
---|
451 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
452 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
453 |
|
---|
454 | rc = ds_display_create(gc, df_none, &disp);
|
---|
455 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
456 |
|
---|
457 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
458 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
459 |
|
---|
460 | rc = ds_seat_create(disp, &seat);
|
---|
461 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
462 |
|
---|
463 | display_wnd_params_init(¶ms);
|
---|
464 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
465 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
466 |
|
---|
467 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
468 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
469 |
|
---|
470 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
---|
471 |
|
---|
472 | wnd->dpos.x = 10;
|
---|
473 | wnd->dpos.y = 10;
|
---|
474 |
|
---|
475 | event.type = POS_PRESS;
|
---|
476 | event.btn_num = 2;
|
---|
477 | event.hpos = 10;
|
---|
478 | event.vpos = 10;
|
---|
479 | rc = ds_window_post_pos_event(wnd, &event);
|
---|
480 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
481 |
|
---|
482 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
---|
483 |
|
---|
484 | event.type = POS_UPDATE;
|
---|
485 | event.hpos = 11;
|
---|
486 | event.vpos = 12;
|
---|
487 | rc = ds_window_post_pos_event(wnd, &event);
|
---|
488 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
489 |
|
---|
490 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
---|
491 | /* Window position does not update until after release */
|
---|
492 | PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.x);
|
---|
493 | PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.y);
|
---|
494 |
|
---|
495 | event.type = POS_RELEASE;
|
---|
496 | event.hpos = 13;
|
---|
497 | event.vpos = 14;
|
---|
498 |
|
---|
499 | rc = ds_window_post_pos_event(wnd, &event);
|
---|
500 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
501 |
|
---|
502 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
---|
503 | PCUT_ASSERT_INT_EQUALS(13, wnd->dpos.x);
|
---|
504 | PCUT_ASSERT_INT_EQUALS(14, wnd->dpos.y);
|
---|
505 |
|
---|
506 | ds_window_destroy(wnd);
|
---|
507 | ds_seat_destroy(seat);
|
---|
508 | ds_client_destroy(client);
|
---|
509 | ds_display_destroy(disp);
|
---|
510 | }
|
---|
511 |
|
---|
512 | /** Test ds_window_move_req() */
|
---|
513 | PCUT_TEST(window_move_req)
|
---|
514 | {
|
---|
515 | gfx_context_t *gc;
|
---|
516 | ds_display_t *disp;
|
---|
517 | ds_client_t *client;
|
---|
518 | ds_seat_t *seat;
|
---|
519 | ds_window_t *wnd;
|
---|
520 | display_wnd_params_t params;
|
---|
521 | gfx_coord2_t pos;
|
---|
522 | errno_t rc;
|
---|
523 |
|
---|
524 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
525 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
526 |
|
---|
527 | rc = ds_display_create(gc, df_none, &disp);
|
---|
528 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
529 |
|
---|
530 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
531 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
532 |
|
---|
533 | rc = ds_seat_create(disp, &seat);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | display_wnd_params_init(¶ms);
|
---|
537 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
538 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
539 |
|
---|
540 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
541 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
542 |
|
---|
543 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
---|
544 |
|
---|
545 | pos.x = 42;
|
---|
546 | pos.y = 43;
|
---|
547 | ds_window_move_req(wnd, &pos);
|
---|
548 |
|
---|
549 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
---|
550 | PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
|
---|
551 | PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
|
---|
552 |
|
---|
553 | ds_window_destroy(wnd);
|
---|
554 | ds_seat_destroy(seat);
|
---|
555 | ds_client_destroy(client);
|
---|
556 | ds_display_destroy(disp);
|
---|
557 | }
|
---|
558 |
|
---|
559 | /** Test ds_window_resize_req() */
|
---|
560 | PCUT_TEST(window_resize_req)
|
---|
561 | {
|
---|
562 | gfx_context_t *gc;
|
---|
563 | ds_display_t *disp;
|
---|
564 | ds_client_t *client;
|
---|
565 | ds_seat_t *seat;
|
---|
566 | ds_window_t *wnd;
|
---|
567 | display_wnd_params_t params;
|
---|
568 | gfx_coord2_t pos;
|
---|
569 | errno_t rc;
|
---|
570 |
|
---|
571 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
573 |
|
---|
574 | rc = ds_display_create(gc, df_none, &disp);
|
---|
575 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
576 |
|
---|
577 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
578 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
579 |
|
---|
580 | rc = ds_seat_create(disp, &seat);
|
---|
581 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
582 |
|
---|
583 | display_wnd_params_init(¶ms);
|
---|
584 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
585 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
586 |
|
---|
587 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
588 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
589 |
|
---|
590 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
---|
591 |
|
---|
592 | pos.x = 42;
|
---|
593 | pos.y = 43;
|
---|
594 | ds_window_resize_req(wnd, display_wr_top_right, &pos);
|
---|
595 |
|
---|
596 | PCUT_ASSERT_INT_EQUALS(dsw_resizing, wnd->state);
|
---|
597 | PCUT_ASSERT_INT_EQUALS(display_wr_top_right, wnd->rsztype);
|
---|
598 | PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
|
---|
599 | PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
|
---|
600 |
|
---|
601 | ds_window_destroy(wnd);
|
---|
602 | ds_seat_destroy(seat);
|
---|
603 | ds_client_destroy(client);
|
---|
604 | ds_display_destroy(disp);
|
---|
605 | }
|
---|
606 |
|
---|
607 | PCUT_TEST(window_calc_resize)
|
---|
608 | {
|
---|
609 | ds_display_t *disp;
|
---|
610 | ds_client_t *client;
|
---|
611 | ds_seat_t *seat;
|
---|
612 | ds_window_t *wnd;
|
---|
613 | display_wnd_params_t params;
|
---|
614 | gfx_coord2_t dresize;
|
---|
615 | gfx_coord2_t dresizen;
|
---|
616 | gfx_coord2_t dresizeb;
|
---|
617 | gfx_coord2_t dresizebn;
|
---|
618 | gfx_rect_t nrect;
|
---|
619 | errno_t rc;
|
---|
620 |
|
---|
621 | rc = ds_display_create(NULL, df_none, &disp);
|
---|
622 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
623 |
|
---|
624 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
625 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
626 |
|
---|
627 | rc = ds_seat_create(disp, &seat);
|
---|
628 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
629 |
|
---|
630 | display_wnd_params_init(¶ms);
|
---|
631 | params.rect.p0.x = 10;
|
---|
632 | params.rect.p0.y = 11;
|
---|
633 | params.rect.p1.x = 30;
|
---|
634 | params.rect.p1.y = 31;
|
---|
635 | params.min_size.x = 2;
|
---|
636 | params.min_size.y = 3;
|
---|
637 |
|
---|
638 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
639 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
640 |
|
---|
641 | wnd->state = dsw_resizing;
|
---|
642 |
|
---|
643 | dresize.x = 5;
|
---|
644 | dresize.y = 6;
|
---|
645 |
|
---|
646 | dresizen.x = -5;
|
---|
647 | dresizen.y = -6;
|
---|
648 |
|
---|
649 | dresizeb.x = 50;
|
---|
650 | dresizeb.y = 60;
|
---|
651 |
|
---|
652 | dresizebn.x = -50;
|
---|
653 | dresizebn.y = -60;
|
---|
654 |
|
---|
655 | /* Resize top */
|
---|
656 | wnd->rsztype = display_wr_top;
|
---|
657 |
|
---|
658 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
659 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
660 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
---|
661 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
662 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
663 |
|
---|
664 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
665 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
666 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
---|
667 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
668 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
669 |
|
---|
670 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
671 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
672 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
---|
673 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
674 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
675 |
|
---|
676 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
677 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
678 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
---|
679 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
680 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
681 |
|
---|
682 | /* Resize top left */
|
---|
683 | wnd->rsztype = display_wr_top_left;
|
---|
684 |
|
---|
685 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
686 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
---|
687 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
---|
688 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
689 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
690 |
|
---|
691 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
692 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
---|
693 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
---|
694 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
695 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
696 |
|
---|
697 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
698 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
---|
699 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
---|
700 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
701 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
702 |
|
---|
703 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
704 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
---|
705 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
---|
706 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
707 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
708 |
|
---|
709 | /* Resize left */
|
---|
710 | wnd->rsztype = display_wr_left;
|
---|
711 |
|
---|
712 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
713 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
---|
714 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
715 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
716 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
717 |
|
---|
718 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
719 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
---|
720 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
721 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
722 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
723 |
|
---|
724 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
725 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
---|
726 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
727 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
728 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
729 |
|
---|
730 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
731 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
---|
732 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
733 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
734 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
735 |
|
---|
736 | /* Resize bottom left */
|
---|
737 | wnd->rsztype = display_wr_bottom_left;
|
---|
738 |
|
---|
739 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
740 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
---|
741 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
742 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
743 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
---|
744 |
|
---|
745 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
746 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
---|
747 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
748 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
749 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
---|
750 |
|
---|
751 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
752 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
---|
753 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
754 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
755 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
---|
756 |
|
---|
757 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
758 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
---|
759 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
760 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
761 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
---|
762 |
|
---|
763 | /* Resize bottom */
|
---|
764 | wnd->rsztype = display_wr_bottom;
|
---|
765 |
|
---|
766 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
767 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
768 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
769 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
770 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
---|
771 |
|
---|
772 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
773 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
774 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
775 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
776 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
---|
777 |
|
---|
778 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
779 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
780 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
781 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
782 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
---|
783 |
|
---|
784 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
785 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
786 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
787 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
---|
788 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
---|
789 |
|
---|
790 | /* Resize bottom right */
|
---|
791 | wnd->rsztype = display_wr_bottom_right;
|
---|
792 |
|
---|
793 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
794 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
795 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
796 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
---|
797 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
---|
798 |
|
---|
799 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
800 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
801 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
802 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
---|
803 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
---|
804 |
|
---|
805 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
806 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
807 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
808 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
---|
809 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
---|
810 |
|
---|
811 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
812 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
813 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
814 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
---|
815 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
---|
816 |
|
---|
817 | /* Resize right */
|
---|
818 | wnd->rsztype = display_wr_right;
|
---|
819 |
|
---|
820 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
821 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
822 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
823 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
---|
824 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
825 |
|
---|
826 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
827 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
828 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
829 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
---|
830 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
831 |
|
---|
832 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
833 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
834 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
835 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
---|
836 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
837 |
|
---|
838 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
839 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
840 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
---|
841 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
---|
842 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
843 |
|
---|
844 | /* Resize top right */
|
---|
845 | wnd->rsztype = display_wr_top_right;
|
---|
846 |
|
---|
847 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
---|
848 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
849 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
---|
850 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
---|
851 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
852 |
|
---|
853 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
---|
854 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
855 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
---|
856 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
---|
857 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
858 |
|
---|
859 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
---|
860 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
861 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
---|
862 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
---|
863 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
864 |
|
---|
865 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
---|
866 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
---|
867 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
---|
868 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
---|
869 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
---|
870 |
|
---|
871 | ds_window_destroy(wnd);
|
---|
872 | ds_seat_destroy(seat);
|
---|
873 | ds_client_destroy(client);
|
---|
874 | ds_display_destroy(disp);
|
---|
875 | }
|
---|
876 |
|
---|
877 | /** Test ds_window_set_cursor() */
|
---|
878 | PCUT_TEST(window_set_cursor)
|
---|
879 | {
|
---|
880 | gfx_context_t *gc;
|
---|
881 | ds_display_t *disp;
|
---|
882 | ds_client_t *client;
|
---|
883 | ds_seat_t *seat;
|
---|
884 | ds_window_t *wnd;
|
---|
885 | display_wnd_params_t params;
|
---|
886 | errno_t rc;
|
---|
887 |
|
---|
888 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
889 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
890 |
|
---|
891 | rc = ds_display_create(gc, df_none, &disp);
|
---|
892 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
893 |
|
---|
894 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
895 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
896 |
|
---|
897 | rc = ds_seat_create(disp, &seat);
|
---|
898 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
899 |
|
---|
900 | display_wnd_params_init(¶ms);
|
---|
901 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
902 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
903 |
|
---|
904 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
905 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
906 |
|
---|
907 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
---|
908 |
|
---|
909 | rc = ds_window_set_cursor(wnd, -1);
|
---|
910 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
911 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
---|
912 |
|
---|
913 | rc = ds_window_set_cursor(wnd, dcurs_limit);
|
---|
914 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
915 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
---|
916 |
|
---|
917 | rc = ds_window_set_cursor(wnd, dcurs_limit + 1);
|
---|
918 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
---|
919 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
---|
920 |
|
---|
921 | rc = ds_window_set_cursor(wnd, dcurs_size_lr);
|
---|
922 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
923 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_size_lr], wnd->cursor);
|
---|
924 |
|
---|
925 | ds_window_destroy(wnd);
|
---|
926 | ds_seat_destroy(seat);
|
---|
927 | ds_client_destroy(client);
|
---|
928 | ds_display_destroy(disp);
|
---|
929 | }
|
---|
930 |
|
---|
931 | /** Test ds_window_set_caption() */
|
---|
932 | PCUT_TEST(window_set_caption)
|
---|
933 | {
|
---|
934 | gfx_context_t *gc;
|
---|
935 | ds_display_t *disp;
|
---|
936 | ds_client_t *client;
|
---|
937 | ds_seat_t *seat;
|
---|
938 | ds_window_t *wnd;
|
---|
939 | display_wnd_params_t params;
|
---|
940 | errno_t rc;
|
---|
941 |
|
---|
942 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
---|
943 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
944 |
|
---|
945 | rc = ds_display_create(gc, df_none, &disp);
|
---|
946 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
947 |
|
---|
948 | rc = ds_client_create(disp, NULL, NULL, &client);
|
---|
949 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
950 |
|
---|
951 | rc = ds_seat_create(disp, &seat);
|
---|
952 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
953 |
|
---|
954 | display_wnd_params_init(¶ms);
|
---|
955 | params.rect.p0.x = params.rect.p0.y = 0;
|
---|
956 | params.rect.p1.x = params.rect.p1.y = 1;
|
---|
957 |
|
---|
958 | rc = ds_window_create(client, ¶ms, &wnd);
|
---|
959 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
960 |
|
---|
961 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
---|
962 |
|
---|
963 | rc = ds_window_set_caption(wnd, "Hello");
|
---|
964 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
965 | PCUT_ASSERT_INT_EQUALS(0, str_cmp("Hello", wnd->caption));
|
---|
966 |
|
---|
967 | ds_window_destroy(wnd);
|
---|
968 | ds_seat_destroy(seat);
|
---|
969 | ds_client_destroy(client);
|
---|
970 | ds_display_destroy(disp);
|
---|
971 | }
|
---|
972 |
|
---|
973 | static errno_t dummy_set_color(void *arg, gfx_color_t *color)
|
---|
974 | {
|
---|
975 | return EOK;
|
---|
976 | }
|
---|
977 |
|
---|
978 | static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
979 | {
|
---|
980 | return EOK;
|
---|
981 | }
|
---|
982 |
|
---|
983 | PCUT_EXPORT(window);
|
---|