diff options
Diffstat (limited to 'libutils/tests/LruCache_test.cpp')
-rw-r--r-- | libutils/tests/LruCache_test.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp index dd95c576d..de440fd7e 100644 --- a/libutils/tests/LruCache_test.cpp +++ b/libutils/tests/LruCache_test.cpp @@ -80,6 +80,14 @@ struct KeyWithPointer { } }; +struct KeyFailsOnCopy : public ComplexKey { + public: + KeyFailsOnCopy(const KeyFailsOnCopy& key) : ComplexKey(key) { + ADD_FAILURE(); + } + KeyFailsOnCopy(int key) : ComplexKey(key) { } +}; + } // namespace @@ -95,6 +103,10 @@ template<> inline android::hash_t hash_type(const KeyWithPointer& value) { return hash_type(*value.ptr); } +template<> inline android::hash_t hash_type(const KeyFailsOnCopy& value) { + return hash_type<ComplexKey>(value); +} + class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> { public: EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(NULL) { } @@ -437,4 +449,10 @@ TEST_F(LruCacheTest, RemoveNonMember) { EXPECT_EQ(std::unordered_set<int>({ 4, 5, 6 }), returnedValues); } +TEST_F(LruCacheTest, DontCopyKeyInGet) { + LruCache<KeyFailsOnCopy, KeyFailsOnCopy> cache(1); + // Check that get doesn't copy the key + cache.get(KeyFailsOnCopy(0)); +} + } |