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_line.c (3061B)

      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 * line = NULL;
      8 
      9 static const uint16_t default_point_num = 0U;
     10 static const lv_coord_t initial_extra_draw_size = 5U;
     11 static const lv_coord_t final_extra_draw_size = 10U;
     12 
     13 void setUp(void)
     14 {
     15     active_screen = lv_scr_act();
     16     line = lv_line_create(active_screen);
     17 }
     18 
     19 void tearDown(void)
     20 {
     21     lv_obj_clean(active_screen);
     22 }
     23 
     24 void test_line_should_have_valid_documented_default_values(void)
     25 {
     26     lv_line_t * line_ptr = (lv_line_t *) line;
     27     TEST_ASSERT_EQUAL_UINT16(default_point_num, line_ptr->point_num);
     28     TEST_ASSERT_NULL(line_ptr->point_array);
     29     TEST_ASSERT_FALSE(lv_line_get_y_invert(line));
     30     TEST_ASSERT_FALSE(lv_obj_has_flag(line, LV_OBJ_FLAG_CLICKABLE));
     31     /* line doesn't have any points, so it's 0,0 in size */
     32     TEST_ASSERT_EQUAL_UINT16(0U, lv_obj_get_self_width(line));
     33     TEST_ASSERT_EQUAL_UINT16(0U, lv_obj_get_self_height(line));
     34 }
     35 
     36 void test_line_should_return_valid_y_invert(void)
     37 {
     38     lv_line_set_y_invert(line, true);
     39     TEST_ASSERT_TRUE(lv_line_get_y_invert(line));
     40 }
     41 
     42 void test_line_size_should_be_updated_after_adding_points(void)
     43 {
     44     static lv_point_t points[] = { {5, 5} };
     45     uint16_t point_cnt = (uint16_t) sizeof(points) / sizeof(lv_point_t);
     46     lv_line_set_points(line, points, point_cnt);
     47 
     48     lv_coord_t calculated_width = 0;
     49     lv_coord_t calculated_height = 0;
     50 
     51     /* Get the biggest coordinate on both axis */
     52     uint16_t point_idx = 0;
     53     for(point_idx = 0; point_idx < point_cnt; point_idx++) {
     54         calculated_width = LV_MAX(points[point_idx].x, calculated_width);
     55         calculated_height = LV_MAX(points[point_idx].y, calculated_height);
     56     }
     57     /* Add style line width */
     58     lv_coord_t line_width = lv_obj_get_style_line_width(line, LV_PART_MAIN);
     59     calculated_width += line_width;
     60     calculated_height += line_width;
     61 
     62     TEST_ASSERT_EQUAL_UINT16(calculated_width, lv_obj_get_self_width(line));
     63     TEST_ASSERT_EQUAL_UINT16(calculated_height, lv_obj_get_self_height(line));
     64 }
     65 
     66 static void line_event_cb(lv_event_t * e)
     67 {
     68     lv_event_code_t code = lv_event_get_code(e);
     69 
     70     if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
     71         /* Set the new line extra draw size */
     72         lv_event_set_ext_draw_size(e, initial_extra_draw_size);
     73     }
     74 }
     75 
     76 void test_line_should_update_extra_draw_size_based_on_style(void)
     77 {
     78     /* Setup an event handler for line extra draw size event */
     79     lv_obj_add_event_cb(line, line_event_cb, LV_EVENT_ALL, NULL);
     80     /* Trigger the extra draw size event */
     81     lv_obj_refresh_ext_draw_size(line);
     82 
     83     TEST_ASSERT_EQUAL(initial_extra_draw_size, _lv_obj_get_ext_draw_size(line));
     84 
     85     /* Update line width style, the event handler should set the extra draw size
     86      * to the line width */
     87     lv_obj_set_style_line_width(line, final_extra_draw_size, LV_PART_MAIN);
     88 
     89     /* Trigger the extra draw size event */
     90     lv_obj_refresh_ext_draw_size(line);
     91 
     92     TEST_ASSERT_EQUAL(final_extra_draw_size, _lv_obj_get_ext_draw_size(line));
     93 }
     94 
     95 #endif