2 * Copyright (c) 2021 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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>
33 #include <pcut/pcut.h>
35 #include <ui/control.h>
37 #include <ui/resource.h>
39 #include <ui/window.h>
40 #include "../private/entry.h"
44 PCUT_TEST_SUITE(entry
);
46 /** Create and destroy text entry */
47 PCUT_TEST(create_destroy
)
49 ui_entry_t
*entry
= NULL
;
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 */
69 ui_control_t
*control
;
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 */
88 rc
= ui_entry_create(NULL
, "Hello", &entry
);
89 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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
)
110 ui_window_t
*window
= NULL
;
111 ui_wnd_params_t params
;
114 rc
= ui_create_disp(NULL
, &ui
);
115 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
117 ui_wnd_params_init(¶ms
);
118 params
.caption
= "Hello";
120 rc
= ui_window_create(ui
, ¶ms
, &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
);
137 /** Set entry read only flag sets internal field */
138 PCUT_TEST(set_read_only
)
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 */
161 rc
= ui_entry_create(NULL
, "Hello", &entry
);
162 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
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 */
183 ui_window_t
*window
= NULL
;
184 ui_wnd_params_t params
;
187 rc
= ui_create_disp(NULL
, &ui
);
188 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
190 ui_wnd_params_init(¶ms
);
191 params
.caption
= "Hello";
193 rc
= ui_window_create(ui
, ¶ms
, &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
);
208 /** ui_entry_delete_sel() deletes selected text */
209 PCUT_TEST(delete_sel
)
213 ui_window_t
*window
= NULL
;
214 ui_wnd_params_t params
;
217 rc
= ui_create_disp(NULL
, &ui
);
218 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
220 ui_wnd_params_init(¶ms
);
221 params
.caption
= "Hello";
223 rc
= ui_window_create(ui
, ¶ms
, &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
);
249 /** ui_entry_insert_str() inserts string at cursor. */
250 PCUT_TEST(insert_str
)
254 ui_window_t
*window
= NULL
;
255 ui_wnd_params_t params
;
258 rc
= ui_create_disp(NULL
, &ui
);
259 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
261 ui_wnd_params_init(¶ms
);
262 params
.caption
= "Hello";
264 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
298 /** ui_entry_insert_str() deletes selection before inserting string */
299 PCUT_TEST(insert_str_with_sel
)
303 ui_window_t
*window
= NULL
;
304 ui_wnd_params_t params
;
307 rc
= ui_create_disp(NULL
, &ui
);
308 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
310 ui_wnd_params_init(¶ms
);
311 params
.caption
= "Hello";
313 rc
= ui_window_create(ui
, ¶ms
, &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
);
339 /** ui_entry_backspace() deletes character before cursor. */
344 ui_window_t
*window
= NULL
;
345 ui_wnd_params_t params
;
348 rc
= ui_create_disp(NULL
, &ui
);
349 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
351 ui_wnd_params_init(¶ms
);
352 params
.caption
= "Hello";
354 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
382 /** ui_entry_backspace() with selected text deletes selection. */
383 PCUT_TEST(backspace_with_sel
)
387 ui_window_t
*window
= NULL
;
388 ui_wnd_params_t params
;
391 rc
= ui_create_disp(NULL
, &ui
);
392 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
394 ui_wnd_params_init(¶ms
);
395 params
.caption
= "Hello";
397 rc
= ui_window_create(ui
, ¶ms
, &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
);
422 /** ui_entry_delete() deletes character after cursor. */
427 ui_window_t
*window
= NULL
;
428 ui_wnd_params_t params
;
431 rc
= ui_create_disp(NULL
, &ui
);
432 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
434 ui_wnd_params_init(¶ms
);
435 params
.caption
= "Hello";
437 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
465 /** ui_entry_delete() with selected text deletes selection. */
466 PCUT_TEST(delete_with_sel
)
470 ui_window_t
*window
= NULL
;
471 ui_wnd_params_t params
;
474 rc
= ui_create_disp(NULL
, &ui
);
475 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
477 ui_wnd_params_init(¶ms
);
478 params
.caption
= "Hello";
480 rc
= ui_window_create(ui
, ¶ms
, &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
);
505 /** ui_entry_copy() copies selected text to clipboard. */
510 ui_window_t
*window
= NULL
;
511 ui_wnd_params_t params
;
515 rc
= ui_create_disp(NULL
, &ui
);
516 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
518 ui_wnd_params_init(¶ms
);
519 params
.caption
= "Hello";
521 rc
= ui_window_create(ui
, ¶ms
, &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
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
);
544 ui_entry_destroy(entry
);
545 ui_window_destroy(window
);
549 /** ui_entry_cut() cuts selected text to clipboard. */
554 ui_window_t
*window
= NULL
;
555 ui_wnd_params_t params
;
559 rc
= ui_create_disp(NULL
, &ui
);
560 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
562 ui_wnd_params_init(¶ms
);
563 params
.caption
= "Hello";
565 rc
= ui_window_create(ui
, ¶ms
, &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
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
);
588 ui_entry_destroy(entry
);
589 ui_window_destroy(window
);
593 /** ui_entry_paste() pastes text from clipboard. */
598 ui_window_t
*window
= NULL
;
599 ui_wnd_params_t params
;
602 rc
= ui_create_disp(NULL
, &ui
);
603 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
605 ui_wnd_params_init(¶ms
);
606 params
.caption
= "Hello";
608 rc
= ui_window_create(ui
, ¶ms
, &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
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
);
633 /** ui_entry_seek_start() moves cursor to beginning of text */
634 PCUT_TEST(seek_start
)
638 ui_window_t
*window
= NULL
;
639 ui_wnd_params_t params
;
642 rc
= ui_create_disp(NULL
, &ui
);
643 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
645 ui_wnd_params_init(¶ms
);
646 params
.caption
= "Hello";
648 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
673 /** ui_entry_seek_end() moves cursor to the end of text */
678 ui_window_t
*window
= NULL
;
679 ui_wnd_params_t params
;
682 rc
= ui_create_disp(NULL
, &ui
);
683 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
685 ui_wnd_params_init(¶ms
);
686 params
.caption
= "Hello";
688 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
711 /** ui_entry_seek_prev_char() moves cursor to the previous character */
712 PCUT_TEST(seek_prev_char
)
716 ui_window_t
*window
= NULL
;
717 ui_wnd_params_t params
;
720 rc
= ui_create_disp(NULL
, &ui
);
721 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
723 ui_wnd_params_init(¶ms
);
724 params
.caption
= "Hello";
726 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
750 /** ui_entry_seek_prev_char() moves cursor to the next character */
751 PCUT_TEST(seek_next_char
)
755 ui_window_t
*window
= NULL
;
756 ui_wnd_params_t params
;
759 rc
= ui_create_disp(NULL
, &ui
);
760 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
762 ui_wnd_params_init(¶ms
);
763 params
.caption
= "Hello";
765 rc
= ui_window_create(ui
, ¶ms
, &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
);
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
);
788 /** ui_entry_activate() / ui_entry_deactivate() */
789 PCUT_TEST(activate_deactivate
)
793 ui_window_t
*window
= NULL
;
794 ui_wnd_params_t params
;
797 rc
= ui_create_disp(NULL
, &ui
);
798 PCUT_ASSERT_ERRNO_VAL(EOK
, rc
);
800 ui_wnd_params_init(¶ms
);
801 params
.caption
= "Hello";
803 rc
= ui_window_create(ui
, ¶ms
, &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
);