OLD | NEW |
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 "SkDiscardableMemory.h" | 8 #include "SkDiscardableMemory.h" |
9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 REPORTER_ASSERT(reporter, -1 == value); | 49 REPORTER_ASSERT(reporter, -1 == value); |
50 | 50 |
51 cache.add(SkNEW_ARGS(TestingRec, (key, i))); | 51 cache.add(SkNEW_ARGS(TestingRec, (key, i))); |
52 | 52 |
53 REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value)); | 53 REPORTER_ASSERT(reporter, cache.find(key, TestingRec::Visitor, &value)); |
54 REPORTER_ASSERT(reporter, i == value); | 54 REPORTER_ASSERT(reporter, i == value); |
55 } | 55 } |
56 | 56 |
57 if (testPurge) { | 57 if (testPurge) { |
58 // stress test, should trigger purges | 58 // stress test, should trigger purges |
59 for (size_t i = 0; i < COUNT * 100; ++i) { | 59 for (int i = 0; i < COUNT * 100; ++i) { |
60 TestingKey key(i); | 60 TestingKey key(i); |
61 cache.add(SkNEW_ARGS(TestingRec, (key, i))); | 61 cache.add(SkNEW_ARGS(TestingRec, (key, i))); |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 // test the originals after all that purging | 65 // test the originals after all that purging |
66 for (int i = 0; i < COUNT; ++i) { | 66 for (int i = 0; i < COUNT; ++i) { |
67 intptr_t value; | 67 intptr_t value; |
68 (void)cache.find(TestingKey(i), TestingRec::Visitor, &value); | 68 (void)cache.find(TestingKey(i), TestingRec::Visitor, &value); |
69 } | 69 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 TestingKey key(1); | 106 TestingKey key(1); |
107 | 107 |
108 cache.add(SkNEW_ARGS(TestingRec, (key, 2))); | 108 cache.add(SkNEW_ARGS(TestingRec, (key, 2))); |
109 cache.add(SkNEW_ARGS(TestingRec, (key, 3))); | 109 cache.add(SkNEW_ARGS(TestingRec, (key, 3))); |
110 | 110 |
111 // Lookup can return either value. | 111 // Lookup can return either value. |
112 intptr_t value = -1; | 112 intptr_t value = -1; |
113 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); | 113 REPORTER_ASSERT(r, cache.find(key, TestingRec::Visitor, &value)); |
114 REPORTER_ASSERT(r, 2 == value || 3 == value); | 114 REPORTER_ASSERT(r, 2 == value || 3 == value); |
115 } | 115 } |
OLD | NEW |