1 /**
2  * @file lv_test_obj.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "../../lvgl.h"
10 #include "../lv_test_assert.h"
11 #include "lv_test_obj.h"
12 
13 #if LV_BUILD_TEST
14 
15 /*********************
16  *      DEFINES
17  *********************/
18 
19 /**********************
20  *      TYPEDEFS
21  **********************/
22 
23 /**********************
24  *  STATIC PROTOTYPES
25  **********************/
26 static void create_delete_change_parent(void);
27 
28 /**********************
29  *  STATIC VARIABLES
30  **********************/
31 
32 /**********************
33  *      MACROS
34  **********************/
35 
36 /**********************
37  *   GLOBAL FUNCTIONS
38  **********************/
39 
lv_test_obj(void)40 void lv_test_obj(void)
41 {
42     lv_test_print("");
43     lv_test_print("==================");
44     lv_test_print("Start lv_obj tests");
45     lv_test_print("==================");
46 
47     create_delete_change_parent();
48 }
49 
50 
51 /**********************
52  *   STATIC FUNCTIONS
53  **********************/
54 
create_delete_change_parent(void)55 static void create_delete_change_parent(void)
56 {
57 
58     lv_test_print("");
59     lv_test_print("Create, delete, change parent of a simple object:");
60     lv_test_print("-------------------------------------------------");
61 
62 
63     lv_test_print("Create an object on the default screen");
64     lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count before creation");
65 
66     lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL);
67     lv_test_assert_int_eq(1, lv_obj_count_children(lv_scr_act()), "Screen's children count after creation");
68     lv_test_assert_int_eq(0, lv_obj_count_children(obj), "New object's children count after creation");
69 
70     lv_test_print("Delete the created object");
71     lv_obj_del(obj);
72     obj = NULL;
73     lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count after delete");
74 
75     lv_test_print("Create two objects");
76     lv_obj_t * obj_parent = lv_obj_create(lv_scr_act(), NULL);
77     lv_obj_t * obj_child = lv_obj_create(lv_scr_act(), NULL);
78     lv_test_assert_int_eq(2, lv_obj_count_children(lv_scr_act()), "Screen's children count after creation");
79 
80     lv_test_print("Change the parent of the second object to the first");
81     lv_obj_set_parent(obj_child, obj_parent);
82     lv_test_assert_int_eq(1, lv_obj_count_children(lv_scr_act()), "Screen's children count after parent change");
83     lv_test_assert_int_eq(1, lv_obj_count_children(obj_parent), "Parent object's children count after parent change");
84     lv_test_assert_int_eq(0, lv_obj_count_children(obj_child), "Child object's children count after parent change");
85 
86     lv_test_print("Remove the parent object");
87     lv_obj_del(obj_parent);
88     lv_test_assert_int_eq(0, lv_obj_count_children(lv_scr_act()), "Screen's children count after delete");
89 }
90 #endif
91