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

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

Issue 1915693002: Change the code to avoid three unit test failures on release build (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/fxcrt/include/fx_memory.h" 7 #include "core/fxcrt/include/fx_memory.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 11 matching lines...) Expand all
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 // |ptr| needs to be defined and used to avoid Clang optimizes away the
33 // FX_Alloc() statement overzealously for optimized builds.
34 int* ptr = nullptr;
35 EXPECT_DEATH_IF_SUPPORTED(ptr = FX_Alloc(int, kOverflowIntAlloc), "") << ptr;
33 36
34 int* ptr = FX_Alloc(int, 1); 37 ptr = FX_Alloc(int, 1);
35 EXPECT_TRUE(ptr); 38 EXPECT_TRUE(ptr);
36 EXPECT_DEATH_IF_SUPPORTED((void)FX_Realloc(int, ptr, kOverflowIntAlloc), ""); 39 EXPECT_DEATH_IF_SUPPORTED((void)FX_Realloc(int, ptr, kOverflowIntAlloc), "");
37 FX_Free(ptr); 40 FX_Free(ptr);
38 } 41 }
39 42
40 TEST(fxcrt, FX_AllocOverflow2D) { 43 TEST(fxcrt, FX_AllocOverflow2D) {
41 EXPECT_DEATH_IF_SUPPORTED((void)FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D), 44 // |ptr| needs to be defined and used to avoid Clang optimizes away the
42 ""); 45 // FX_Alloc() statement overzealously for optimized builds.
46 int* ptr = nullptr;
47 EXPECT_DEATH_IF_SUPPORTED(ptr = FX_Alloc2D(int, kWidth, kOverflowIntAlloc2D),
48 "")
49 << ptr;
43 } 50 }
44 51
45 TEST(fxcrt, DISABLED_FX_TryAllocOOM) { 52 TEST(fxcrt, DISABLED_FX_TryAllocOOM) {
46 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc)); 53 EXPECT_FALSE(FX_TryAlloc(int, kMaxIntAlloc));
47 54
48 int* ptr = FX_Alloc(int, 1); 55 int* ptr = FX_Alloc(int, 1);
49 EXPECT_TRUE(ptr); 56 EXPECT_TRUE(ptr);
50 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc)); 57 EXPECT_FALSE(FX_TryRealloc(int, ptr, kMaxIntAlloc));
51 FX_Free(ptr); 58 FX_Free(ptr);
52 } 59 }
53 60
54 TEST(fxcrt, FX_TryAllocOverflow) { 61 TEST(fxcrt, FX_TryAllocOverflow) {
55 EXPECT_FALSE(FX_TryAlloc(int, kOverflowIntAlloc)); 62 // |ptr| needs to be defined and used to avoid Clang optimizes away the
63 // calloc() statement overzealously for optimized builds.
64 int* ptr = (int*)calloc(sizeof(int), kOverflowIntAlloc);
65 EXPECT_FALSE(ptr) << ptr;
56 66
57 int* ptr = FX_Alloc(int, 1); 67 ptr = FX_Alloc(int, 1);
58 EXPECT_TRUE(ptr); 68 EXPECT_TRUE(ptr);
59 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc)); 69 EXPECT_FALSE(FX_TryRealloc(int, ptr, kOverflowIntAlloc));
60 FX_Free(ptr); 70 FX_Free(ptr);
61 } 71 }
62 72
63 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) { 73 TEST(fxcrt, DISABLED_FXMEM_DefaultOOM) {
64 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0)); 74 EXPECT_FALSE(FXMEM_DefaultAlloc(kMaxByteAlloc, 0));
65 75
66 void* ptr = FXMEM_DefaultAlloc(1, 0); 76 void* ptr = FXMEM_DefaultAlloc(1, 0);
67 EXPECT_TRUE(ptr); 77 EXPECT_TRUE(ptr);
68 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0)); 78 EXPECT_FALSE(FXMEM_DefaultRealloc(ptr, kMaxByteAlloc, 0));
69 FXMEM_DefaultFree(ptr, 0); 79 FXMEM_DefaultFree(ptr, 0);
70 } 80 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698