chromium/third_party/pdfium/core/fxcrt/fx_memory_unittest.cpp

// Copyright 2015 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/fxcrt/fx_memory.h"

#include <limits>
#include <memory>

#include "build/build_config.h"
#include "core/fxcrt/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"

#if defined(PDF_USE_PARTITION_ALLOC)
#include "partition_alloc/partition_address_space.h"
#endif

namespace {

constexpr size_t kMaxByteAlloc =;
constexpr size_t kMaxIntAlloc =;
constexpr size_t kOverflowIntAlloc =;
constexpr size_t kWidth =;
constexpr size_t kOverflowIntAlloc2D =;
constexpr size_t kCloseToMaxIntAlloc =;
constexpr size_t kCloseToMaxByteAlloc =;

}  // namespace

TEST(fxcrt, FX_AllocZero) {}

TEST(fxcrt, FXAllocOOM) {}

TEST(fxcrt, FX_AllocOverflow) {}

TEST(fxcrt, FX_AllocOverflow2D) {}

TEST(fxcrt, FXTryAllocOOM) {}

TEST(fxcrt, FXTryAllocUninit) {}

TEST(fxcrt, FXTryAllocUninitOOM) {}

#if !defined(COMPILER_GCC)
TEST(fxcrt, FX_TryAllocOverflow) {
  // |ptr| needs to be defined and used to avoid Clang optimizes away the
  // calloc() statement overzealously for optimized builds.
  int* ptr = (int*)calloc(sizeof(int), kOverflowIntAlloc);
  EXPECT_FALSE(ptr) << ptr;

  ptr = FX_Alloc(int, 1);
  EXPECT_TRUE(ptr);
  *ptr = 1492;  // Arbitrary sentinel.
  EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
  EXPECT_EQ(1492, *ptr);
  FX_Free(ptr);
}
#endif

TEST(fxcrt, FXMEMDefaultOOM) {}

TEST(fxcrt, AllocZeroesMemory) {}

TEST(fxcrt, FXAlign) {}

#if defined(PDF_USE_PARTITION_ALLOC)
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
    PA_BUILDFLAG(HAS_64_BIT_POINTERS)
TEST(FxMemory, NewOperatorResultIsPA) {}

TEST(FxMemory, MallocResultIsPA) {}

TEST(FxMemory, StackObjectIsNotPA) {}
#endif  // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) &&
        // PA_BUILDFLAG(HAS_64_BIT_POINTERS)
#endif  // defined(PDF_USE_PARTITION_ALLOC)