NsCookieParserTest.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "NsCookieParser.h"
  2. #include "RecoverableException.h"
  3. #include "Util.h"
  4. #include <iostream>
  5. #include <cppunit/extensions/HelperMacros.h>
  6. namespace aria2 {
  7. class NsCookieParserTest:public CppUnit::TestFixture {
  8. CPPUNIT_TEST_SUITE(NsCookieParserTest);
  9. CPPUNIT_TEST(testParse);
  10. CPPUNIT_TEST(testParse_fileNotFound);
  11. CPPUNIT_TEST_SUITE_END();
  12. public:
  13. void setUp() {}
  14. void tearDown() {}
  15. void testParse();
  16. void testParse_fileNotFound();
  17. };
  18. CPPUNIT_TEST_SUITE_REGISTRATION(NsCookieParserTest);
  19. void NsCookieParserTest::testParse()
  20. {
  21. NsCookieParser parser;
  22. std::deque<Cookie> cookies = parser.parse("nscookietest.txt");
  23. CPPUNIT_ASSERT_EQUAL((size_t)4, cookies.size());
  24. Cookie c = cookies[0];
  25. CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
  26. CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
  27. CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
  28. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
  29. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
  30. c = cookies[1];
  31. CPPUNIT_ASSERT_EQUAL(std::string("user"), c.name);
  32. CPPUNIT_ASSERT_EQUAL(std::string("me"), c.value);
  33. CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
  34. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
  35. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
  36. c = cookies[2];
  37. CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
  38. CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.value);
  39. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
  40. CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.path);
  41. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
  42. c = cookies[3];
  43. CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.name);
  44. CPPUNIT_ASSERT_EQUAL(std::string(""), c.value);
  45. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
  46. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
  47. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
  48. }
  49. void NsCookieParserTest::testParse_fileNotFound()
  50. {
  51. NsCookieParser parser;
  52. try {
  53. parser.parse("fileNotFound");
  54. CPPUNIT_FAIL("exception must be thrown.");
  55. } catch(RecoverableException& e) {
  56. // SUCCESS
  57. }
  58. }
  59. } // namespace aria2