CookieStorageTest.cc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. #include "CookieStorage.h"
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <limits>
  5. #include <cppunit/extensions/HelperMacros.h>
  6. #include "Exception.h"
  7. #include "util.h"
  8. #include "TimeA2.h"
  9. #include "RecoverableException.h"
  10. #include "File.h"
  11. #include "TestUtil.h"
  12. #include "TimerA2.h"
  13. namespace aria2 {
  14. class CookieStorageTest : public CppUnit::TestFixture {
  15. CPPUNIT_TEST_SUITE(CookieStorageTest);
  16. CPPUNIT_TEST(testStore);
  17. CPPUNIT_TEST(testParseAndStore);
  18. CPPUNIT_TEST(testCriteriaFind);
  19. CPPUNIT_TEST(testCriteriaFind_cookieOrder);
  20. CPPUNIT_TEST(testLoad);
  21. CPPUNIT_TEST(testLoad_sqlite3);
  22. CPPUNIT_TEST(testLoad_fileNotfound);
  23. CPPUNIT_TEST(testSaveNsFormat);
  24. CPPUNIT_TEST(testSaveNsFormat_fail);
  25. CPPUNIT_TEST(testCookieIsFull);
  26. CPPUNIT_TEST(testDomainIsFull);
  27. CPPUNIT_TEST(testEviction);
  28. CPPUNIT_TEST_SUITE_END();
  29. public:
  30. void setUp() {}
  31. void tearDown() {}
  32. void testStore();
  33. void testParseAndStore();
  34. void testCriteriaFind();
  35. void testCriteriaFind_cookieOrder();
  36. void testLoad();
  37. void testLoad_sqlite3();
  38. void testLoad_fileNotfound();
  39. void testSaveNsFormat();
  40. void testSaveNsFormat_fail();
  41. void testCookieIsFull();
  42. void testDomainIsFull();
  43. void testEviction();
  44. };
  45. CPPUNIT_TEST_SUITE_REGISTRATION(CookieStorageTest);
  46. namespace {
  47. std::vector<const Cookie*> dumpCookie(const CookieStorage& st)
  48. {
  49. auto res = std::vector<const Cookie*>{};
  50. st.dumpCookie(std::back_inserter(res));
  51. std::sort(res.begin(), res.end(), CookieSorter());
  52. return res;
  53. }
  54. } // namespace
  55. void CookieStorageTest::testStore()
  56. {
  57. time_t now = 999;
  58. auto st = CookieStorage{};
  59. auto goodCookie = [&]() {
  60. auto c = createCookie("k", "v", "localhost", true, "/", false);
  61. c->setCreationTime(now);
  62. return c;
  63. };
  64. CPPUNIT_ASSERT(st.store(goodCookie(), now));
  65. CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
  66. CPPUNIT_ASSERT(st.contains(*goodCookie()));
  67. auto anotherCookie =
  68. []() { return createCookie("k", "v", "mirror", true, "/", true); };
  69. CPPUNIT_ASSERT(st.store(anotherCookie(), now));
  70. CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
  71. CPPUNIT_ASSERT(st.contains(*anotherCookie()));
  72. CPPUNIT_ASSERT(st.contains(*goodCookie()));
  73. ++now;
  74. auto updateGoodCookie = [&]() {
  75. auto c = createCookie("k", "v2", "localhost", true, "/", false);
  76. c->setCreationTime(now);
  77. return c;
  78. };
  79. CPPUNIT_ASSERT(st.store(updateGoodCookie(), now));
  80. CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
  81. CPPUNIT_ASSERT(st.contains(*updateGoodCookie()));
  82. CPPUNIT_ASSERT(st.contains(*anotherCookie()));
  83. auto cookies = st.criteriaFind("localhost", "/", now, false);
  84. CPPUNIT_ASSERT_EQUAL((size_t)1, cookies.size());
  85. CPPUNIT_ASSERT_EQUAL(std::string("v2"), cookies[0]->getValue());
  86. // New cookie's creation time must match old cookie's creation time.
  87. CPPUNIT_ASSERT_EQUAL((time_t)999, cookies[0]->getCreationTime());
  88. auto expireGoodCookie = []() {
  89. return createCookie("k", "v3", 0, "localhost", true, "/", false);
  90. };
  91. CPPUNIT_ASSERT(!st.store(expireGoodCookie(), now));
  92. CPPUNIT_ASSERT_EQUAL((size_t)1, st.size());
  93. CPPUNIT_ASSERT(st.contains(*anotherCookie()));
  94. auto fromNumericHost =
  95. []() { return createCookie("k", "v", "192.168.1.1", true, "/", false); };
  96. CPPUNIT_ASSERT(st.store(fromNumericHost(), now));
  97. CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
  98. CPPUNIT_ASSERT(st.contains(*fromNumericHost()));
  99. }
  100. void CookieStorageTest::testParseAndStore()
  101. {
  102. auto st = CookieStorage{};
  103. time_t now = 1000;
  104. std::string localhostCookieStr =
  105. "k=v;"
  106. " expires=Fri, 01 Jan 2038 00:00:00 GMT; path=/; domain=localhost;";
  107. CPPUNIT_ASSERT(
  108. st.parseAndStore(localhostCookieStr, "localhost", "/downloads", now));
  109. CPPUNIT_ASSERT(
  110. !st.parseAndStore(localhostCookieStr, "mirror", "/downloads", now));
  111. CPPUNIT_ASSERT(
  112. !st.parseAndStore(localhostCookieStr, "127.0.0.1", "/downloads", now));
  113. std::string numericHostCookieStr =
  114. "k=v;"
  115. " expires=Fri, 01 Jan 2038 00:00:00 GMT; path=/; domain=192.168.1.1;";
  116. CPPUNIT_ASSERT(
  117. st.parseAndStore(numericHostCookieStr, "192.168.1.1", "/", now));
  118. // No domain and no path are specified.
  119. std::string noDomainPathCookieStr = "k=v";
  120. CPPUNIT_ASSERT(st.parseAndStore(noDomainPathCookieStr, "aria2.sf.net",
  121. "/downloads", now));
  122. }
  123. void CookieStorageTest::testCriteriaFind()
  124. {
  125. auto st = CookieStorage{};
  126. time_t now = 1000;
  127. auto alpha = []() {
  128. return createCookie("alpha", "ALPHA", "aria2.org", false, "/", false);
  129. };
  130. auto bravo = []() {
  131. return createCookie("bravo", "BRAVO", 1060, "aria2.org", false, "/foo",
  132. false);
  133. };
  134. auto charlie = []() {
  135. return createCookie("charlie", "CHARLIE", "aria2.org", false, "/", true);
  136. };
  137. auto delta = []() {
  138. return createCookie("delta", "DELTA", "aria2.org", false, "/foo/bar",
  139. false);
  140. };
  141. auto echo = []() {
  142. return createCookie("echo", "ECHO", "www.dl.aria2.org", false, "/", false);
  143. };
  144. auto foxtrot = []() {
  145. return createCookie("foxtrot", "FOXTROT", "sf.net", false, "/", false);
  146. };
  147. auto golf = []() {
  148. return createCookie("golf", "GOLF", "192.168.1.1", true, "/", false);
  149. };
  150. auto hotel1 = []() {
  151. return createCookie("hotel", "HOTEL1", "samename.x", false, "/", false);
  152. };
  153. auto hotel2 = []() {
  154. return createCookie("hotel", "HOTEL2", "samename.x", false, "/hotel",
  155. false);
  156. };
  157. auto hotel3 = []() {
  158. return createCookie("hotel", "HOTEL3", "samename.x", false, "/bar/wine",
  159. false);
  160. };
  161. auto hotel4 = []() {
  162. return createCookie("hotel", "HOTEL4", "samename.x", false, "/bar/", false);
  163. };
  164. auto india1 = []() {
  165. return createCookie("india", "INDIA1", "default.domain", true, "/foo",
  166. false);
  167. };
  168. auto india2 = []() {
  169. return createCookie("india", "INDIA2", "default.domain", false, "/", false);
  170. };
  171. auto juliet1 = []() {
  172. return createCookie("juliet", "JULIET1", "localhost", true, "/foo", false);
  173. };
  174. CPPUNIT_ASSERT(st.store(alpha(), now));
  175. CPPUNIT_ASSERT(st.store(bravo(), now));
  176. CPPUNIT_ASSERT(st.store(charlie(), now));
  177. CPPUNIT_ASSERT(st.store(delta(), now));
  178. CPPUNIT_ASSERT(st.store(echo(), now));
  179. CPPUNIT_ASSERT(st.store(foxtrot(), now));
  180. CPPUNIT_ASSERT(st.store(golf(), now));
  181. CPPUNIT_ASSERT(st.store(hotel1(), now));
  182. CPPUNIT_ASSERT(st.store(hotel2(), now));
  183. CPPUNIT_ASSERT(st.store(hotel3(), now));
  184. CPPUNIT_ASSERT(st.store(hotel4(), now));
  185. CPPUNIT_ASSERT(st.store(india1(), now));
  186. CPPUNIT_ASSERT(st.store(india2(), now));
  187. CPPUNIT_ASSERT(st.store(juliet1(), now));
  188. auto aria2Slash = st.criteriaFind("www.dl.aria2.org", "/", 0, false);
  189. CPPUNIT_ASSERT_EQUAL((size_t)2, aria2Slash.size());
  190. CPPUNIT_ASSERT(derefFind(aria2Slash, alpha()));
  191. CPPUNIT_ASSERT(derefFind(aria2Slash, echo()));
  192. auto aria2SlashFoo = st.criteriaFind("www.dl.aria2.org", "/foo", 0, false);
  193. CPPUNIT_ASSERT_EQUAL((size_t)3, aria2SlashFoo.size());
  194. CPPUNIT_ASSERT_EQUAL(std::string("bravo"), aria2SlashFoo[0]->getName());
  195. CPPUNIT_ASSERT(derefFind(aria2SlashFoo, alpha()));
  196. CPPUNIT_ASSERT(derefFind(aria2SlashFoo, echo()));
  197. auto aria2Expires = st.criteriaFind("www.dl.aria2.org", "/foo", 1120, false);
  198. CPPUNIT_ASSERT_EQUAL((size_t)2, aria2Expires.size());
  199. CPPUNIT_ASSERT(derefFind(aria2Expires, alpha()));
  200. CPPUNIT_ASSERT(derefFind(aria2Expires, echo()));
  201. auto dlAria2 = st.criteriaFind("dl.aria2.org", "/", 0, false);
  202. CPPUNIT_ASSERT_EQUAL((size_t)1, dlAria2.size());
  203. CPPUNIT_ASSERT_EQUAL(std::string("alpha"), dlAria2[0]->getName());
  204. auto tailmatchAria2 = st.criteriaFind("myaria2.org", "/", 0, false);
  205. CPPUNIT_ASSERT(tailmatchAria2.empty());
  206. auto numericHostCookies = st.criteriaFind("192.168.1.1", "/", 0, false);
  207. CPPUNIT_ASSERT_EQUAL((size_t)1, numericHostCookies.size());
  208. CPPUNIT_ASSERT_EQUAL(std::string("golf"), numericHostCookies[0]->getName());
  209. auto sameNameCookies = st.criteriaFind("samename.x", "/bar/wine", 0, false);
  210. CPPUNIT_ASSERT_EQUAL((size_t)3, sameNameCookies.size());
  211. CPPUNIT_ASSERT_EQUAL(std::string("HOTEL3"), sameNameCookies[0]->getValue());
  212. CPPUNIT_ASSERT_EQUAL(std::string("HOTEL4"), sameNameCookies[1]->getValue());
  213. CPPUNIT_ASSERT_EQUAL(std::string("HOTEL1"), sameNameCookies[2]->getValue());
  214. auto defaultDomainCookies =
  215. st.criteriaFind("default.domain", "/foo", 0, false);
  216. CPPUNIT_ASSERT_EQUAL((size_t)2, defaultDomainCookies.size());
  217. CPPUNIT_ASSERT_EQUAL(std::string("INDIA1"),
  218. defaultDomainCookies[0]->getValue());
  219. CPPUNIT_ASSERT_EQUAL(std::string("INDIA2"),
  220. defaultDomainCookies[1]->getValue());
  221. defaultDomainCookies =
  222. st.criteriaFind("sub.default.domain", "/foo", 0, false);
  223. CPPUNIT_ASSERT_EQUAL((size_t)1, defaultDomainCookies.size());
  224. CPPUNIT_ASSERT_EQUAL(std::string("INDIA2"),
  225. defaultDomainCookies[0]->getValue());
  226. // localhost.local case
  227. auto localDomainCookies = st.criteriaFind("localhost", "/foo", 0, false);
  228. CPPUNIT_ASSERT_EQUAL((size_t)1, localDomainCookies.size());
  229. CPPUNIT_ASSERT_EQUAL(std::string("JULIET1"),
  230. localDomainCookies[0]->getValue());
  231. }
  232. void CookieStorageTest::testCriteriaFind_cookieOrder()
  233. {
  234. auto st = CookieStorage{};
  235. auto a = createCookie("a", "0", "host", true, "/", false);
  236. a->setCreationTime(1000);
  237. auto b = createCookie("b", "0", "host", true, "/foo", false);
  238. b->setCreationTime(5000);
  239. auto c = createCookie("c", "0", "host", true, "/foo", false);
  240. c->setCreationTime(4000);
  241. auto d = createCookie("d", "0", "host", true, "/foo/bar", false);
  242. d->setCreationTime(6000);
  243. st.store(std::move(a), 0);
  244. st.store(std::move(b), 0);
  245. st.store(std::move(c), 0);
  246. st.store(std::move(d), 0);
  247. auto cookies = st.criteriaFind("host", "/foo/bar", 0, false);
  248. CPPUNIT_ASSERT_EQUAL((size_t)4, cookies.size());
  249. CPPUNIT_ASSERT_EQUAL(std::string("d"), cookies[0]->getName());
  250. CPPUNIT_ASSERT_EQUAL(std::string("c"), cookies[1]->getName());
  251. CPPUNIT_ASSERT_EQUAL(std::string("b"), cookies[2]->getName());
  252. CPPUNIT_ASSERT_EQUAL(std::string("a"), cookies[3]->getName());
  253. }
  254. void CookieStorageTest::testLoad()
  255. {
  256. auto st = CookieStorage{};
  257. st.load(A2_TEST_DIR "/nscookietest.txt", 1001);
  258. CPPUNIT_ASSERT_EQUAL((size_t)4, st.size());
  259. auto cookies = dumpCookie(st);
  260. auto c = cookies[0];
  261. CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c->getName());
  262. CPPUNIT_ASSERT_EQUAL(std::string("secret"), c->getValue());
  263. CPPUNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), c->getExpiryTime());
  264. CPPUNIT_ASSERT(!c->getPersistent());
  265. CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c->getPath());
  266. CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), c->getDomain());
  267. CPPUNIT_ASSERT(c->getHostOnly());
  268. CPPUNIT_ASSERT(!c->getSecure());
  269. c = cookies[1];
  270. CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c->getName());
  271. CPPUNIT_ASSERT_EQUAL(std::string(""), c->getValue());
  272. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c->getExpiryTime());
  273. CPPUNIT_ASSERT(c->getPersistent());
  274. CPPUNIT_ASSERT_EQUAL(std::string("/"), c->getPath());
  275. CPPUNIT_ASSERT_EQUAL(std::string("example.org"), c->getDomain());
  276. CPPUNIT_ASSERT(!c->getHostOnly());
  277. CPPUNIT_ASSERT(!c->getSecure());
  278. c = cookies[2];
  279. CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c->getName());
  280. CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c->getValue());
  281. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c->getExpiryTime());
  282. CPPUNIT_ASSERT_EQUAL(std::string("/"), c->getPath());
  283. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c->getDomain());
  284. CPPUNIT_ASSERT(c->getHostOnly());
  285. CPPUNIT_ASSERT(c->getSecure());
  286. c = cookies[3];
  287. CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c->getName());
  288. CPPUNIT_ASSERT_EQUAL(std::string("1000"), c->getValue());
  289. CPPUNIT_ASSERT_EQUAL((time_t)1463304912, c->getExpiryTime());
  290. CPPUNIT_ASSERT(c->getPersistent());
  291. CPPUNIT_ASSERT_EQUAL(std::string("/"), c->getPath());
  292. CPPUNIT_ASSERT_EQUAL(std::string("something"), c->getDomain());
  293. CPPUNIT_ASSERT(!c->getSecure());
  294. }
  295. void CookieStorageTest::testLoad_sqlite3()
  296. {
  297. auto st = CookieStorage{};
  298. #ifdef HAVE_SQLITE3
  299. st.load(A2_TEST_DIR "/cookies.sqlite", 1000);
  300. CPPUNIT_ASSERT_EQUAL((size_t)2, st.size());
  301. auto cookies = dumpCookie(st);
  302. auto c = cookies[0];
  303. CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c->getName());
  304. CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c->getValue());
  305. CPPUNIT_ASSERT_EQUAL((time_t)INT32_MAX, c->getExpiryTime());
  306. CPPUNIT_ASSERT(c->getPersistent());
  307. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c->getDomain());
  308. CPPUNIT_ASSERT(c->getHostOnly());
  309. CPPUNIT_ASSERT_EQUAL(std::string("/"), c->getPath());
  310. CPPUNIT_ASSERT(c->getSecure());
  311. c = cookies[1];
  312. CPPUNIT_ASSERT_EQUAL(std::string("foo"), c->getName());
  313. CPPUNIT_ASSERT_EQUAL(std::string("bar"), c->getValue());
  314. CPPUNIT_ASSERT((time_t)INT32_MAX <= c->getExpiryTime());
  315. CPPUNIT_ASSERT(c->getPersistent());
  316. CPPUNIT_ASSERT_EQUAL(std::string("overflow.time_t.org"), c->getDomain());
  317. CPPUNIT_ASSERT(!c->getHostOnly());
  318. CPPUNIT_ASSERT_EQUAL(std::string("/path/to"), c->getPath());
  319. CPPUNIT_ASSERT(!c->getSecure());
  320. #else // !HAVE_SQLITE3
  321. CPPUNIT_ASSERT(!st.load(A2_TEST_DIR "/cookies.sqlite", 1000));
  322. #endif // !HAVE_SQLITE3
  323. }
  324. void CookieStorageTest::testLoad_fileNotfound()
  325. {
  326. auto st = CookieStorage{};
  327. CPPUNIT_ASSERT(
  328. !st.load("./aria2_CookieStorageTest_testLoad_fileNotfound", 0));
  329. }
  330. void CookieStorageTest::testSaveNsFormat()
  331. {
  332. // TODO add cookie with default domain
  333. std::string filename =
  334. A2_TEST_OUT_DIR "/aria2_CookieStorageTest_testSaveNsFormat";
  335. File(filename).remove();
  336. auto st = CookieStorage{};
  337. time_t now = 1000;
  338. st.store(
  339. createCookie("favorite", "classic", "domain.org", false, "/config", true),
  340. now);
  341. st.store(createCookie("uid", "tujikawa", now, "domain.org", true, "/", false),
  342. now);
  343. CPPUNIT_ASSERT(st.saveNsFormat(filename));
  344. auto loadst = CookieStorage{};
  345. loadst.load(filename, now);
  346. CPPUNIT_ASSERT_EQUAL((size_t)2, loadst.size());
  347. auto cookies = dumpCookie(loadst);
  348. CPPUNIT_ASSERT_EQUAL((size_t)2, cookies.size());
  349. CPPUNIT_ASSERT_EQUAL(std::string("favorite"), cookies[0]->getName());
  350. CPPUNIT_ASSERT_EQUAL(std::string("uid"), cookies[1]->getName());
  351. }
  352. void CookieStorageTest::testSaveNsFormat_fail()
  353. {
  354. std::string filename =
  355. A2_TEST_OUT_DIR "/aria2_CookieStorageTest_testSaveNsFormat_fail";
  356. File f(filename);
  357. f.remove();
  358. f.mkdirs();
  359. CPPUNIT_ASSERT(f.isDir());
  360. auto st = CookieStorage{};
  361. CPPUNIT_ASSERT(!st.saveNsFormat(filename));
  362. }
  363. void CookieStorageTest::testCookieIsFull()
  364. {
  365. auto st = CookieStorage{};
  366. for (size_t i = 0; i < CookieStorage::MAX_COOKIE_PER_DOMAIN + 1; ++i) {
  367. st.store(
  368. createCookie("k" + util::itos(i), "v", "aria2.org", false, "/", false),
  369. 0);
  370. }
  371. CPPUNIT_ASSERT_EQUAL((size_t)CookieStorage::MAX_COOKIE_PER_DOMAIN, st.size());
  372. }
  373. void CookieStorageTest::testDomainIsFull()
  374. {
  375. // See DOMAIN_EVICTION_TRIGGER and DOMAIN_EVICTION_RATE in
  376. // CookieStorage.cc
  377. auto st = CookieStorage{};
  378. for (size_t i = 0; i < 2001; ++i) {
  379. st.store(createCookie("k", "v", "domain" + util::itos(i), true, "/", false),
  380. 0);
  381. }
  382. CPPUNIT_ASSERT_EQUAL((size_t)1801, st.size());
  383. }
  384. void CookieStorageTest::testEviction()
  385. {
  386. auto st = CookieStorage{};
  387. auto alpha = []() {
  388. return createCookie("a", "alpha", "aria2.sf.net", false, "/", false);
  389. };
  390. auto bravo = []() {
  391. return createCookie("b", "bravo", "d.aria2.sf.net", false, "/", false);
  392. };
  393. auto charlie = []() {
  394. return createCookie("c", "charlie", "a2.github.com", false, "/", false);
  395. };
  396. auto delta = []() {
  397. return createCookie("d", "delta", "aria2.sf.net", false, "/", false);
  398. };
  399. st.store(alpha(), 0);
  400. CPPUNIT_ASSERT_EQUAL((size_t)1, st.getLruTrackerSize());
  401. st.store(bravo(), 1);
  402. CPPUNIT_ASSERT_EQUAL((size_t)2, st.getLruTrackerSize());
  403. st.store(charlie(), 2);
  404. CPPUNIT_ASSERT_EQUAL((size_t)3, st.getLruTrackerSize());
  405. st.store(delta(), 0);
  406. CPPUNIT_ASSERT_EQUAL((size_t)3, st.getLruTrackerSize());
  407. // aria2.sf.net will be evicted
  408. st.evictNode(1);
  409. CPPUNIT_ASSERT_EQUAL((size_t)2, st.getLruTrackerSize());
  410. CPPUNIT_ASSERT(!st.contains(*alpha()));
  411. CPPUNIT_ASSERT(st.contains(*bravo()));
  412. CPPUNIT_ASSERT(st.contains(*charlie()));
  413. CPPUNIT_ASSERT(!st.contains(*delta()));
  414. // d.aria2.sf.net will be evicted
  415. st.evictNode(1);
  416. CPPUNIT_ASSERT_EQUAL((size_t)1, st.getLruTrackerSize());
  417. CPPUNIT_ASSERT(!st.contains(*bravo()));
  418. CPPUNIT_ASSERT(st.contains(*charlie()));
  419. // a2.github.com will be evicted
  420. st.evictNode(1);
  421. CPPUNIT_ASSERT_EQUAL((size_t)0, st.getLruTrackerSize());
  422. CPPUNIT_ASSERT(!st.contains(*charlie()));
  423. CPPUNIT_ASSERT_EQUAL((size_t)0, st.size());
  424. CPPUNIT_ASSERT(!st.getRootNode()->hasNext());
  425. }
  426. } // namespace aria2