Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: core/src/fxcrt/fx_basic_memmgr_unittest.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 const size_t kWidth = 640; 15 const size_t kWidth = 640;
16 const size_t kOverflowIntAlloc2D = kMaxIntAlloc / kWidth + 10; 16 const size_t kOverflowIntAlloc2D = kMaxIntAlloc / kWidth + 10;
17 17
18 } // namespace 18 } // namespace
19 19
20 // TODO(tsepez): re-enable OOM tests if we can find a way to 20 // TODO(tsepez): re-enable OOM tests if we can find a way to
21 // prevent it from hosing the bots. 21 // prevent it from hosing the bots.
22 TEST(fxcrt, DISABLED_FX_AllocOOM) { 22 TEST(fxcrt, DISABLED_FX_AllocOOM) {
23 EXPECT_DEATH_IF_SUPPORTED((void) FX_Alloc(int, kMaxIntAlloc), ""); 23 EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc(int, kMaxIntAlloc), "");
24 24
25 int* ptr = FX_Alloc(int, 1); 25 int* ptr = FX_Alloc(int, 1);
26 EXPECT_TRUE(ptr); 26 EXPECT_TRUE(ptr);
27 EXPECT_DEATH_IF_SUPPORTED((void) FX_Realloc(int, ptr, kMaxIntAlloc), ""); 27 EXPECT_DEATH_IF_SUPPORTED((void)FX_Realloc(int, ptr, kMaxIntAlloc), "");
28 FX_Free(ptr); 28 FX_Free(ptr);
29 } 29 }
30 30
31 TEST(fxcrt, FX_AllocOverflow) { 31 TEST(fxcrt, FX_AllocOverflow) {
32 EXPECT_DEATH_IF_SUPPORTED((void) FX_Alloc(int, kOverflowIntAlloc), ""); 32 EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc(int, kOverflowIntAlloc), "");
33 33
34 int* ptr = FX_Alloc(int, 1); 34 int* ptr = FX_Alloc(int, 1);
35 EXPECT_TRUE(ptr); 35 EXPECT_TRUE(ptr);
36 EXPECT_DEATH_IF_SUPPORTED( 36 EXPECT_DEATH_IF_SUPPORTED((void)FX_Realloc(int, ptr, kOverflowIntAlloc), "");
37 (void) FX_Realloc(int, ptr, kOverflowIntAlloc), ""); 37 FX_Free(ptr);
38 FX_Free(ptr);
39 } 38 }
40 39
41 TEST(fxcrt, FX_AllocOverflow2D) { 40 TEST(fxcrt, FX_AllocOverflow2D) {
42 EXPECT_DEATH_IF_SUPPORTED( 41 EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D),
43 (void) FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D), ""); 42 "");
44 } 43 }
45 44
46 TEST(fxcrt, DISABLED_FX_TryAllocOOM) { 45 TEST(fxcrt, DISABLED_FX_TryAllocOOM) {
47 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc)); 46 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc));
48 47
49 int* ptr = FX_Alloc(int, 1); 48 int* ptr = FX_Alloc(int, 1);
50 EXPECT_TRUE(ptr); 49 EXPECT_TRUE(ptr);
51 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc)); 50 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc));
52 FX_Free(ptr); 51 FX_Free(ptr);
53 } 52 }
54 53
55 TEST(fxcrt, FX_TryAllocOverflow) { 54 TEST(fxcrt, FX_TryAllocOverflow) {
56 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc)); 55 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc));
57 56
58 int* ptr = FX_Alloc(int, 1); 57 int* ptr = FX_Alloc(int, 1);
59 EXPECT_TRUE(ptr); 58 EXPECT_TRUE(ptr);
60 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc)); 59 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
61 FX_Free(ptr); 60 FX_Free(ptr);
62 } 61 }
63 62
64 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) { 63 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) {
65 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0)); 64 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0));
66 65
67 void* ptr = FXMEM_DefaultAlloc(1, 0); 66 void* ptr = FXMEM_DefaultAlloc(1, 0);
68 EXPECT_TRUE(ptr); 67 EXPECT_TRUE(ptr);
69 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0)); 68 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0));
70 FXMEM_DefaultFree(ptr, 0); 69 FXMEM_DefaultFree(ptr, 0);
71 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698