source: mainline/uspace/srv/hid/display/test/seat.c@ fb420e48

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fb420e48 was 3434233, checked in by Jiri Svoboda <jiri@…>, 6 years ago

Store dimensions in display server window structure

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2019 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 <pcut/pcut.h>
32#include <stdio.h>
33#include <str.h>
34
35#include "../client.h"
36#include "../display.h"
37#include "../seat.h"
38#include "../window.h"
39
40PCUT_INIT;
41
42PCUT_TEST_SUITE(seat);
43
44static void test_ds_ev_pending(void *);
45
46static ds_client_cb_t test_ds_client_cb = {
47 .ev_pending = test_ds_ev_pending
48};
49
50static void test_ds_ev_pending(void *arg)
51{
52 bool *called_cb = (bool *) arg;
53 printf("test_ds_ev_pending\n");
54 *called_cb = true;
55
56}
57
58/** Set focus. */
59PCUT_TEST(set_focus)
60{
61 ds_display_t *disp;
62 ds_client_t *client;
63 ds_seat_t *seat;
64 ds_window_t *wnd;
65 display_wnd_params_t params;
66 errno_t rc;
67
68 rc = ds_display_create(NULL, &disp);
69 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
70
71 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
72 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
73
74 rc = ds_seat_create(disp, &seat);
75 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
76
77 display_wnd_params_init(&params);
78 params.rect.p0.x = params.rect.p0.y = 0;
79 params.rect.p1.x = params.rect.p1.y = 1;
80
81 rc = ds_window_create(client, &params, &wnd);
82 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
83
84 ds_seat_set_focus(seat, wnd);
85 PCUT_ASSERT_EQUALS(wnd, seat->focus);
86
87 ds_window_destroy(wnd);
88 ds_seat_destroy(seat);
89 ds_client_destroy(client);
90 ds_display_destroy(disp);
91}
92
93/** Evacuate focus. */
94PCUT_TEST(evac_focus)
95{
96 ds_display_t *disp;
97 ds_client_t *client;
98 ds_seat_t *seat;
99 ds_window_t *w0;
100 ds_window_t *w1;
101 display_wnd_params_t params;
102 errno_t rc;
103
104 rc = ds_display_create(NULL, &disp);
105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
106
107 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
108 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
109
110 rc = ds_seat_create(disp, &seat);
111 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
112
113 display_wnd_params_init(&params);
114 params.rect.p0.x = params.rect.p0.y = 0;
115 params.rect.p1.x = params.rect.p1.y = 1;
116
117 rc = ds_window_create(client, &params, &w1);
118 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
119
120 rc = ds_window_create(client, &params, &w0);
121 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
122
123 ds_seat_set_focus(seat, w1);
124 PCUT_ASSERT_EQUALS(w1, seat->focus);
125
126 ds_seat_evac_focus(seat, w1);
127 PCUT_ASSERT_EQUALS(w0, seat->focus);
128
129 ds_window_destroy(w0);
130 ds_window_destroy(w1);
131 ds_seat_destroy(seat);
132 ds_client_destroy(client);
133 ds_display_destroy(disp);
134}
135
136PCUT_EXPORT(seat);
Note: See TracBrowser for help on using the repository browser.