CookieStorageTest.cc 17 KB

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