blob: cabd14b6ea4ef31b9bdf003512d34041018ff34b [file] [log] [blame]
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +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#include "SkDiscardableMemoryPool.h"
8
9#include "Test.h"
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000010
11DEF_TEST(DiscardableMemoryPool, reporter) {
12 SkAutoTUnref<SkDiscardableMemoryPool> pool(
halcanary96fcdcc2015-08-27 07:41:13 -070013 SkDiscardableMemoryPool::Create(1, nullptr));
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000014 pool->setRAMBudget(3);
15 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
16
17 SkAutoTDelete<SkDiscardableMemory> dm1(pool->create(100));
halcanary96fcdcc2015-08-27 07:41:13 -070018 REPORTER_ASSERT(reporter, dm1->data() != nullptr);
halcanary@google.com2c7c7ee2013-12-05 18:31:42 +000019 REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed());
20 dm1->unlock();
21 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
22 REPORTER_ASSERT(reporter, !dm1->lock());
23
24
25 SkAutoTDelete<SkDiscardableMemory> dm2(pool->create(200));
26 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
27 pool->setRAMBudget(400);
28 dm2->unlock();
29 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed());
30 REPORTER_ASSERT(reporter, dm2->lock());
31 dm2->unlock();
32 pool->dumpPool();
33 REPORTER_ASSERT(reporter, !dm2->lock());
34 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed());
35}