CookieStorageTest.cc 16 KB

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