| 237 | |
| 238 | template <int stack_elements> |
| 239 | static void TestArray(int n) { |
| 240 | SCOPED_TRACE(n); |
| 241 | SCOPED_TRACE(stack_elements); |
| 242 | ConstructionTester::constructions = 0; |
| 243 | ConstructionTester::destructions = 0; |
| 244 | { |
| 245 | ceres::internal::FixedArray<ConstructionTester, stack_elements> array(n); |
| 246 | |
| 247 | EXPECT_THAT(array.size(), n); |
| 248 | EXPECT_THAT(array.memsize(), sizeof(ConstructionTester) * n); |
| 249 | EXPECT_THAT(array.begin() + n, array.end()); |
| 250 | |
| 251 | // Check that all elements were constructed |
| 252 | for (int i = 0; i < n; i++) { |
| 253 | array[i].CheckConstructed(); |
| 254 | } |
| 255 | // Check that no other elements were constructed |
| 256 | EXPECT_THAT(ConstructionTester::constructions, n); |
| 257 | |
| 258 | // Test operator[] |
| 259 | for (int i = 0; i < n; i++) { |
| 260 | array[i].set(i); |
| 261 | } |
| 262 | for (int i = 0; i < n; i++) { |
| 263 | EXPECT_THAT(array[i].get(), i); |
| 264 | EXPECT_THAT(array.data()[i].get(), i); |
| 265 | } |
| 266 | |
| 267 | // Test data() |
| 268 | for (int i = 0; i < n; i++) { |
| 269 | array.data()[i].set(i + 1); |
| 270 | } |
| 271 | for (int i = 0; i < n; i++) { |
| 272 | EXPECT_THAT(array[i].get(), i + 1); |
| 273 | EXPECT_THAT(array.data()[i].get(), i + 1); |
| 274 | } |
| 275 | } // Close scope containing 'array'. |
| 276 | |
| 277 | // Check that all constructed elements were destructed. |
| 278 | EXPECT_EQ(ConstructionTester::constructions, |
| 279 | ConstructionTester::destructions); |
| 280 | } |
| 281 | |
| 282 | template <int elements_per_inner_array, int inline_elements> |
| 283 | static void TestArrayOfArrays(int n) { |