OLD | NEW |
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 "SkDiscardableMemory.h" |
9 | 9 |
10 #include "Test.h" | 10 #include "Test.h" |
11 #include "TestClassDef.h" | |
12 | 11 |
13 DEF_TEST(DiscardableMemory, reporter) { | 12 DEF_TEST(DiscardableMemory, reporter) { |
14 const char testString[] = "HELLO, WORLD!"; | 13 const char testString[] = "HELLO, WORLD!"; |
15 const size_t len = sizeof(testString); | 14 const size_t len = sizeof(testString); |
16 SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len)); | 15 SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len)); |
17 REPORTER_ASSERT(reporter, dm.get() != NULL); | 16 REPORTER_ASSERT(reporter, dm.get() != NULL); |
18 if (NULL == dm.get()) { | 17 if (NULL == dm.get()) { |
19 return; | 18 return; |
20 } | 19 } |
21 void* ptr = dm->data(); | 20 void* ptr = dm->data(); |
22 REPORTER_ASSERT(reporter, ptr != NULL); | 21 REPORTER_ASSERT(reporter, ptr != NULL); |
23 memcpy(ptr, testString, sizeof(testString)); | 22 memcpy(ptr, testString, sizeof(testString)); |
24 dm->unlock(); | 23 dm->unlock(); |
25 bool success = dm->lock(); | 24 bool success = dm->lock(); |
26 REPORTER_ASSERT(reporter, success); | 25 REPORTER_ASSERT(reporter, success); |
27 if (!success) { | 26 if (!success) { |
28 return; | 27 return; |
29 } | 28 } |
30 ptr = dm->data(); | 29 ptr = dm->data(); |
31 REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); | 30 REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); |
32 dm->unlock(); | 31 dm->unlock(); |
33 } | 32 } |
OLD | NEW |