[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[PATCH] Add test suit for HttpSession getCreationTime(),
From: Sergey Jukov <sergey@total-knowledge.com>
diff --git a/ChangeLog b/ChangeLog
index bed96db..b1ac1ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sergey Jukov <sergey@total-knowledge.com> Fri, 29 Sep 2006 14:00:00 -0800
+- Add testing suit for HttpSession functions getCreationTime(),
+ getLastAccessedTime(), setAttribute().
+
Sergey Jukov <sergey@total-knowledge.com> Fri, 29 Sep 2006 10:30:00 -0800
- Add testing suit for HttpSession functions getId(), isNew(),
getMaxInactiveInterval().
diff --git a/session/Makefile.adon b/session/Makefile.adon
index eda641f..6636c58 100644
--- a/session/Makefile.adon
+++ b/session/Makefile.adon
@@ -1,4 +1,5 @@
noinst_LTLIBRARIES := SessionServlet
SessionServlet_SOURCES := session.cpp
noinst_HEADERS := session.h
-check_SCRIPTS:=sessionGetSessionId.pl sessionGetSession.pl sessionGetMaxTime.pl
+check_SCRIPTS:=sessionGetSessionId.pl sessionGetSession.pl sessionGetMaxTime.pl sessionGetCreationTime.pl sessionGetAccessedTime.pl sessionGetNumberHits.pl
+
diff --git a/session/sessionGetAccessedTime.pl b/session/sessionGetAccessedTime.pl
new file mode 100755
index 0000000..cfcae27
--- /dev/null
+++ b/session/sessionGetAccessedTime.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+# This script sessionGetAccessedTime.pl tests
+# work of HttpSession::getLastAccessedTime() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+use POSIX qw(strftime);
+do "tests/output.pl";
+
+my $test = "HttpSession::getLastAccessedTime()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my @access_times;
+my @now_strings;
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run 3 times, sleep at least 30 seconds for the new session.
+while($counter < 3) {
+ sleep 2;
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$2","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /Last Accessed time:\s(.+)Maximum/;
+ $access_times[$counter] = $1;
+ $now_strings[$counter] = strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime);
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ $counter++;
+ if($counter == 1){
+ sleep 30;
+ }
+}
+
+# Compare results.
+if(($now_strings[1] eq $access_times[1]) && ($now_strings[2] eq $access_times[2])) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
diff --git a/session/sessionGetCreationTime.pl b/session/sessionGetCreationTime.pl
new file mode 100755
index 0000000..79a9626
--- /dev/null
+++ b/session/sessionGetCreationTime.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+
+# This script sessionGetCreationTime.pl tests work of
+# HttpSession::getCreationTime() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+use POSIX qw(strftime);
+do "tests/output.pl";
+
+my $test = "HttpSession::getCreationTime()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my @creation_times;
+my @strings;
+my @now_strings;
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run 3 times, sleep at least 30 seconds for the new session.
+while($counter < 3) {
+ sleep 2;
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$2","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /<PRE>(.*)You hit.*Creation time:\s(.+)Last/;
+ $strings[$counter] = $1;
+ $creation_times[$counter] = $2;
+ $now_strings[$counter] = strftime ("%a, %d %b %Y %H:%M:%S GMT", gmtime);
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ $counter++;
+ if($counter == 1){
+ sleep 30;
+ }
+}
+
+# Compare results.
+if(($now_strings[1] eq $creation_times[1]) && ($strings[1] eq "New session!") && ($strings[2] eq "Old session") && ($creation_times[1] eq $creation_times[2])) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
diff --git a/session/sessionGetNumberHits.pl b/session/sessionGetNumberHits.pl
new file mode 100755
index 0000000..6a69e03
--- /dev/null
+++ b/session/sessionGetNumberHits.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+
+# This script sessionGetNumberHits.pl tests work of
+# HttpSession::setAttribute() function.
+
+use LWP::UserAgent;
+use HTTP::Cookies;
+do "tests/output.pl";
+
+my $test = "HttpSession::setAttribute()";
+my $servletName = "SessionServlet";
+my $urlbase = $ENV{CPPSERV_TEST_URLBASE};
+my $url = $urlbase."/".$servletName;
+my @hits;
+my $counter = 0;
+my $file = "tests/lwp_cookies.dat";
+
+# Run 3 times, sleep at least 30 seconds for the new session
+OUT: while($counter < 3) {
+ if($counter == 0){
+ sleep 30;
+ } else {
+ sleep 1;
+ }
+ my $ua = LWP::UserAgent->new;
+ my $req = HTTP::Request->new(POST => $url);
+ $req->content_type('application/x-www-form-urlencoded');
+ my $cookie_jar = HTTP::Cookies->new(
+ file => $file,
+ autosave => 1,
+ ignore_discard => 1,
+ );
+ if(-e $file) {
+ $ua->cookie_jar($cookie_jar);
+ my $cookieString = $cookie_jar->as_string;
+ $cookieString =~ /Set-Cookie[\d]*: (.+)=(.+); path=\"(.*)\"; domain=(.*?);/;
+ # Hack, change cookie version from 1 to 0.
+ $cookie_jar->set_cookie("0","$1","$2","$3","$4");
+ }
+ my $res = $ua->request($req);
+ if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ $line =~ /You hit this page\s(\d+)\stimes/;
+ $hits[$counter] = $1;
+ } else {
+ die &test_die($url, $res->status_line);
+ }
+ $counter ++;
+}
+
+# Compare results.
+if($hits[0] == 0 && $hits[1] == 1 && $hits[2] == 2) {
+ print &test_ok($test);
+} else {
+ print &test_not_ok($test);
+}
--
1.4.2