2 * Copyright © 2020 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include <gtest/gtest.h>
28 class test_node_inherite
: public exec_node
{
32 virtual ~test_node_inherite() = default;
35 class list_iterators_node_inherite
: public ::testing::TestWithParam
<size_t> {
38 virtual void TearDown();
46 list_iterators_node_inherite::SetUp()
48 mem_ctx
= ralloc_context(NULL
);
50 exec_list_make_empty(&node_list
);
52 for (size_t i
= 0; i
< GetParam(); i
++) {
53 test_node_inherite
*node
= new(mem_ctx
) test_node_inherite();
55 exec_list_push_tail(&node_list
, node
);
60 list_iterators_node_inherite::TearDown()
62 exec_list_make_empty(&node_list
);
68 INSTANTIATE_TEST_CASE_P(
69 list_iterators_node_inherite
,
70 list_iterators_node_inherite
,
71 ::testing::Values(0, 1, 10)
74 TEST_P(list_iterators_node_inherite
, foreach_in_list
)
77 foreach_in_list(test_node_inherite
, n
, &node_list
) {
78 EXPECT_EQ(n
->value
, i
);
83 TEST_P(list_iterators_node_inherite
, foreach_in_list_reverse
)
85 size_t i
= GetParam() - 1;
86 foreach_in_list_reverse(test_node_inherite
, n
, &node_list
) {
87 EXPECT_EQ(n
->value
, i
);
92 TEST_P(list_iterators_node_inherite
, foreach_in_list_safe
)
95 foreach_in_list_safe(test_node_inherite
, n
, &node_list
) {
96 EXPECT_EQ(n
->value
, i
);
105 exec_list_validate(&node_list
);
108 TEST_P(list_iterators_node_inherite
, foreach_in_list_reverse_safe
)
110 size_t i
= GetParam() - 1;
111 foreach_in_list_reverse_safe(test_node_inherite
, n
, &node_list
) {
112 EXPECT_EQ(n
->value
, i
);
121 exec_list_validate(&node_list
);
124 TEST_P(list_iterators_node_inherite
, foreach_in_list_use_after
)
127 foreach_in_list_use_after(test_node_inherite
, n
, &node_list
) {
128 EXPECT_EQ(n
->value
, i
);
130 if (i
== GetParam() / 2) {
137 if (GetParam() > 0) {
138 EXPECT_EQ(n
->value
, GetParam() / 2);
142 class test_node_embed
{
143 DECLARE_RZALLOC_CXX_OPERATORS(test_node_embed
)
146 uint32_t value_header
;
148 uint32_t value_footer
;
150 virtual ~test_node_embed() = default;
153 class list_iterators_node_embed
: public ::testing::TestWithParam
<size_t> {
155 virtual void SetUp();
156 virtual void TearDown();
164 list_iterators_node_embed::SetUp()
166 mem_ctx
= ralloc_context(NULL
);
168 exec_list_make_empty(&node_list
);
170 for (size_t i
= 0; i
< GetParam(); i
++) {
171 test_node_embed
*node
= new(mem_ctx
) test_node_embed();
172 node
->value_header
= i
;
173 node
->value_footer
= i
;
174 exec_list_push_tail(&node_list
, &node
->node
);
179 list_iterators_node_embed::TearDown()
181 exec_list_make_empty(&node_list
);
183 ralloc_free(mem_ctx
);
187 INSTANTIATE_TEST_CASE_P(
188 list_iterators_node_embed
,
189 list_iterators_node_embed
,
190 ::testing::Values(0, 1, 10)
193 TEST_P(list_iterators_node_embed
, foreach_list_typed
)
196 foreach_list_typed(test_node_embed
, n
, node
, &node_list
) {
197 EXPECT_EQ(n
->value_header
, i
);
198 EXPECT_EQ(n
->value_footer
, i
);
203 TEST_P(list_iterators_node_embed
, foreach_list_typed_from
)
205 if (GetParam() == 0) {
209 exec_node
*start_node
= node_list
.get_head();
212 for (; i
< GetParam() / 2; i
++) {
213 start_node
= start_node
->get_next();
216 foreach_list_typed_from(test_node_embed
, n
, node
, &node_list
, start_node
) {
217 EXPECT_EQ(n
->value_header
, i
);
218 EXPECT_EQ(n
->value_footer
, i
);
223 TEST_P(list_iterators_node_embed
, foreach_list_typed_reverse
)
225 size_t i
= GetParam() - 1;
226 foreach_list_typed_reverse(test_node_embed
, n
, node
, &node_list
) {
227 EXPECT_EQ(n
->value_header
, i
);
228 EXPECT_EQ(n
->value_footer
, i
);
233 TEST_P(list_iterators_node_embed
, foreach_list_typed_safe
)
236 foreach_list_typed_safe(test_node_embed
, n
, node
, &node_list
) {
237 EXPECT_EQ(n
->value_header
, i
);
238 EXPECT_EQ(n
->value_footer
, i
);
241 exec_node_remove(&n
->node
);
247 exec_list_validate(&node_list
);
250 TEST_P(list_iterators_node_embed
, foreach_list_typed_reverse_safe
)
252 size_t i
= GetParam() - 1;
253 foreach_list_typed_reverse_safe(test_node_embed
, n
, node
, &node_list
) {
254 EXPECT_EQ(n
->value_header
, i
);
255 EXPECT_EQ(n
->value_footer
, i
);
258 exec_node_remove(&n
->node
);
264 exec_list_validate(&node_list
);