source: mainline/uspace/lib/ui/test/ui.c@ 5823aef3

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

Popping up a message, in text mode as well

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2020 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_run() / ui_quit() */
72PCUT_TEST(run_quit)
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 /* Set exit flag */
82 ui_quit(ui);
83
84 /* ui_run() should return immediately */
85 ui_run(ui);
86
87 ui_destroy(ui);
88}
89
90/** ui_paint() */
91PCUT_TEST(paint)
92{
93 ui_t *ui = NULL;
94 errno_t rc;
95
96 rc = ui_create_cons(NULL, &ui);
97 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
98 PCUT_ASSERT_NOT_NULL(ui);
99
100 /* In absence of windows ui_paint() should just return EOK */
101 rc = ui_paint(ui);
102 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
103
104 ui_destroy(ui);
105}
106
107/** ui_is_textmode() */
108PCUT_TEST(is_textmode)
109{
110 ui_t *ui = NULL;
111 errno_t rc;
112
113 rc = ui_create_disp((display_t *)(-1), &ui);
114 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
115 PCUT_ASSERT_NOT_NULL(ui);
116
117 PCUT_ASSERT_FALSE(ui_is_textmode(ui));
118
119 ui_destroy(ui);
120
121 rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
122 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
123 PCUT_ASSERT_NOT_NULL(ui);
124
125 PCUT_ASSERT_TRUE(ui_is_textmode(ui));
126
127 ui_destroy(ui);
128}
129
130/** ui_is_fullscreen() */
131PCUT_TEST(is_fullscreen)
132{
133 ui_t *ui = NULL;
134 errno_t rc;
135
136 rc = ui_create_disp((display_t *)(-1), &ui);
137 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
138 PCUT_ASSERT_NOT_NULL(ui);
139
140 PCUT_ASSERT_FALSE(ui_is_fullscreen(ui));
141
142 ui_destroy(ui);
143
144 rc = ui_create_cons((console_ctrl_t *)(-1), &ui);
145 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
146 PCUT_ASSERT_NOT_NULL(ui);
147
148 PCUT_ASSERT_TRUE(ui_is_fullscreen(ui));
149
150 ui_destroy(ui);
151}
152
153PCUT_EXPORT(ui);
Note: See TracBrowser for help on using the repository browser.