2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali-test-suite-utils.h>
22 #include <dali/internal/text/text-abstraction/plugin/lru-cache-container.h>
24 using namespace Dali::TextAbstraction::Internal;
25 using TestLRUCacheIntInt = LRUCacheContainer<int, int>;
26 using TestLRUCacheIntString = LRUCacheContainer<int, std::string>;
30 template<typename K, typename E>
31 void TestLRUCacheExist(LRUCacheContainer<K, E>& cache, const K& key, bool expectExist, const char* location)
33 auto iter = cache.Find(key);
34 DALI_TEST_EQUALS((iter != cache.End()), expectExist, location);
37 template<typename K, typename E>
38 void TestLRUCachePop(LRUCacheContainer<K, E>& cache, const E& expectElement, const char* location)
40 auto popElement = cache.Pop();
41 DALI_TEST_EQUALS(popElement, expectElement, location);
45 void utc_dali_internal_lru_cache_container_startup(void)
47 test_return_value = TET_UNDEF;
50 void utc_dali_internal_lru_cache_container_cleanup(void)
52 test_return_value = TET_PASS;
55 int UtcDaliLRUCacheContainerPushPopTest(void)
57 TestLRUCacheIntInt cache(3);
59 tet_infoline("Test LRUCache Push and Pop");
61 DALI_TEST_EQUALS(cache.IsEmpty(), true, TEST_LOCATION);
62 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
64 cache.Push(1111, 111);
65 DALI_TEST_EQUALS(cache.IsEmpty(), false, TEST_LOCATION);
67 cache.Push(2222, 222);
68 cache.Push(3333, 333);
69 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
71 cache.Push(4444, 444);
72 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
74 TestLRUCacheExist(cache, 1111, false, TEST_LOCATION);
75 TestLRUCacheExist(cache, 2222, true, TEST_LOCATION);
76 TestLRUCacheExist(cache, 3333, true, TEST_LOCATION);
77 TestLRUCacheExist(cache, 4444, true, TEST_LOCATION);
79 TestLRUCachePop(cache, 222, TEST_LOCATION);
80 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
82 TestLRUCachePop(cache, 333, TEST_LOCATION);
83 DALI_TEST_EQUALS(cache.IsEmpty(), false, TEST_LOCATION);
84 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
86 cache.Push(5555, 555);
87 cache.Push(6666, 666);
90 cache.Push(5555, 777);
91 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
94 DALI_TEST_EQUALS(cache.Get(5555), 777, TEST_LOCATION);
95 cache.Get(5555) = 888;
96 DALI_TEST_EQUALS(cache.Get(5555), 888, TEST_LOCATION);
98 TestLRUCachePop(cache, 444, TEST_LOCATION);
100 TestLRUCacheExist(cache, 2222, false, TEST_LOCATION);
101 TestLRUCacheExist(cache, 3333, false, TEST_LOCATION);
102 TestLRUCacheExist(cache, 4444, false, TEST_LOCATION);
104 TestLRUCachePop(cache, 666, TEST_LOCATION);
105 TestLRUCachePop(cache, 888, TEST_LOCATION);
106 DALI_TEST_EQUALS(cache.IsEmpty(), true, TEST_LOCATION);
111 int UtcDaliLRUCacheContainerPushPopTest2(void)
113 TestLRUCacheIntString cache(3);
115 tet_infoline("Test LRUCache Push and Pop 2");
117 DALI_TEST_EQUALS(cache.IsEmpty(), true, TEST_LOCATION);
118 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
120 cache.Push(1111, "111");
121 DALI_TEST_EQUALS(cache.IsEmpty(), false, TEST_LOCATION);
123 cache.Push(2222, "222");
124 cache.Push(3333, "333");
125 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
127 cache.Push(4444, "444");
128 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
130 TestLRUCacheExist(cache, 1111, false, TEST_LOCATION);
131 TestLRUCacheExist(cache, 2222, true, TEST_LOCATION);
132 TestLRUCacheExist(cache, 3333, true, TEST_LOCATION);
133 TestLRUCacheExist(cache, 4444, true, TEST_LOCATION);
135 TestLRUCachePop(cache, std::string("222"), TEST_LOCATION);
136 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
138 TestLRUCachePop(cache, std::string("333"), TEST_LOCATION);
139 DALI_TEST_EQUALS(cache.IsEmpty(), false, TEST_LOCATION);
140 DALI_TEST_EQUALS(cache.IsFull(), false, TEST_LOCATION);
142 cache.Push(5555, "555");
143 cache.Push(6666, "666");
146 cache.Push(5555, "777");
147 DALI_TEST_EQUALS(cache.IsFull(), true, TEST_LOCATION);
150 DALI_TEST_EQUALS(cache.Get(5555), "777", TEST_LOCATION);
151 cache.Get(5555) = "888";
152 DALI_TEST_EQUALS(cache.Get(5555), "888", TEST_LOCATION);
154 TestLRUCachePop(cache, std::string("444"), TEST_LOCATION);
156 TestLRUCacheExist(cache, 2222, false, TEST_LOCATION);
157 TestLRUCacheExist(cache, 3333, false, TEST_LOCATION);
158 TestLRUCacheExist(cache, 4444, false, TEST_LOCATION);
160 TestLRUCachePop(cache, std::string("666"), TEST_LOCATION);
161 TestLRUCachePop(cache, std::string("888"), TEST_LOCATION);
162 DALI_TEST_EQUALS(cache.IsEmpty(), true, TEST_LOCATION);
167 int UtcDaliLRUCacheContainerPopEmptyNegative(void)
169 TestLRUCacheIntInt cache(3);
171 tet_infoline("Test LRUCache Pop empty");
176 DALI_TEST_CHECK(false); // Should not get here
180 DALI_TEST_CHECK(true); // Asserted
186 int UtcDaliLRUCacheContainerGetInvalidNegative(void)
188 TestLRUCacheIntInt cache(3);
190 tet_infoline("Test LRUCache Get with invalid key");
200 DALI_TEST_CHECK(false); // Should not get here
204 DALI_TEST_CHECK(true); // Asserted