Skip to content

Commit

Permalink
test(obj_tree): Add assertions in get_index and move_to_index
Browse files Browse the repository at this point in the history
  • Loading branch information
C47D committed Jan 17, 2024
1 parent d6d576c commit 3e8a888
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/lv_obj_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index)
}

const uint32_t parent_child_count = lv_obj_get_child_count(parent);
/* old_index only can be 0 or greater, this point can not be reached if the parent is null */
const int32_t old_index = lv_obj_get_index(obj);
LV_ASSERT(0 <= old_index);

if(index < 0) {
index += parent_child_count;
Expand Down Expand Up @@ -416,14 +418,16 @@ int32_t lv_obj_get_index(const lv_obj_t * obj)
LV_ASSERT_OBJ(obj, MY_CLASS);

lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent == NULL) return 0xFFFFFFFF;
if(parent == NULL) return -1;

int32_t i = 0;
for(i = 0; i < parent->spec_attr->child_cnt; i++) {
if(parent->spec_attr->children[i] == obj) return i;
}

return -1; /*Shouldn't happen*/
/*Shouldn't reach this point*/
LV_ASSERT(0);
return -1;
}

int32_t lv_obj_get_index_by_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)
Expand Down

0 comments on commit 3e8a888

Please sign in to comment.