[f7a90df] | 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 |
|
---|
| 33 | PCUT_INIT;
|
---|
| 34 |
|
---|
| 35 | PCUT_TEST_SUITE(ui);
|
---|
| 36 |
|
---|
[252d03c] | 37 | /** Create and destroy UI with display */
|
---|
| 38 | PCUT_TEST(create_disp_destroy)
|
---|
[f7a90df] | 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 |
|
---|
[252d03c] | 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 |
|
---|
[f7a90df] | 65 | /** ui_destroy() can take NULL argument (no-op) */
|
---|
| 66 | PCUT_TEST(destroy_null)
|
---|
| 67 | {
|
---|
| 68 | ui_destroy(NULL);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[2651dc5] | 71 | /** ui_suspend() / ui_resume() do nothing if we don't have a console */
|
---|
| 72 | PCUT_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 |
|
---|
[252d03c] | 89 | /** ui_run() / ui_quit() */
|
---|
| 90 | PCUT_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() */
|
---|
| 109 | PCUT_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() */
|
---|
| 126 | PCUT_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() */
|
---|
| 149 | PCUT_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 |
|
---|
[f7a90df] | 171 | PCUT_EXPORT(ui);
|
---|