コード例 #1
0
ファイル: CookieTest.cpp プロジェクト: SummerSnail2014/haiku
void
CookieTest::OverwriteTest()
{
	BNetworkCookieJar jar;
	status_t result;

	BUrl url("http://testsuites.opera.com/cookies/015/015.php");
	result = jar.AddCookie("015-01=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015-1.php");
	result = jar.AddCookie("015-01=1", url);
	result = jar.AddCookie("015-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015/015-2.php");
	result = jar.AddCookie("015-01=1", url);
	result = jar.AddCookie("015-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015/015-3.php");
	BNetworkCookieJar::UrlIterator it = jar.GetUrlIterator(url);
	int count = 0;

	while (it.HasNext()) {
		it.Next();
		count++;
	}

	CPPUNIT_ASSERT_EQUAL(4, count);
}
コード例 #2
0
ファイル: CookieTest.cpp プロジェクト: SummerSnail2014/haiku
void
CookieTest::OrderTest()
{
	BNetworkCookieJar jar;
	status_t result;

	BUrl url("http://testsuites.opera.com/cookies/016.php");
	result = jar.AddCookie("016-01=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/016/016-1.php");
	result = jar.AddCookie("016-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/016/016-2.php");
	BNetworkCookieJar::UrlIterator it = jar.GetUrlIterator(url);
	int count = 0;

	// Check that the cookie with the most specific path is sent first
	while (it.HasNext()) {
		const BNetworkCookie* cookie = it.Next();
		switch(count)
		{
			case 0:
				CPPUNIT_ASSERT_EQUAL(BString("016-02"), cookie->Name());
				break;
			case 1:
				CPPUNIT_ASSERT_EQUAL(BString("016-01"), cookie->Name());
				break;
		}
		count++;
	}

	CPPUNIT_ASSERT_EQUAL(2, count);
}
コード例 #3
0
void stressTest(int32 domainNumber, int32 totalCookies, char** flat, ssize_t* size)
{
	char **domains = new char*[domainNumber];
	
	cout << "Creating random domains" << endl;
	srand(time(NULL));
	for (int32 i = 0; i < domainNumber; i++) {
		int16 charNum = (rand() % 16) + 1;
		
		domains[i] = new char[charNum + 5];
		
		// Random domain
		for (int32 c = 0; c < charNum; c++) 
			domains[i][c] = (rand() % 26) + 'a';
		
		domains[i][charNum] = '.';
		
		// Random tld
		for (int32 c = 0; c < 3; c++) 
			domains[i][charNum+1+c] = (rand() % 26) + 'a';
			
		domains[i][charNum+4] = 0;
	}
	
	BNetworkCookieJar j;
	BStopWatch* watch = new BStopWatch("Cookie insertion");
	for (int32 i = 0; i < totalCookies; i++) {
		BNetworkCookie c;
		int16 domain = (rand() % domainNumber);
		BString name("Foo");
		name << i;
		
		c.SetName(name);
		c.SetValue("Bar");
		c.SetDomain(domains[domain]);
		c.SetPath("/");
		
		j.AddCookie(c);
	}
	delete watch;
	
	BNetworkCookie* c;
	int16 domain = (rand() % domainNumber);
	BString host("http://");
	host << domains[domain] << "/";
	
	watch = new BStopWatch("Cookie filtering");
	BUrl url(host);
	int32 count = 0;
	for (BNetworkCookieJar::UrlIterator it(j.GetUrlIterator(url)); (c = it.Next()); ) {
	//for (BNetworkCookieJar::Iterator it(j.GetIterator()); c = it.Next(); ) {
		count++;
	}
	delete watch;
	cout << "Count for " << host << ": " << count << endl;
	
	
	cout << "Flat view of cookie jar is " << j.FlattenedSize() << " bytes large." << endl;
	*flat = new char[j.FlattenedSize()];
	*size = j.FlattenedSize();
	
	if (j.Flatten(*flat, j.FlattenedSize()) == B_OK)
		cout << "Flatten() success!" << endl;
	else
		cout << "Flatten() error!" << endl;
	
	delete[] domains;
}