aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/DiscardableMemoryPoolTest.cpp
blob: cabd14b6ea4ef31b9bdf003512d34041018ff34b (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
35
/*
 * 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 "SkDiscardableMemoryPool.h"

#include "Test.h"

DEF_TEST(DiscardableMemoryPool, reporter) {
    SkAutoTUnref<SkDiscardableMemoryPool> pool(
        SkDiscardableMemoryPool::Create(1, nullptr));
    pool->setRAMBudget(3);
    REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());

    SkAutoTDelete<SkDiscardableMemory> dm1(pool->create(100));
    REPORTER_ASSERT(reporter, dm1->data() != nullptr);
    REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed());
    dm1->unlock();
    REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
    REPORTER_ASSERT(reporter, !dm1->lock());


    SkAutoTDelete<SkDiscardableMemory> dm2(pool->create(200));
    REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
    pool->setRAMBudget(400);
    dm2->unlock();
    REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
    REPORTER_ASSERT(reporter, dm2->lock());
    dm2->unlock();
    pool->dumpPool();
    REPORTER_ASSERT(reporter, !dm2->lock());
    REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
}