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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3434233 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: 6.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 "../window.h"
38
39PCUT_INIT;
40
41PCUT_TEST_SUITE(client);
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/** Client creation and destruction. */
58PCUT_TEST(client_create_destroy)
59{
60 ds_display_t *disp;
61 ds_client_t *client;
62 errno_t rc;
63
64 rc = ds_display_create(NULL, &disp);
65 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
66
67 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
68 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
69
70 ds_client_destroy(client);
71 ds_display_destroy(disp);
72}
73
74/** Test ds_client_find_window().
75 *
76 * ds_client_add_window() and ds_client_remove_window() are indirectly
77 * tested too as part of creating and destroying the window
78 */
79PCUT_TEST(client_find_window)
80{
81 ds_display_t *disp;
82 ds_client_t *client;
83 ds_window_t *w0;
84 ds_window_t *w1;
85 ds_window_t *wnd;
86 display_wnd_params_t params;
87 errno_t rc;
88
89 rc = ds_display_create(NULL, &disp);
90 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
91
92 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
93 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
94
95 display_wnd_params_init(&params);
96 params.rect.p0.x = params.rect.p0.y = 0;
97 params.rect.p1.x = params.rect.p1.y = 1;
98
99 rc = ds_window_create(client, &params, &w0);
100 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
101
102 rc = ds_window_create(client, &params, &w1);
103 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
104
105 wnd = ds_client_find_window(client, w0->id);
106 PCUT_ASSERT_EQUALS(w0, wnd);
107
108 wnd = ds_client_find_window(client, w1->id);
109 PCUT_ASSERT_EQUALS(w1, wnd);
110
111 wnd = ds_client_find_window(client, 0);
112 PCUT_ASSERT_NULL(wnd);
113
114 wnd = ds_client_find_window(client, w1->id + 1);
115 PCUT_ASSERT_NULL(wnd);
116
117 ds_window_destroy(w0);
118 ds_window_destroy(w1);
119 ds_client_destroy(client);
120 ds_display_destroy(disp);
121}
122
123/** Test ds_client_first_window() / ds_client_next_window. */
124PCUT_TEST(client_first_next_window)
125{
126 ds_display_t *disp;
127 ds_client_t *client;
128 ds_window_t *w0;
129 ds_window_t *w1;
130 ds_window_t *wnd;
131 display_wnd_params_t params;
132 errno_t rc;
133
134 rc = ds_display_create(NULL, &disp);
135 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
136
137 rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
138 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
139
140 display_wnd_params_init(&params);
141 params.rect.p0.x = params.rect.p0.y = 0;
142 params.rect.p1.x = params.rect.p1.y = 1;
143
144 rc = ds_window_create(client, &params, &w0);
145 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
146
147 rc = ds_window_create(client, &params, &w1);
148 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
149
150 wnd = ds_client_first_window(client);
151 PCUT_ASSERT_EQUALS(w0, wnd);
152
153 wnd = ds_client_next_window(w0);
154 PCUT_ASSERT_EQUALS(w1, wnd);
155
156 wnd = ds_client_next_window(w1);
157 PCUT_ASSERT_NULL(wnd);
158
159 ds_window_destroy(w0);
160 ds_window_destroy(w1);
161 ds_client_destroy(client);
162 ds_display_destroy(disp);
163}
164
165/** Test ds_client_get_event(), ds_client_post_kbd_event(). */
166PCUT_TEST(display_get_post_kbd_event)
167{
168 ds_display_t *disp;
169 ds_client_t *client;
170 ds_window_t *wnd;
171 display_wnd_params_t params;
172 kbd_event_t event;
173 ds_window_t *rwindow;
174 display_wnd_ev_t revent;
175 bool called_cb = NULL;
176 errno_t rc;
177
178 rc = ds_display_create(NULL, &disp);
179 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
180
181 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
182 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
183
184 display_wnd_params_init(&params);
185 params.rect.p0.x = params.rect.p0.y = 0;
186 params.rect.p1.x = params.rect.p1.y = 1;
187
188 rc = ds_window_create(client, &params, &wnd);
189 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
190
191 event.type = KEY_PRESS;
192 event.key = KC_ENTER;
193 event.mods = 0;
194 event.c = L'\0';
195
196 PCUT_ASSERT_FALSE(called_cb);
197
198 rc = ds_client_get_event(client, &rwindow, &revent);
199 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
200
201 rc = ds_client_post_kbd_event(client, wnd, &event);
202 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
203 PCUT_ASSERT_TRUE(called_cb);
204
205 rc = ds_client_get_event(client, &rwindow, &revent);
206 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
207 PCUT_ASSERT_EQUALS(wnd, rwindow);
208 PCUT_ASSERT_EQUALS(event.type, revent.kbd_event.type);
209 PCUT_ASSERT_EQUALS(event.key, revent.kbd_event.key);
210 PCUT_ASSERT_EQUALS(event.mods, revent.kbd_event.mods);
211 PCUT_ASSERT_EQUALS(event.c, revent.kbd_event.c);
212
213 rc = ds_client_get_event(client, &rwindow, &revent);
214 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
215
216 ds_window_destroy(wnd);
217 ds_client_destroy(client);
218 ds_display_destroy(disp);
219}
220
221/** Test client being destroyed while still having a window.
222 *
223 * This can happen if client forgets to destroy window or if the client
224 * is disconnected (or terminated).
225 */
226PCUT_TEST(client_leftover_window)
227{
228 ds_display_t *disp;
229 ds_client_t *client;
230 ds_window_t *wnd;
231 display_wnd_params_t params;
232 errno_t rc;
233
234 rc = ds_display_create(NULL, &disp);
235 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
236
237 rc = ds_client_create(disp, NULL, NULL, &client);
238 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
239
240 display_wnd_params_init(&params);
241 params.rect.p0.x = params.rect.p0.y = 0;
242 params.rect.p1.x = params.rect.p1.y = 1;
243
244 rc = ds_window_create(client, &params, &wnd);
245 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
246
247 ds_client_destroy(client);
248 ds_display_destroy(disp);
249}
250
251PCUT_EXPORT(client);
Note: See TracBrowser for help on using the repository browser.