1 /* 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" 10 11 DEF_TEST(DiscardableMemoryPool, reporter) { 12 sk_sp<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Make(1)); 13 pool->setRAMBudget(3); 14 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 15 16 std::unique_ptr<SkDiscardableMemory> dm1(pool->create(100)); 17 REPORTER_ASSERT(reporter, dm1->data() != nullptr); 18 REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed()); 19 dm1->unlock(); 20 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 21 REPORTER_ASSERT(reporter, !dm1->lock()); 22 23 24 std::unique_ptr<SkDiscardableMemory> dm2(pool->create(200)); 25 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); 26 pool->setRAMBudget(400); 27 dm2->unlock(); 28 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); 29 REPORTER_ASSERT(reporter, dm2->lock()); 30 dm2->unlock(); 31 pool->dumpPool(); 32 REPORTER_ASSERT(reporter, !dm2->lock()); 33 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 34 } 35