NsCookieParserTest.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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)5, cookies.size());
  24. Cookie c = cookies[0];
  25. CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.getName());
  26. CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.getValue());
  27. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
  28. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
  29. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
  30. c = cookies[1];
  31. CPPUNIT_ASSERT_EQUAL(std::string("user"), c.getName());
  32. CPPUNIT_ASSERT_EQUAL(std::string("me"), c.getValue());
  33. CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.getExpiry());
  34. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
  35. CPPUNIT_ASSERT_EQUAL(std::string("expired"), c.getDomain());
  36. c = cookies[2];
  37. CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.getName());
  38. CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.getValue());
  39. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
  40. CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.getPath());
  41. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
  42. c = cookies[3];
  43. CPPUNIT_ASSERT_EQUAL(std::string("TAX"), c.getName());
  44. CPPUNIT_ASSERT_EQUAL(std::string("1000"), c.getValue());
  45. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
  46. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
  47. CPPUNIT_ASSERT_EQUAL(std::string("overflow"), c.getDomain());
  48. c = cookies[4];
  49. CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.getName());
  50. CPPUNIT_ASSERT_EQUAL(std::string(""), c.getValue());
  51. CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.getExpiry());
  52. CPPUNIT_ASSERT_EQUAL(std::string("/"), c.getPath());
  53. CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.getDomain());
  54. }
  55. void NsCookieParserTest::testParse_fileNotFound()
  56. {
  57. NsCookieParser parser;
  58. try {
  59. parser.parse("fileNotFound");
  60. CPPUNIT_FAIL("exception must be thrown.");
  61. } catch(RecoverableException& e) {
  62. // SUCCESS
  63. }
  64. }
  65. } // namespace aria2