[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[PATCH] Add test suit for HttpSession functions
From: Sergey Jukov <sergey@total-knowledge.com>
---
ChangeLog | 4 ++++
session/Makefile.adon | 1 +
session/output.pl | 14 ++++++++++++++
session/sessionGetAccessedTime.pl | 27 +++++++++++++++++++++++++++
session/sessionGetCreationTime.pl | 27 +++++++++++++++++++++++++++
session/sessionGetMaxTime.pl | 27 +++++++++++++++++++++++++++
session/sessionGetNumberHits.pl | 27 +++++++++++++++++++++++++++
session/sessionGetSession.pl | 27 +++++++++++++++++++++++++++
session/sessionGetSessionId.pl | 27 +++++++++++++++++++++++++++
9 files changed, 181 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b25c28c..67dbf64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sergey Jukov <sergey@total-knowledge.com> Tue, 26 Sep 2006 18:00:00 -0800
+- Add testing suit for HttpSession functions isNew(), getAttribute(),
+ getId(), getCreationTime(), getLastAccessedTime(), getMaxInactiveInterval().
+
Sergey Jukov <sergey@total-knowledge.com> Wed, 20 Sep 2006 14:40:00 -0800
- Add testing getId(), getCreationTime(), getLastAccessedTime(),
setMaxInactiveInterval(), getMaxInactiveInterval(), isNew() and
diff --git a/session/Makefile.adon b/session/Makefile.adon
index a9b3298..c230c74 100644
--- a/session/Makefile.adon
+++ b/session/Makefile.adon
@@ -1,3 +1,4 @@
noinst_LTLIBRARIES := SessionServlet
SessionServlet_SOURCES := session.cpp
noinst_HEADERS := session.h
+check_SCRIPTS:=sessionGetSession.pl sessionGetNumberHits.pl sessionGetSessionId.pl sessionGetCreationTime.pl sessionGetAccessedTime.pl sessionGetMaxTime.pl
diff --git a/session/output.pl b/session/output.pl
new file mode 100755
index 0000000..e820d94
--- /dev/null
+++ b/session/output.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+# This script output.pl prints formatted output
+# for test suit.
+
+sub test_ok {
+ return $_[0]." OK\n";
+}
+sub test_not_ok {
+ return "Check ".$_[0]." failed. NOT OK\n";
+}
+sub test_die {
+ return "Cannot get ".$_[0].": ".$_[1]." NOT OK\n";
+}
diff --git a/session/sessionGetAccessedTime.pl b/session/sessionGetAccessedTime.pl
new file mode 100755
index 0000000..8af0250
--- /dev/null
+++ b/session/sessionGetAccessedTime.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetAccessedTime.pl tests
+# work of HttpSession::getLastAccessedTime() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::getLastAccessedTime()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if($line =~ /Last Accessed time:\s(.+)Maximum/) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
diff --git a/session/sessionGetCreationTime.pl b/session/sessionGetCreationTime.pl
new file mode 100755
index 0000000..06695cb
--- /dev/null
+++ b/session/sessionGetCreationTime.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetCreationTime.pl tests work of
+# HttpSession::getCreationTime() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::getCreationTime()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if($line =~ /Creation time:\s(.+)Last/) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
diff --git a/session/sessionGetMaxTime.pl b/session/sessionGetMaxTime.pl
new file mode 100755
index 0000000..ef24b6c
--- /dev/null
+++ b/session/sessionGetMaxTime.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetMaxTime.pl tests work of
+# HttpSession::getMaxInactiveInterval() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::getMaxInactiveInterval()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if($line =~ /Maximum time interval:\s(.*)\sseconds/) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
diff --git a/session/sessionGetNumberHits.pl b/session/sessionGetNumberHits.pl
new file mode 100755
index 0000000..db24af4
--- /dev/null
+++ b/session/sessionGetNumberHits.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetNumberHits.pl tests work of
+# HttpSession::getAttribute() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::getAttribute()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if($line =~ /You hit this page\s(\d+)\stimes/) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
diff --git a/session/sessionGetSession.pl b/session/sessionGetSession.pl
new file mode 100755
index 0000000..012b622
--- /dev/null
+++ b/session/sessionGetSession.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetSession.pl tests work of
+# HttpSession::isNew() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::isNew()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if(($line =~ /New\ssession/) || ($line =~ /Old\ssession/)) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
diff --git a/session/sessionGetSessionId.pl b/session/sessionGetSessionId.pl
new file mode 100755
index 0000000..a1ae022
--- /dev/null
+++ b/session/sessionGetSessionId.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+# This script sessionGetSessionId.pl tests work of
+# HttpSession::getId() function.
+
+use LWP::UserAgent;
+do "session/output.pl";
+
+my $test = "HttpSession::getId()";
+my $ua = LWP::UserAgent->new;
+my $host = $ENV{HOSTNAME};
+my $servletName = "SessionServlet";
+my $url = "http://localhost/~".$host."/csp/".$servletName;
+my $req = HTTP::Request->new(POST => $url);
+$req->content_type('application/x-www-form-urlencoded');
+my $res = $ua->request($req);
+if ($res->is_success) {
+ my $line = $res->content;
+ $line =~ s/\n+//g;
+ if($line =~ /SessionID:\s(.+)Creation/) {
+ print &test_ok($test);
+ } else {
+ print &test_not_ok($test);
+ }
+} else {
+ die &test_die($url, $res->status_line);
+}
--
1.4.2