CPPSERV


Home Projects Jobs Clientele Contact

cppserv


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add test suit for HttpSession functions



Aha. Much better.
$ENV{HOSTNAME} may not nessesarily point to accessible/usable hostname.
And virtual path may be different too. Make these come from somewhere else.
one option is to use some of your own env variables (i.e.
CPPSERV_TEST_HOST, CPPSERV_TEST_URLBASE)
and set them up from Makefiles.
Hint: info make, then search (forward slash (/) goes into search mode)
for "export" and
variables.

See below for comments.

Sergey wrote:
> From: Sergey Jukov <sergey@total-knowledge.com>
>
> ---
>  ChangeLog                         |    4 ++++
>  session/Makefile.adon             |    1 +
>  session/output.pl                 |   14 ++++++++++++++
>   
Hmm.. Perhaps this could be generic across all tests? Then it needs to be
in separate directory.
>  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/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);
>   
How does it actually test that function worked _correctly_? What if
it returned something completely random?
> +	} 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);
>   
Same as above.
> +	} 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);
>   
Well, and how does this test that it is actually truly maximum inactive
interval,
as opposed to random number?

Same questions apply to rest of your tests.

-- 
Ilya A. Volynets-Evenbakh
Total Knowledge. CTO
http://www.total-knowledge.com


Authoright © Total Knowledge: 2001-2008