blob: da36ffd8b00342accac6eb7d2baee83d76beac19 [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));
16 REPORTER_ASSERT(reporter, dm.get() != NULL);
17 if (NULL == dm.get()) {
18 return;
19 }
20 void* ptr = dm->data();
21 REPORTER_ASSERT(reporter, ptr != NULL);
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}