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

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

Introduce window focus, housed in a seat object

  • Property mode set to 100644
File size: 4.8 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 <errno.h>
30#include <pcut/pcut.h>
31#include <stdio.h>
32#include <str.h>
33
34#include "../client.h"
35#include "../display.h"
36#include "../seat.h"
37#include "../window.h"
38
39PCUT_INIT;
40
41PCUT_TEST_SUITE(display);
42
43static void test_ds_ev_pending(void *);
44
45static ds_client_cb_t test_ds_client_cb = {
46 .ev_pending = test_ds_ev_pending
47};
48
49static void test_ds_ev_pending(void *arg)
50{
51 bool *called_cb = (bool *) arg;
52 printf("test_ds_ev_pending\n");
53 *called_cb = true;
54
55}
56
57/** Display creation and destruction. */
58PCUT_TEST(display_create_destroy)
59{
60 ds_display_t *disp;
61 errno_t rc;
62
63 rc = ds_display_create(NULL, &disp);
64 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
65
66 ds_display_destroy(disp);
67}
68
69/** Basic client operation. */
70PCUT_TEST(display_client)
71{
72 ds_display_t *disp;
73 ds_client_t *client;
74 ds_client_t *c0, *c1;
75 errno_t rc;
76
77 rc = ds_display_create(NULL, &disp);
78 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
79
80 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
81 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
82
83 c0 = ds_display_first_client(disp);
84 PCUT_ASSERT_EQUALS(c0, client);
85
86 c1 = ds_display_next_client(c0);
87 PCUT_ASSERT_NULL(c1);
88
89 ds_client_destroy(client);
90 ds_display_destroy(disp);
91}
92
93/** Test ds_display_find_window(). */
94PCUT_TEST(display_find_window)
95{
96 ds_display_t *disp;
97 ds_client_t *client;
98 ds_window_t *w0;
99 ds_window_t *w1;
100 ds_window_t *wnd;
101 errno_t rc;
102
103 rc = ds_display_create(NULL, &disp);
104 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
105
106 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
107 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
108
109 rc = ds_window_create(client, &w0);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111
112 rc = ds_window_create(client, &w1);
113 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
114
115 wnd = ds_display_find_window(disp, w0->id);
116 PCUT_ASSERT_EQUALS(w0, wnd);
117
118 wnd = ds_display_find_window(disp, w1->id);
119 PCUT_ASSERT_EQUALS(w1, wnd);
120
121 wnd = ds_display_find_window(disp, 0);
122 PCUT_ASSERT_NULL(wnd);
123
124 wnd = ds_display_find_window(disp, w1->id + 1);
125 PCUT_ASSERT_NULL(wnd);
126
127 ds_window_destroy(w0);
128 ds_window_destroy(w1);
129 ds_client_destroy(client);
130 ds_display_destroy(disp);
131}
132
133/** Basic seat operation. */
134PCUT_TEST(display_seat)
135{
136 ds_display_t *disp;
137 ds_seat_t *seat;
138 ds_seat_t *s0, *s1;
139 errno_t rc;
140
141 rc = ds_display_create(NULL, &disp);
142 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
143
144 rc = ds_seat_create(disp, &seat);
145 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
146
147 s0 = ds_display_first_seat(disp);
148 PCUT_ASSERT_EQUALS(s0, seat);
149
150 s1 = ds_display_next_seat(s0);
151 PCUT_ASSERT_NULL(s1);
152
153 ds_seat_destroy(seat);
154 ds_display_destroy(disp);
155}
156
157/** Test ds_display_post_kbd_event(). */
158PCUT_TEST(display_post_kbd_event)
159{
160 ds_display_t *disp;
161 ds_seat_t *seat;
162 ds_client_t *client;
163 ds_window_t *wnd;
164 kbd_event_t event;
165 bool called_cb = NULL;
166 errno_t rc;
167
168 rc = ds_display_create(NULL, &disp);
169 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
170
171 rc = ds_seat_create(disp, &seat);
172 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
173
174 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
175 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
176
177 rc = ds_window_create(client, &wnd);
178 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
179
180 event.type = KEY_PRESS;
181 event.key = KC_ENTER;
182 event.mods = 0;
183 event.c = L'\0';
184
185 PCUT_ASSERT_FALSE(called_cb);
186
187 rc = ds_display_post_kbd_event(disp, &event);
188 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
189 PCUT_ASSERT_TRUE(called_cb);
190
191 ds_window_destroy(wnd);
192 ds_client_destroy(client);
193 ds_seat_destroy(seat);
194 ds_display_destroy(disp);
195}
196
197PCUT_EXPORT(display);
Note: See TracBrowser for help on using the repository browser.