2007-06-10 07:55:43 +00:00
|
|
|
#include "CookieBoxFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "CookieBox.h"
|
2007-06-10 07:55:43 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
class CookieBoxFactoryTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(CookieBoxFactoryTest);
|
|
|
|
CPPUNIT_TEST(testLoadDefaultCookie);
|
|
|
|
CPPUNIT_TEST(testCreateNewInstance);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testLoadDefaultCookie();
|
|
|
|
void testCreateNewInstance();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( CookieBoxFactoryTest );
|
|
|
|
|
|
|
|
void CookieBoxFactoryTest::testLoadDefaultCookie()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::ifstream f("nscookietest.txt");
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
CookieBoxFactory factory;
|
|
|
|
|
|
|
|
factory.loadDefaultCookie(f);
|
|
|
|
|
|
|
|
Cookies cookies = factory.getDefaultCookies();
|
|
|
|
|
2007-07-23 14:09:46 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)4, (int32_t)cookies.size());
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
Cookie c = cookies[0];
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("JSESSIONID"), c.name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("123456789"), c.value);
|
2007-12-15 14:34:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
c = cookies[1];
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("user"), c.name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("me"), c.value);
|
2007-12-15 14:34:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)1181473200, c.expires);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
c = cookies[2];
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("passwd"), c.name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("secret"), c.value);
|
2007-12-15 14:34:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/cgi-bin"), c.path);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
|
2007-06-10 07:55:43 +00:00
|
|
|
|
|
|
|
c = cookies[3];
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("novalue"), c.name);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), c.value);
|
2007-12-15 14:34:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((time_t)2147483647, c.expires);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("/"), c.path);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("localhost"), c.domain);
|
2007-06-10 07:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CookieBoxFactoryTest::testCreateNewInstance()
|
|
|
|
{
|
2008-02-08 15:53:45 +00:00
|
|
|
std::ifstream f("nscookietest.txt");
|
2007-06-10 07:55:43 +00:00
|
|
|
CookieBoxFactory factory;
|
|
|
|
factory.loadDefaultCookie(f);
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<CookieBox> box = factory.createNewInstance();
|
|
|
|
std::deque<Cookie> cookies = box->criteriaFind("localhost", "/", 0, true);
|
2007-06-10 07:55:43 +00:00
|
|
|
|
2007-12-15 14:34:31 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)3, (int32_t)cookies.size());
|
2007-06-10 07:55:43 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|