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

Side by Side Diff: tests/DiscardableMemoryTest.cpp

Issue 2323013002: Tests: DiscardableMemory test no longer relies on global state (Closed)
Patch Set: Created 4 years, 3 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 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDiscardableMemory.h" 8 #include "SkDiscardableMemoryPool.h"
9 9
10 #include "Test.h" 10 #include "Test.h"
11 11
12 DEF_TEST(DiscardableMemory, reporter) { 12 namespace {
13 const char testString[] = "HELLO, WORLD!"; 13 constexpr char kTestString[] = "HELLO, WORLD!";
14 const size_t len = sizeof(testString); 14 constexpr size_t kTestStringLength = sizeof(kTestString);
15 SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len)); 15 }
16 REPORTER_ASSERT(reporter, dm.get() != nullptr); 16
17 if (nullptr == dm.get()) { 17 static void test_dm(skiatest::Reporter* reporter,
18 SkDiscardableMemory* dm,
19 bool assertRelock) {
20 REPORTER_ASSERT(reporter, dm);
21 if (!dm) {
18 return; 22 return;
19 } 23 }
20 void* ptr = dm->data(); 24 void* ptr = dm->data();
21 REPORTER_ASSERT(reporter, ptr != nullptr); 25 REPORTER_ASSERT(reporter, ptr);
22 memcpy(ptr, testString, sizeof(testString)); 26 if (!ptr) {
27 return;
28 }
29 memcpy(ptr, kTestString, sizeof(kTestString));
23 dm->unlock(); 30 dm->unlock();
24 bool success = dm->lock(); 31 bool relockSuccess = dm->lock();
25 REPORTER_ASSERT(reporter, success); 32 if (assertRelock) {
26 if (!success) { 33 REPORTER_ASSERT(reporter, relockSuccess);
34 }
35 if (!relockSuccess) {
27 return; 36 return;
28 } 37 }
29 ptr = dm->data(); 38 ptr = dm->data();
30 REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); 39 REPORTER_ASSERT(reporter, ptr);
40 if (!ptr) {
41 return;
42 }
43 REPORTER_ASSERT(reporter, 0 == memcmp(ptr, kTestString, kTestStringLength));
31 dm->unlock(); 44 dm->unlock();
32 } 45 }
46
47 DEF_TEST(DiscardableMemory_global, reporter) {
48 std::unique_ptr<SkDiscardableMemory> dm(SkDiscardableMemory::Create(kTestStr ingLength));
49 // lock() test is allowed to fail, since other threads could be
50 // using global pool.
51 test_dm(reporter, dm.get(), false);
52 }
53
54 DEF_TEST(DiscardableMemory_nonglobal, reporter) {
55 std::unique_ptr<SkDiscardableMemoryPool> pool(
56 SkDiscardableMemoryPool::Create(1024, /* mutex = */ nullptr));
57 std::unique_ptr<SkDiscardableMemory> dm(pool->create(kTestStringLength));
58 test_dm(reporter, dm.get(), true);
59 }
60
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