Editor needs to hide cursor when menu bar is activated
[helenos.git] / uspace / lib / ui / test / entry.c
blob12e8d5ab5e44d1cd16a959a6efe4c44701088c32
1 /*
2 * Copyright (c) 2021 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
29 #include <clipboard.h>
30 #include <gfx/context.h>
31 #include <gfx/coord.h>
32 #include <mem.h>
33 #include <pcut/pcut.h>
34 #include <stdbool.h>
35 #include <ui/control.h>
36 #include <ui/entry.h>
37 #include <ui/resource.h>
38 #include <ui/ui.h>
39 #include <ui/window.h>
40 #include "../private/entry.h"
42 PCUT_INIT;
44 PCUT_TEST_SUITE(entry);
46 /** Create and destroy text entry */
47 PCUT_TEST(create_destroy)
49 ui_entry_t *entry = NULL;
50 errno_t rc;
52 rc = ui_entry_create(NULL, "Hello", &entry);
53 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
54 PCUT_ASSERT_NOT_NULL(entry);
56 ui_entry_destroy(entry);
59 /** ui_entry_destroy() can take NULL argument (no-op) */
60 PCUT_TEST(destroy_null)
62 ui_entry_destroy(NULL);
65 /** ui_entry_ctl() returns control that has a working virtual destructor */
66 PCUT_TEST(ctl)
68 ui_entry_t *entry;
69 ui_control_t *control;
70 errno_t rc;
72 rc = ui_entry_create(NULL, "Hello", &entry);
73 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
75 control = ui_entry_ctl(entry);
76 PCUT_ASSERT_NOT_NULL(control);
78 ui_control_destroy(control);
81 /** Set text entry rectangle sets internal field */
82 PCUT_TEST(set_rect)
84 ui_entry_t *entry;
85 gfx_rect_t rect;
86 errno_t rc;
88 rc = ui_entry_create(NULL, "Hello", &entry);
89 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
91 rect.p0.x = 1;
92 rect.p0.y = 2;
93 rect.p1.x = 3;
94 rect.p1.y = 4;
96 ui_entry_set_rect(entry, &rect);
97 PCUT_ASSERT_INT_EQUALS(rect.p0.x, entry->rect.p0.x);
98 PCUT_ASSERT_INT_EQUALS(rect.p0.y, entry->rect.p0.y);
99 PCUT_ASSERT_INT_EQUALS(rect.p1.x, entry->rect.p1.x);
100 PCUT_ASSERT_INT_EQUALS(rect.p1.y, entry->rect.p1.y);
102 ui_entry_destroy(entry);
105 /** Set entry text horizontal alignment sets internal field */
106 PCUT_TEST(set_halign)
108 errno_t rc;
109 ui_t *ui = NULL;
110 ui_window_t *window = NULL;
111 ui_wnd_params_t params;
112 ui_entry_t *entry;
114 rc = ui_create_disp(NULL, &ui);
115 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
117 ui_wnd_params_init(&params);
118 params.caption = "Hello";
120 rc = ui_window_create(ui, &params, &window);
121 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
122 PCUT_ASSERT_NOT_NULL(window);
124 rc = ui_entry_create(window, "Hello", &entry);
125 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
127 ui_entry_set_halign(entry, gfx_halign_left);
128 PCUT_ASSERT_EQUALS(gfx_halign_left, entry->halign);
129 ui_entry_set_halign(entry, gfx_halign_center);
130 PCUT_ASSERT_EQUALS(gfx_halign_center, entry->halign);
132 ui_entry_destroy(entry);
133 ui_window_destroy(window);
134 ui_destroy(ui);
137 /** Set entry read only flag sets internal field */
138 PCUT_TEST(set_read_only)
140 ui_entry_t *entry;
141 errno_t rc;
143 rc = ui_entry_create(NULL, "Hello", &entry);
144 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
146 ui_entry_set_read_only(entry, true);
147 PCUT_ASSERT_TRUE(entry->read_only);
148 ui_entry_set_read_only(entry, false);
149 PCUT_ASSERT_FALSE(entry->read_only);
151 ui_entry_destroy(entry);
154 /** Set text entry rectangle sets internal field */
155 PCUT_TEST(set_text)
157 ui_entry_t *entry;
158 gfx_rect_t rect;
159 errno_t rc;
161 rc = ui_entry_create(NULL, "Hello", &entry);
162 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
164 rect.p0.x = 1;
165 rect.p0.y = 2;
166 rect.p1.x = 3;
167 rect.p1.y = 4;
169 ui_entry_set_rect(entry, &rect);
170 PCUT_ASSERT_INT_EQUALS(rect.p0.x, entry->rect.p0.x);
171 PCUT_ASSERT_INT_EQUALS(rect.p0.y, entry->rect.p0.y);
172 PCUT_ASSERT_INT_EQUALS(rect.p1.x, entry->rect.p1.x);
173 PCUT_ASSERT_INT_EQUALS(rect.p1.y, entry->rect.p1.y);
175 ui_entry_destroy(entry);
178 /** Paint text entry */
179 PCUT_TEST(paint)
181 errno_t rc;
182 ui_t *ui = NULL;
183 ui_window_t *window = NULL;
184 ui_wnd_params_t params;
185 ui_entry_t *entry;
187 rc = ui_create_disp(NULL, &ui);
188 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
190 ui_wnd_params_init(&params);
191 params.caption = "Hello";
193 rc = ui_window_create(ui, &params, &window);
194 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
195 PCUT_ASSERT_NOT_NULL(window);
197 rc = ui_entry_create(window, "Hello", &entry);
198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
200 rc = ui_entry_paint(entry);
201 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
203 ui_entry_destroy(entry);
204 ui_window_destroy(window);
205 ui_destroy(ui);
208 /** ui_entry_delete_sel() deletes selected text */
209 PCUT_TEST(delete_sel)
211 errno_t rc;
212 ui_t *ui = NULL;
213 ui_window_t *window = NULL;
214 ui_wnd_params_t params;
215 ui_entry_t *entry;
217 rc = ui_create_disp(NULL, &ui);
218 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
220 ui_wnd_params_init(&params);
221 params.caption = "Hello";
223 rc = ui_window_create(ui, &params, &window);
224 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
225 PCUT_ASSERT_NOT_NULL(window);
227 rc = ui_entry_create(window, "ABCDEF", &entry);
228 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
230 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
232 ui_entry_activate(entry);
234 /* Select all but first and last character */
235 ui_entry_seek_start(entry, false);
236 ui_entry_seek_next_char(entry, false);
237 ui_entry_seek_end(entry, true);
238 ui_entry_seek_prev_char(entry, true);
240 ui_entry_delete_sel(entry);
242 PCUT_ASSERT_STR_EQUALS("AF", entry->text);
244 ui_entry_destroy(entry);
245 ui_window_destroy(window);
246 ui_destroy(ui);
249 /** ui_entry_insert_str() inserts string at cursor. */
250 PCUT_TEST(insert_str)
252 errno_t rc;
253 ui_t *ui = NULL;
254 ui_window_t *window = NULL;
255 ui_wnd_params_t params;
256 ui_entry_t *entry;
258 rc = ui_create_disp(NULL, &ui);
259 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
261 ui_wnd_params_init(&params);
262 params.caption = "Hello";
264 rc = ui_window_create(ui, &params, &window);
265 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
266 PCUT_ASSERT_NOT_NULL(window);
268 rc = ui_entry_create(window, "A", &entry);
269 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
271 PCUT_ASSERT_STR_EQUALS("A", entry->text);
273 ui_entry_activate(entry);
274 ui_entry_seek_end(entry, false);
276 rc = ui_entry_insert_str(entry, "B");
277 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
279 PCUT_ASSERT_STR_EQUALS("AB", entry->text);
281 rc = ui_entry_insert_str(entry, "EF");
282 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
284 PCUT_ASSERT_STR_EQUALS("ABEF", entry->text);
286 entry->pos = 2;
287 entry->sel_start = 2;
288 rc = ui_entry_insert_str(entry, "CD");
289 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
291 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
293 ui_entry_destroy(entry);
294 ui_window_destroy(window);
295 ui_destroy(ui);
298 /** ui_entry_insert_str() deletes selection before inserting string */
299 PCUT_TEST(insert_str_with_sel)
301 errno_t rc;
302 ui_t *ui = NULL;
303 ui_window_t *window = NULL;
304 ui_wnd_params_t params;
305 ui_entry_t *entry;
307 rc = ui_create_disp(NULL, &ui);
308 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
310 ui_wnd_params_init(&params);
311 params.caption = "Hello";
313 rc = ui_window_create(ui, &params, &window);
314 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
315 PCUT_ASSERT_NOT_NULL(window);
317 rc = ui_entry_create(window, "ABCDE", &entry);
318 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
320 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
322 /* Select all but the first and last character */
323 ui_entry_activate(entry);
324 ui_entry_seek_start(entry, false);
325 ui_entry_seek_next_char(entry, false);
326 ui_entry_seek_end(entry, true);
327 ui_entry_seek_prev_char(entry, true);
329 rc = ui_entry_insert_str(entry, "123");
330 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
332 PCUT_ASSERT_STR_EQUALS("A123E", entry->text);
334 ui_entry_destroy(entry);
335 ui_window_destroy(window);
336 ui_destroy(ui);
339 /** ui_entry_backspace() deletes character before cursor. */
340 PCUT_TEST(backspace)
342 errno_t rc;
343 ui_t *ui = NULL;
344 ui_window_t *window = NULL;
345 ui_wnd_params_t params;
346 ui_entry_t *entry;
348 rc = ui_create_disp(NULL, &ui);
349 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
351 ui_wnd_params_init(&params);
352 params.caption = "Hello";
354 rc = ui_window_create(ui, &params, &window);
355 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
356 PCUT_ASSERT_NOT_NULL(window);
358 rc = ui_entry_create(window, "ABCD", &entry);
359 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
361 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
362 entry->pos = 3;
363 entry->sel_start = 3;
365 ui_entry_backspace(entry);
366 PCUT_ASSERT_STR_EQUALS("ABD", entry->text);
368 ui_entry_backspace(entry);
369 PCUT_ASSERT_STR_EQUALS("AD", entry->text);
371 ui_entry_backspace(entry);
372 PCUT_ASSERT_STR_EQUALS("D", entry->text);
374 ui_entry_backspace(entry);
375 PCUT_ASSERT_STR_EQUALS("D", entry->text);
377 ui_entry_destroy(entry);
378 ui_window_destroy(window);
379 ui_destroy(ui);
382 /** ui_entry_backspace() with selected text deletes selection. */
383 PCUT_TEST(backspace_with_sel)
385 errno_t rc;
386 ui_t *ui = NULL;
387 ui_window_t *window = NULL;
388 ui_wnd_params_t params;
389 ui_entry_t *entry;
391 rc = ui_create_disp(NULL, &ui);
392 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
394 ui_wnd_params_init(&params);
395 params.caption = "Hello";
397 rc = ui_window_create(ui, &params, &window);
398 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
399 PCUT_ASSERT_NOT_NULL(window);
401 rc = ui_entry_create(window, "ABCDE", &entry);
402 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
404 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
406 /* Select all but the first and last character */
407 ui_entry_activate(entry);
408 ui_entry_seek_start(entry, false);
409 ui_entry_seek_next_char(entry, false);
410 ui_entry_seek_end(entry, true);
411 ui_entry_seek_prev_char(entry, true);
413 ui_entry_backspace(entry);
415 PCUT_ASSERT_STR_EQUALS("AE", entry->text);
417 ui_entry_destroy(entry);
418 ui_window_destroy(window);
419 ui_destroy(ui);
422 /** ui_entry_delete() deletes character after cursor. */
423 PCUT_TEST(delete)
425 errno_t rc;
426 ui_t *ui = NULL;
427 ui_window_t *window = NULL;
428 ui_wnd_params_t params;
429 ui_entry_t *entry;
431 rc = ui_create_disp(NULL, &ui);
432 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
434 ui_wnd_params_init(&params);
435 params.caption = "Hello";
437 rc = ui_window_create(ui, &params, &window);
438 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
439 PCUT_ASSERT_NOT_NULL(window);
441 rc = ui_entry_create(window, "ABCD", &entry);
442 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
444 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
445 entry->pos = 1;
446 entry->sel_start = 1;
448 ui_entry_delete(entry);
449 PCUT_ASSERT_STR_EQUALS("ACD", entry->text);
451 ui_entry_delete(entry);
452 PCUT_ASSERT_STR_EQUALS("AD", entry->text);
454 ui_entry_delete(entry);
455 PCUT_ASSERT_STR_EQUALS("A", entry->text);
457 ui_entry_delete(entry);
458 PCUT_ASSERT_STR_EQUALS("A", entry->text);
460 ui_entry_destroy(entry);
461 ui_window_destroy(window);
462 ui_destroy(ui);
465 /** ui_entry_delete() with selected text deletes selection. */
466 PCUT_TEST(delete_with_sel)
468 errno_t rc;
469 ui_t *ui = NULL;
470 ui_window_t *window = NULL;
471 ui_wnd_params_t params;
472 ui_entry_t *entry;
474 rc = ui_create_disp(NULL, &ui);
475 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
477 ui_wnd_params_init(&params);
478 params.caption = "Hello";
480 rc = ui_window_create(ui, &params, &window);
481 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
482 PCUT_ASSERT_NOT_NULL(window);
484 rc = ui_entry_create(window, "ABCDE", &entry);
485 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
487 PCUT_ASSERT_STR_EQUALS("ABCDE", entry->text);
489 /* Select all but the first and last character */
490 ui_entry_activate(entry);
491 ui_entry_seek_start(entry, false);
492 ui_entry_seek_next_char(entry, false);
493 ui_entry_seek_end(entry, true);
494 ui_entry_seek_prev_char(entry, true);
496 ui_entry_delete(entry);
498 PCUT_ASSERT_STR_EQUALS("AE", entry->text);
500 ui_entry_destroy(entry);
501 ui_window_destroy(window);
502 ui_destroy(ui);
505 /** ui_entry_copy() copies selected text to clipboard. */
506 PCUT_TEST(copy)
508 errno_t rc;
509 ui_t *ui = NULL;
510 ui_window_t *window = NULL;
511 ui_wnd_params_t params;
512 ui_entry_t *entry;
513 char *str;
515 rc = ui_create_disp(NULL, &ui);
516 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
518 ui_wnd_params_init(&params);
519 params.caption = "Hello";
521 rc = ui_window_create(ui, &params, &window);
522 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
523 PCUT_ASSERT_NOT_NULL(window);
525 rc = ui_entry_create(window, "ABCDEF", &entry);
526 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
528 ui_entry_activate(entry);
529 ui_entry_seek_start(entry, false);
530 ui_entry_seek_next_char(entry, false);
531 ui_entry_seek_end(entry, true);
532 ui_entry_seek_prev_char(entry, true);
534 // FIXME: This is not safe unless we could create a private
535 // test clipboard
537 ui_entry_copy(entry);
538 rc = clipboard_get_str(&str);
539 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
540 PCUT_ASSERT_STR_EQUALS("BCDE", str);
541 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text);
542 free(str);
544 ui_entry_destroy(entry);
545 ui_window_destroy(window);
546 ui_destroy(ui);
549 /** ui_entry_cut() cuts selected text to clipboard. */
550 PCUT_TEST(cut)
552 errno_t rc;
553 ui_t *ui = NULL;
554 ui_window_t *window = NULL;
555 ui_wnd_params_t params;
556 ui_entry_t *entry;
557 char *str;
559 rc = ui_create_disp(NULL, &ui);
560 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
562 ui_wnd_params_init(&params);
563 params.caption = "Hello";
565 rc = ui_window_create(ui, &params, &window);
566 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
567 PCUT_ASSERT_NOT_NULL(window);
569 rc = ui_entry_create(window, "ABCDEF", &entry);
570 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
572 ui_entry_activate(entry);
573 ui_entry_seek_start(entry, false);
574 ui_entry_seek_next_char(entry, false);
575 ui_entry_seek_end(entry, true);
576 ui_entry_seek_prev_char(entry, true);
578 // FIXME: This is not safe unless we could create a private
579 // test clipboard
581 ui_entry_cut(entry);
582 rc = clipboard_get_str(&str);
583 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
584 PCUT_ASSERT_STR_EQUALS("BCDE", str);
585 PCUT_ASSERT_STR_EQUALS("AF", entry->text);
586 free(str);
588 ui_entry_destroy(entry);
589 ui_window_destroy(window);
590 ui_destroy(ui);
593 /** ui_entry_paste() pastes text from clipboard. */
594 PCUT_TEST(paste)
596 errno_t rc;
597 ui_t *ui = NULL;
598 ui_window_t *window = NULL;
599 ui_wnd_params_t params;
600 ui_entry_t *entry;
602 rc = ui_create_disp(NULL, &ui);
603 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
605 ui_wnd_params_init(&params);
606 params.caption = "Hello";
608 rc = ui_window_create(ui, &params, &window);
609 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
610 PCUT_ASSERT_NOT_NULL(window);
612 rc = ui_entry_create(window, "AB", &entry);
613 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
615 ui_entry_activate(entry);
616 ui_entry_seek_start(entry, false);
617 ui_entry_seek_next_char(entry, false);
619 // FIXME: This is not safe unless we could create a private
620 // test clipboard
622 rc = clipboard_put_str("123");
623 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
625 ui_entry_paste(entry);
626 PCUT_ASSERT_STR_EQUALS("A123B", entry->text);
628 ui_entry_destroy(entry);
629 ui_window_destroy(window);
630 ui_destroy(ui);
633 /** ui_entry_seek_start() moves cursor to beginning of text */
634 PCUT_TEST(seek_start)
636 errno_t rc;
637 ui_t *ui = NULL;
638 ui_window_t *window = NULL;
639 ui_wnd_params_t params;
640 ui_entry_t *entry;
642 rc = ui_create_disp(NULL, &ui);
643 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
645 ui_wnd_params_init(&params);
646 params.caption = "Hello";
648 rc = ui_window_create(ui, &params, &window);
649 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
650 PCUT_ASSERT_NOT_NULL(window);
652 rc = ui_entry_create(window, "ABCDEF", &entry);
653 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
655 ui_entry_activate(entry);
657 entry->pos = 2;
658 entry->sel_start = 2;
660 ui_entry_seek_start(entry, true);
661 PCUT_ASSERT_INT_EQUALS(0, entry->pos);
662 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start);
664 ui_entry_seek_start(entry, false);
665 PCUT_ASSERT_INT_EQUALS(0, entry->pos);
666 PCUT_ASSERT_INT_EQUALS(0, entry->sel_start);
668 ui_entry_destroy(entry);
669 ui_window_destroy(window);
670 ui_destroy(ui);
673 /** ui_entry_seek_end() moves cursor to the end of text */
674 PCUT_TEST(seek_end)
676 errno_t rc;
677 ui_t *ui = NULL;
678 ui_window_t *window = NULL;
679 ui_wnd_params_t params;
680 ui_entry_t *entry;
682 rc = ui_create_disp(NULL, &ui);
683 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
685 ui_wnd_params_init(&params);
686 params.caption = "Hello";
688 rc = ui_window_create(ui, &params, &window);
689 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
690 PCUT_ASSERT_NOT_NULL(window);
692 rc = ui_entry_create(window, "ABCD", &entry);
693 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
695 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
696 entry->pos = 2;
697 entry->sel_start = 2;
699 ui_entry_seek_end(entry, true);
700 PCUT_ASSERT_INT_EQUALS(4, entry->pos);
701 PCUT_ASSERT_INT_EQUALS(2, entry->sel_start);
702 ui_entry_seek_end(entry, false);
703 PCUT_ASSERT_INT_EQUALS(4, entry->pos);
704 PCUT_ASSERT_INT_EQUALS(4, entry->sel_start);
706 ui_entry_destroy(entry);
707 ui_window_destroy(window);
708 ui_destroy(ui);
711 /** ui_entry_seek_prev_char() moves cursor to the previous character */
712 PCUT_TEST(seek_prev_char)
714 errno_t rc;
715 ui_t *ui = NULL;
716 ui_window_t *window = NULL;
717 ui_wnd_params_t params;
718 ui_entry_t *entry;
720 rc = ui_create_disp(NULL, &ui);
721 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
723 ui_wnd_params_init(&params);
724 params.caption = "Hello";
726 rc = ui_window_create(ui, &params, &window);
727 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
728 PCUT_ASSERT_NOT_NULL(window);
730 rc = ui_entry_create(window, "ABCD", &entry);
731 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
733 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
734 entry->pos = 3;
735 entry->sel_start = 3;
737 ui_entry_seek_prev_char(entry, true);
738 PCUT_ASSERT_INT_EQUALS(2, entry->pos);
739 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start);
741 ui_entry_seek_prev_char(entry, false);
742 PCUT_ASSERT_INT_EQUALS(1, entry->pos);
743 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start);
745 ui_entry_destroy(entry);
746 ui_window_destroy(window);
747 ui_destroy(ui);
750 /** ui_entry_seek_prev_char() moves cursor to the next character */
751 PCUT_TEST(seek_next_char)
753 errno_t rc;
754 ui_t *ui = NULL;
755 ui_window_t *window = NULL;
756 ui_wnd_params_t params;
757 ui_entry_t *entry;
759 rc = ui_create_disp(NULL, &ui);
760 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
762 ui_wnd_params_init(&params);
763 params.caption = "Hello";
765 rc = ui_window_create(ui, &params, &window);
766 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
767 PCUT_ASSERT_NOT_NULL(window);
769 rc = ui_entry_create(window, "ABCD", &entry);
770 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
772 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text);
773 entry->pos = 1;
774 entry->sel_start = 1;
776 ui_entry_seek_next_char(entry, true);
777 PCUT_ASSERT_INT_EQUALS(2, entry->pos);
778 PCUT_ASSERT_INT_EQUALS(1, entry->sel_start);
779 ui_entry_seek_next_char(entry, false);
780 PCUT_ASSERT_INT_EQUALS(3, entry->pos);
781 PCUT_ASSERT_INT_EQUALS(3, entry->sel_start);
783 ui_entry_destroy(entry);
784 ui_window_destroy(window);
785 ui_destroy(ui);
788 /** ui_entry_activate() / ui_entry_deactivate() */
789 PCUT_TEST(activate_deactivate)
791 errno_t rc;
792 ui_t *ui = NULL;
793 ui_window_t *window = NULL;
794 ui_wnd_params_t params;
795 ui_entry_t *entry;
797 rc = ui_create_disp(NULL, &ui);
798 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
800 ui_wnd_params_init(&params);
801 params.caption = "Hello";
803 rc = ui_window_create(ui, &params, &window);
804 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
805 PCUT_ASSERT_NOT_NULL(window);
807 rc = ui_entry_create(window, "ABC", &entry);
808 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
810 PCUT_ASSERT_FALSE(entry->active);
812 ui_entry_activate(entry);
813 PCUT_ASSERT_TRUE(entry->active);
815 ui_entry_deactivate(entry);
816 PCUT_ASSERT_FALSE(entry->active);
818 ui_entry_destroy(entry);
819 ui_window_destroy(window);
820 ui_destroy(ui);
823 PCUT_EXPORT(entry);