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 #include "TestClassDef.h" 11 12 DEF_TEST(DiscardableMemoryPool, reporter) { 13 SkAutoTUnref<SkDiscardableMemoryPool> pool( 14 SkNEW_ARGS(SkDiscardableMemoryPool, (1, NULL))); 15 pool->setRAMBudget(3); 16 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 17 18 SkAutoTDelete<SkDiscardableMemory> dm1(pool->create(100)); 19 REPORTER_ASSERT(reporter, dm1->data() != NULL); 20 REPORTER_ASSERT(reporter, 100 == pool->getRAMUsed()); 21 dm1->unlock(); 22 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 23 REPORTER_ASSERT(reporter, !dm1->lock()); 24 25 26 SkAutoTDelete<SkDiscardableMemory> dm2(pool->create(200)); 27 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); 28 pool->setRAMBudget(400); 29 dm2->unlock(); 30 REPORTER_ASSERT(reporter, 200 == pool->getRAMUsed()); 31 REPORTER_ASSERT(reporter, dm2->lock()); 32 dm2->unlock(); 33 pool->dumpPool(); 34 REPORTER_ASSERT(reporter, !dm2->lock()); 35 REPORTER_ASSERT(reporter, 0 == pool->getRAMUsed()); 36 } 37