source: mainline/uspace/lib/ui/test/ui.c@ 8965860c

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

Clickmatic

A class that periodically generates when held, after initial delay.
This is quite similar to the typematic feature found in PC keyboards.
We use it to automatically scroll when scrollbar button or through
is held.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2022 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 <pcut/pcut.h>
30#include <ui/ui.h>
31#include "../private/ui.h"
32
33PCUT_INIT;
34
35PCUT_TEST_SUITE(ui);
36
37/** Create and destroy UI with display */
38PCUT_TEST(create_disp_destroy)
39{
40 ui_t *ui = NULL;
41 errno_t rc;
42
43 rc = ui_create_disp(NULL, &ui);
44 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
45 PCUT_ASSERT_NOT_NULL(ui);
46 PCUT_ASSERT_NULL(ui->display);
47
48 ui_destroy(ui);
49}
50
51/** Create and destroy UI with console */
52PCUT_TEST(create_cons_destroy)
53{
54 ui_t *ui = NULL;
55 errno_t rc;
56
57 rc = ui_create_cons(NULL, &ui);
58 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
59 PCUT_ASSERT_NOT_NULL(ui);
60 PCUT_ASSERT_NULL(ui->console);
61
62 ui_destroy(ui);
63}
64
65/** ui_destroy() can take NULL argument (no-op) */
66PCUT_TEST(destroy_null)
67{
68 ui_destroy(NULL);
69}
70
71/** ui_suspend() / ui_resume() do nothing if we don't have a console */
72PCUT_TEST(suspend_resume)
73{
74 ui_t *ui = NULL;
75 errno_t rc;
76
77 rc = ui_create_disp(NULL, &ui);
78 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
79 PCUT_ASSERT_NOT_NULL(ui);
80
81 rc = ui_suspend(ui);
82 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
83 rc = ui_resume(ui);
84 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
85
86 ui_destroy(ui);
87}
88
89/** ui_run() / ui_quit() */
90PCUT_TEST(run_quit)
91{
92 ui_t *ui = NULL;
93 errno_t rc;
94
95 rc = ui_create_disp(NULL, &ui);
96 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
97 PCUT_ASSERT_NOT_NULL(ui);
98
99 /* Set exit flag */
100 ui_quit(ui);
101
102 /* ui_run() should return immediately */
103 ui_run(ui);
104
105 ui_destroy(ui);
106}
107
108/** ui_paint() */
109PCUT_TEST(paint)
110{
111 ui_t *ui = NULL;
112 errno_t rc;
113
114 rc = ui_create_cons(NULL, &ui);
115 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
116 PCUT_ASSERT_NOT_NULL(ui);
117
118 /* In absence of windows ui_paint() should just return EOK */
119 rc = ui_paint(ui);
120 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
121
122 ui_destroy(ui);
123}
124
125/** ui_is_textmode() */
126PCUT_TEST(is_textmode)
127{
128 ui_t *ui = NULL;
129 errno_t rc;
130
131 rc = ui_create_disp((display_t *)(-1), &ui);
132 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
133 PCUT_ASSERT_NOT_NULL(ui);
134
135 PCUT_ASSERT_FALSE(ui_is_textmode(ui));
136
137 ui_destroy(ui);
138
139 rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
140 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
141 PCUT_ASSERT_NOT_NULL(ui);
142
143 PCUT_ASSERT_TRUE(ui_is_textmode(ui));
144
145 ui_destroy(ui);
146}
147
148/** ui_is_fullscreen() */
149PCUT_TEST(is_fullscreen)
150{
151 ui_t *ui = NULL;
152 errno_t rc;
153
154 rc = ui_create_disp((display_t *)(-1), &ui);
155 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
156 PCUT_ASSERT_NOT_NULL(ui);
157
158 PCUT_ASSERT_FALSE(ui_is_fullscreen(ui));
159
160 ui_destroy(ui);
161
162 rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
163 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
164 PCUT_ASSERT_NOT_NULL(ui);
165
166 PCUT_ASSERT_TRUE(ui_is_fullscreen(ui));
167
168 ui_destroy(ui);
169}
170
171/** ui_lock(), ui_unlock() */
172PCUT_TEST(lock_unlock)
173{
174 ui_t *ui = NULL;
175 errno_t rc;
176
177 rc = ui_create_disp((display_t *)(-1), &ui);
178 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
179 PCUT_ASSERT_NOT_NULL(ui);
180
181 ui_lock(ui);
182 ui_unlock(ui);
183
184 ui_destroy(ui);
185}
186
187PCUT_EXPORT(ui);
Note: See TracBrowser for help on using the repository browser.