test(obj): Add initial tests for lv_obj_move_to_index (#5284)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
This commit is contained in:
@@ -80,4 +80,106 @@ void test_obj_tree_3(void)
|
||||
TEST_ASSERT_EQUAL(lv_obj_get_child(parent2, 0), child1);
|
||||
}
|
||||
|
||||
/** lv_obj_move_to_index **/
|
||||
|
||||
void test_obj_move_to_index_move_to_the_background(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
lv_obj_t * child2 = NULL;
|
||||
|
||||
parent = lv_obj_create(lv_screen_active());
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
/* index is 1 */
|
||||
child2 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child2, 0);
|
||||
|
||||
TEST_ASSERT_EQUAL(1, lv_obj_get_index(child1));
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_index(child2));
|
||||
}
|
||||
|
||||
void test_obj_move_to_index_move_forward(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
lv_obj_t * child2 = NULL;
|
||||
|
||||
parent = lv_obj_create(lv_screen_active());
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
/* index is 1 */
|
||||
child2 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child1, lv_obj_get_index(child1) - 1);
|
||||
|
||||
TEST_ASSERT_EQUAL(1, lv_obj_get_index(child1));
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_index(child2));
|
||||
}
|
||||
|
||||
/* Tests scenarios when no operation is performed */
|
||||
void test_obj_move_to_index_no_operation_when_parent_is_null(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child1, 0);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0xFFFFFFFF, lv_obj_get_index(child1));
|
||||
}
|
||||
|
||||
void test_obj_move_to_index_no_operation_when_index_is_same_or_bigger_than_parent_child_count(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
|
||||
parent = lv_obj_create(lv_screen_active());
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child1, 3U);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_index(child1));
|
||||
}
|
||||
|
||||
void test_obj_move_to_index_no_operation_when_new_index_is_the_same_as_previous_index(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
lv_obj_t * child2 = NULL;
|
||||
|
||||
parent = lv_obj_create(lv_screen_active());
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
/* index is 1 */
|
||||
child2 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child2, 1U);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_index(child1));
|
||||
TEST_ASSERT_EQUAL(1, lv_obj_get_index(child2));
|
||||
}
|
||||
|
||||
void test_obj_move_to_index_no_operation_when_requested_negative_index_is_greater_than_child_count(void)
|
||||
{
|
||||
lv_obj_t * parent = NULL;
|
||||
lv_obj_t * child1 = NULL;
|
||||
lv_obj_t * child2 = NULL;
|
||||
|
||||
parent = lv_obj_create(lv_screen_active());
|
||||
/* index is 0 */
|
||||
child1 = lv_obj_create(parent);
|
||||
/* index is 1 */
|
||||
child2 = lv_obj_create(parent);
|
||||
|
||||
lv_obj_move_to_index(child1, -4);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, lv_obj_get_index(child1));
|
||||
TEST_ASSERT_EQUAL(1, lv_obj_get_index(child2));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user