chromium/third_party/abseil-cpp/absl/container/fixed_array_test.cc

// Copyright 2019 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#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 {

// Helper routine to determine if a absl::FixedArray used stack allocation.
template <typename ArrayType>
static bool IsOnStack(const ArrayType& a) {}

class ConstructionTester {};

int ConstructionTester::constructions =;
int ConstructionTester::destructions =;

// ThreeInts will initialize its three ints to the value stored in
// ThreeInts::counter. The constructor increments counter so that each object
// in an array of ThreeInts will have different values.
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) {}

// If value_type is put inside of a struct container,
// we might evoke this error in a hardened build unless data() is carefully
// written, so check on that.
//     error: call to int __builtin___sprintf_chk(etc...)
//     will always overflow destination buffer [-Werror]
TEST(FixedArrayTest, AvoidParanoidDiagnostics) {}

TEST(FixedArrayTest, TooBigInlinedSpace) {}

// PickyDelete EXPECTs its class-scope deallocation funcs are unused.
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  // __GNUC__

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();
  // Note: raw[-1] is pointing to 12 bytes before the container range. However,
  // there is only a 8-byte red zone before the container range, so we only
  // access the last 4 bytes of the struct to make sure it stays within the red
  // zone.
  EXPECT_DEATH_IF_SUPPORTED(raw[-1].z_ = 0, "container-overflow");
  EXPECT_DEATH_IF_SUPPORTED(raw[10] = ThreeInts(), "container-overflow");
  // The actual size of storage is kDefaultBytes=256, 21*12 = 252,
  // so reading raw[21] should still trigger the correct warning.
  EXPECT_DEATH_IF_SUPPORTED(raw[21] = ThreeInts(), "container-overflow");
}
#endif  // ABSL_HAVE_ADDRESS_SANITIZER

TEST(FixedArrayTest, AbslHashValueWorks) {}

}  // namespace