CookieBoxTest.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "CookieBox.h"
  2. #include <string>
  3. #include <cppunit/extensions/HelperMacros.h>
  4. namespace aria2 {
  5. class CookieBoxTest : public CppUnit::TestFixture {
  6. CPPUNIT_TEST_SUITE(CookieBoxTest);
  7. CPPUNIT_TEST(testCriteriaFind);
  8. CPPUNIT_TEST_SUITE_END();
  9. private:
  10. public:
  11. void setUp() {}
  12. void testCriteriaFind();
  13. };
  14. CPPUNIT_TEST_SUITE_REGISTRATION(CookieBoxTest);
  15. void CookieBoxTest::testCriteriaFind()
  16. {
  17. // 1181473200 = Sun Jun 10 11:00:00 2007 GMT
  18. Cookie c1("SESSIONID1", "1", 1181473200, "/downloads", "rednoah.com", false);
  19. Cookie c2("SESSIONID2", "2", 1181473200, "/downloads", "rednoah.com", false);
  20. Cookie c3("USER", "user", "/home", "aria.rednoah.com", false);
  21. Cookie c4("PASS", "pass", "/downloads", "rednoah.com", true);
  22. CookieBox box;
  23. box.add(c1);
  24. box.add(c2);
  25. box.add(c3);
  26. box.add(c4);
  27. Cookies result1 =
  28. box.criteriaFind("rednoah.com", "/downloads", 1181473100, false);
  29. CPPUNIT_ASSERT_EQUAL(2, (int)result1.size());
  30. Cookies::iterator itr = result1.begin();
  31. CPPUNIT_ASSERT_EQUAL(std::string("SESSIONID1=1"), (*itr).toString());
  32. itr++;
  33. CPPUNIT_ASSERT_EQUAL(std::string("SESSIONID2=2"), (*itr).toString());
  34. result1 = box.criteriaFind("rednoah.com", "/downloads", 1181473100, true);
  35. CPPUNIT_ASSERT_EQUAL(3, (int)result1.size());
  36. itr = result1.begin();
  37. CPPUNIT_ASSERT_EQUAL(std::string("SESSIONID1=1"), (*itr).toString());
  38. itr++;
  39. CPPUNIT_ASSERT_EQUAL(std::string("SESSIONID2=2"), (*itr).toString());
  40. itr++;
  41. CPPUNIT_ASSERT_EQUAL(std::string("PASS=pass"), (*itr).toString());
  42. result1 = box.criteriaFind("aria.rednoah.com", "/", 1181473100, false);
  43. CPPUNIT_ASSERT_EQUAL(0, (int)result1.size());
  44. result1 = box.criteriaFind("aria.rednoah.com", "/home", 1181473100, false);
  45. CPPUNIT_ASSERT_EQUAL(1, (int)result1.size());
  46. itr = result1.begin();
  47. CPPUNIT_ASSERT_EQUAL(std::string("USER=user"), (*itr).toString());
  48. result1 = box.criteriaFind("rednoah.com", "/downloads", 1181473200, false);
  49. CPPUNIT_ASSERT_EQUAL(0, (int)result1.size());
  50. }
  51. } // namespace aria2