blob: 28dd6e98a5d1bf35eacc3414986efc0885a3833c [file] [log] [blame]
halcanary@google.combc55eec2013-12-10 18:33:07 +00001/*
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.combc55eec2013-12-10 18:33:07 +000011
12DEF_TEST(DiscardableMemory, reporter) {
13 const char testString[] = "HELLO, WORLD!";
14 const size_t len = sizeof(testString);
15 SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len));
halcanary96fcdcc2015-08-27 07:41:13 -070016 REPORTER_ASSERT(reporter, dm.get() != nullptr);
17 if (nullptr == dm.get()) {
halcanary@google.combc55eec2013-12-10 18:33:07 +000018 return;
19 }
20 void* ptr = dm->data();
halcanary96fcdcc2015-08-27 07:41:13 -070021 REPORTER_ASSERT(reporter, ptr != nullptr);
halcanary@google.combc55eec2013-12-10 18:33:07 +000022 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}