Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv8832/tests
Modified Files:
TestHTML.tst
Log Message:
Start of test suite for HTML interface
Index: TestHTML.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestHTML.tst,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** TestHTML.tst 31 Jul 2003 16:32:22 -0000 1.3
--- TestHTML.tst 20 Aug 2003 03:09:03 -0000 1.4
***************
*** 23,26 ****
--- 23,49 ----
# ---------------------------------------------------------------------------------------------
+ use POSIX ":sys_wait_h";
+
+ sub pipeready
+ {
+ my ( $pipe ) = @_;
+
+ if ( !defined( $pipe ) ) {
+ return 0;
+ }
+
+ if ( $^O eq 'MSWin32' ) {
+ return ( ( -s $pipe ) > 0 );
+ } else {
+ my $rin = '';
+ vec( $rin, fileno( $pipe ), 1 ) = 1;
+ my $ready = select( $rin, undef, undef, 0.01 );
+ return ( $ready > 0 );
+ }
+ }
+
+ test_assert( `rm -rf messages` == 0 );
+
+ use Classifier::Bayes;
use UI::HTML;
use POPFile::Configuration;
***************
*** 31,38 ****
--- 54,63 ----
my $mq = new POPFile::MQ;
my $l = new POPFile::Logger;
+ my $b = new Classifier::Bayes;
$c->configuration( $c );
$c->mq( $mq );
$c->logger( $l );
+ $c->initialize();
$l->configuration( $c );
***************
*** 46,49 ****
--- 71,80 ----
$mq->logger( $l );
+ $b->configuration( $c );
+ $b->mq( $mq );
+ $b->logger( $l );
+
+ $b->initialize();
+
my $h = new UI::HTML;
***************
*** 51,54 ****
--- 82,87 ----
$h->mq( $mq );
$h->logger( $l );
+ $h->classifier( $b );
+ $h->initialize();
test_assert_equal( $h->url_encode_( ']' ), '%5d' );
***************
*** 56,58 ****
--- 89,159 ----
test_assert_equal( $h->url_encode_( '[]' ), '%5b%5d' );
test_assert_equal( $h->url_encode_( '[foo]' ), '%5bfoo%5d' );
+
+ my $port = 9000 + int(rand(1000));
+ pipe my $dreader, my $dwriter;
+ pipe my $ureader, my $uwriter;
+ my $pid = fork();
+
+ if ( $pid == 0 ) {
+
+ # CHILD THAT WILL RUN THE HTML INTERFACE
+
+ close $dwriter;
+ close $ureader;
+
+ $h->version( 'testsuite' );
+ $h->config_( 'port', $port );
+ $h->start();
+
+ while ( 1 ) {
+ last if !$h->service();
+
+ if ( pipeready( $dreader ) ) {
+ my $command = <$dreader>;
+
+ if ( $command =~ /__QUIT/ ) {
+ print $uwriter "OK\n";
+ last;
+ }
+ }
+ }
+
+ close $dreader;
+ close $uwriter;
+
+ exit(0);
+ } else {
+
+ # PARENT THAT WILL SEND COMMANDS TO THE WEB INTERFACE
+
+ close $dreader;
+ close $uwriter;
+ $dwriter->autoflush(1);
+
+ use LWP::Simple;
+ use URI::URL;
+
+ # Test the simplest functionality of the HTML interface
+
+ my $url = url( "http://127.0.0.1:$port" );
+ my $content = get($url);
+
+ # TODO Look for elements that should appear at the TOP and BOTTOM
+ # of every page
+
+ test_assert_regexp( $content, "<title>POPFile Control Center</title>" );
+
+ # TODO Validate every page in the interface against the W3C HTML 4.01
+ # validation service
+
+ print $dwriter "__QUIT\n";
+ $content = <$ureader>;
+ test_assert_equal( $content, "OK\n" );
+ close $dwriter;
+ close $ureader;
+
+ while ( waitpid( $pid, &WNOHANG ) != $pid ) {
+ }
+ }
+
|