| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 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 "../idevcfg.h"
|
|---|
| 39 | #include "../seat.h"
|
|---|
| 40 | #include "../window.h"
|
|---|
| 41 |
|
|---|
| 42 | PCUT_INIT;
|
|---|
| 43 |
|
|---|
| 44 | PCUT_TEST_SUITE(window);
|
|---|
| 45 |
|
|---|
| 46 | static errno_t dummy_set_color(void *, gfx_color_t *);
|
|---|
| 47 | static errno_t dummy_fill_rect(void *, gfx_rect_t *);
|
|---|
| 48 |
|
|---|
| 49 | static gfx_context_ops_t dummy_ops = {
|
|---|
| 50 | .set_color = dummy_set_color,
|
|---|
| 51 | .fill_rect = dummy_fill_rect
|
|---|
| 52 | };
|
|---|
| 53 |
|
|---|
| 54 | /** Test creating and destroying window */
|
|---|
| 55 | PCUT_TEST(create_destroy)
|
|---|
| 56 | {
|
|---|
| 57 | ds_display_t *disp;
|
|---|
| 58 | ds_client_t *client;
|
|---|
| 59 | ds_seat_t *seat;
|
|---|
| 60 | ds_window_t *wnd;
|
|---|
| 61 | display_wnd_params_t params;
|
|---|
| 62 | errno_t rc;
|
|---|
| 63 |
|
|---|
| 64 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 65 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 66 |
|
|---|
| 67 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 68 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 69 |
|
|---|
| 70 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 71 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 72 |
|
|---|
| 73 | display_wnd_params_init(¶ms);
|
|---|
| 74 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 75 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 76 |
|
|---|
| 77 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 78 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 79 |
|
|---|
| 80 | ds_window_destroy(wnd);
|
|---|
| 81 | ds_seat_destroy(seat);
|
|---|
| 82 | ds_client_destroy(client);
|
|---|
| 83 | ds_display_destroy(disp);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | /** Test ds_window_bring_to_top() brings window to top */
|
|---|
| 87 | PCUT_TEST(bring_to_top)
|
|---|
| 88 | {
|
|---|
| 89 | ds_display_t *disp;
|
|---|
| 90 | ds_client_t *client;
|
|---|
| 91 | ds_seat_t *seat;
|
|---|
| 92 | ds_window_t *w1;
|
|---|
| 93 | ds_window_t *w2;
|
|---|
| 94 | display_wnd_params_t params;
|
|---|
| 95 | errno_t rc;
|
|---|
| 96 |
|
|---|
| 97 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 98 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 99 |
|
|---|
| 100 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 101 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 102 |
|
|---|
| 103 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 104 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 105 |
|
|---|
| 106 | display_wnd_params_init(¶ms);
|
|---|
| 107 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 108 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 109 |
|
|---|
| 110 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 111 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 112 |
|
|---|
| 113 | rc = ds_window_create(client, ¶ms, &w2);
|
|---|
| 114 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 115 |
|
|---|
| 116 | /* w2 should be on the top */
|
|---|
| 117 | PCUT_ASSERT_EQUALS(w2, ds_display_first_window(disp));
|
|---|
| 118 |
|
|---|
| 119 | /* Bring w1 to top */
|
|---|
| 120 | ds_window_bring_to_top(w1);
|
|---|
| 121 |
|
|---|
| 122 | /* Now w1 should be on the top */
|
|---|
| 123 | PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
|
|---|
| 124 |
|
|---|
| 125 | ds_window_destroy(w1);
|
|---|
| 126 | ds_window_destroy(w2);
|
|---|
| 127 | ds_seat_destroy(seat);
|
|---|
| 128 | ds_client_destroy(client);
|
|---|
| 129 | ds_display_destroy(disp);
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /** Test ds_window_resize(). */
|
|---|
| 133 | PCUT_TEST(window_resize)
|
|---|
| 134 | {
|
|---|
| 135 | ds_display_t *disp;
|
|---|
| 136 | ds_client_t *client;
|
|---|
| 137 | ds_seat_t *seat;
|
|---|
| 138 | ds_window_t *wnd;
|
|---|
| 139 | display_wnd_params_t params;
|
|---|
| 140 | gfx_coord2_t offs;
|
|---|
| 141 | gfx_rect_t nrect;
|
|---|
| 142 | errno_t rc;
|
|---|
| 143 |
|
|---|
| 144 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 145 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 146 |
|
|---|
| 147 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 148 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 149 |
|
|---|
| 150 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 151 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 152 |
|
|---|
| 153 | display_wnd_params_init(¶ms);
|
|---|
| 154 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 155 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 156 |
|
|---|
| 157 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 158 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 159 |
|
|---|
| 160 | wnd->dpos.x = 100;
|
|---|
| 161 | wnd->dpos.y = 100;
|
|---|
| 162 |
|
|---|
| 163 | offs.x = -2;
|
|---|
| 164 | offs.y = -3;
|
|---|
| 165 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 166 | params.rect.p1.x = 12;
|
|---|
| 167 | params.rect.p1.y = 13;
|
|---|
| 168 | rc = ds_window_resize(wnd, &offs, &nrect);
|
|---|
| 169 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 170 |
|
|---|
| 171 | PCUT_ASSERT_INT_EQUALS(98, wnd->dpos.x);
|
|---|
| 172 | PCUT_ASSERT_INT_EQUALS(97, wnd->dpos.y);
|
|---|
| 173 |
|
|---|
| 174 | ds_window_destroy(wnd);
|
|---|
| 175 | ds_seat_destroy(seat);
|
|---|
| 176 | ds_client_destroy(client);
|
|---|
| 177 | ds_display_destroy(disp);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | /** Test ds_window_get_pos(). */
|
|---|
| 181 | PCUT_TEST(get_pos)
|
|---|
| 182 | {
|
|---|
| 183 | ds_display_t *disp;
|
|---|
| 184 | ds_client_t *client;
|
|---|
| 185 | ds_seat_t *seat;
|
|---|
| 186 | ds_window_t *wnd;
|
|---|
| 187 | display_wnd_params_t params;
|
|---|
| 188 | gfx_coord2_t pos;
|
|---|
| 189 | errno_t rc;
|
|---|
| 190 |
|
|---|
| 191 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 192 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 193 |
|
|---|
| 194 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 196 |
|
|---|
| 197 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 198 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 199 |
|
|---|
| 200 | display_wnd_params_init(¶ms);
|
|---|
| 201 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 202 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 203 |
|
|---|
| 204 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 206 |
|
|---|
| 207 | wnd->dpos.x = 100;
|
|---|
| 208 | wnd->dpos.y = 100;
|
|---|
| 209 |
|
|---|
| 210 | ds_window_get_pos(wnd, &pos);
|
|---|
| 211 |
|
|---|
| 212 | PCUT_ASSERT_INT_EQUALS(100, pos.x);
|
|---|
| 213 | PCUT_ASSERT_INT_EQUALS(100, pos.y);
|
|---|
| 214 |
|
|---|
| 215 | ds_window_destroy(wnd);
|
|---|
| 216 | ds_seat_destroy(seat);
|
|---|
| 217 | ds_client_destroy(client);
|
|---|
| 218 | ds_display_destroy(disp);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|
| 221 | /** Test ds_window_get_max_rect(). */
|
|---|
| 222 | PCUT_TEST(get_max_rect)
|
|---|
| 223 | {
|
|---|
| 224 | ds_display_t *disp;
|
|---|
| 225 | ds_client_t *client;
|
|---|
| 226 | ds_seat_t *seat;
|
|---|
| 227 | ds_window_t *wnd;
|
|---|
| 228 | display_wnd_params_t params;
|
|---|
| 229 | gfx_rect_t rect;
|
|---|
| 230 | errno_t rc;
|
|---|
| 231 |
|
|---|
| 232 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 233 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 234 |
|
|---|
| 235 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 236 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 237 |
|
|---|
| 238 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 239 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 240 |
|
|---|
| 241 | display_wnd_params_init(¶ms);
|
|---|
| 242 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 243 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 244 |
|
|---|
| 245 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 246 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 247 |
|
|---|
| 248 | wnd->dpos.x = 100;
|
|---|
| 249 | wnd->dpos.y = 100;
|
|---|
| 250 |
|
|---|
| 251 | ds_window_get_max_rect(wnd, &rect);
|
|---|
| 252 |
|
|---|
| 253 | PCUT_ASSERT_INT_EQUALS(disp->rect.p0.x, rect.p0.x);
|
|---|
| 254 | PCUT_ASSERT_INT_EQUALS(disp->rect.p0.y, rect.p0.y);
|
|---|
| 255 | PCUT_ASSERT_INT_EQUALS(disp->rect.p1.x, rect.p1.x);
|
|---|
| 256 | PCUT_ASSERT_INT_EQUALS(disp->rect.p1.y, rect.p1.y);
|
|---|
| 257 |
|
|---|
| 258 | ds_window_destroy(wnd);
|
|---|
| 259 | ds_seat_destroy(seat);
|
|---|
| 260 | ds_client_destroy(client);
|
|---|
| 261 | ds_display_destroy(disp);
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | /** Test ds_window_minimize(). */
|
|---|
| 265 | PCUT_TEST(window_minimize)
|
|---|
| 266 | {
|
|---|
| 267 | ds_display_t *disp;
|
|---|
| 268 | ds_client_t *client;
|
|---|
| 269 | ds_seat_t *seat;
|
|---|
| 270 | ds_window_t *wnd;
|
|---|
| 271 | display_wnd_params_t params;
|
|---|
| 272 | errno_t rc;
|
|---|
| 273 |
|
|---|
| 274 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 275 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 276 |
|
|---|
| 277 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 278 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 279 |
|
|---|
| 280 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 281 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 282 |
|
|---|
| 283 | display_wnd_params_init(¶ms);
|
|---|
| 284 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 285 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 286 |
|
|---|
| 287 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 288 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 289 |
|
|---|
| 290 | rc = ds_window_minimize(wnd);
|
|---|
| 291 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 292 |
|
|---|
| 293 | PCUT_ASSERT_INT_EQUALS(wndf_minimized, wnd->flags & wndf_minimized);
|
|---|
| 294 |
|
|---|
| 295 | ds_window_destroy(wnd);
|
|---|
| 296 | ds_seat_destroy(seat);
|
|---|
| 297 | ds_client_destroy(client);
|
|---|
| 298 | ds_display_destroy(disp);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | /** Test ds_window_unminimize(). */
|
|---|
| 302 | PCUT_TEST(window_unminimize)
|
|---|
| 303 | {
|
|---|
| 304 | ds_display_t *disp;
|
|---|
| 305 | ds_client_t *client;
|
|---|
| 306 | ds_seat_t *seat;
|
|---|
| 307 | ds_window_t *wnd;
|
|---|
| 308 | display_wnd_params_t params;
|
|---|
| 309 | errno_t rc;
|
|---|
| 310 |
|
|---|
| 311 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 312 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 313 |
|
|---|
| 314 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 315 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 316 |
|
|---|
| 317 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 318 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 319 |
|
|---|
| 320 | display_wnd_params_init(¶ms);
|
|---|
| 321 | params.flags |= wndf_minimized;
|
|---|
| 322 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 323 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 324 |
|
|---|
| 325 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 326 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 327 |
|
|---|
| 328 | rc = ds_window_unminimize(wnd);
|
|---|
| 329 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 330 |
|
|---|
| 331 | PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_minimized);
|
|---|
| 332 |
|
|---|
| 333 | ds_window_destroy(wnd);
|
|---|
| 334 | ds_seat_destroy(seat);
|
|---|
| 335 | ds_client_destroy(client);
|
|---|
| 336 | ds_display_destroy(disp);
|
|---|
| 337 | }
|
|---|
| 338 |
|
|---|
| 339 | /** Test ds_window_maximize(). */
|
|---|
| 340 | PCUT_TEST(window_maximize)
|
|---|
| 341 | {
|
|---|
| 342 | ds_display_t *disp;
|
|---|
| 343 | ds_client_t *client;
|
|---|
| 344 | ds_seat_t *seat;
|
|---|
| 345 | ds_window_t *wnd;
|
|---|
| 346 | display_wnd_params_t params;
|
|---|
| 347 | errno_t rc;
|
|---|
| 348 |
|
|---|
| 349 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 350 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 351 |
|
|---|
| 352 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 353 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 354 |
|
|---|
| 355 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 356 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 357 |
|
|---|
| 358 | display_wnd_params_init(¶ms);
|
|---|
| 359 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 360 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 361 |
|
|---|
| 362 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 363 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 364 |
|
|---|
| 365 | wnd->dpos.x = 100;
|
|---|
| 366 | wnd->dpos.y = 100;
|
|---|
| 367 |
|
|---|
| 368 | rc = ds_window_maximize(wnd);
|
|---|
| 369 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 370 |
|
|---|
| 371 | PCUT_ASSERT_INT_EQUALS(wndf_maximized, wnd->flags & wndf_maximized);
|
|---|
| 372 |
|
|---|
| 373 | ds_window_destroy(wnd);
|
|---|
| 374 | ds_seat_destroy(seat);
|
|---|
| 375 | ds_client_destroy(client);
|
|---|
| 376 | ds_display_destroy(disp);
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /** Test ds_window_unmaximize(). */
|
|---|
| 380 | PCUT_TEST(window_unmaximize)
|
|---|
| 381 | {
|
|---|
| 382 | ds_display_t *disp;
|
|---|
| 383 | ds_client_t *client;
|
|---|
| 384 | ds_seat_t *seat;
|
|---|
| 385 | ds_window_t *wnd;
|
|---|
| 386 | display_wnd_params_t params;
|
|---|
| 387 | errno_t rc;
|
|---|
| 388 |
|
|---|
| 389 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 390 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 391 |
|
|---|
| 392 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 393 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 394 |
|
|---|
| 395 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 396 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 397 |
|
|---|
| 398 | display_wnd_params_init(¶ms);
|
|---|
| 399 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 400 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 401 |
|
|---|
| 402 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 403 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 404 |
|
|---|
| 405 | wnd->dpos.x = 100;
|
|---|
| 406 | wnd->dpos.y = 100;
|
|---|
| 407 |
|
|---|
| 408 | rc = ds_window_maximize(wnd);
|
|---|
| 409 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 410 |
|
|---|
| 411 | rc = ds_window_unmaximize(wnd);
|
|---|
| 412 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 413 |
|
|---|
| 414 | PCUT_ASSERT_INT_EQUALS(0, wnd->flags & wndf_maximized);
|
|---|
| 415 |
|
|---|
| 416 | ds_window_destroy(wnd);
|
|---|
| 417 | ds_seat_destroy(seat);
|
|---|
| 418 | ds_client_destroy(client);
|
|---|
| 419 | ds_display_destroy(disp);
|
|---|
| 420 | }
|
|---|
| 421 |
|
|---|
| 422 | /** Test ds_window_get_ctx(). */
|
|---|
| 423 | PCUT_TEST(window_get_ctx)
|
|---|
| 424 | {
|
|---|
| 425 | ds_display_t *disp;
|
|---|
| 426 | ds_client_t *client;
|
|---|
| 427 | ds_seat_t *seat;
|
|---|
| 428 | ds_window_t *wnd;
|
|---|
| 429 | display_wnd_params_t params;
|
|---|
| 430 | gfx_context_t *gc;
|
|---|
| 431 | errno_t rc;
|
|---|
| 432 |
|
|---|
| 433 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 434 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 435 |
|
|---|
| 436 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 437 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 438 |
|
|---|
| 439 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 440 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 441 |
|
|---|
| 442 | display_wnd_params_init(¶ms);
|
|---|
| 443 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 444 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 445 |
|
|---|
| 446 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 447 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 448 |
|
|---|
| 449 | gc = ds_window_get_ctx(wnd);
|
|---|
| 450 | PCUT_ASSERT_NOT_NULL(gc);
|
|---|
| 451 |
|
|---|
| 452 | ds_window_destroy(wnd);
|
|---|
| 453 | ds_seat_destroy(seat);
|
|---|
| 454 | ds_client_destroy(client);
|
|---|
| 455 | ds_display_destroy(disp);
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | /** Test ds_window_is_visible() */
|
|---|
| 459 | PCUT_TEST(is_visible)
|
|---|
| 460 | {
|
|---|
| 461 | ds_display_t *disp;
|
|---|
| 462 | ds_client_t *client;
|
|---|
| 463 | ds_seat_t *seat;
|
|---|
| 464 | ds_window_t *wnd;
|
|---|
| 465 | display_wnd_params_t params;
|
|---|
| 466 | errno_t rc;
|
|---|
| 467 |
|
|---|
| 468 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 469 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 470 |
|
|---|
| 471 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 472 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 473 |
|
|---|
| 474 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 475 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 476 |
|
|---|
| 477 | display_wnd_params_init(¶ms);
|
|---|
| 478 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 479 | params.rect.p1.x = params.rect.p1.y = 10;
|
|---|
| 480 |
|
|---|
| 481 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 482 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 483 |
|
|---|
| 484 | PCUT_ASSERT_TRUE(ds_window_is_visible(wnd));
|
|---|
| 485 |
|
|---|
| 486 | wnd->flags |= wndf_minimized;
|
|---|
| 487 |
|
|---|
| 488 | PCUT_ASSERT_FALSE(ds_window_is_visible(wnd));
|
|---|
| 489 |
|
|---|
| 490 | ds_window_destroy(wnd);
|
|---|
| 491 | ds_seat_destroy(seat);
|
|---|
| 492 | ds_client_destroy(client);
|
|---|
| 493 | ds_display_destroy(disp);
|
|---|
| 494 | }
|
|---|
| 495 |
|
|---|
| 496 | /** Test ds_window_post_kbd_event() with Alt-F4 sends close event */
|
|---|
| 497 | PCUT_TEST(window_post_kbd_event_alt_f4)
|
|---|
| 498 | {
|
|---|
| 499 | gfx_context_t *gc;
|
|---|
| 500 | ds_display_t *disp;
|
|---|
| 501 | ds_client_t *client;
|
|---|
| 502 | ds_seat_t *seat;
|
|---|
| 503 | ds_window_t *wnd;
|
|---|
| 504 | ds_window_t *rwindow;
|
|---|
| 505 | display_wnd_ev_t revent;
|
|---|
| 506 | display_wnd_params_t params;
|
|---|
| 507 | kbd_event_t event;
|
|---|
| 508 | errno_t rc;
|
|---|
| 509 |
|
|---|
| 510 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 511 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 512 |
|
|---|
| 513 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 514 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 515 |
|
|---|
| 516 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 517 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 518 |
|
|---|
| 519 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 520 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 521 |
|
|---|
| 522 | display_wnd_params_init(¶ms);
|
|---|
| 523 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 524 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 525 |
|
|---|
| 526 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 527 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 528 |
|
|---|
| 529 | /* New window gets focused event */
|
|---|
| 530 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 531 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 532 |
|
|---|
| 533 | event.type = KEY_PRESS;
|
|---|
| 534 | event.mods = KM_ALT;
|
|---|
| 535 | event.key = KC_F4;
|
|---|
| 536 | rc = ds_window_post_kbd_event(wnd, &event);
|
|---|
| 537 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 538 |
|
|---|
| 539 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 540 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 541 | PCUT_ASSERT_EQUALS(wnd, rwindow);
|
|---|
| 542 | PCUT_ASSERT_EQUALS(wev_close, revent.etype);
|
|---|
| 543 |
|
|---|
| 544 | rc = ds_client_get_event(client, &rwindow, &revent);
|
|---|
| 545 | PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
|
|---|
| 546 |
|
|---|
| 547 | ds_window_destroy(wnd);
|
|---|
| 548 | ds_seat_destroy(seat);
|
|---|
| 549 | ds_client_destroy(client);
|
|---|
| 550 | ds_display_destroy(disp);
|
|---|
| 551 | }
|
|---|
| 552 |
|
|---|
| 553 | /** Test ds_window_post_pos_event() */
|
|---|
| 554 | PCUT_TEST(window_post_pos_event)
|
|---|
| 555 | {
|
|---|
| 556 | gfx_context_t *gc;
|
|---|
| 557 | ds_display_t *disp;
|
|---|
| 558 | ds_client_t *client;
|
|---|
| 559 | ds_seat_t *seat;
|
|---|
| 560 | ds_window_t *wnd;
|
|---|
| 561 | display_wnd_params_t params;
|
|---|
| 562 | pos_event_t event;
|
|---|
| 563 | errno_t rc;
|
|---|
| 564 |
|
|---|
| 565 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 566 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 567 |
|
|---|
| 568 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 569 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 570 |
|
|---|
| 571 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 572 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 573 |
|
|---|
| 574 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 575 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 576 |
|
|---|
| 577 | display_wnd_params_init(¶ms);
|
|---|
| 578 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 579 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 580 |
|
|---|
| 581 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 582 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 583 |
|
|---|
| 584 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
|---|
| 585 |
|
|---|
| 586 | wnd->dpos.x = 10;
|
|---|
| 587 | wnd->dpos.y = 10;
|
|---|
| 588 |
|
|---|
| 589 | event.type = POS_PRESS;
|
|---|
| 590 | event.btn_num = 2;
|
|---|
| 591 | event.hpos = 10;
|
|---|
| 592 | event.vpos = 10;
|
|---|
| 593 | rc = ds_window_post_pos_event(wnd, &event);
|
|---|
| 594 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 595 |
|
|---|
| 596 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
|---|
| 597 |
|
|---|
| 598 | event.type = POS_UPDATE;
|
|---|
| 599 | event.hpos = 11;
|
|---|
| 600 | event.vpos = 12;
|
|---|
| 601 | rc = ds_window_post_pos_event(wnd, &event);
|
|---|
| 602 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 603 |
|
|---|
| 604 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
|---|
| 605 | /* Window position does not update until after release */
|
|---|
| 606 | PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.x);
|
|---|
| 607 | PCUT_ASSERT_INT_EQUALS(10, wnd->dpos.y);
|
|---|
| 608 |
|
|---|
| 609 | event.type = POS_RELEASE;
|
|---|
| 610 | event.hpos = 13;
|
|---|
| 611 | event.vpos = 14;
|
|---|
| 612 |
|
|---|
| 613 | rc = ds_window_post_pos_event(wnd, &event);
|
|---|
| 614 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 615 |
|
|---|
| 616 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
|---|
| 617 | PCUT_ASSERT_INT_EQUALS(13, wnd->dpos.x);
|
|---|
| 618 | PCUT_ASSERT_INT_EQUALS(14, wnd->dpos.y);
|
|---|
| 619 |
|
|---|
| 620 | ds_window_destroy(wnd);
|
|---|
| 621 | ds_seat_destroy(seat);
|
|---|
| 622 | ds_client_destroy(client);
|
|---|
| 623 | ds_display_destroy(disp);
|
|---|
| 624 | }
|
|---|
| 625 |
|
|---|
| 626 | /** Test ds_window_post_focus_event() */
|
|---|
| 627 | PCUT_TEST(window_post_focus_event)
|
|---|
| 628 | {
|
|---|
| 629 | gfx_context_t *gc;
|
|---|
| 630 | ds_display_t *disp;
|
|---|
| 631 | ds_client_t *client;
|
|---|
| 632 | ds_seat_t *seat;
|
|---|
| 633 | ds_window_t *wnd;
|
|---|
| 634 | display_wnd_params_t params;
|
|---|
| 635 | errno_t rc;
|
|---|
| 636 |
|
|---|
| 637 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 638 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 639 |
|
|---|
| 640 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 641 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 642 |
|
|---|
| 643 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 644 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 645 |
|
|---|
| 646 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 647 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 648 |
|
|---|
| 649 | display_wnd_params_init(¶ms);
|
|---|
| 650 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 651 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 652 |
|
|---|
| 653 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 654 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 655 |
|
|---|
| 656 | rc = ds_window_post_focus_event(wnd);
|
|---|
| 657 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 658 |
|
|---|
| 659 | ds_window_destroy(wnd);
|
|---|
| 660 | ds_seat_destroy(seat);
|
|---|
| 661 | ds_client_destroy(client);
|
|---|
| 662 | ds_display_destroy(disp);
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | /** Test ds_window_post_unfocus_event() */
|
|---|
| 666 | PCUT_TEST(window_post_unfocus_event)
|
|---|
| 667 | {
|
|---|
| 668 | gfx_context_t *gc;
|
|---|
| 669 | ds_display_t *disp;
|
|---|
| 670 | ds_client_t *client;
|
|---|
| 671 | ds_seat_t *seat;
|
|---|
| 672 | ds_window_t *wnd;
|
|---|
| 673 | display_wnd_params_t params;
|
|---|
| 674 | errno_t rc;
|
|---|
| 675 |
|
|---|
| 676 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 677 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 678 |
|
|---|
| 679 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 680 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 681 |
|
|---|
| 682 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 683 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 684 |
|
|---|
| 685 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 686 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 687 |
|
|---|
| 688 | display_wnd_params_init(¶ms);
|
|---|
| 689 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 690 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 691 |
|
|---|
| 692 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 693 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 694 |
|
|---|
| 695 | rc = ds_window_post_focus_event(wnd);
|
|---|
| 696 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 697 |
|
|---|
| 698 | ds_window_destroy(wnd);
|
|---|
| 699 | ds_seat_destroy(seat);
|
|---|
| 700 | ds_client_destroy(client);
|
|---|
| 701 | ds_display_destroy(disp);
|
|---|
| 702 | }
|
|---|
| 703 |
|
|---|
| 704 | /** Test ds_window_move_req() */
|
|---|
| 705 | PCUT_TEST(window_move_req)
|
|---|
| 706 | {
|
|---|
| 707 | gfx_context_t *gc;
|
|---|
| 708 | ds_display_t *disp;
|
|---|
| 709 | ds_client_t *client;
|
|---|
| 710 | ds_seat_t *seat;
|
|---|
| 711 | ds_window_t *wnd;
|
|---|
| 712 | display_wnd_params_t params;
|
|---|
| 713 | gfx_coord2_t pos;
|
|---|
| 714 | sysarg_t pos_id;
|
|---|
| 715 | errno_t rc;
|
|---|
| 716 |
|
|---|
| 717 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 718 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 719 |
|
|---|
| 720 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 721 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 722 |
|
|---|
| 723 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 724 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 725 |
|
|---|
| 726 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 727 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 728 |
|
|---|
| 729 | display_wnd_params_init(¶ms);
|
|---|
| 730 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 731 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 732 |
|
|---|
| 733 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 734 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 735 |
|
|---|
| 736 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
|---|
| 737 |
|
|---|
| 738 | pos.x = 42;
|
|---|
| 739 | pos.y = 43;
|
|---|
| 740 | pos_id = 44;
|
|---|
| 741 | ds_window_move_req(wnd, &pos, pos_id);
|
|---|
| 742 |
|
|---|
| 743 | PCUT_ASSERT_INT_EQUALS(dsw_moving, wnd->state);
|
|---|
| 744 | PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
|
|---|
| 745 | PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
|
|---|
| 746 | PCUT_ASSERT_INT_EQUALS(pos_id, wnd->orig_pos_id);
|
|---|
| 747 |
|
|---|
| 748 | ds_window_destroy(wnd);
|
|---|
| 749 | ds_seat_destroy(seat);
|
|---|
| 750 | ds_client_destroy(client);
|
|---|
| 751 | ds_display_destroy(disp);
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | /** Test ds_window_resize_req() */
|
|---|
| 755 | PCUT_TEST(window_resize_req)
|
|---|
| 756 | {
|
|---|
| 757 | gfx_context_t *gc;
|
|---|
| 758 | ds_display_t *disp;
|
|---|
| 759 | ds_client_t *client;
|
|---|
| 760 | ds_seat_t *seat;
|
|---|
| 761 | ds_window_t *wnd;
|
|---|
| 762 | display_wnd_params_t params;
|
|---|
| 763 | gfx_coord2_t pos;
|
|---|
| 764 | sysarg_t pos_id;
|
|---|
| 765 | errno_t rc;
|
|---|
| 766 |
|
|---|
| 767 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 768 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 769 |
|
|---|
| 770 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 771 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 772 |
|
|---|
| 773 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 774 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 775 |
|
|---|
| 776 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 777 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 778 |
|
|---|
| 779 | display_wnd_params_init(¶ms);
|
|---|
| 780 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 781 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 782 |
|
|---|
| 783 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 784 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 785 |
|
|---|
| 786 | PCUT_ASSERT_INT_EQUALS(dsw_idle, wnd->state);
|
|---|
| 787 |
|
|---|
| 788 | pos.x = 42;
|
|---|
| 789 | pos.y = 43;
|
|---|
| 790 | pos_id = 44;
|
|---|
| 791 | ds_window_resize_req(wnd, display_wr_top_right, &pos, pos_id);
|
|---|
| 792 |
|
|---|
| 793 | PCUT_ASSERT_INT_EQUALS(dsw_resizing, wnd->state);
|
|---|
| 794 | PCUT_ASSERT_INT_EQUALS(display_wr_top_right, wnd->rsztype);
|
|---|
| 795 | PCUT_ASSERT_INT_EQUALS(pos.x, wnd->orig_pos.x);
|
|---|
| 796 | PCUT_ASSERT_INT_EQUALS(pos.y, wnd->orig_pos.y);
|
|---|
| 797 | PCUT_ASSERT_INT_EQUALS(pos_id, wnd->orig_pos_id);
|
|---|
| 798 |
|
|---|
| 799 | ds_window_destroy(wnd);
|
|---|
| 800 | ds_seat_destroy(seat);
|
|---|
| 801 | ds_client_destroy(client);
|
|---|
| 802 | ds_display_destroy(disp);
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | PCUT_TEST(window_calc_resize)
|
|---|
| 806 | {
|
|---|
| 807 | ds_display_t *disp;
|
|---|
| 808 | ds_client_t *client;
|
|---|
| 809 | ds_seat_t *seat;
|
|---|
| 810 | ds_window_t *wnd;
|
|---|
| 811 | display_wnd_params_t params;
|
|---|
| 812 | gfx_coord2_t dresize;
|
|---|
| 813 | gfx_coord2_t dresizen;
|
|---|
| 814 | gfx_coord2_t dresizeb;
|
|---|
| 815 | gfx_coord2_t dresizebn;
|
|---|
| 816 | gfx_rect_t nrect;
|
|---|
| 817 | errno_t rc;
|
|---|
| 818 |
|
|---|
| 819 | rc = ds_display_create(NULL, df_none, &disp);
|
|---|
| 820 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 821 |
|
|---|
| 822 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 823 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 824 |
|
|---|
| 825 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 826 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 827 |
|
|---|
| 828 | display_wnd_params_init(¶ms);
|
|---|
| 829 | params.rect.p0.x = 10;
|
|---|
| 830 | params.rect.p0.y = 11;
|
|---|
| 831 | params.rect.p1.x = 30;
|
|---|
| 832 | params.rect.p1.y = 31;
|
|---|
| 833 | params.min_size.x = 2;
|
|---|
| 834 | params.min_size.y = 3;
|
|---|
| 835 |
|
|---|
| 836 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 837 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 838 |
|
|---|
| 839 | wnd->state = dsw_resizing;
|
|---|
| 840 |
|
|---|
| 841 | dresize.x = 5;
|
|---|
| 842 | dresize.y = 6;
|
|---|
| 843 |
|
|---|
| 844 | dresizen.x = -5;
|
|---|
| 845 | dresizen.y = -6;
|
|---|
| 846 |
|
|---|
| 847 | dresizeb.x = 50;
|
|---|
| 848 | dresizeb.y = 60;
|
|---|
| 849 |
|
|---|
| 850 | dresizebn.x = -50;
|
|---|
| 851 | dresizebn.y = -60;
|
|---|
| 852 |
|
|---|
| 853 | /* Resize top */
|
|---|
| 854 | wnd->rsztype = display_wr_top;
|
|---|
| 855 |
|
|---|
| 856 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 857 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 858 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
|---|
| 859 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 860 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 861 |
|
|---|
| 862 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 863 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 864 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
|---|
| 865 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 866 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 867 |
|
|---|
| 868 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 869 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 870 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
|---|
| 871 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 872 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 873 |
|
|---|
| 874 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 875 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 876 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
|---|
| 877 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 878 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 879 |
|
|---|
| 880 | /* Resize top left */
|
|---|
| 881 | wnd->rsztype = display_wr_top_left;
|
|---|
| 882 |
|
|---|
| 883 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 884 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
|---|
| 885 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
|---|
| 886 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 887 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 888 |
|
|---|
| 889 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 890 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
|---|
| 891 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
|---|
| 892 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 893 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 894 |
|
|---|
| 895 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 896 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
|---|
| 897 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
|---|
| 898 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 899 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 900 |
|
|---|
| 901 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 902 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
|---|
| 903 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
|---|
| 904 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 905 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 906 |
|
|---|
| 907 | /* Resize left */
|
|---|
| 908 | wnd->rsztype = display_wr_left;
|
|---|
| 909 |
|
|---|
| 910 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 911 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
|---|
| 912 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 913 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 914 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 915 |
|
|---|
| 916 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 917 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
|---|
| 918 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 919 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 920 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 921 |
|
|---|
| 922 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 923 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
|---|
| 924 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 925 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 926 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 927 |
|
|---|
| 928 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 929 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
|---|
| 930 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 931 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 932 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 933 |
|
|---|
| 934 | /* Resize bottom left */
|
|---|
| 935 | wnd->rsztype = display_wr_bottom_left;
|
|---|
| 936 |
|
|---|
| 937 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 938 | PCUT_ASSERT_INT_EQUALS(15, nrect.p0.x);
|
|---|
| 939 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 940 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 941 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
|---|
| 942 |
|
|---|
| 943 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 944 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.x);
|
|---|
| 945 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 946 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 947 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
|---|
| 948 |
|
|---|
| 949 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 950 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.x);
|
|---|
| 951 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 952 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 953 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
|---|
| 954 |
|
|---|
| 955 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 956 | PCUT_ASSERT_INT_EQUALS(-40, nrect.p0.x);
|
|---|
| 957 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 958 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 959 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
|---|
| 960 |
|
|---|
| 961 | /* Resize bottom */
|
|---|
| 962 | wnd->rsztype = display_wr_bottom;
|
|---|
| 963 |
|
|---|
| 964 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 965 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 966 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 967 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 968 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
|---|
| 969 |
|
|---|
| 970 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 971 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 972 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 973 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 974 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
|---|
| 975 |
|
|---|
| 976 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 977 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 978 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 979 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 980 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
|---|
| 981 |
|
|---|
| 982 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 983 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 984 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 985 | PCUT_ASSERT_INT_EQUALS(30, nrect.p1.x);
|
|---|
| 986 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
|---|
| 987 |
|
|---|
| 988 | /* Resize bottom right */
|
|---|
| 989 | wnd->rsztype = display_wr_bottom_right;
|
|---|
| 990 |
|
|---|
| 991 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 992 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 993 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 994 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
|---|
| 995 | PCUT_ASSERT_INT_EQUALS(37, nrect.p1.y);
|
|---|
| 996 |
|
|---|
| 997 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 998 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 999 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1000 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
|---|
| 1001 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.y);
|
|---|
| 1002 |
|
|---|
| 1003 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 1004 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1005 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1006 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
|---|
| 1007 | PCUT_ASSERT_INT_EQUALS(91, nrect.p1.y);
|
|---|
| 1008 |
|
|---|
| 1009 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 1010 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1011 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1012 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
|---|
| 1013 | PCUT_ASSERT_INT_EQUALS(14, nrect.p1.y);
|
|---|
| 1014 |
|
|---|
| 1015 | /* Resize right */
|
|---|
| 1016 | wnd->rsztype = display_wr_right;
|
|---|
| 1017 |
|
|---|
| 1018 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 1019 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1020 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1021 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
|---|
| 1022 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1023 |
|
|---|
| 1024 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 1025 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1026 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1027 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
|---|
| 1028 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1029 |
|
|---|
| 1030 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 1031 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1032 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1033 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
|---|
| 1034 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1035 |
|
|---|
| 1036 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 1037 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1038 | PCUT_ASSERT_INT_EQUALS(11, nrect.p0.y);
|
|---|
| 1039 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
|---|
| 1040 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1041 |
|
|---|
| 1042 | /* Resize top right */
|
|---|
| 1043 | wnd->rsztype = display_wr_top_right;
|
|---|
| 1044 |
|
|---|
| 1045 | ds_window_calc_resize(wnd, &dresize, &nrect);
|
|---|
| 1046 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1047 | PCUT_ASSERT_INT_EQUALS(17, nrect.p0.y);
|
|---|
| 1048 | PCUT_ASSERT_INT_EQUALS(35, nrect.p1.x);
|
|---|
| 1049 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1050 |
|
|---|
| 1051 | ds_window_calc_resize(wnd, &dresizen, &nrect);
|
|---|
| 1052 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1053 | PCUT_ASSERT_INT_EQUALS(5, nrect.p0.y);
|
|---|
| 1054 | PCUT_ASSERT_INT_EQUALS(25, nrect.p1.x);
|
|---|
| 1055 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1056 |
|
|---|
| 1057 | ds_window_calc_resize(wnd, &dresizeb, &nrect);
|
|---|
| 1058 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1059 | PCUT_ASSERT_INT_EQUALS(28, nrect.p0.y);
|
|---|
| 1060 | PCUT_ASSERT_INT_EQUALS(80, nrect.p1.x);
|
|---|
| 1061 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1062 |
|
|---|
| 1063 | ds_window_calc_resize(wnd, &dresizebn, &nrect);
|
|---|
| 1064 | PCUT_ASSERT_INT_EQUALS(10, nrect.p0.x);
|
|---|
| 1065 | PCUT_ASSERT_INT_EQUALS(-49, nrect.p0.y);
|
|---|
| 1066 | PCUT_ASSERT_INT_EQUALS(12, nrect.p1.x);
|
|---|
| 1067 | PCUT_ASSERT_INT_EQUALS(31, nrect.p1.y);
|
|---|
| 1068 |
|
|---|
| 1069 | ds_window_destroy(wnd);
|
|---|
| 1070 | ds_seat_destroy(seat);
|
|---|
| 1071 | ds_client_destroy(client);
|
|---|
| 1072 | ds_display_destroy(disp);
|
|---|
| 1073 | }
|
|---|
| 1074 |
|
|---|
| 1075 | /** Test ds_window_set_cursor() */
|
|---|
| 1076 | PCUT_TEST(window_set_cursor)
|
|---|
| 1077 | {
|
|---|
| 1078 | gfx_context_t *gc;
|
|---|
| 1079 | ds_display_t *disp;
|
|---|
| 1080 | ds_client_t *client;
|
|---|
| 1081 | ds_seat_t *seat;
|
|---|
| 1082 | ds_window_t *wnd;
|
|---|
| 1083 | display_wnd_params_t params;
|
|---|
| 1084 | errno_t rc;
|
|---|
| 1085 |
|
|---|
| 1086 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 1087 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1088 |
|
|---|
| 1089 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 1090 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1091 |
|
|---|
| 1092 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 1093 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1094 |
|
|---|
| 1095 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 1096 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1097 |
|
|---|
| 1098 | display_wnd_params_init(¶ms);
|
|---|
| 1099 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 1100 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 1101 |
|
|---|
| 1102 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 1103 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1104 |
|
|---|
| 1105 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
|---|
| 1106 |
|
|---|
| 1107 | rc = ds_window_set_cursor(wnd, -1);
|
|---|
| 1108 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
|---|
| 1109 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
|---|
| 1110 |
|
|---|
| 1111 | // Check that invalid cursors cannot be set: ignore enum conversions
|
|---|
| 1112 | // as we are out-of-bounds
|
|---|
| 1113 | #pragma GCC diagnostic push
|
|---|
| 1114 | #pragma GCC diagnostic ignored "-Wenum-conversion"
|
|---|
| 1115 | rc = ds_window_set_cursor(wnd, dcurs_limit);
|
|---|
| 1116 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
|---|
| 1117 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
|---|
| 1118 |
|
|---|
| 1119 | rc = ds_window_set_cursor(wnd, dcurs_limit + 1);
|
|---|
| 1120 | PCUT_ASSERT_ERRNO_VAL(EINVAL, rc);
|
|---|
| 1121 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
|---|
| 1122 | #pragma GCC diagnostic pop
|
|---|
| 1123 |
|
|---|
| 1124 | rc = ds_window_set_cursor(wnd, dcurs_size_lr);
|
|---|
| 1125 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1126 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_size_lr], wnd->cursor);
|
|---|
| 1127 |
|
|---|
| 1128 | ds_window_destroy(wnd);
|
|---|
| 1129 | ds_seat_destroy(seat);
|
|---|
| 1130 | ds_client_destroy(client);
|
|---|
| 1131 | ds_display_destroy(disp);
|
|---|
| 1132 | }
|
|---|
| 1133 |
|
|---|
| 1134 | /** Test ds_window_set_caption() */
|
|---|
| 1135 | PCUT_TEST(window_set_caption)
|
|---|
| 1136 | {
|
|---|
| 1137 | gfx_context_t *gc;
|
|---|
| 1138 | ds_display_t *disp;
|
|---|
| 1139 | ds_client_t *client;
|
|---|
| 1140 | ds_seat_t *seat;
|
|---|
| 1141 | ds_window_t *wnd;
|
|---|
| 1142 | display_wnd_params_t params;
|
|---|
| 1143 | errno_t rc;
|
|---|
| 1144 |
|
|---|
| 1145 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 1146 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1147 |
|
|---|
| 1148 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 1149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1150 |
|
|---|
| 1151 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 1152 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1153 |
|
|---|
| 1154 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 1155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1156 |
|
|---|
| 1157 | display_wnd_params_init(¶ms);
|
|---|
| 1158 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 1159 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 1160 |
|
|---|
| 1161 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 1162 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1163 |
|
|---|
| 1164 | PCUT_ASSERT_EQUALS(wnd->display->cursor[dcurs_arrow], wnd->cursor);
|
|---|
| 1165 |
|
|---|
| 1166 | rc = ds_window_set_caption(wnd, "Hello");
|
|---|
| 1167 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1168 | PCUT_ASSERT_INT_EQUALS(0, str_cmp("Hello", wnd->caption));
|
|---|
| 1169 |
|
|---|
| 1170 | ds_window_destroy(wnd);
|
|---|
| 1171 | ds_seat_destroy(seat);
|
|---|
| 1172 | ds_client_destroy(client);
|
|---|
| 1173 | ds_display_destroy(disp);
|
|---|
| 1174 | }
|
|---|
| 1175 |
|
|---|
| 1176 | /** ds_window_find_alt() finds alternate window by flags */
|
|---|
| 1177 | PCUT_TEST(window_find_alt)
|
|---|
| 1178 | {
|
|---|
| 1179 | gfx_context_t *gc;
|
|---|
| 1180 | ds_display_t *disp;
|
|---|
| 1181 | ds_client_t *client;
|
|---|
| 1182 | ds_seat_t *seat;
|
|---|
| 1183 | ds_window_t *w0;
|
|---|
| 1184 | ds_window_t *w1;
|
|---|
| 1185 | ds_window_t *w2;
|
|---|
| 1186 | ds_window_t *wnd;
|
|---|
| 1187 | display_wnd_params_t params;
|
|---|
| 1188 | errno_t rc;
|
|---|
| 1189 |
|
|---|
| 1190 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 1191 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1192 |
|
|---|
| 1193 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 1194 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1195 |
|
|---|
| 1196 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 1197 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1198 |
|
|---|
| 1199 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 1200 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1201 |
|
|---|
| 1202 | display_wnd_params_init(¶ms);
|
|---|
| 1203 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 1204 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 1205 |
|
|---|
| 1206 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 1207 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1208 |
|
|---|
| 1209 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 1210 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1211 | w1->flags |= wndf_minimized;
|
|---|
| 1212 |
|
|---|
| 1213 | rc = ds_window_create(client, ¶ms, &w2);
|
|---|
| 1214 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1215 | w2->flags |= wndf_system;
|
|---|
| 1216 |
|
|---|
| 1217 | wnd = ds_window_find_alt(w0, wndf_minimized);
|
|---|
| 1218 | PCUT_ASSERT_EQUALS(w1, wnd);
|
|---|
| 1219 |
|
|---|
| 1220 | wnd = ds_window_find_alt(w0, wndf_system);
|
|---|
| 1221 | PCUT_ASSERT_EQUALS(w2, wnd);
|
|---|
| 1222 |
|
|---|
| 1223 | wnd = ds_window_find_alt(w0, wndf_maximized);
|
|---|
| 1224 | PCUT_ASSERT_NULL(wnd);
|
|---|
| 1225 |
|
|---|
| 1226 | ds_window_destroy(w0);
|
|---|
| 1227 | ds_window_destroy(w1);
|
|---|
| 1228 | ds_window_destroy(w2);
|
|---|
| 1229 | ds_seat_destroy(seat);
|
|---|
| 1230 | ds_client_destroy(client);
|
|---|
| 1231 | ds_display_destroy(disp);
|
|---|
| 1232 | }
|
|---|
| 1233 |
|
|---|
| 1234 | /** ds_window_unfocus() switches to another window */
|
|---|
| 1235 | PCUT_TEST(window_unfocus)
|
|---|
| 1236 | {
|
|---|
| 1237 | gfx_context_t *gc;
|
|---|
| 1238 | ds_display_t *disp;
|
|---|
| 1239 | ds_client_t *client;
|
|---|
| 1240 | ds_seat_t *seat;
|
|---|
| 1241 | ds_window_t *w0;
|
|---|
| 1242 | ds_window_t *w1;
|
|---|
| 1243 | display_wnd_params_t params;
|
|---|
| 1244 | errno_t rc;
|
|---|
| 1245 |
|
|---|
| 1246 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 1247 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1248 |
|
|---|
| 1249 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 1250 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1251 |
|
|---|
| 1252 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 1253 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1254 |
|
|---|
| 1255 | rc = ds_seat_create(disp, "Alice", &seat);
|
|---|
| 1256 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1257 |
|
|---|
| 1258 | display_wnd_params_init(¶ms);
|
|---|
| 1259 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 1260 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 1261 |
|
|---|
| 1262 | rc = ds_window_create(client, ¶ms, &w1);
|
|---|
| 1263 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1264 |
|
|---|
| 1265 | rc = ds_window_create(client, ¶ms, &w0);
|
|---|
| 1266 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1267 |
|
|---|
| 1268 | PCUT_ASSERT_EQUALS(w0, seat->focus);
|
|---|
| 1269 |
|
|---|
| 1270 | ds_window_unfocus(w0);
|
|---|
| 1271 |
|
|---|
| 1272 | PCUT_ASSERT_EQUALS(w1, seat->focus);
|
|---|
| 1273 |
|
|---|
| 1274 | ds_window_destroy(w0);
|
|---|
| 1275 | ds_window_destroy(w1);
|
|---|
| 1276 | ds_seat_destroy(seat);
|
|---|
| 1277 | ds_client_destroy(client);
|
|---|
| 1278 | ds_display_destroy(disp);
|
|---|
| 1279 | }
|
|---|
| 1280 |
|
|---|
| 1281 | /** ds_window_orig_seat() correctly compares seats */
|
|---|
| 1282 | PCUT_TEST(window_orig_seat)
|
|---|
| 1283 | {
|
|---|
| 1284 | gfx_context_t *gc;
|
|---|
| 1285 | ds_display_t *disp;
|
|---|
| 1286 | ds_client_t *client;
|
|---|
| 1287 | ds_seat_t *seat0;
|
|---|
| 1288 | ds_seat_t *seat1;
|
|---|
| 1289 | sysarg_t devid0;
|
|---|
| 1290 | sysarg_t devid1;
|
|---|
| 1291 | ds_idevcfg_t *cfg0;
|
|---|
| 1292 | ds_idevcfg_t *cfg1;
|
|---|
| 1293 | ds_window_t *wnd;
|
|---|
| 1294 | display_wnd_params_t params;
|
|---|
| 1295 | errno_t rc;
|
|---|
| 1296 |
|
|---|
| 1297 | rc = gfx_context_new(&dummy_ops, NULL, &gc);
|
|---|
| 1298 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1299 |
|
|---|
| 1300 | rc = ds_display_create(gc, df_none, &disp);
|
|---|
| 1301 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1302 |
|
|---|
| 1303 | rc = ds_client_create(disp, NULL, NULL, &client);
|
|---|
| 1304 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1305 |
|
|---|
| 1306 | rc = ds_seat_create(disp, "Alice", &seat0);
|
|---|
| 1307 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1308 |
|
|---|
| 1309 | rc = ds_seat_create(disp, "Bob", &seat1);
|
|---|
| 1310 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1311 |
|
|---|
| 1312 | display_wnd_params_init(¶ms);
|
|---|
| 1313 | params.rect.p0.x = params.rect.p0.y = 0;
|
|---|
| 1314 | params.rect.p1.x = params.rect.p1.y = 1;
|
|---|
| 1315 |
|
|---|
| 1316 | rc = ds_window_create(client, ¶ms, &wnd);
|
|---|
| 1317 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1318 |
|
|---|
| 1319 | devid0 = 42;
|
|---|
| 1320 | devid1 = 43;
|
|---|
| 1321 |
|
|---|
| 1322 | rc = ds_idevcfg_create(disp, devid0, seat0, &cfg0);
|
|---|
| 1323 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1324 |
|
|---|
| 1325 | rc = ds_idevcfg_create(disp, devid1, seat1, &cfg1);
|
|---|
| 1326 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 1327 |
|
|---|
| 1328 | wnd->state = dsw_moving;
|
|---|
| 1329 | wnd->orig_pos_id = devid0;
|
|---|
| 1330 |
|
|---|
| 1331 | PCUT_ASSERT_TRUE(ds_window_orig_seat(wnd, devid0));
|
|---|
| 1332 | PCUT_ASSERT_FALSE(ds_window_orig_seat(wnd, devid1));
|
|---|
| 1333 |
|
|---|
| 1334 | ds_idevcfg_destroy(cfg0);
|
|---|
| 1335 | ds_idevcfg_destroy(cfg1);
|
|---|
| 1336 | ds_window_destroy(wnd);
|
|---|
| 1337 | ds_seat_destroy(seat0);
|
|---|
| 1338 | ds_seat_destroy(seat1);
|
|---|
| 1339 | ds_client_destroy(client);
|
|---|
| 1340 | ds_display_destroy(disp);
|
|---|
| 1341 | }
|
|---|
| 1342 |
|
|---|
| 1343 | static errno_t dummy_set_color(void *arg, gfx_color_t *color)
|
|---|
| 1344 | {
|
|---|
| 1345 | return EOK;
|
|---|
| 1346 | }
|
|---|
| 1347 |
|
|---|
| 1348 | static errno_t dummy_fill_rect(void *arg, gfx_rect_t *rect)
|
|---|
| 1349 | {
|
|---|
| 1350 | return EOK;
|
|---|
| 1351 | }
|
|---|
| 1352 |
|
|---|
| 1353 | PCUT_EXPORT(window);
|
|---|