int
main(int, char**)
{
	cout << "Running explodeImplodeTest:" << endl;
	explodeImplodeTest();
	cout << endl << endl;
	
	cout << "Running stressTest:" << endl;
	char* flatJar;
	ssize_t size;
	stressTest(10000, 40000, &flatJar, &size);
	
	BNetworkCookieJar j;
	j.Unflatten(B_ANY_TYPE, flatJar, size);
	
	int32 count = 0;
	BNetworkCookie* c;
	for (BNetworkCookieJar::Iterator it(j.GetIterator()); (c = it.Next()); )
		count++;
	cout << "Count : " << count << endl;
	
	delete[] flatJar;
	
	return EXIT_SUCCESS;
}
Exemple #2
0
void
CookieTest::SimpleTest()
{
	BNetworkCookieJar jar;
	char buffer[256];
	BUrl url("http://www.chipchapin.com/WebTools/cookietest.php");

	time_t t = time(NULL) + 6400; // Cookies expire in 1h45
	struct tm* now = gmtime(&t);
	status_t result;

	// Add various cookies
	result = jar.AddCookie("testcookie1=present;", url);
	CPPUNIT_ASSERT(result == B_OK);

	strftime(buffer, sizeof(buffer),
		"testcookie2=present; expires=%A, %d-%b-%Y %H:%M:%S", now);
	result = jar.AddCookie(buffer, url);
	CPPUNIT_ASSERT(result == B_OK);

	strftime(buffer, sizeof(buffer),
		"testcookie3=present; expires=%A, %d-%b-%Y %H:%M:%S; path=/", now);
	result = jar.AddCookie(buffer, url);
	CPPUNIT_ASSERT(result == B_OK);

	t += 3200; // expire in 2h40
	now = gmtime(&t);
	strftime(buffer, sizeof(buffer),
		"testcookie4=present; path=/; domain=www.chipchapin.com; "
		"expires=%A, %d-%b-%Y %H:%M:%S", now);
	result = jar.AddCookie(buffer, url);
	CPPUNIT_ASSERT(result == B_OK);

	// Now check they were all properly added
	BNetworkCookieJar::Iterator it = jar.GetIterator();

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

	CPPUNIT_ASSERT_EQUAL(4, count);
}