| 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 27 matching lines...) Expand all Loading... |
| 38 SkResourceCache::ID id; | 38 SkResourceCache::ID id; |
| 39 | 39 |
| 40 for (int i = 0; i < COUNT; ++i) { | 40 for (int i = 0; i < COUNT; ++i) { |
| 41 TestingKey key(i); | 41 TestingKey key(i); |
| 42 | 42 |
| 43 const TestingRec* rec = (const TestingRec*)cache.findAndLock(key); | 43 const TestingRec* rec = (const TestingRec*)cache.findAndLock(key); |
| 44 REPORTER_ASSERT(reporter, NULL == rec); | 44 REPORTER_ASSERT(reporter, NULL == rec); |
| 45 | 45 |
| 46 TestingRec* newRec = SkNEW_ARGS(TestingRec, (key, i)); | 46 TestingRec* newRec = SkNEW_ARGS(TestingRec, (key, i)); |
| 47 const TestingRec* addedRec = (const TestingRec*)cache.addAndLock(newRec)
; | 47 const TestingRec* addedRec = (const TestingRec*)cache.addAndLock(newRec)
; |
| 48 REPORTER_ASSERT(reporter, NULL != addedRec); | 48 REPORTER_ASSERT(reporter, addedRec); |
| 49 | 49 |
| 50 const TestingRec* foundRec = (const TestingRec*)cache.findAndLock(key); | 50 const TestingRec* foundRec = (const TestingRec*)cache.findAndLock(key); |
| 51 REPORTER_ASSERT(reporter, foundRec == addedRec); | 51 REPORTER_ASSERT(reporter, foundRec == addedRec); |
| 52 REPORTER_ASSERT(reporter, foundRec->fValue == i); | 52 REPORTER_ASSERT(reporter, foundRec->fValue == i); |
| 53 cache.unlock(foundRec); | 53 cache.unlock(foundRec); |
| 54 cache.unlock(addedRec); | 54 cache.unlock(addedRec); |
| 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 (size_t i = 0; i < COUNT * 100; ++i) { |
| 60 TestingKey key(i); | 60 TestingKey key(i); |
| 61 SkResourceCache::ID id = cache.addAndLock(SkNEW_ARGS(TestingRec, (ke
y, i))); | 61 SkResourceCache::ID id = cache.addAndLock(SkNEW_ARGS(TestingRec, (ke
y, i))); |
| 62 REPORTER_ASSERT(reporter, NULL != id); | 62 REPORTER_ASSERT(reporter, id); |
| 63 cache.unlock(id); | 63 cache.unlock(id); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 // test the originals after all that purging | 67 // test the originals after all that purging |
| 68 for (int i = 0; i < COUNT; ++i) { | 68 for (int i = 0; i < COUNT; ++i) { |
| 69 id = cache.findAndLock(TestingKey(i)); | 69 id = cache.findAndLock(TestingKey(i)); |
| 70 if (id) { | 70 if (id) { |
| 71 cache.unlock(id); | 71 cache.unlock(id); |
| 72 } | 72 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 TestingKey key(1); | 110 TestingKey key(1); |
| 111 | 111 |
| 112 SkResourceCache::ID id1 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 2)))
; | 112 SkResourceCache::ID id1 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 2)))
; |
| 113 SkResourceCache::ID id2 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 3)))
; | 113 SkResourceCache::ID id2 = cache.addAndLock(SkNEW_ARGS(TestingRec, (key, 3)))
; |
| 114 // We don't really care if id1 == id2 as long as unlocking both works. | 114 // We don't really care if id1 == id2 as long as unlocking both works. |
| 115 cache.unlock(id1); | 115 cache.unlock(id1); |
| 116 cache.unlock(id2); | 116 cache.unlock(id2); |
| 117 | 117 |
| 118 // Lookup can return either value. | 118 // Lookup can return either value. |
| 119 const TestingRec* rec = (const TestingRec*)cache.findAndLock(key); | 119 const TestingRec* rec = (const TestingRec*)cache.findAndLock(key); |
| 120 REPORTER_ASSERT(r, NULL != rec); | 120 REPORTER_ASSERT(r, rec); |
| 121 REPORTER_ASSERT(r, 2 == rec->fValue || 3 == rec->fValue); | 121 REPORTER_ASSERT(r, 2 == rec->fValue || 3 == rec->fValue); |
| 122 cache.unlock(rec); | 122 cache.unlock(rec); |
| 123 } | 123 } |
| OLD | NEW |