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

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

ds_window_delete should be ds_window_destroy

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