1 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "../../include/fxcrt/fx_memory.h"
12 const size_t kMaxByteAlloc = std::numeric_limits<size_t>::max();
13 const size_t kMaxIntAlloc = kMaxByteAlloc / sizeof(int);
14 const size_t kOverflowIntAlloc = kMaxIntAlloc + 100;
15 const size_t kWidth = 640;
16 const size_t kOverflowIntAlloc2D = kMaxIntAlloc / kWidth + 10;
20 // TODO(tsepez): re-enable OOM tests if we can find a way to
21 // prevent it from hosing the bots.
22 TEST(fxcrt, DISABLED_FX_AllocOOM) {
23 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kMaxIntAlloc), "");
25 int* ptr = FX_Alloc(int, 1);
27 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kMaxIntAlloc), "");
31 TEST(fxcrt, FX_AllocOverflow) {
32 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kOverflowIntAlloc), "");
34 int* ptr = FX_Alloc(int, 1);
36 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kOverflowIntAlloc), "");
40 TEST(fxcrt, FX_AllocOverflow2D) {
41 EXPECT_DEATH_IF_SUPPORTED(
42 FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D), "");
45 TEST(fxcrt, DISABLED_FX_TryAllocOOM) {
46 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc));
48 int* ptr = FX_Alloc(int, 1);
50 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc));
54 TEST(fxcrt, FX_TryAllocOverflow) {
55 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc));
57 int* ptr = FX_Alloc(int, 1);
59 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
63 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) {
64 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0));
66 void* ptr = FXMEM_DefaultAlloc(1, 0);
68 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0));
69 FXMEM_DefaultFree(ptr, 0);