Fix Content-Transfer-Encoding value
[TortoiseGit.git] / test / UnitTests / LruCacheTest.cpp
bloba7e5cc1bc4b1aa641c510f74c7de612c0f592809
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2016 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
22 #include "LruCache.h"
24 TEST(LruCache, InsertGet)
26 LruCache<int, int> cache(2);
27 cache.insert_or_assign(1, 100);
28 cache.insert_or_assign(2, 200);
29 // Emulate access to key '1'
30 cache.try_get(1);
32 // Add third entry. Key '2' should be evicted/
33 cache.insert_or_assign(3, 300);
35 EXPECT_NE(nullptr, cache.try_get(1));
36 EXPECT_EQ(100, *cache.try_get(1));
38 EXPECT_EQ(nullptr, cache.try_get(2));
40 EXPECT_NE(nullptr, cache.try_get(3));
41 EXPECT_EQ(300, *cache.try_get(3));
43 // Test LruCache.clear()
44 cache.clear();
45 EXPECT_EQ(nullptr, cache.try_get(1));
46 EXPECT_EQ(nullptr, cache.try_get(2));
47 EXPECT_EQ(nullptr, cache.try_get(3));
49 cache.insert_or_assign(1, 100);
50 cache.insert_or_assign(3, 300);
52 EXPECT_NE(nullptr, cache.try_get(1));
53 EXPECT_EQ(100, *cache.try_get(1));
54 EXPECT_NE(nullptr, cache.try_get(3));
55 EXPECT_EQ(300, *cache.try_get(3));
57 // Replace value associated with key '1'.
58 cache.insert_or_assign(1, 101);
59 EXPECT_NE(nullptr, cache.try_get(1));
61 EXPECT_EQ(101, *cache.try_get(1));
62 EXPECT_NE(nullptr, cache.try_get(3));
63 EXPECT_EQ(300, *cache.try_get(3));
66 TEST(LruCache, EmptyCache)
68 LruCache<int, int> cache(5);
69 EXPECT_EQ(nullptr, cache.try_get(1));
70 EXPECT_EQ(nullptr, cache.try_get(2));
71 EXPECT_EQ(nullptr, cache.try_get(3));