skia2/tests/DiscardableMemoryTest.cpp
commit-bot@chromium.org e2eac8b2fd Move macros from TestClassDef.h to Test.h
Motivation: those macros don't make any sense without the definitions
in Test.h.

BUG=
R=mtklein@google.com

Author: halcanary@google.com

Review URL: https://codereview.chromium.org/138563004

git-svn-id: http://skia.googlecode.com/svn/trunk@13074 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-14 21:04:37 +00:00

33 lines
864 B
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkDiscardableMemory.h"
#include "Test.h"
DEF_TEST(DiscardableMemory, reporter) {
const char testString[] = "HELLO, WORLD!";
const size_t len = sizeof(testString);
SkAutoTDelete<SkDiscardableMemory> dm(SkDiscardableMemory::Create(len));
REPORTER_ASSERT(reporter, dm.get() != NULL);
if (NULL == dm.get()) {
return;
}
void* ptr = dm->data();
REPORTER_ASSERT(reporter, ptr != NULL);
memcpy(ptr, testString, sizeof(testString));
dm->unlock();
bool success = dm->lock();
REPORTER_ASSERT(reporter, success);
if (!success) {
return;
}
ptr = dm->data();
REPORTER_ASSERT(reporter, 0 == memcmp(ptr, testString, len));
dm->unlock();
}