Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: tests/ImageCacheTest.cpp

Issue 100113004: Use DEFINE_TESTCLASS_SHORT macro in tests. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/HashCacheTest.cpp ('k') | tests/ImageDecodingTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h"
9 #include "SkDiscardableMemory.h" 10 #include "SkDiscardableMemory.h"
10 #include "SkScaledImageCache.h" 11 #include "SkScaledImageCache.h"
11 12
12 static void make_bm(SkBitmap* bm, int w, int h) { 13 static void make_bm(SkBitmap* bm, int w, int h) {
13 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h); 14 bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
14 bm->allocPixels(); 15 bm->allocPixels();
15 } 16 }
16 17
17 static const int COUNT = 10; 18 static const int COUNT = 10;
18 static const int DIM = 256; 19 static const int DIM = 256;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 cache.setByteLimit(0); 79 cache.setByteLimit(0);
79 } 80 }
80 81
81 #include "SkDiscardableMemoryPool.h" 82 #include "SkDiscardableMemoryPool.h"
82 83
83 static SkDiscardableMemoryPool* gPool; 84 static SkDiscardableMemoryPool* gPool;
84 static SkDiscardableMemory* pool_factory(size_t bytes) { 85 static SkDiscardableMemory* pool_factory(size_t bytes) {
85 return gPool->create(bytes); 86 return gPool->create(bytes);
86 } 87 }
87 88
88 static void TestImageCache(skiatest::Reporter* reporter) { 89 DEF_TEST(ImageCache, reporter) {
89 static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop 90 static const size_t defLimit = DIM * DIM * 4 * COUNT + 1024; // 1K slop
90 91
91 { 92 {
92 SkScaledImageCache cache(defLimit); 93 SkScaledImageCache cache(defLimit);
93 test_cache(reporter, cache, true); 94 test_cache(reporter, cache, true);
94 } 95 }
95 { 96 {
96 SkDiscardableMemoryPool pool(defLimit); 97 SkDiscardableMemoryPool pool(defLimit);
97 gPool = &pool; 98 gPool = &pool;
98 SkScaledImageCache cache(pool_factory); 99 SkScaledImageCache cache(pool_factory);
99 test_cache(reporter, cache, true); 100 test_cache(reporter, cache, true);
100 } 101 }
101 { 102 {
102 SkScaledImageCache cache(SkDiscardableMemory::Create); 103 SkScaledImageCache cache(SkDiscardableMemory::Create);
103 test_cache(reporter, cache, false); 104 test_cache(reporter, cache, false);
104 } 105 }
105 } 106 }
106 107
107 #include "TestClassDef.h"
108 DEFINE_TESTCLASS("ImageCache", TestImageCacheClass, TestImageCache)
109
110 DEF_TEST(ImageCache_doubleAdd, r) { 108 DEF_TEST(ImageCache_doubleAdd, r) {
111 // Adding the same key twice should be safe. 109 // Adding the same key twice should be safe.
112 SkScaledImageCache cache(1024); 110 SkScaledImageCache cache(1024);
113 111
114 SkBitmap original; 112 SkBitmap original;
115 original.setConfig(SkBitmap::kARGB_8888_Config, 40, 40); 113 original.setConfig(SkBitmap::kARGB_8888_Config, 40, 40);
116 original.allocPixels(); 114 original.allocPixels();
117 115
118 SkBitmap scaled; 116 SkBitmap scaled;
119 scaled.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); 117 scaled.setConfig(SkBitmap::kARGB_8888_Config, 20, 20);
120 scaled.allocPixels(); 118 scaled.allocPixels();
121 119
122 SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ; 120 SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ;
123 SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ; 121 SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled) ;
124 // We don't really care if id1 == id2 as long as unlocking both works. 122 // We don't really care if id1 == id2 as long as unlocking both works.
125 cache.unlock(id1); 123 cache.unlock(id1);
126 cache.unlock(id2); 124 cache.unlock(id2);
127 } 125 }
OLDNEW
« no previous file with comments | « tests/HashCacheTest.cpp ('k') | tests/ImageDecodingTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698