static void TestBitmapFactory(skiatest::Reporter* reporter) { SkAutoTDelete<SkBitmap> bitmap(create_bitmap()); SkASSERT(bitmap.get() != NULL); SkAutoDataUnref encodedBitmap(create_data_from_bitmap(*bitmap.get())); bool encodeSucceeded = encodedBitmap.get() != NULL; SkASSERT(encodeSucceeded); ImageCacheHolder cacheHolder; SkAutoTUnref<SkLruImageCache> lruCache(SkNEW_ARGS(SkLruImageCache, (1024 * 1024))); cacheHolder.addImageCache(lruCache); cacheHolder.addImageCache(NULL); SkImageCache* purgeableCache = SkPurgeableImageCache::Create(); if (purgeableCache != NULL) { cacheHolder.addImageCache(purgeableCache); purgeableCache->unref(); } for (int i = 0; i < cacheHolder.count(); i++) { SkImageCache* cache = cacheHolder.getAt(i); if (cache != NULL) { test_cache(reporter, cache); } if (encodeSucceeded) { test_factory(reporter, cache, encodedBitmap, *bitmap.get()); } } }
int main(int argc, char **argv) { unoekone::interview::LRUCache<int> lruCache(5); lruCache.add("hello", 1); lruCache.add("jello", 2); lruCache.add("mello", 3); lruCache.print(); int out = -1; lruCache.get("jello", out); std::cout << "jello = " << out << std::endl; lruCache.print(); lruCache.get("hello", out); std::cout << "hello = " << out << std::endl; lruCache.print(); lruCache.add("fello", 4); lruCache.print(); std::cout << "remove(\"fello\") = " << lruCache.remove("fello") << std::endl; lruCache.print(); return 0; }