acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
test_textarea.c (3649B)
1 #if LV_BUILD_TEST 2 #include "../lvgl.h" 3 4 #include "unity/unity.h" 5 6 static lv_obj_t * active_screen = NULL; 7 static lv_obj_t * textarea = NULL; 8 9 static const char * textarea_default_text = ""; 10 11 void setUp(void) 12 { 13 active_screen = lv_scr_act(); 14 textarea = lv_textarea_create(active_screen); 15 } 16 17 void tearDown(void) 18 { 19 /* Function run after every test */ 20 } 21 22 void test_textarea_should_have_valid_documented_defualt_values(void) 23 { 24 TEST_ASSERT(lv_textarea_get_cursor_click_pos(textarea)); 25 TEST_ASSERT_EQUAL(0U, lv_textarea_get_one_line(textarea)); 26 /* No placeholder text should be set on widget creation */ 27 TEST_ASSERT_EQUAL_STRING(textarea_default_text, lv_textarea_get_placeholder_text(textarea)); 28 TEST_ASSERT_EQUAL_STRING(textarea_default_text, lv_textarea_get_text(textarea)); 29 } 30 31 /* When in password mode the lv_textarea_get_text function returns 32 * the actual text, not the bullet characters. */ 33 void test_textarea_should_return_actual_text_when_password_mode_is_enabled(void) 34 { 35 const char * text = "Hello LVGL!"; 36 37 lv_textarea_add_text(textarea, text); 38 lv_textarea_set_password_mode(textarea, true); 39 40 TEST_ASSERT_TRUE(lv_textarea_get_password_mode(textarea)); 41 TEST_ASSERT_EQUAL_STRING(text, lv_textarea_get_text(textarea)); 42 } 43 44 void test_textarea_should_update_label_style_with_one_line_enabled(void) 45 { 46 lv_textarea_t * txt_ptr = (lv_textarea_t *) textarea; 47 48 lv_textarea_add_text(textarea, "Hi"); 49 lv_textarea_set_one_line(textarea, true); 50 51 lv_coord_t left_padding = lv_obj_get_style_pad_left(txt_ptr->label, LV_PART_MAIN); 52 lv_coord_t right_padding = lv_obj_get_style_pad_right(txt_ptr->label, LV_PART_MAIN); 53 lv_coord_t line_width = lv_obj_get_width(txt_ptr->label); 54 lv_coord_t expected_size = left_padding + right_padding + line_width; 55 56 TEST_ASSERT(lv_textarea_get_one_line(textarea)); 57 TEST_ASSERT_EQUAL_UINT16(expected_size, lv_obj_get_width(txt_ptr->label)); 58 TEST_ASSERT_EQUAL_UINT16(lv_pct(100), lv_obj_get_style_min_width(txt_ptr->label, LV_PART_MAIN)); 59 } 60 61 void test_textarea_cursor_click_pos_field_update(void) 62 { 63 lv_textarea_set_cursor_click_pos(textarea, false); 64 65 TEST_ASSERT_FALSE(lv_textarea_get_cursor_click_pos(textarea)); 66 } 67 68 void test_textarea_should_update_placeholder_text(void) 69 { 70 const char * new_placeholder = "LVGL Rocks!!!!!"; 71 const char * text = "Hello LVGL!"; 72 73 /* Allocating memory for placeholder text */ 74 lv_textarea_set_placeholder_text(textarea, text); 75 TEST_ASSERT_EQUAL_STRING(text, lv_textarea_get_placeholder_text(textarea)); 76 77 /* Reallocating memory for the new placeholder text */ 78 lv_textarea_set_placeholder_text(textarea, new_placeholder); 79 TEST_ASSERT_EQUAL_STRING(new_placeholder, lv_textarea_get_placeholder_text(textarea)); 80 81 /* Freeing allocated memory for placeholder text */ 82 lv_textarea_set_placeholder_text(textarea, ""); 83 TEST_ASSERT_EQUAL_STRING("", lv_textarea_get_placeholder_text(textarea)); 84 } 85 86 void test_textarea_should_keep_only_accepted_chars(void) 87 { 88 const char * accepted_list = "abcd"; 89 90 lv_textarea_set_accepted_chars(textarea, accepted_list); 91 lv_textarea_set_text(textarea, "abcde"); 92 93 TEST_ASSERT_EQUAL_STRING(accepted_list, lv_textarea_get_text(textarea)); 94 } 95 96 void test_textarea_in_one_line_mode_should_ignore_line_break_characters(void) 97 { 98 lv_textarea_set_one_line(textarea, true); 99 100 lv_textarea_add_char(textarea, '\n'); 101 TEST_ASSERT_EQUAL_STRING(textarea_default_text, lv_textarea_get_text(textarea)); 102 103 lv_textarea_add_char(textarea, '\r'); 104 TEST_ASSERT_EQUAL_STRING(textarea_default_text, lv_textarea_get_text(textarea)); 105 } 106 107 #endif