| 1 | /*
|
|---|
| 2 | * Copyright (c) 2021 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 <gfx/context.h>
|
|---|
| 30 | #include <gfx/coord.h>
|
|---|
| 31 | #include <mem.h>
|
|---|
| 32 | #include <pcut/pcut.h>
|
|---|
| 33 | #include <stdbool.h>
|
|---|
| 34 | #include <ui/control.h>
|
|---|
| 35 | #include <ui/entry.h>
|
|---|
| 36 | #include <ui/resource.h>
|
|---|
| 37 | #include <ui/ui.h>
|
|---|
| 38 | #include <ui/window.h>
|
|---|
| 39 | #include "../private/entry.h"
|
|---|
| 40 |
|
|---|
| 41 | PCUT_INIT;
|
|---|
| 42 |
|
|---|
| 43 | PCUT_TEST_SUITE(entry);
|
|---|
| 44 |
|
|---|
| 45 | /** Create and destroy text entry */
|
|---|
| 46 | PCUT_TEST(create_destroy)
|
|---|
| 47 | {
|
|---|
| 48 | ui_entry_t *entry = NULL;
|
|---|
| 49 | errno_t rc;
|
|---|
| 50 |
|
|---|
| 51 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 52 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 53 | PCUT_ASSERT_NOT_NULL(entry);
|
|---|
| 54 |
|
|---|
| 55 | ui_entry_destroy(entry);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | /** ui_entry_destroy() can take NULL argument (no-op) */
|
|---|
| 59 | PCUT_TEST(destroy_null)
|
|---|
| 60 | {
|
|---|
| 61 | ui_entry_destroy(NULL);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /** ui_entry_ctl() returns control that has a working virtual destructor */
|
|---|
| 65 | PCUT_TEST(ctl)
|
|---|
| 66 | {
|
|---|
| 67 | ui_entry_t *entry;
|
|---|
| 68 | ui_control_t *control;
|
|---|
| 69 | errno_t rc;
|
|---|
| 70 |
|
|---|
| 71 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 72 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 73 |
|
|---|
| 74 | control = ui_entry_ctl(entry);
|
|---|
| 75 | PCUT_ASSERT_NOT_NULL(control);
|
|---|
| 76 |
|
|---|
| 77 | ui_control_destroy(control);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /** Set text entry rectangle sets internal field */
|
|---|
| 81 | PCUT_TEST(set_rect)
|
|---|
| 82 | {
|
|---|
| 83 | ui_entry_t *entry;
|
|---|
| 84 | gfx_rect_t rect;
|
|---|
| 85 | errno_t rc;
|
|---|
| 86 |
|
|---|
| 87 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 88 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 89 |
|
|---|
| 90 | rect.p0.x = 1;
|
|---|
| 91 | rect.p0.y = 2;
|
|---|
| 92 | rect.p1.x = 3;
|
|---|
| 93 | rect.p1.y = 4;
|
|---|
| 94 |
|
|---|
| 95 | ui_entry_set_rect(entry, &rect);
|
|---|
| 96 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, entry->rect.p0.x);
|
|---|
| 97 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, entry->rect.p0.y);
|
|---|
| 98 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, entry->rect.p1.x);
|
|---|
| 99 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, entry->rect.p1.y);
|
|---|
| 100 |
|
|---|
| 101 | ui_entry_destroy(entry);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /** Set entry text horizontal alignment sets internal field */
|
|---|
| 105 | PCUT_TEST(set_halign)
|
|---|
| 106 | {
|
|---|
| 107 | ui_entry_t *entry;
|
|---|
| 108 | errno_t rc;
|
|---|
| 109 |
|
|---|
| 110 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 111 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 112 |
|
|---|
| 113 | ui_entry_set_halign(entry, gfx_halign_left);
|
|---|
| 114 | PCUT_ASSERT_EQUALS(gfx_halign_left, entry->halign);
|
|---|
| 115 | ui_entry_set_halign(entry, gfx_halign_center);
|
|---|
| 116 | PCUT_ASSERT_EQUALS(gfx_halign_center, entry->halign);
|
|---|
| 117 |
|
|---|
| 118 | ui_entry_destroy(entry);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /** Set entry read only flag sets internal field */
|
|---|
| 122 | PCUT_TEST(set_read_only)
|
|---|
| 123 | {
|
|---|
| 124 | ui_entry_t *entry;
|
|---|
| 125 | errno_t rc;
|
|---|
| 126 |
|
|---|
| 127 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 128 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 129 |
|
|---|
| 130 | ui_entry_set_read_only(entry, true);
|
|---|
| 131 | PCUT_ASSERT_TRUE(entry->read_only);
|
|---|
| 132 | ui_entry_set_read_only(entry, false);
|
|---|
| 133 | PCUT_ASSERT_FALSE(entry->read_only);
|
|---|
| 134 |
|
|---|
| 135 | ui_entry_destroy(entry);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /** Set text entry rectangle sets internal field */
|
|---|
| 139 | PCUT_TEST(set_text)
|
|---|
| 140 | {
|
|---|
| 141 | ui_entry_t *entry;
|
|---|
| 142 | gfx_rect_t rect;
|
|---|
| 143 | errno_t rc;
|
|---|
| 144 |
|
|---|
| 145 | rc = ui_entry_create(NULL, "Hello", &entry);
|
|---|
| 146 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 147 |
|
|---|
| 148 | rect.p0.x = 1;
|
|---|
| 149 | rect.p0.y = 2;
|
|---|
| 150 | rect.p1.x = 3;
|
|---|
| 151 | rect.p1.y = 4;
|
|---|
| 152 |
|
|---|
| 153 | ui_entry_set_rect(entry, &rect);
|
|---|
| 154 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, entry->rect.p0.x);
|
|---|
| 155 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, entry->rect.p0.y);
|
|---|
| 156 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, entry->rect.p1.x);
|
|---|
| 157 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, entry->rect.p1.y);
|
|---|
| 158 |
|
|---|
| 159 | ui_entry_destroy(entry);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | /** Paint text entry */
|
|---|
| 163 | PCUT_TEST(paint)
|
|---|
| 164 | {
|
|---|
| 165 | errno_t rc;
|
|---|
| 166 | ui_t *ui = NULL;
|
|---|
| 167 | ui_window_t *window = NULL;
|
|---|
| 168 | ui_wnd_params_t params;
|
|---|
| 169 | ui_entry_t *entry;
|
|---|
| 170 |
|
|---|
| 171 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 172 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 173 |
|
|---|
| 174 | ui_wnd_params_init(¶ms);
|
|---|
| 175 | params.caption = "Hello";
|
|---|
| 176 |
|
|---|
| 177 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 178 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 179 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 180 |
|
|---|
| 181 | rc = ui_entry_create(window, "Hello", &entry);
|
|---|
| 182 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 183 |
|
|---|
| 184 | rc = ui_entry_paint(entry);
|
|---|
| 185 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 186 |
|
|---|
| 187 | ui_entry_destroy(entry);
|
|---|
| 188 | ui_window_destroy(window);
|
|---|
| 189 | ui_destroy(ui);
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | /** ui_entry_insert_str() inserts string at cursor. */
|
|---|
| 193 | PCUT_TEST(insert_str)
|
|---|
| 194 | {
|
|---|
| 195 | errno_t rc;
|
|---|
| 196 | ui_t *ui = NULL;
|
|---|
| 197 | ui_window_t *window = NULL;
|
|---|
| 198 | ui_wnd_params_t params;
|
|---|
| 199 | ui_entry_t *entry;
|
|---|
| 200 |
|
|---|
| 201 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 202 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 203 |
|
|---|
| 204 | ui_wnd_params_init(¶ms);
|
|---|
| 205 | params.caption = "Hello";
|
|---|
| 206 |
|
|---|
| 207 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 208 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 209 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 210 |
|
|---|
| 211 | rc = ui_entry_create(window, "A", &entry);
|
|---|
| 212 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 213 |
|
|---|
| 214 | PCUT_ASSERT_STR_EQUALS("A", entry->text);
|
|---|
| 215 |
|
|---|
| 216 | /* This moves the cursor to the end of the text */
|
|---|
| 217 | ui_entry_activate(entry);
|
|---|
| 218 |
|
|---|
| 219 | rc = ui_entry_insert_str(entry, "B");
|
|---|
| 220 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 221 |
|
|---|
| 222 | PCUT_ASSERT_STR_EQUALS("AB", entry->text);
|
|---|
| 223 |
|
|---|
| 224 | rc = ui_entry_insert_str(entry, "EF");
|
|---|
| 225 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 226 |
|
|---|
| 227 | PCUT_ASSERT_STR_EQUALS("ABEF", entry->text);
|
|---|
| 228 |
|
|---|
| 229 | entry->pos = 2;
|
|---|
| 230 | rc = ui_entry_insert_str(entry, "CD");
|
|---|
| 231 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 232 |
|
|---|
| 233 | PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
|
|---|
| 234 |
|
|---|
| 235 | ui_entry_destroy(entry);
|
|---|
| 236 | ui_window_destroy(window);
|
|---|
| 237 | ui_destroy(ui);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /** ui_entry_backspace() deletes character before cursor. */
|
|---|
| 241 | PCUT_TEST(backspace)
|
|---|
| 242 | {
|
|---|
| 243 | errno_t rc;
|
|---|
| 244 | ui_t *ui = NULL;
|
|---|
| 245 | ui_window_t *window = NULL;
|
|---|
| 246 | ui_wnd_params_t params;
|
|---|
| 247 | ui_entry_t *entry;
|
|---|
| 248 |
|
|---|
| 249 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 250 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 251 |
|
|---|
| 252 | ui_wnd_params_init(¶ms);
|
|---|
| 253 | params.caption = "Hello";
|
|---|
| 254 |
|
|---|
| 255 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 256 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 257 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 258 |
|
|---|
| 259 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 260 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 261 |
|
|---|
| 262 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 263 | entry->pos = 3;
|
|---|
| 264 |
|
|---|
| 265 | ui_entry_backspace(entry);
|
|---|
| 266 | PCUT_ASSERT_STR_EQUALS("ABD", entry->text);
|
|---|
| 267 |
|
|---|
| 268 | ui_entry_backspace(entry);
|
|---|
| 269 | PCUT_ASSERT_STR_EQUALS("AD", entry->text);
|
|---|
| 270 |
|
|---|
| 271 | ui_entry_backspace(entry);
|
|---|
| 272 | PCUT_ASSERT_STR_EQUALS("D", entry->text);
|
|---|
| 273 |
|
|---|
| 274 | ui_entry_backspace(entry);
|
|---|
| 275 | PCUT_ASSERT_STR_EQUALS("D", entry->text);
|
|---|
| 276 |
|
|---|
| 277 | ui_entry_destroy(entry);
|
|---|
| 278 | ui_window_destroy(window);
|
|---|
| 279 | ui_destroy(ui);
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | /** ui_entry_delete() deletes character after cursor. */
|
|---|
| 283 | PCUT_TEST(delete)
|
|---|
| 284 | {
|
|---|
| 285 | errno_t rc;
|
|---|
| 286 | ui_t *ui = NULL;
|
|---|
| 287 | ui_window_t *window = NULL;
|
|---|
| 288 | ui_wnd_params_t params;
|
|---|
| 289 | ui_entry_t *entry;
|
|---|
| 290 |
|
|---|
| 291 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 292 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 293 |
|
|---|
| 294 | ui_wnd_params_init(¶ms);
|
|---|
| 295 | params.caption = "Hello";
|
|---|
| 296 |
|
|---|
| 297 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 298 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 299 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 300 |
|
|---|
| 301 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 302 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 303 |
|
|---|
| 304 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 305 | entry->pos = 1;
|
|---|
| 306 |
|
|---|
| 307 | ui_entry_delete(entry);
|
|---|
| 308 | PCUT_ASSERT_STR_EQUALS("ACD", entry->text);
|
|---|
| 309 |
|
|---|
| 310 | ui_entry_delete(entry);
|
|---|
| 311 | PCUT_ASSERT_STR_EQUALS("AD", entry->text);
|
|---|
| 312 |
|
|---|
| 313 | ui_entry_delete(entry);
|
|---|
| 314 | PCUT_ASSERT_STR_EQUALS("A", entry->text);
|
|---|
| 315 |
|
|---|
| 316 | ui_entry_delete(entry);
|
|---|
| 317 | PCUT_ASSERT_STR_EQUALS("A", entry->text);
|
|---|
| 318 |
|
|---|
| 319 | ui_entry_destroy(entry);
|
|---|
| 320 | ui_window_destroy(window);
|
|---|
| 321 | ui_destroy(ui);
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | /** ui_entry_seek_start() moves cursor to beginning of text */
|
|---|
| 325 | PCUT_TEST(seek_start)
|
|---|
| 326 | {
|
|---|
| 327 | errno_t rc;
|
|---|
| 328 | ui_t *ui = NULL;
|
|---|
| 329 | ui_window_t *window = NULL;
|
|---|
| 330 | ui_wnd_params_t params;
|
|---|
| 331 | ui_entry_t *entry;
|
|---|
| 332 |
|
|---|
| 333 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 334 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 335 |
|
|---|
| 336 | ui_wnd_params_init(¶ms);
|
|---|
| 337 | params.caption = "Hello";
|
|---|
| 338 |
|
|---|
| 339 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 340 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 341 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 342 |
|
|---|
| 343 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 344 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 345 |
|
|---|
| 346 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 347 | entry->pos = 2;
|
|---|
| 348 |
|
|---|
| 349 | ui_entry_seek_start(entry);
|
|---|
| 350 | PCUT_ASSERT_INT_EQUALS(0, entry->pos);
|
|---|
| 351 |
|
|---|
| 352 | ui_entry_destroy(entry);
|
|---|
| 353 | ui_window_destroy(window);
|
|---|
| 354 | ui_destroy(ui);
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | /** ui_entry_seek_end() moves cursor to the end of text */
|
|---|
| 358 | PCUT_TEST(seek_end)
|
|---|
| 359 | {
|
|---|
| 360 | errno_t rc;
|
|---|
| 361 | ui_t *ui = NULL;
|
|---|
| 362 | ui_window_t *window = NULL;
|
|---|
| 363 | ui_wnd_params_t params;
|
|---|
| 364 | ui_entry_t *entry;
|
|---|
| 365 |
|
|---|
| 366 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 367 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 368 |
|
|---|
| 369 | ui_wnd_params_init(¶ms);
|
|---|
| 370 | params.caption = "Hello";
|
|---|
| 371 |
|
|---|
| 372 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 373 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 374 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 375 |
|
|---|
| 376 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 377 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 378 |
|
|---|
| 379 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 380 | entry->pos = 2;
|
|---|
| 381 |
|
|---|
| 382 | ui_entry_seek_end(entry);
|
|---|
| 383 | PCUT_ASSERT_INT_EQUALS(4, entry->pos);
|
|---|
| 384 |
|
|---|
| 385 | ui_entry_destroy(entry);
|
|---|
| 386 | ui_window_destroy(window);
|
|---|
| 387 | ui_destroy(ui);
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | /** ui_entry_seek_prev_char() moves cursor to the previous character */
|
|---|
| 391 | PCUT_TEST(seek_prev_char)
|
|---|
| 392 | {
|
|---|
| 393 | errno_t rc;
|
|---|
| 394 | ui_t *ui = NULL;
|
|---|
| 395 | ui_window_t *window = NULL;
|
|---|
| 396 | ui_wnd_params_t params;
|
|---|
| 397 | ui_entry_t *entry;
|
|---|
| 398 |
|
|---|
| 399 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 400 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 401 |
|
|---|
| 402 | ui_wnd_params_init(¶ms);
|
|---|
| 403 | params.caption = "Hello";
|
|---|
| 404 |
|
|---|
| 405 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 406 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 407 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 408 |
|
|---|
| 409 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 410 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 411 |
|
|---|
| 412 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 413 | entry->pos = 2;
|
|---|
| 414 |
|
|---|
| 415 | ui_entry_seek_prev_char(entry);
|
|---|
| 416 | PCUT_ASSERT_INT_EQUALS(1, entry->pos);
|
|---|
| 417 |
|
|---|
| 418 | ui_entry_destroy(entry);
|
|---|
| 419 | ui_window_destroy(window);
|
|---|
| 420 | ui_destroy(ui);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | /** ui_entry_seek_prev_char() moves cursor to the next character */
|
|---|
| 424 | PCUT_TEST(seek_next_char)
|
|---|
| 425 | {
|
|---|
| 426 | errno_t rc;
|
|---|
| 427 | ui_t *ui = NULL;
|
|---|
| 428 | ui_window_t *window = NULL;
|
|---|
| 429 | ui_wnd_params_t params;
|
|---|
| 430 | ui_entry_t *entry;
|
|---|
| 431 |
|
|---|
| 432 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 433 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 434 |
|
|---|
| 435 | ui_wnd_params_init(¶ms);
|
|---|
| 436 | params.caption = "Hello";
|
|---|
| 437 |
|
|---|
| 438 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 439 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 440 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 441 |
|
|---|
| 442 | rc = ui_entry_create(window, "ABCD", &entry);
|
|---|
| 443 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 444 |
|
|---|
| 445 | PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
|
|---|
| 446 | entry->pos = 2;
|
|---|
| 447 |
|
|---|
| 448 | ui_entry_seek_next_char(entry);
|
|---|
| 449 | PCUT_ASSERT_INT_EQUALS(3, entry->pos);
|
|---|
| 450 |
|
|---|
| 451 | ui_entry_destroy(entry);
|
|---|
| 452 | ui_window_destroy(window);
|
|---|
| 453 | ui_destroy(ui);
|
|---|
| 454 | }
|
|---|
| 455 |
|
|---|
| 456 | /** ui_entry_activate() / ui_entry_deactivate() */
|
|---|
| 457 | PCUT_TEST(activate_deactivate)
|
|---|
| 458 | {
|
|---|
| 459 | errno_t rc;
|
|---|
| 460 | ui_t *ui = NULL;
|
|---|
| 461 | ui_window_t *window = NULL;
|
|---|
| 462 | ui_wnd_params_t params;
|
|---|
| 463 | ui_entry_t *entry;
|
|---|
| 464 |
|
|---|
| 465 | rc = ui_create_disp(NULL, &ui);
|
|---|
| 466 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 467 |
|
|---|
| 468 | ui_wnd_params_init(¶ms);
|
|---|
| 469 | params.caption = "Hello";
|
|---|
| 470 |
|
|---|
| 471 | rc = ui_window_create(ui, ¶ms, &window);
|
|---|
| 472 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 473 | PCUT_ASSERT_NOT_NULL(window);
|
|---|
| 474 |
|
|---|
| 475 | rc = ui_entry_create(window, "ABC", &entry);
|
|---|
| 476 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
|---|
| 477 |
|
|---|
| 478 | PCUT_ASSERT_FALSE(entry->active);
|
|---|
| 479 |
|
|---|
| 480 | ui_entry_activate(entry);
|
|---|
| 481 | PCUT_ASSERT_TRUE(entry->active);
|
|---|
| 482 |
|
|---|
| 483 | ui_entry_deactivate(entry);
|
|---|
| 484 | PCUT_ASSERT_FALSE(entry->active);
|
|---|
| 485 |
|
|---|
| 486 | ui_entry_destroy(entry);
|
|---|
| 487 | ui_window_destroy(window);
|
|---|
| 488 | ui_destroy(ui);
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | PCUT_EXPORT(entry);
|
|---|