#include "absl/container/fixed_array.h"
#include <stdio.h>
#include <cstring>
#include <list>
#include <memory>
#include <numeric>
#include <scoped_allocator>
#include <stdexcept>
#include <string>
#include <vector>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/internal/exception_testing.h"
#include "absl/base/options.h"
#include "absl/container/internal/test_allocator.h"
#include "absl/hash/hash_testing.h"
#include "absl/memory/memory.h"
ElementsAreArray;
namespace {
template <typename ArrayType>
static bool IsOnStack(const ArrayType& a) { … }
class ConstructionTester { … };
int ConstructionTester::constructions = …;
int ConstructionTester::destructions = …;
class ThreeInts { … };
int ThreeInts::counter = …;
TEST(FixedArrayTest, CopyCtor) { … }
TEST(FixedArrayTest, MoveCtor) { … }
TEST(FixedArrayTest, SmallObjects) { … }
TEST(FixedArrayTest, AtThrows) { … }
TEST(FixedArrayTest, Hardened) { … }
TEST(FixedArrayRelationalsTest, EqualArrays) { … }
TEST(FixedArrayRelationalsTest, UnequalArrays) { … }
template <int stack_elements>
static void TestArray(int n) { … }
template <int elements_per_inner_array, int inline_elements>
static void TestArrayOfArrays(int n) { … }
TEST(IteratorConstructorTest, NonInline) { … }
TEST(IteratorConstructorTest, Inline) { … }
TEST(IteratorConstructorTest, NonPod) { … }
TEST(IteratorConstructorTest, FromEmptyVector) { … }
TEST(IteratorConstructorTest, FromNonEmptyVector) { … }
TEST(IteratorConstructorTest, FromBidirectionalIteratorRange) { … }
TEST(InitListConstructorTest, InitListConstruction) { … }
TEST(FillConstructorTest, NonEmptyArrays) { … }
TEST(FillConstructorTest, EmptyArray) { … }
TEST(FillConstructorTest, NotTriviallyCopyable) { … }
TEST(FillConstructorTest, Disambiguation) { … }
TEST(FixedArrayTest, ManySizedArrays) { … }
TEST(FixedArrayTest, ManySizedArraysOfArraysOf1) { … }
TEST(FixedArrayTest, ManySizedArraysOfArraysOf2) { … }
TEST(FixedArrayTest, AvoidParanoidDiagnostics) { … }
TEST(FixedArrayTest, TooBigInlinedSpace) { … }
struct PickyDelete { … };
TEST(FixedArrayTest, UsesGlobalAlloc) { … }
TEST(FixedArrayTest, Data) { … }
TEST(FixedArrayTest, Empty) { … }
TEST(FixedArrayTest, FrontAndBack) { … }
TEST(FixedArrayTest, ReverseIteratorInlined) { … }
TEST(FixedArrayTest, ReverseIteratorAllocated) { … }
TEST(FixedArrayTest, Fill) { … }
#ifndef __GNUC__
TEST(FixedArrayTest, DefaultCtorDoesNotValueInit) {
using T = char;
constexpr auto capacity = 10;
using FixedArrType = absl::FixedArray<T, capacity>;
constexpr auto scrubbed_bits = 0x95;
constexpr auto length = capacity / 2;
alignas(FixedArrType) unsigned char buff[sizeof(FixedArrType)];
std::memset(std::addressof(buff), scrubbed_bits, sizeof(FixedArrType));
FixedArrType* arr =
::new (static_cast<void*>(std::addressof(buff))) FixedArrType(length);
EXPECT_THAT(*arr, testing::Each(scrubbed_bits));
arr->~FixedArrType();
}
#endif
TEST(AllocatorSupportTest, CountInlineAllocations) { … }
TEST(AllocatorSupportTest, CountOutoflineAllocations) { … }
TEST(AllocatorSupportTest, CountCopyInlineAllocations) { … }
TEST(AllocatorSupportTest, CountCopyOutoflineAllocations) { … }
TEST(AllocatorSupportTest, SizeValAllocConstructor) { … }
TEST(AllocatorSupportTest, PropagatesStatefulAllocator) { … }
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
TEST(FixedArrayTest, AddressSanitizerAnnotations1) {
absl::FixedArray<int, 32> a(10);
int* raw = a.data();
raw[0] = 0;
raw[9] = 0;
EXPECT_DEATH_IF_SUPPORTED(raw[-2] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[10] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[31] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations2) {
absl::FixedArray<char, 17> a(12);
char* raw = a.data();
raw[0] = 0;
raw[11] = 0;
EXPECT_DEATH_IF_SUPPORTED(raw[-7] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[12] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[17] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations3) {
absl::FixedArray<uint64_t, 20> a(20);
uint64_t* raw = a.data();
raw[0] = 0;
raw[19] = 0;
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[20] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations4) {
absl::FixedArray<ThreeInts> a(10);
ThreeInts* raw = a.data();
raw[0] = ThreeInts();
raw[9] = ThreeInts();
EXPECT_DEATH_IF_SUPPORTED(raw[-1].z_ = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[10] = ThreeInts(), "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[21] = ThreeInts(), "container-overflow");
}
#endif
TEST(FixedArrayTest, AbslHashValueWorks) { … }
}