annotate OrthancFramework/UnitTestsSources/MemoryCacheTests.cpp @ 4094:1c89208fbba9

fix build of orthanc framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 17:00:18 +0200
parents e00f3d089991
children bf7b9edf6b81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1654
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3557
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
7 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
8 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
10 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
12 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
13 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
16 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
20 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
21 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
22 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
23 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
24 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
27 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
28 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
29 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
31 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
32
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
33
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
35 // Must be the first to be sure to use the Orthanc framework shared library
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 # include <OrthancFramework.h>
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #endif
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
39 #include <gtest/gtest.h>
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1367
diff changeset
40
4059
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
41 #include "../Sources/Cache/MemoryCache.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 #include "../Sources/Cache/MemoryStringCache.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
43 #include "../Sources/Cache/SharedArchive.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
44 #include "../Sources/IDynamicObject.h"
e241e5f3f088 moved LuaTests and MemoryCacheTests from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
45 #include "../Sources/Logging.h"
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
47 #include <memory>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
48 #include <algorithm>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
49 #include <boost/thread.hpp>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
50 #include <boost/lexical_cast.hpp>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4059
diff changeset
51
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
53 TEST(LRU, Basic)
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
55 Orthanc::LeastRecentlyUsedIndex<std::string> r;
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 r.Add("d");
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 r.Add("a");
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 r.Add("c");
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 r.Add("b");
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
62 r.MakeMostRecent("a");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
63 r.MakeMostRecent("d");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
64 r.MakeMostRecent("b");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
65 r.MakeMostRecent("c");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
66 r.MakeMostRecent("d");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
67 r.MakeMostRecent("c");
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
69 ASSERT_EQ("a", r.GetOldest());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ASSERT_EQ("a", r.RemoveOldest());
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
71 ASSERT_EQ("b", r.GetOldest());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ASSERT_EQ("b", r.RemoveOldest());
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
73 ASSERT_EQ("d", r.GetOldest());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_EQ("d", r.RemoveOldest());
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
75 ASSERT_EQ("c", r.GetOldest());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_EQ("c", r.RemoveOldest());
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ASSERT_TRUE(r.IsEmpty());
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
79
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
80 ASSERT_THROW(r.GetOldest(), Orthanc::OrthancException);
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
81 ASSERT_THROW(r.RemoveOldest(), Orthanc::OrthancException);
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
85 TEST(LRU, Payload)
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 {
505
f59e4518fd57 rename CacheIndex as LeastRecentlyUsedIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 285
diff changeset
87 Orthanc::LeastRecentlyUsedIndex<std::string, int> r;
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 r.Add("a", 420);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 r.Add("b", 421);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 r.Add("c", 422);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 r.Add("d", 423);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
94 r.MakeMostRecent("a");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
95 r.MakeMostRecent("d");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
96 r.MakeMostRecent("b");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
97 r.MakeMostRecent("c");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
98 r.MakeMostRecent("d");
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
99 r.MakeMostRecent("c");
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_TRUE(r.Contains("b"));
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ASSERT_EQ(421, r.Invalidate("b"));
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ASSERT_FALSE(r.Contains("b"));
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 int p;
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
106 ASSERT_TRUE(r.Contains("a", p)); ASSERT_EQ(420, p);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
107 ASSERT_TRUE(r.Contains("c", p)); ASSERT_EQ(422, p);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
108 ASSERT_TRUE(r.Contains("d", p)); ASSERT_EQ(423, p);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
109
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
110 ASSERT_EQ("a", r.GetOldest());
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
111 ASSERT_EQ(420, r.GetOldestPayload());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_EQ("a", r.RemoveOldest(p)); ASSERT_EQ(420, p);
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
113
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
114 ASSERT_EQ("d", r.GetOldest());
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
115 ASSERT_EQ(423, r.GetOldestPayload());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_EQ("d", r.RemoveOldest(p)); ASSERT_EQ(423, p);
507
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
117
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
118 ASSERT_EQ("c", r.GetOldest());
c4122c3a47c1 access to oldest item in LRUCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 505
diff changeset
119 ASSERT_EQ(422, r.GetOldestPayload());
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 ASSERT_EQ("c", r.RemoveOldest(p)); ASSERT_EQ(422, p);
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ASSERT_TRUE(r.IsEmpty());
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
126 TEST(LRU, PayloadUpdate)
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
127 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
128 Orthanc::LeastRecentlyUsedIndex<std::string, int> r;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
129
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
130 r.Add("a", 420);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
131 r.Add("b", 421);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
132 r.Add("d", 423);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
133
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
134 r.MakeMostRecent("a", 424);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
135 r.MakeMostRecent("d", 421);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
136
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
137 ASSERT_EQ("b", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
138 ASSERT_EQ(421, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
139 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
140
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
141 ASSERT_EQ("a", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
142 ASSERT_EQ(424, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
143 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
144
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
145 ASSERT_EQ("d", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
146 ASSERT_EQ(421, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
147 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
148
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
149 ASSERT_TRUE(r.IsEmpty());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
150 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
151
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
152
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
153
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
154 TEST(LRU, PayloadUpdateBis)
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
155 {
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
156 Orthanc::LeastRecentlyUsedIndex<std::string, int> r;
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
157
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
158 r.AddOrMakeMostRecent("a", 420);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
159 r.AddOrMakeMostRecent("b", 421);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
160 r.AddOrMakeMostRecent("d", 423);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
161 r.AddOrMakeMostRecent("a", 424);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
162 r.AddOrMakeMostRecent("d", 421);
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
163
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
164 ASSERT_EQ("b", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
165 ASSERT_EQ(421, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
166 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
167
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
168 ASSERT_EQ("a", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
169 ASSERT_EQ(424, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
170 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
171
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
172 ASSERT_EQ("d", r.GetOldest());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
173 ASSERT_EQ(421, r.GetOldestPayload());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
174 r.RemoveOldest();
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
175
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
176 ASSERT_TRUE(r.IsEmpty());
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
177 }
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
178
3454
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
179 TEST(LRU, GetAllKeys)
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
180 {
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
181 Orthanc::LeastRecentlyUsedIndex<std::string, int> r;
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
182 std::vector<std::string> keys;
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
183
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
184 r.AddOrMakeMostRecent("a", 420);
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
185 r.GetAllKeys(keys);
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
186
3497
db71bd11affc fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3454
diff changeset
187 ASSERT_EQ(1u, keys.size());
3454
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
188 ASSERT_EQ("a", keys[0]);
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
189
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
190 r.AddOrMakeMostRecent("b", 421);
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
191 r.GetAllKeys(keys);
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
192
3497
db71bd11affc fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3454
diff changeset
193 ASSERT_EQ(2u, keys.size());
3454
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
194 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"a") != keys.end());
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
195 ASSERT_TRUE(std::find(keys.begin(), keys.end(),"b") != keys.end());
0e3c26e4b8ec LeastRecentlyUsedIndex::GetAllKeys (test)
Alain Mazy <alain@mazy.be>
parents: 3060
diff changeset
196 }
509
e7841864c97c StableResourcesMonitor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 507
diff changeset
197
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
198
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
199
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
200 namespace
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
201 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
202 class Integer : public Orthanc::IDynamicObject
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
203 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
204 private:
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
205 std::string& log_;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
206 int value_;
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 public:
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
209 Integer(std::string& log, int v) : log_(log), value_(v)
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
210 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
211 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
212
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
213 virtual ~Integer() ORTHANC_OVERRIDE
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
214 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
215 LOG(INFO) << "Removing cache entry for " << value_;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
216 log_ += boost::lexical_cast<std::string>(value_) + " ";
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
217 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
218 };
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
219
3557
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
220 class IntegerProvider : public Orthanc::Deprecated::ICachePageProvider
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
221 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
222 public:
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
223 std::string log_;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
224
2924
22524fd06225 macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
225 virtual Orthanc::IDynamicObject* Provide(const std::string& s) ORTHANC_OVERRIDE
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
226 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
227 LOG(INFO) << "Providing " << s;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
228 return new Integer(log_, boost::lexical_cast<int>(s));
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
229 }
282
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 };
915ed24547ea cache lru policy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
232
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
233
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
234 TEST(MemoryCache, Basic)
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
235 {
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
236 IntegerProvider provider;
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
237
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
238 {
3557
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
239 Orthanc::Deprecated::MemoryCache cache(provider, 3);
285
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
240 cache.Access("42"); // 42 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
241 cache.Access("43"); // 43, 42 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
242 cache.Access("45"); // 45, 43, 42 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
243 cache.Access("42"); // 42, 45, 43 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
244 cache.Access("43"); // 43, 42, 45 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
245 cache.Access("47"); // 45 is removed; 47, 43, 42 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
246 cache.Access("44"); // 42 is removed; 44, 47, 43 -> exit
4031f73fe0e4 access to the raw dicom tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 284
diff changeset
247 cache.Access("42"); // 43 is removed; 42, 44, 47 -> exit
283
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
248 // Closing the cache: 47, 44, 42 are successively removed
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
249 }
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
250
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
251 ASSERT_EQ("45 42 43 47 44 42 ", provider.log_);
c9977db00e1d caching
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 282
diff changeset
252 }
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
253
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
254
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
255
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
256
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
257
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
258 namespace
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
259 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
260 class S : public Orthanc::IDynamicObject
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
261 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
262 private:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
263 std::string value_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
264
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
265 public:
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
266 S(const std::string& value) : value_(value)
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
267 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
268 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
269
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
270 const std::string& GetValue() const
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
271 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
272 return value_;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
273 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
274 };
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
275 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
276
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
277
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
278 TEST(LRU, SharedArchive)
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
279 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
280 std::string first, second;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
281 Orthanc::SharedArchive a(3);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
282 first = a.Add(new S("First item"));
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
283 second = a.Add(new S("Second item"));
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
284
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
285 for (int i = 1; i < 100; i++)
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
286 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
287 a.Add(new S("Item " + boost::lexical_cast<std::string>(i)));
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
288
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
289 // Continuously protect the two first items
2976
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
290 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
291 Orthanc::SharedArchive::Accessor accessor(a, first);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
292 ASSERT_TRUE(accessor.IsValid());
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
293 ASSERT_EQ("First item", dynamic_cast<S&>(accessor.GetItem()).GetValue());
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
294 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
295
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
296 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
297 Orthanc::SharedArchive::Accessor accessor(a, second);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
298 ASSERT_TRUE(accessor.IsValid());
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
299 ASSERT_EQ("Second item", dynamic_cast<S&>(accessor.GetItem()).GetValue());
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
300 }
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
301
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
302 {
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
303 Orthanc::SharedArchive::Accessor accessor(a, "nope");
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
304 ASSERT_FALSE(accessor.IsValid());
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
305 ASSERT_THROW(accessor.GetItem(), Orthanc::OrthancException);
cb5d75143da0 Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2924
diff changeset
306 }
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
307 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
308
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
309 std::list<std::string> i;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
310 a.List(i);
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
311
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
312 size_t count = 0;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
313 for (std::list<std::string>::const_iterator
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
314 it = i.begin(); it != i.end(); it++)
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
315 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
316 if (*it == first ||
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
317 *it == second)
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
318 {
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
319 count++;
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
320 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
321 }
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
322
1492
9f66a12eb8fc fix warnings for gcc 5
jodogne
parents: 1486
diff changeset
323 ASSERT_EQ(2u, count);
1367
fe6e5a9f1ea2 SharedArchive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
324 }
3557
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
325
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
326
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
327 TEST(MemoryStringCache, Basic)
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
328 {
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
329 Orthanc::MemoryStringCache c;
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
330 ASSERT_THROW(c.SetMaximumSize(0), Orthanc::OrthancException);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
331
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
332 c.SetMaximumSize(2);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
333
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
334 std::string v;
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
335 ASSERT_FALSE(c.Fetch(v, "hello"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
336
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
337 c.Add("hello", "a");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
338 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
339 ASSERT_FALSE(c.Fetch(v, "hello2"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
340 ASSERT_FALSE(c.Fetch(v, "hello3"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
341
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
342 c.Add("hello2", "b");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
343 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
344 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
345 ASSERT_FALSE(c.Fetch(v, "hello3"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
346
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
347 c.Add("hello3", "too large value");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
348 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
349 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
350 ASSERT_FALSE(c.Fetch(v, "hello3"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
351
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
352 c.Add("hello3", "c");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
353 ASSERT_FALSE(c.Fetch(v, "hello")); // Recycled
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
354 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
355 ASSERT_TRUE(c.Fetch(v, "hello3")); ASSERT_EQ("c", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
356 }
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
357
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
358
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
359 TEST(MemoryStringCache, Invalidate)
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
360 {
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
361 Orthanc::MemoryStringCache c;
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
362 c.Add("hello", "a");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
363 c.Add("hello2", "b");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
364
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
365 std::string v;
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
366 ASSERT_TRUE(c.Fetch(v, "hello")); ASSERT_EQ("a", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
367 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
368
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
369 c.Invalidate("hello");
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
370 ASSERT_FALSE(c.Fetch(v, "hello"));
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
371 ASSERT_TRUE(c.Fetch(v, "hello2")); ASSERT_EQ("b", v);
4d809b2e1141 better cache toolbox: MemoryObjectCache
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3497
diff changeset
372 }