1 | /*
|
---|
2 | * Copyright (c) 2023 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 |
|
---|
33 | PCUT_INIT;
|
---|
34 |
|
---|
35 | PCUT_TEST_SUITE(ui);
|
---|
36 |
|
---|
37 | /** Create and destroy UI with display */
|
---|
38 | PCUT_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 */
|
---|
52 | PCUT_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) */
|
---|
66 | PCUT_TEST(destroy_null)
|
---|
67 | {
|
---|
68 | ui_destroy(NULL);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** ui_suspend() / ui_resume() do nothing if we don't have a console,
|
---|
72 | * ui_is_suspended() returns suspend status
|
---|
73 | */
|
---|
74 | PCUT_TEST(suspend_resume)
|
---|
75 | {
|
---|
76 | ui_t *ui = NULL;
|
---|
77 | errno_t rc;
|
---|
78 |
|
---|
79 | rc = ui_create_disp(NULL, &ui);
|
---|
80 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
81 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
82 |
|
---|
83 | PCUT_ASSERT_FALSE(ui_is_suspended(ui));
|
---|
84 |
|
---|
85 | rc = ui_suspend(ui);
|
---|
86 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
87 |
|
---|
88 | PCUT_ASSERT_TRUE(ui_is_suspended(ui));
|
---|
89 |
|
---|
90 | rc = ui_resume(ui);
|
---|
91 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
92 |
|
---|
93 | PCUT_ASSERT_FALSE(ui_is_suspended(ui));
|
---|
94 |
|
---|
95 | ui_destroy(ui);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /** ui_run() / ui_quit() */
|
---|
99 | PCUT_TEST(run_quit)
|
---|
100 | {
|
---|
101 | ui_t *ui = NULL;
|
---|
102 | errno_t rc;
|
---|
103 |
|
---|
104 | rc = ui_create_disp(NULL, &ui);
|
---|
105 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
106 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
107 |
|
---|
108 | /* Set exit flag */
|
---|
109 | ui_quit(ui);
|
---|
110 |
|
---|
111 | /* ui_run() should return immediately */
|
---|
112 | ui_run(ui);
|
---|
113 |
|
---|
114 | ui_destroy(ui);
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** ui_paint() */
|
---|
118 | PCUT_TEST(paint)
|
---|
119 | {
|
---|
120 | ui_t *ui = NULL;
|
---|
121 | errno_t rc;
|
---|
122 |
|
---|
123 | rc = ui_create_cons(NULL, &ui);
|
---|
124 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
125 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
126 |
|
---|
127 | /* In absence of windows ui_paint() should just return EOK */
|
---|
128 | rc = ui_paint(ui);
|
---|
129 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
130 |
|
---|
131 | ui_destroy(ui);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** ui_is_textmode() */
|
---|
135 | PCUT_TEST(is_textmode)
|
---|
136 | {
|
---|
137 | ui_t *ui = NULL;
|
---|
138 | errno_t rc;
|
---|
139 |
|
---|
140 | rc = ui_create_disp((display_t *)(-1), &ui);
|
---|
141 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
142 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
143 |
|
---|
144 | PCUT_ASSERT_FALSE(ui_is_textmode(ui));
|
---|
145 |
|
---|
146 | ui_destroy(ui);
|
---|
147 |
|
---|
148 | rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
|
---|
149 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
150 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
151 |
|
---|
152 | PCUT_ASSERT_TRUE(ui_is_textmode(ui));
|
---|
153 |
|
---|
154 | ui_destroy(ui);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /** ui_is_fullscreen() */
|
---|
158 | PCUT_TEST(is_fullscreen)
|
---|
159 | {
|
---|
160 | ui_t *ui = NULL;
|
---|
161 | errno_t rc;
|
---|
162 |
|
---|
163 | rc = ui_create_disp((display_t *)(-1), &ui);
|
---|
164 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
165 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
166 |
|
---|
167 | PCUT_ASSERT_FALSE(ui_is_fullscreen(ui));
|
---|
168 |
|
---|
169 | ui_destroy(ui);
|
---|
170 |
|
---|
171 | rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
|
---|
172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
173 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
174 |
|
---|
175 | PCUT_ASSERT_TRUE(ui_is_fullscreen(ui));
|
---|
176 |
|
---|
177 | ui_destroy(ui);
|
---|
178 | }
|
---|
179 |
|
---|
180 | /** ui_is_get_rect() */
|
---|
181 | PCUT_TEST(get_rect)
|
---|
182 | {
|
---|
183 | ui_t *ui = NULL;
|
---|
184 | gfx_rect_t rect;
|
---|
185 | errno_t rc;
|
---|
186 |
|
---|
187 | rc = ui_create_disp(NULL, &ui);
|
---|
188 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
189 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
190 |
|
---|
191 | /* This won't work without a display service */
|
---|
192 | rc = ui_get_rect(ui, &rect);
|
---|
193 | PCUT_ASSERT_ERRNO_VAL(ENOTSUP, rc);
|
---|
194 |
|
---|
195 | ui_destroy(ui);
|
---|
196 | }
|
---|
197 |
|
---|
198 | /** ui_lock(), ui_unlock() */
|
---|
199 | PCUT_TEST(lock_unlock)
|
---|
200 | {
|
---|
201 | ui_t *ui = NULL;
|
---|
202 | errno_t rc;
|
---|
203 |
|
---|
204 | rc = ui_create_disp((display_t *)(-1), &ui);
|
---|
205 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
206 | PCUT_ASSERT_NOT_NULL(ui);
|
---|
207 |
|
---|
208 | ui_lock(ui);
|
---|
209 | ui_unlock(ui);
|
---|
210 |
|
---|
211 | ui_destroy(ui);
|
---|
212 | }
|
---|
213 |
|
---|
214 | PCUT_EXPORT(ui);
|
---|