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_arc.c (4902B)
1 #if LV_BUILD_TEST 2 #include "../lvgl.h" 3 4 #include "unity/unity.h" 5 #include "lv_test_indev.h" 6 7 /* This function runs before each test */ 8 void setUp(void); 9 10 void test_arc_creation_successfull(void); 11 void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void); 12 void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void); 13 void test_arc_should_update_value_after_updating_range(void); 14 void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void); 15 void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void); 16 void test_arc_angles_when_reversed(void); 17 18 static lv_obj_t * active_screen = NULL; 19 static lv_obj_t * arc = NULL; 20 static uint32_t event_cnt; 21 22 static void dummy_event_cb(lv_event_t * e); 23 24 void setUp(void) 25 { 26 active_screen = lv_scr_act(); 27 } 28 29 void test_arc_creation_successfull(void) 30 { 31 arc = lv_arc_create(active_screen); 32 33 TEST_ASSERT_NOT_NULL(arc); 34 } 35 36 void test_arc_should_truncate_to_max_range_when_new_value_exceeds_it(void) 37 { 38 /* Default max range is 100 */ 39 int16_t value_after_truncation = 100; 40 41 arc = lv_arc_create(active_screen); 42 43 lv_arc_set_value(arc, 200); 44 45 TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc)); 46 } 47 48 void test_arc_should_truncate_to_min_range_when_new_value_is_inferior(void) 49 { 50 /* Default min range is 100 */ 51 int16_t value_after_truncation = 0; 52 53 arc = lv_arc_create(active_screen); 54 55 lv_arc_set_value(arc, 0); 56 57 TEST_ASSERT_EQUAL_INT16(value_after_truncation, lv_arc_get_value(arc)); 58 } 59 60 void test_arc_should_update_value_after_updating_range(void) 61 { 62 int16_t value_after_updating_max_range = 50; 63 int16_t value_after_updating_min_range = 30; 64 65 arc = lv_arc_create(active_screen); 66 67 lv_arc_set_value(arc, 80); 68 lv_arc_set_range(arc, 1, 50); 69 70 TEST_ASSERT_EQUAL_INT16(value_after_updating_max_range, lv_arc_get_value(arc)); 71 72 lv_arc_set_value(arc, 10); 73 lv_arc_set_range(arc, 30, 50); 74 75 TEST_ASSERT_EQUAL_INT16(value_after_updating_min_range, lv_arc_get_value(arc)); 76 } 77 78 void test_arc_should_update_angles_when_changing_to_symmetrical_mode(void) 79 { 80 int16_t expected_angle_start = 135; 81 int16_t expected_angle_end = 270; 82 83 /* start angle is 135, end angle is 45 at creation */ 84 arc = lv_arc_create(active_screen); 85 lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL); 86 87 TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc)); 88 TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc)); 89 } 90 91 void test_arc_should_update_angles_when_changing_to_symmetrical_mode_value_more_than_middle_range(void) 92 { 93 int16_t expected_angle_start = 270; 94 int16_t expected_angle_end = 45; 95 96 /* start angle is 135, end angle is 45 at creation */ 97 arc = lv_arc_create(active_screen); 98 lv_arc_set_value(arc, 100); 99 lv_arc_set_mode(arc, LV_ARC_MODE_SYMMETRICAL); 100 101 TEST_ASSERT_EQUAL_INT16(expected_angle_start, lv_arc_get_angle_start(arc)); 102 TEST_ASSERT_EQUAL_INT16(expected_angle_end, lv_arc_get_angle_end(arc)); 103 } 104 105 /* See #2522 for more information */ 106 void test_arc_angles_when_reversed(void) 107 { 108 uint16_t expected_start_angle = 36; 109 uint16_t expected_end_angle = 90; 110 int16_t expected_value = 40; 111 112 lv_obj_t * arcBlack; 113 arcBlack = lv_arc_create(lv_scr_act()); 114 115 lv_arc_set_mode(arcBlack, LV_ARC_MODE_REVERSE); 116 117 lv_arc_set_bg_angles(arcBlack, 0, 90); 118 119 lv_arc_set_value(arcBlack, expected_value); 120 121 TEST_ASSERT_EQUAL_UINT16(expected_start_angle, lv_arc_get_angle_start(arcBlack)); 122 TEST_ASSERT_EQUAL_UINT16(expected_end_angle, lv_arc_get_angle_end(arcBlack)); 123 TEST_ASSERT_EQUAL_INT16(expected_value, lv_arc_get_value(arcBlack)); 124 } 125 126 void test_arc_click_area_with_adv_hittest(void) 127 { 128 arc = lv_arc_create(lv_scr_act()); 129 lv_obj_set_size(arc, 100, 100); 130 lv_obj_set_style_arc_width(arc, 10, 0); 131 lv_obj_add_flag(arc, LV_OBJ_FLAG_ADV_HITTEST); 132 lv_obj_add_event_cb(arc, dummy_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 133 lv_obj_set_ext_click_area(arc, 5); 134 135 /*No click detected at the middle*/ 136 event_cnt = 0; 137 lv_test_mouse_click_at(50, 50); 138 TEST_ASSERT_EQUAL_UINT32(0, event_cnt); 139 140 /*No click close to the radius - bg_arc - ext_click_area*/ 141 event_cnt = 0; 142 lv_test_mouse_click_at(83, 50); 143 TEST_ASSERT_EQUAL_UINT32(0, event_cnt); 144 145 /*Click on the radius - bg_arc - ext_click_area*/ 146 event_cnt = 0; 147 lv_test_mouse_click_at(86, 50); 148 TEST_ASSERT_GREATER_THAN(0, event_cnt); 149 150 /*Click on the radius + ext_click_area*/ 151 event_cnt = 0; 152 lv_test_mouse_click_at(104, 50); 153 TEST_ASSERT_GREATER_THAN(0, event_cnt); 154 155 /*No click beyond to the radius + ext_click_area*/ 156 event_cnt = 0; 157 lv_test_mouse_click_at(106, 50); 158 TEST_ASSERT_EQUAL_UINT32(0, event_cnt); 159 } 160 161 static void dummy_event_cb(lv_event_t * e) 162 { 163 LV_UNUSED(e); 164 event_cnt++; 165 } 166 167 #endif