1 #if LV_BUILD_TEST
2 #include "../lvgl.h"
3 #include "../../lvgl_private.h"
4
5 #include "unity/unity.h"
6 #include <string.h>
7
test_obj_id_should_match_class_name(void)8 void test_obj_id_should_match_class_name(void)
9 {
10 char buf[128];
11 lv_obj_t * obj = lv_obj_create(NULL);
12 lv_obj_stringify_id(obj, buf, sizeof(buf));
13
14 TEST_ASSERT_TRUE(strncmp("obj", buf, strlen("obj")) == 0);
15
16 lv_obj_t * img = lv_image_create(NULL);
17 lv_obj_stringify_id(img, buf, sizeof(buf));
18 TEST_ASSERT_TRUE(strncmp("image", buf, strlen("image")) == 0);
19 }
20
test_obj_id_should_grow_by_one(void)21 void test_obj_id_should_grow_by_one(void)
22 {
23 uint32_t id1, id2;
24 lv_obj_t * obj1 = lv_label_create(NULL);
25 id1 = (lv_uintptr_t)obj1->id;
26 lv_obj_t * obj2 = lv_label_create(NULL);
27 id2 = (lv_uintptr_t)obj2->id;
28 TEST_ASSERT_EQUAL(id1 + 1, id2);
29 }
30
test_obj_id_get_child(void)31 void test_obj_id_get_child(void)
32 {
33 lv_obj_t * parent = lv_obj_create(lv_screen_active());
34 lv_obj_t * child = lv_label_create(parent);
35 lv_obj_t * grandchild = lv_label_create(child);
36
37 lv_obj_set_id(child, (void *)(lv_uintptr_t)1);
38 lv_obj_set_id(grandchild, (void *)(lv_uintptr_t)2);
39
40 TEST_ASSERT_EQUAL_PTR(child, lv_obj_get_child_by_id(NULL, (void *)(lv_uintptr_t)1));
41 TEST_ASSERT_EQUAL_PTR(grandchild, lv_obj_get_child_by_id(NULL, (void *)(lv_uintptr_t)2));
42 }
43
44 #endif
45