[c77cfd8] | 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 <errno.h>
|
---|
| 30 | #include <gfx/coord.h>
|
---|
| 31 | #include <pcut/pcut.h>
|
---|
| 32 | #include <ui/ui.h>
|
---|
| 33 | #include <ui/window.h>
|
---|
| 34 | #include "../clock.h"
|
---|
| 35 |
|
---|
| 36 | PCUT_INIT;
|
---|
| 37 |
|
---|
| 38 | PCUT_TEST_SUITE(clock);
|
---|
| 39 |
|
---|
| 40 | /** Creating and destroying taskbar clock */
|
---|
| 41 | PCUT_TEST(create_destroy)
|
---|
| 42 | {
|
---|
| 43 | errno_t rc;
|
---|
| 44 | ui_t *ui = NULL;
|
---|
| 45 | ui_wnd_params_t params;
|
---|
| 46 | ui_window_t *window = NULL;
|
---|
| 47 | taskbar_clock_t *clock;
|
---|
| 48 |
|
---|
| 49 | rc = ui_create_disp(NULL, &ui);
|
---|
| 50 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 51 |
|
---|
| 52 | ui_wnd_params_init(¶ms);
|
---|
| 53 | params.caption = "Hello";
|
---|
| 54 |
|
---|
| 55 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 56 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 57 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 58 |
|
---|
| 59 | rc = taskbar_clock_create(window, &clock);
|
---|
| 60 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 61 |
|
---|
| 62 | taskbar_clock_destroy(clock);
|
---|
| 63 | ui_window_destroy(window);
|
---|
| 64 | ui_destroy(ui);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /** Painting taskbar clock */
|
---|
| 68 | PCUT_TEST(paint)
|
---|
| 69 | {
|
---|
| 70 | errno_t rc;
|
---|
| 71 | ui_t *ui = NULL;
|
---|
| 72 | ui_wnd_params_t params;
|
---|
| 73 | ui_window_t *window = NULL;
|
---|
| 74 | taskbar_clock_t *clock;
|
---|
| 75 |
|
---|
| 76 | rc = ui_create_disp(NULL, &ui);
|
---|
| 77 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 78 |
|
---|
| 79 | ui_wnd_params_init(¶ms);
|
---|
| 80 | params.caption = "Hello";
|
---|
| 81 |
|
---|
| 82 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 83 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 84 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 85 |
|
---|
| 86 | rc = taskbar_clock_create(window, &clock);
|
---|
| 87 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 88 |
|
---|
| 89 | rc = taskbar_clock_paint(clock);
|
---|
| 90 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 91 |
|
---|
| 92 | taskbar_clock_destroy(clock);
|
---|
| 93 | ui_window_destroy(window);
|
---|
| 94 | ui_destroy(ui);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | /** Keyboard event */
|
---|
| 98 | PCUT_TEST(kbd_event)
|
---|
| 99 | {
|
---|
| 100 | errno_t rc;
|
---|
| 101 | ui_t *ui = NULL;
|
---|
| 102 | ui_wnd_params_t params;
|
---|
| 103 | ui_window_t *window = NULL;
|
---|
| 104 | taskbar_clock_t *clock;
|
---|
| 105 | kbd_event_t event;
|
---|
| 106 | ui_evclaim_t claim;
|
---|
| 107 |
|
---|
| 108 | rc = ui_create_disp(NULL, &ui);
|
---|
| 109 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 110 |
|
---|
| 111 | ui_wnd_params_init(¶ms);
|
---|
| 112 | params.caption = "Hello";
|
---|
| 113 |
|
---|
| 114 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 115 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 116 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 117 |
|
---|
| 118 | rc = taskbar_clock_create(window, &clock);
|
---|
| 119 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 120 |
|
---|
| 121 | event.type = KEY_PRESS;
|
---|
| 122 | event.key = KC_ENTER;
|
---|
| 123 | event.mods = 0;
|
---|
| 124 | claim = taskbar_clock_kbd_event(clock, &event);
|
---|
| 125 | PCUT_ASSERT_EQUALS(ui_unclaimed, claim);
|
---|
| 126 |
|
---|
| 127 | taskbar_clock_destroy(clock);
|
---|
| 128 | ui_window_destroy(window);
|
---|
| 129 | ui_destroy(ui);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /** Position event */
|
---|
| 133 | PCUT_TEST(pos_event)
|
---|
| 134 | {
|
---|
| 135 | errno_t rc;
|
---|
| 136 | ui_t *ui = NULL;
|
---|
| 137 | ui_wnd_params_t params;
|
---|
| 138 | ui_window_t *window = NULL;
|
---|
| 139 | taskbar_clock_t *clock;
|
---|
| 140 | pos_event_t event;
|
---|
| 141 | ui_evclaim_t claim;
|
---|
| 142 |
|
---|
| 143 | rc = ui_create_disp(NULL, &ui);
|
---|
| 144 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 145 |
|
---|
| 146 | ui_wnd_params_init(¶ms);
|
---|
| 147 | params.caption = "Hello";
|
---|
| 148 |
|
---|
| 149 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 150 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 151 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 152 |
|
---|
| 153 | rc = taskbar_clock_create(window, &clock);
|
---|
| 154 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 155 |
|
---|
| 156 | event.type = POS_PRESS;
|
---|
| 157 | event.hpos = 0;
|
---|
| 158 | event.vpos = 0;
|
---|
| 159 | claim = taskbar_clock_pos_event(clock, &event);
|
---|
| 160 | PCUT_ASSERT_EQUALS(ui_unclaimed, claim);
|
---|
| 161 |
|
---|
| 162 | taskbar_clock_destroy(clock);
|
---|
| 163 | ui_window_destroy(window);
|
---|
| 164 | ui_destroy(ui);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | /** taskbar_clock_ctl returns a usable UI control */
|
---|
| 168 | PCUT_TEST(ctl)
|
---|
| 169 | {
|
---|
| 170 | errno_t rc;
|
---|
| 171 | ui_t *ui = NULL;
|
---|
| 172 | ui_wnd_params_t params;
|
---|
| 173 | ui_window_t *window = NULL;
|
---|
| 174 | taskbar_clock_t *clock;
|
---|
| 175 | ui_control_t *ctl;
|
---|
| 176 |
|
---|
| 177 | rc = ui_create_disp(NULL, &ui);
|
---|
| 178 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 179 |
|
---|
| 180 | ui_wnd_params_init(¶ms);
|
---|
| 181 | params.caption = "Hello";
|
---|
| 182 |
|
---|
| 183 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 184 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 185 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 186 |
|
---|
| 187 | rc = taskbar_clock_create(window, &clock);
|
---|
| 188 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 189 |
|
---|
| 190 | ctl = taskbar_clock_ctl(clock);
|
---|
| 191 | PCUT_ASSERT_NOT_NULL(ctl);
|
---|
| 192 |
|
---|
| 193 | rc = ui_control_paint(ctl);
|
---|
| 194 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 195 |
|
---|
| 196 | taskbar_clock_destroy(clock);
|
---|
| 197 | ui_window_destroy(window);
|
---|
| 198 | ui_destroy(ui);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /** taskbar_clock_set_rect() sets internal field */
|
---|
| 202 | PCUT_TEST(set_rect)
|
---|
| 203 | {
|
---|
| 204 | errno_t rc;
|
---|
| 205 | ui_t *ui = NULL;
|
---|
| 206 | ui_wnd_params_t params;
|
---|
| 207 | ui_window_t *window = NULL;
|
---|
| 208 | taskbar_clock_t *clock;
|
---|
| 209 | gfx_rect_t rect;
|
---|
| 210 |
|
---|
| 211 | rc = ui_create_disp(NULL, &ui);
|
---|
| 212 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 213 |
|
---|
| 214 | ui_wnd_params_init(¶ms);
|
---|
| 215 | params.caption = "Hello";
|
---|
| 216 |
|
---|
| 217 | rc = ui_window_create(ui, ¶ms, &window);
|
---|
| 218 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 219 | PCUT_ASSERT_NOT_NULL(window);
|
---|
| 220 |
|
---|
| 221 | rc = taskbar_clock_create(window, &clock);
|
---|
| 222 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
| 223 |
|
---|
| 224 | rect.p0.x = 1;
|
---|
| 225 | rect.p0.y = 2;
|
---|
| 226 | rect.p1.x = 3;
|
---|
| 227 | rect.p1.y = 4;
|
---|
| 228 | taskbar_clock_set_rect(clock, &rect);
|
---|
| 229 |
|
---|
| 230 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, clock->rect.p0.x);
|
---|
| 231 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, clock->rect.p0.y);
|
---|
| 232 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, clock->rect.p1.x);
|
---|
| 233 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, clock->rect.p1.y);
|
---|
| 234 |
|
---|
| 235 | taskbar_clock_destroy(clock);
|
---|
| 236 | ui_window_destroy(window);
|
---|
| 237 | ui_destroy(ui);
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | PCUT_EXPORT(clock);
|
---|