OLD | NEW |
1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "../../include/fxcrt/fx_memory.h" | 8 #include "../../include/fxcrt/fx_memory.h" |
9 | 9 |
10 namespace { | 10 namespace { |
11 | 11 |
12 const size_t kMaxByteAlloc = std::numeric_limits<size_t>::max(); | 12 const size_t kMaxByteAlloc = std::numeric_limits<size_t>::max(); |
13 const size_t kMaxIntAlloc = kMaxByteAlloc / sizeof(int); | 13 const size_t kMaxIntAlloc = kMaxByteAlloc / sizeof(int); |
14 const size_t kOverflowIntAlloc = kMaxIntAlloc + 100; | 14 const size_t kOverflowIntAlloc = kMaxIntAlloc + 100; |
15 | 15 |
16 } // namespace | 16 } // namespace |
17 | 17 |
18 TEST(fxcrt, FX_AllocOOM) { | 18 // TODO(tsepez): re-enable OOM tests if we can find a way to |
| 19 // prevent it from hosing the bots. |
| 20 TEST(fxcrt, DISABLED_FX_AllocOOM) { |
19 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kMaxIntAlloc), ""); | 21 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kMaxIntAlloc), ""); |
| 22 |
| 23 int* ptr = FX_Alloc(int, 1); |
| 24 EXPECT_TRUE(ptr); |
| 25 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kMaxIntAlloc), ""); |
| 26 FX_Free(ptr); |
| 27 } |
| 28 |
| 29 TEST(fxcrt, FX_AllocOverflow) { |
20 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kOverflowIntAlloc), ""); | 30 EXPECT_DEATH_IF_SUPPORTED(FX_Alloc(int, kOverflowIntAlloc), ""); |
21 | 31 |
22 int* ptr = FX_Alloc(int, 1); | 32 int* ptr = FX_Alloc(int, 1); |
23 EXPECT_TRUE(ptr); | 33 EXPECT_TRUE(ptr); |
24 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kMaxIntAlloc), ""); | |
25 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kOverflowIntAlloc), ""); | 34 EXPECT_DEATH_IF_SUPPORTED(FX_Realloc(int, ptr, kOverflowIntAlloc), ""); |
26 FX_Free(ptr); | 35 FX_Free(ptr); |
27 } | 36 } |
28 | 37 |
29 TEST(fxcrt, FX_TryAllocOOM) { | 38 TEST(fxcrt, DISABLED_FX_TryAllocOOM) { |
30 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc)); | 39 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc)); |
| 40 |
| 41 int* ptr = FX_Alloc(int, 1); |
| 42 EXPECT_TRUE(ptr); |
| 43 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc)); |
| 44 FX_Free(ptr); |
| 45 } |
| 46 |
| 47 TEST(fxcrt, FX_TryAllocOverflow) { |
31 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc)); | 48 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc)); |
32 | 49 |
33 int* ptr = FX_Alloc(int, 1); | 50 int* ptr = FX_Alloc(int, 1); |
34 EXPECT_TRUE(ptr); | 51 EXPECT_TRUE(ptr); |
35 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc)); | |
36 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc)); | 52 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc)); |
37 FX_Free(ptr); | 53 FX_Free(ptr); |
38 } | 54 } |
39 | 55 |
40 TEST(fxcrt, FXMEM_DefaultOOM) { | 56 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) { |
41 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0)); | 57 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0)); |
42 | 58 |
43 void* ptr = FXMEM_DefaultAlloc(1, 0); | 59 void* ptr = FXMEM_DefaultAlloc(1, 0); |
44 EXPECT_TRUE(ptr); | 60 EXPECT_TRUE(ptr); |
45 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0)); | 61 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0)); |
46 FXMEM_DefaultFree(ptr, 0); | 62 FXMEM_DefaultFree(ptr, 0); |
47 } | 63 } |
OLD | NEW |