17 #include "my_config.h"
18 #include <gtest/gtest.h>
20 #include "sql_array.h"
22 namespace bounds_check_array_unittest {
33 for (
int ix= 0; ix < c_array_size; ++ix)
37 static const int c_array_size= 5;
38 int c_array[c_array_size];
51 std::ostream &operator<<(std::ostream &s,
61 namespace bounds_check_array_unittest {
63 TEST_F(BoundsCheckedArray, Empty)
65 EXPECT_EQ(
sizeof(
int), int_array.element_size());
66 EXPECT_EQ(0
U, int_array.size());
67 EXPECT_TRUE(int_array.is_null());
69 EXPECT_EQ(pi, int_array.array());
72 #if !defined(DBUG_OFF)
75 typedef BoundsCheckedArray BoundsCheckedArrayDeathTest;
77 TEST_F(BoundsCheckedArrayDeathTest, BoundsCheckRead)
79 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
80 int_array= Int_array(c_array, 2);
81 EXPECT_DEATH_IF_SUPPORTED(some_integer= int_array[5],
82 ".*Assertion .*n < m_size.*");
85 TEST_F(BoundsCheckedArrayDeathTest, BoundsCheckAssign)
87 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
88 int_array= Int_array(c_array, 2);
89 EXPECT_DEATH_IF_SUPPORTED(int_array[5]= some_integer,
90 ".*Assertion .*n < m_size.*");
93 TEST_F(BoundsCheckedArrayDeathTest, BoundsCheckPopFront)
95 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
96 int_array= Int_array(c_array, 1);
97 int_array.pop_front();
98 EXPECT_DEATH_IF_SUPPORTED(int_array.pop_front(),
99 ".*Assertion .*m_size > 0.*");
102 TEST_F(BoundsCheckedArrayDeathTest, BoundsCheckResize)
104 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
105 int_array= Int_array(c_array, 1);
106 EXPECT_DEATH_IF_SUPPORTED(int_array.resize(2),
107 ".*Assertion .*new_size <= m_size.*");
110 TEST_F(BoundsCheckedArrayDeathTest, BoundsCheckResizeAssign)
112 ::testing::FLAGS_gtest_death_test_style =
"threadsafe";
113 int_array= Int_array(c_array, 2);
114 int_array[1]= some_integer;
116 EXPECT_DEATH_IF_SUPPORTED(int_array[1]= some_integer,
117 ".*Assertion .*n < m_size.*");
120 #endif // !defined(DBUG_OFF)
122 TEST_F(BoundsCheckedArray, Indexing)
124 int_array= Int_array(c_array, c_array_size);
125 EXPECT_EQ(0, int_array[0]);
127 EXPECT_EQ(42, int_array[0]);
131 TEST_F(BoundsCheckedArray, Reset)
133 int_array= Int_array(c_array, c_array_size);
134 EXPECT_EQ(c_array, int_array.array());
135 EXPECT_FALSE(int_array.is_null());
138 EXPECT_EQ(pi, int_array.array());
139 EXPECT_TRUE(int_array.is_null());
142 TEST_F(BoundsCheckedArray, Resize)
144 int_array= Int_array(c_array, c_array_size);
145 int_array.resize(c_array_size - 1);
146 EXPECT_EQ(c_array_size - 1, static_cast<int>(int_array.size()));
149 while (int_array.size() > 0)
151 EXPECT_EQ(count, int_array[0]);
153 int_array.pop_front();
156 EXPECT_EQ(count, c_array_size - 1);
160 TEST_F(BoundsCheckedArray, PopFront)
162 int_array= Int_array(c_array, c_array_size);
163 for (
int ix= 0; ix < c_array_size; ++ix)
165 EXPECT_EQ(ix, int_array[0]);
166 int_array.pop_front();
170 TEST_F(BoundsCheckedArray, Equality)
172 int_array= Int_array(c_array, c_array_size);
173 EXPECT_EQ(int_array, int_array);
175 Int_array int_array_copy(int_array);
176 EXPECT_EQ(int_array, int_array_copy);
178 int_array_copy.resize(c_array_size - 1);
179 EXPECT_NE(int_array, int_array_copy);
182 Int_array int_array_two(c_array, c_array_size);
183 EXPECT_EQ(int_array, int_array_two);
185 int_array_two.pop_front();
186 EXPECT_NE(int_array, int_array_two);