1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "gtest/gtest.h"
23 #include "ulinklist.h"
25 class ULinkListF : public testing::Test
37 list = u_linklist_create();
38 ASSERT_TRUE(list != NULL);
41 virtual void TearDown()
43 u_linklist_free(&list);
44 ASSERT_EQ(NULL, list);
52 u_linklist_t *list = u_linklist_create();
53 ASSERT_TRUE(list != NULL);
55 u_linklist_free(&list);
56 ASSERT_EQ(NULL, list);
59 TEST(ULinkList, CreateMany)
61 for (int i = 0; i < 100; ++i)
63 u_linklist_t *list = u_linklist_create();
64 ASSERT_TRUE(list != NULL);
66 u_linklist_free(&list);
67 ASSERT_EQ(NULL, list);
71 TEST(ULinkList, FreeNull)
73 u_linklist_free(NULL);
76 TEST_F(ULinkListF, AddHead)
78 ASSERT_EQ(static_cast<uint32_t>(0), u_linklist_length(list));
81 EXPECT_EQ(CA_STATUS_OK, u_linklist_add_head(list, &dummy));
83 ASSERT_EQ(static_cast<uint32_t>(1), u_linklist_length(list));
85 // Add a few times without checking, just in case checking has side-effects
87 EXPECT_EQ(CA_STATUS_OK, u_linklist_add_head(list, &dummy));
89 EXPECT_EQ(CA_STATUS_OK, u_linklist_add_head(list, &dummy));
91 EXPECT_EQ(CA_STATUS_OK, u_linklist_add_head(list, &dummy));
93 ASSERT_EQ(static_cast<uint32_t>(4), u_linklist_length(list));
96 TEST_F(ULinkListF, Length)
98 ASSERT_EQ(static_cast<uint32_t>(0), u_linklist_length(list));
101 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy));
103 ASSERT_EQ(static_cast<uint32_t>(1), u_linklist_length(list));
105 // Add a few times without checking, just in case checking has side-effects
107 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy));
109 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy));
111 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy));
113 ASSERT_EQ(static_cast<uint32_t>(4), u_linklist_length(list));
116 TEST_F(ULinkListF, LengthMulti)
118 ASSERT_EQ(static_cast<uint32_t>(0), u_linklist_length(list));
120 int dummy[1000] = {0};
121 size_t cap = sizeof(dummy) / sizeof(dummy[0]);
123 for (size_t i = 0; i < cap; ++i)
126 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy[i]));
129 ASSERT_EQ(static_cast<uint32_t>(1000), u_linklist_length(list));
132 TEST_F(ULinkListF, Get)
134 ASSERT_EQ(static_cast<uint32_t>(0), u_linklist_length(list));
136 int dummy[1000] = {0};
137 size_t cap = sizeof(dummy) / sizeof(dummy[0]);
139 for (size_t i = 0; i < cap; ++i)
142 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy[i]));
144 ASSERT_EQ(static_cast<uint32_t>(1000), u_linklist_length(list));
146 u_linklist_iterator_t *iterTable = NULL;
147 u_linklist_init_iterator(list, &iterTable);
149 while (NULL != iterTable)
151 void *value = u_linklist_get_data(iterTable);
152 ASSERT_TRUE(value != NULL);
153 u_linklist_get_next(&iterTable);
157 TEST_F(ULinkListF, Remove)
159 ASSERT_EQ(static_cast<uint32_t>(0), u_linklist_length(list));
161 int dummy[1000] = {0};
162 size_t cap = sizeof(dummy) / sizeof(dummy[0]);
164 for (size_t i = 0; i < cap; ++i)
167 EXPECT_EQ(CA_STATUS_OK, u_linklist_add(list, &dummy[i]));
169 ASSERT_EQ(static_cast<uint32_t>(1000), u_linklist_length(list));
171 u_linklist_iterator_t *iterTable = NULL;
172 u_linklist_init_iterator(list, &iterTable);
174 while (NULL != iterTable)
176 EXPECT_EQ(CA_STATUS_OK, u_linklist_remove(list, &iterTable));
177 u_linklist_get_next(&iterTable);