Mercurial > hg > orthanc
comparison UnitTestsSources/MemoryCacheTests.cpp @ 1367:fe6e5a9f1ea2 query-retrieve
SharedArchive
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 22 May 2015 17:40:10 +0200 |
parents | 6e7e5ed91c2d |
children | f967bdf8534e |
comparison
equal
deleted
inserted
replaced
1366:a3559b66fba7 | 1367:fe6e5a9f1ea2 |
---|---|
37 #include <memory> | 37 #include <memory> |
38 #include <boost/thread.hpp> | 38 #include <boost/thread.hpp> |
39 #include <boost/lexical_cast.hpp> | 39 #include <boost/lexical_cast.hpp> |
40 #include "../Core/IDynamicObject.h" | 40 #include "../Core/IDynamicObject.h" |
41 #include "../Core/Cache/MemoryCache.h" | 41 #include "../Core/Cache/MemoryCache.h" |
42 #include "../Core/Cache/SharedArchive.h" | |
42 | 43 |
43 | 44 |
44 TEST(LRU, Basic) | 45 TEST(LRU, Basic) |
45 { | 46 { |
46 Orthanc::LeastRecentlyUsedIndex<std::string> r; | 47 Orthanc::LeastRecentlyUsedIndex<std::string> r; |
226 // Closing the cache: 47, 44, 42 are successively removed | 227 // Closing the cache: 47, 44, 42 are successively removed |
227 } | 228 } |
228 | 229 |
229 ASSERT_EQ("45 42 43 47 44 42 ", provider.log_); | 230 ASSERT_EQ("45 42 43 47 44 42 ", provider.log_); |
230 } | 231 } |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | |
238 | |
239 namespace | |
240 { | |
241 class S : public Orthanc::IDynamicObject | |
242 { | |
243 private: | |
244 std::string value_; | |
245 | |
246 public: | |
247 S(const std::string& value) : value_(value) | |
248 { | |
249 } | |
250 | |
251 const std::string& GetValue() const | |
252 { | |
253 return value_; | |
254 } | |
255 | |
256 static const std::string& Access(const Orthanc::IDynamicObject& obj) | |
257 { | |
258 return dynamic_cast<const S&>(obj).GetValue(); | |
259 } | |
260 }; | |
261 } | |
262 | |
263 | |
264 TEST(LRU, SharedArchive) | |
265 { | |
266 std::string first, second; | |
267 Orthanc::SharedArchive a(3); | |
268 first = a.Add(new S("First item")); | |
269 second = a.Add(new S("Second item")); | |
270 | |
271 for (int i = 1; i < 100; i++) | |
272 { | |
273 a.Add(new S("Item " + boost::lexical_cast<std::string>(i))); | |
274 // Continuously protect the two first items | |
275 try { Orthanc::SharedArchive::Accessor(a, first); } catch (Orthanc::OrthancException&) {} | |
276 try { Orthanc::SharedArchive::Accessor(a, second); } catch (Orthanc::OrthancException&) {} | |
277 } | |
278 | |
279 std::list<std::string> i; | |
280 a.List(i); | |
281 | |
282 size_t count = 0; | |
283 for (std::list<std::string>::const_iterator | |
284 it = i.begin(); it != i.end(); it++) | |
285 { | |
286 if (*it == first || | |
287 *it == second) | |
288 { | |
289 count++; | |
290 } | |
291 } | |
292 | |
293 ASSERT_EQ(2, count); | |
294 } |