Level up Dali::Internal::FreeList as Dali::FreeList
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FreeList.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/common/free-list.h>
20 #include <dali/public-api/dali-core.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 void utc_dali_free_list_startuP(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_free_list_cleanuP(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 int UtcDaliFreeListConstructor01P(void)
37 {
38   TestApplication application;
39   tet_infoline("UtcDaliFreeListConstructor01P simple constructor check");
40   try
41   {
42     FreeList freeList;
43     DALI_TEST_CHECK(true);
44   }
45   catch(...)
46   {
47     DALI_TEST_CHECK(false);
48   }
49
50   END_TEST;
51 }
52
53 int UtcDaliFreeListAddGetRemove(void)
54 {
55   TestApplication application;
56   tet_infoline("UtcDaliFreeListAddGetRemove Add, Get, and Remove test");
57   FreeList list1;
58   FreeList list2;
59
60   auto FreeListAddTest = [](FreeList& list, std::uint32_t value, std::uint32_t exceptIndex, const char* location) {
61     std::uint32_t index = list.Add(value);
62     DALI_TEST_EQUALS(index, exceptIndex, location);
63   };
64   auto FreeListGetTest = [](const FreeList& list, std::uint32_t exceptValue, std::uint32_t index, const char* location) {
65     std::uint32_t value = list[index];
66     DALI_TEST_EQUALS(value, exceptValue, location);
67   };
68
69   tet_printf("Add some values first\n");
70   FreeListAddTest(list1, 111, 0, TEST_LOCATION);
71   FreeListAddTest(list1, 222, 1, TEST_LOCATION);
72   FreeListAddTest(list1, 333, 2, TEST_LOCATION);
73   FreeListAddTest(list1, 444, 3, TEST_LOCATION);
74
75   tet_printf("Check input values exist well\n");
76   FreeListGetTest(list1, 111, 0, TEST_LOCATION);
77   FreeListGetTest(list1, 222, 1, TEST_LOCATION);
78   FreeListGetTest(list1, 333, 2, TEST_LOCATION);
79   FreeListGetTest(list1, 444, 3, TEST_LOCATION);
80
81   tet_printf("Remove 1 and 3 value\n");
82
83   list1.Remove(1);
84   list1.Remove(3);
85   tet_printf("Check not-removed values exist well\n");
86   FreeListGetTest(list1, 111, 0, TEST_LOCATION);
87   FreeListGetTest(list1, 333, 2, TEST_LOCATION);
88
89   tet_printf("Copy list. FreeList is not handle. copy whole info\n");
90   list2 = list1;
91   FreeListGetTest(list2, 111, 0, TEST_LOCATION);
92   FreeListGetTest(list2, 333, 2, TEST_LOCATION);
93
94   tet_printf("Add some values after removed\n");
95   FreeListAddTest(list1, 555, 3, TEST_LOCATION);
96   FreeListAddTest(list1, 666, 1, TEST_LOCATION);
97   FreeListAddTest(list1, 777, 4, TEST_LOCATION);
98   FreeListAddTest(list2, 888, 3, TEST_LOCATION);
99
100   tet_printf("Check input values exist well\n");
101   FreeListGetTest(list1, 111, 0, TEST_LOCATION);
102   FreeListGetTest(list1, 666, 1, TEST_LOCATION);
103   FreeListGetTest(list1, 333, 2, TEST_LOCATION);
104   FreeListGetTest(list1, 555, 3, TEST_LOCATION);
105   FreeListGetTest(list1, 777, 4, TEST_LOCATION);
106   FreeListGetTest(list2, 111, 0, TEST_LOCATION);
107   FreeListGetTest(list2, 333, 2, TEST_LOCATION);
108   FreeListGetTest(list2, 888, 3, TEST_LOCATION);
109
110   tet_printf("Change value directly\n");
111   list2.Remove(2);
112   list2[3] = 999;
113   FreeListGetTest(list2, 111, 0, TEST_LOCATION);
114   FreeListGetTest(list2, 999, 3, TEST_LOCATION);
115
116   END_TEST;
117 }