aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/DiscardableMemoryTest.cpp
blob: 1fbc28478f091d75f93e70e14ad44ea4f4f035eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 * 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"
#include "TestClassDef.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();
}