17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "sql_plist.h"
21 #include "test_utils.h"
23 namespace sql_plist_unittest {
26 template <
class T,
int size,
class L>
27 void insert_values(T (&array)[
size], L *list)
29 uint ix, elements= list->elements();
30 for (ix= 0; ix <
size; ++ix)
31 list->push_back(&array[ix]);
32 EXPECT_EQ(ix + elements, list->elements());
44 : m_int_list(), m_int_list_iter(m_int_list)
55 {
return value == obj.value; }
83 std::ostream &operator<< (std::ostream &s,
91 TEST_F(IPListTest, ConstructAndDestruct)
93 EXPECT_TRUE(m_int_list.is_empty());
94 I_P_ListCountedPushBack<int>::Type *p_int_list;
95 p_int_list=
new I_P_ListCountedPushBack<int>::Type;
96 EXPECT_TRUE(p_int_list->is_empty());
102 TEST_F(IPListTest, BasicOperations)
104 I_P_ListTestValue<int> v1(1), v2(2), v3(3);
105 m_int_list.push_front(&v1);
106 m_int_list.insert_after(&v1, &v2);
107 m_int_list.push_back(&v3);
108 EXPECT_FALSE(m_int_list.is_empty());
109 EXPECT_EQ(3
U, m_int_list.elements());
111 EXPECT_EQ(&v1, m_int_list.front());
112 m_int_list.remove(&v1);
113 EXPECT_EQ(&v2, m_int_list.front());
114 m_int_list.remove(&v2);
115 EXPECT_EQ(&v3, m_int_list.front());
116 m_int_list.remove(&v3);
117 EXPECT_TRUE(m_int_list.is_empty()) <<
"The list should be empty now!";
122 TEST_F(IPListTest, Iterate)
124 I_P_ListTestValue<int> values[]= {3, 2, 1};
125 insert_values(values, &m_int_list);
126 m_int_list_iter.init(m_int_list);
127 for (
int ix= 0; ix < array_size(values); ++ix)
129 EXPECT_EQ(values[ix], *m_int_list_iter++);
131 m_int_list_iter.init(m_int_list);
132 I_P_ListTestValue<int> *value;
134 while ((value= m_int_list_iter++))
136 EXPECT_EQ(values[value_number++], value->value);