|
From: <jgr...@us...> - 2003-07-10 04:28:18
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv8514/tests
Modified Files:
TestModule.tst
Added Files:
TestConfiguration.tst TestMQ.tst
Log Message:
New test suites for MQ and Configuration; helper class for testing MQ; Logger, MQ and Module now over 90% covered by tests
--- NEW FILE: TestConfiguration.tst ---
# ---------------------------------------------------------------------------------------------
#
# Tests for Configuration.pm
#
# Copyright (c) 2003 John Graham-Cumming
#
# ---------------------------------------------------------------------------------------------
use POPFile::Configuration;
use POPFile::MQ;
use POPFile::Logger;
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
my $l = new POPFile::Logger;
$c->configuration( $c );
# Check that we can get and set a parameter
$c->parameter( 'testparam', 'testvalue' );
test_assert_equal( $c->parameter( 'testparam' ), 'testvalue' );
# Check that we can get the full hash of parameters
my @all = $c->configuration_parameters();
test_assert_equal( $#all, 0 );
test_assert_equal( $all[0], 'testparam' );
$c->mq( $mq );
$c->logger( $l );
$l->configuration( $c );
$l->mq( $mq );
$l->logger( $l );
$l->initialize();
$mq->configuration( $c );
$mq->mq( $mq );
$mq->logger( $l );
# Basic tests
test_assert_equal( $c->name(), 'config' );
# Parameters
test_assert_equal( $c->initialize(), 1 );
test_assert_equal( $c->config_( 'piddir' ), './' );
test_assert_equal( $c->global_config_( 'download_count' ), 0 );
test_assert_equal( $c->global_config_( 'timeout' ), 60 );
test_assert_equal( $c->global_config_( 'xtc' ), 1 );
test_assert_equal( $c->global_config_( 'xpl' ), 1 );
test_assert_equal( $c->global_config_( 'subject' ), 1 );
test_assert_equal( $c->global_config_( 'msgdir' ), 'messages/' );
# Check that the PID file gets created and then deleted and
# contains the correct process ID
$c->config_( 'piddir', 'tests/' );
test_assert_equal( $c->start(), 1 );
test_assert( ( -e 'tests/popfile.pid' ) );
open PIDFILE, '<tests/popfile.pid';
my $pid = <PIDFILE>;
close PIDFILE;
test_assert_equal( $pid, $$ );
$c->stop();
test_assert( !( -e 'tests/popfile.pid' ) );
--- NEW FILE: TestMQ.tst ---
# ---------------------------------------------------------------------------------------------
#
# Tests for MQ.pm
#
# Copyright (c) 2003 John Graham-Cumming
#
# ---------------------------------------------------------------------------------------------
use POPFile::Configuration;
use POPFile::MQ;
use POPFile::Logger;
my $c = new POPFile::Configuration;
my $mq = new POPFile::MQ;
my $l = new POPFile::Logger;
$c->configuration( $c );
$c->mq( $mq );
$c->logger( $l );
$l->configuration( $c );
$l->mq( $mq );
$l->logger( $l );
$l->initialize();
$mq->configuration( $c );
$mq->mq( $mq );
$mq->logger( $l );
# Basic configuration
test_assert_equal( $mq->name(), 'mq' );
# This is a helper object with a deliver
# function that can be called by the message queue
# and a read function that we can call to check that
# messages are getting delivered
use Test::MQReceiver;
my $r = new Test::MQReceiver;
# Register three different message types
$mq->register( 'MSG1', $r );
$mq->register( 'MSG2', $r );
$mq->register( 'MSG3', $r );
# Now send messages and check for their receipt
# First send a single message and check that it is
# received
$mq->post( 'MSG1', 'message1', 'param1' );
$mq->service();
my @messages = $r->read();
test_assert_equal( $#messages, 0 );
test_assert_equal( $messages[0][0], 'MSG1' );
test_assert_equal( $messages[0][1], 'message1' );
test_assert_equal( $messages[0][2], 'param1' );
# Now send three messages and check that they are
# received
$mq->post( 'MSG1', 'message1', 'param1' );
$mq->post( 'MSG2', 'message2', 'param2' );
$mq->post( 'MSG3', 'message3', 'param3' );
$mq->service();
my @messages = $r->read();
test_assert_equal( $#messages, 2 );
test_assert_equal( $messages[0][0], 'MSG1' );
test_assert_equal( $messages[0][1], 'message1' );
test_assert_equal( $messages[0][2], 'param1' );
test_assert_equal( $messages[1][0], 'MSG2' );
test_assert_equal( $messages[1][1], 'message2' );
test_assert_equal( $messages[1][2], 'param2' );
test_assert_equal( $messages[2][0], 'MSG3' );
test_assert_equal( $messages[2][1], 'message3' );
test_assert_equal( $messages[2][2], 'param3' );
# Now send a message that we have not registered
# and check that we do not receive it
$mq->post( 'MSG4', 'message4', 'param4' );
$mq->service();
my @messages = $r->read();
test_assert_equal( $#messages, -1 );
# Now register for it and try to get the message
# this should fail as it should have been cleared
$mq->register( 'MSG3', $r );
$mq->service();
my @messages = $r->read();
test_assert_equal( $#messages, -1 );
# Now try sending the same message multiple times
$mq->post( 'MSG1', 'message1', 'param1' );
$mq->post( 'MSG1', 'message1', 'param1' );
$mq->post( 'MSG1', 'message1', 'param1' );
$mq->service();
my @messages = $r->read();
test_assert_equal( $#messages, 2 );
test_assert_equal( $messages[0][0], 'MSG1' );
test_assert_equal( $messages[0][1], 'message1' );
test_assert_equal( $messages[0][2], 'param1' );
test_assert_equal( $messages[1][0], 'MSG1' );
test_assert_equal( $messages[1][1], 'message1' );
test_assert_equal( $messages[1][2], 'param1' );
test_assert_equal( $messages[1][0], 'MSG1' );
test_assert_equal( $messages[1][1], 'message1' );
test_assert_equal( $messages[1][2], 'param1' );
Index: TestModule.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestModule.tst,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TestModule.tst 1 Jul 2003 18:39:00 -0000 1.1
--- TestModule.tst 10 Jul 2003 04:28:16 -0000 1.2
***************
*** 49,52 ****
--- 49,64 ----
test_assert_equal( $mq->{queue__}{DUMMY}[0][1], 'param' );
+ # Check that register UI item sends the right message
+ use Test::MQReceiver;
+ my $r = new Test::MQReceiver;
+ $m->mq_register_( 'UIREG', $r );
+ $m->register_configuration_item_( 'type', 'name', $c );
+ $mq->service();
+ my @messages = $r->read();
+ test_assert_equal( $#messages, 0 );
+ test_assert_equal( $messages[0][0], 'UIREG' );
+ test_assert_equal( $messages[0][1], 'type:name' );
+ test_assert_equal( $messages[0][2], $c );
+
# Check that the logger function works
***************
*** 61,62 ****
--- 73,91 ----
test_assert( $l->{last_ten__}[0] =~ /logmsg/ );
test_assert_equal( $l->last_ten(), $m->last_ten_log_entries() );
+
+ # Check all the setter/getter functions
+
+ test_assert_equal( $m->mq(), $mq );
+ test_assert_equal( $m->configuration(), $c );
+ $m->forker( 'forker' );
+ test_assert_equal( $m->forker(), 'forker' );
+ test_assert_equal( $m->logger(), $l );
+ $m->pipeready( 'pr' );
+ test_assert_equal( $m->pipeready(), 'pr' );
+ test_assert_equal( $m->alive(), 1 );
+ $m->alive(0);
+ test_assert_equal( $m->alive(), 0 );
+ $m->name( 'newname' );
+ test_assert_equal( $m->name(), 'newname' );
+ $m->version( 'vt.t.t' );
+ test_assert_equal( $m->version(), 'vt.t.t' );
|