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

Side by Side Diff: base/process/memory_unittest.cc

Issue 804533005: Standardize usage of virtual/override/final specifiers in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify Created 6 years 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 | « base/prefs/scoped_user_pref_update_unittest.cc ('k') | base/sequence_checker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6 6
7 #include "base/process/memory.h" 7 #include "base/process/memory.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 public: 175 public:
176 OutOfMemoryTest() 176 OutOfMemoryTest()
177 : value_(NULL), 177 : value_(NULL),
178 // Make test size as large as possible minus a few pages so 178 // Make test size as large as possible minus a few pages so
179 // that alignment or other rounding doesn't make it wrap. 179 // that alignment or other rounding doesn't make it wrap.
180 test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024), 180 test_size_(std::numeric_limits<std::size_t>::max() - 12 * 1024),
181 signed_test_size_(std::numeric_limits<ssize_t>::max()) { 181 signed_test_size_(std::numeric_limits<ssize_t>::max()) {
182 } 182 }
183 183
184 #if defined(USE_TCMALLOC) 184 #if defined(USE_TCMALLOC)
185 virtual void SetUp() override { 185 void SetUp() override { tc_set_new_mode(1); }
186 tc_set_new_mode(1);
187 }
188 186
189 virtual void TearDown() override { 187 void TearDown() override { tc_set_new_mode(0); }
190 tc_set_new_mode(0);
191 }
192 #endif // defined(USE_TCMALLOC) 188 #endif // defined(USE_TCMALLOC)
193 189
194 protected: 190 protected:
195 void* value_; 191 void* value_;
196 size_t test_size_; 192 size_t test_size_;
197 ssize_t signed_test_size_; 193 ssize_t signed_test_size_;
198 }; 194 };
199 195
200 class OutOfMemoryDeathTest : public OutOfMemoryTest { 196 class OutOfMemoryDeathTest : public OutOfMemoryTest {
201 public: 197 public:
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 379
384 #endif // !ARCH_CPU_64_BITS 380 #endif // !ARCH_CPU_64_BITS
385 #endif // OS_MACOSX 381 #endif // OS_MACOSX
386 382
387 class OutOfMemoryHandledTest : public OutOfMemoryTest { 383 class OutOfMemoryHandledTest : public OutOfMemoryTest {
388 public: 384 public:
389 static const size_t kSafeMallocSize = 512; 385 static const size_t kSafeMallocSize = 512;
390 static const size_t kSafeCallocSize = 128; 386 static const size_t kSafeCallocSize = 128;
391 static const size_t kSafeCallocItems = 4; 387 static const size_t kSafeCallocItems = 4;
392 388
393 virtual void SetUp() { 389 void SetUp() override {
394 OutOfMemoryTest::SetUp(); 390 OutOfMemoryTest::SetUp();
395 391
396 // We enable termination on OOM - just as Chrome does at early 392 // We enable termination on OOM - just as Chrome does at early
397 // initialization - and test that UncheckedMalloc and UncheckedCalloc 393 // initialization - and test that UncheckedMalloc and UncheckedCalloc
398 // properly by-pass this in order to allow the caller to handle OOM. 394 // properly by-pass this in order to allow the caller to handle OOM.
399 base::EnableTerminationOnOutOfMemory(); 395 base::EnableTerminationOnOutOfMemory();
400 } 396 }
401 }; 397 };
402 398
403 // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work 399 // TODO(b.kelemen): make UncheckedMalloc and UncheckedCalloc work
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 bytes = static_cast<const char*>(value_); 438 bytes = static_cast<const char*>(value_);
443 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i) 439 for (size_t i = 0; i < (kSafeCallocItems * kSafeCallocSize); ++i)
444 EXPECT_EQ(0, bytes[i]); 440 EXPECT_EQ(0, bytes[i]);
445 free(value_); 441 free(value_);
446 442
447 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_)); 443 EXPECT_FALSE(base::UncheckedCalloc(1, test_size_, &value_));
448 EXPECT_TRUE(value_ == NULL); 444 EXPECT_TRUE(value_ == NULL);
449 } 445 }
450 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 446 #endif // !defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
451 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN) 447 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && !defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/prefs/scoped_user_pref_update_unittest.cc ('k') | base/sequence_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698