#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 = …;
}
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) {
int* ptr = (int*)calloc(sizeof(int), kOverflowIntAlloc);
EXPECT_FALSE(ptr) << ptr;
ptr = FX_Alloc(int, 1);
EXPECT_TRUE(ptr);
*ptr = 1492;
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
#endif