halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkDiscardableMemory.h" |
| 9 | |
| 10 | #include "Test.h" |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 11 | |
| 12 | DEF_TEST(DiscardableMemory, reporter) { |
| 13 | const char testString[] = "HELLO, WORLD!"; |
| 14 | const size_t len = sizeof(testString); |
| 15 | SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 16 | REPORTER_ASSERT(reporter, dm.get() != nullptr); |
| 17 | if (nullptr == dm.get()) { |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 18 | return; |
| 19 | } |
| 20 | void* ptr = dm->data(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 21 | REPORTER_ASSERT(reporter, ptr != nullptr); |
halcanary@google.com | bc55eec | 2013-12-10 18:33:07 +0000 | [diff] [blame] | 22 | memcpy(ptr, testString, sizeof(testString)); |
| 23 | dm->unlock(); |
| 24 | bool success = dm->lock(); |
| 25 | REPORTER_ASSERT(reporter, success); |
| 26 | if (!success) { |
| 27 | return; |
| 28 | } |
| 29 | ptr = dm->data(); |
| 30 | REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len)); |
| 31 | dm->unlock(); |
| 32 | } |