From: djfiander Date: Fri, 21 Apr 2006 02:18:47 +0000 (+0000) Subject: Initial test environment X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3abd612ba8b8953073e191d84b18c6efd49b9777;p=SIPServer.git Initial test environment --- diff --git a/Makefile b/Makefile index 595e151..c1c2b3d 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,6 @@ run: tags: find . -name '*.pm' -print | etags - + +test: + cd t; $(MAKE) test diff --git a/t/00sc_status.t b/t/00sc_status.t new file mode 100644 index 0000000..2ae4103 --- /dev/null +++ b/t/00sc_status.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl +# +# sc_status: test basic connection, login, and response +# to the SC Status message, which has to be sent before +# anything else + +use strict; +use warnings; + +use SIPtest; + +my @tests = ( + { id => 'login', + msg => '9300CNscclient|COclientpwd|CPThe basement|', + pat => qr/^941/, + fields => \&SIPtest::no_tagged_fields, }, + + { id => 'SC status', + msg => '9910302.00', + pat => qr/^98[YN]{6}\d{3}\d{3}.{18}[\d]\.\d\d/, + fields => undef, }, + ); + +SIPtest::run_sip_tests(@tests); + +1; diff --git a/t/01patron_status.t b/t/01patron_status.t new file mode 100644 index 0000000..4bcb029 --- /dev/null +++ b/t/01patron_status.t @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# +# patron_status: check status of valid patron and invalid patron + +use strict; +use warnings; + +use SIPtest; + +my @tests = ( + { id => 'login', + msg => '9300CNscclient|COclientpwd|CPThe basement|', + pat => qr/^941/, + fields => \&SIPtest::no_tagged_fields, }, + + { id => 'SC status', + msg => '9910302.00', + pat => qr/^98[YN]{6}\d{3}\d{3}.{18}[\d]\.\d\d/, + fields => undef, }, + { id => 'valid Patron Status', + msg => '2300120060101 084237AOUWOLS|AAdjfiander|AD6789|AC|', + pat => qr/^24 [ Y]{13}\d{3}.{18}/, + fields => undef, }, + { id => 'invalid password Patron Status', + msg => '2300120060101 084237AOUWOLS|AAdjfiander|AC|', + pat => qr/^24Y[ Y]{13}\d{3}.{18}/, + fields => undef, }, + { id => 'invalid Patron Status', + msg => '2300120060101 084237AOUWOLS|AAwshakespeare|AC|', + pat => qr/^24Y[ Y]{13}\d{3}.{18}/, + fields => undef, }, + ); + +SIPtest::run_sip_tests(@tests); + +1; diff --git a/t/Makefile b/t/Makefile new file mode 100644 index 0000000..3202cd4 --- /dev/null +++ b/t/Makefile @@ -0,0 +1,6 @@ +# +# +# + +test: + prove -I.. *.t \ No newline at end of file diff --git a/t/SIPtest.pm b/t/SIPtest.pm new file mode 100644 index 0000000..9d42bcb --- /dev/null +++ b/t/SIPtest.pm @@ -0,0 +1,60 @@ +package SIPtest; + +use Exporter; + +our @ISA = qw(Exporter); + +our @EXPORT_OK = qw(run_sip_tests no_tagged_fields); +use strict; +use warnings; + +# The number of tests is set in run_sip_tests() below, based +# on the size of the array of tests. +use Test::More; + +use IO::Socket::INET; +use Sip qw(:all); +use Sip::Checksum qw(verify_cksum); + +# If a message has no tagged fields, we can just return true +# for that message's field test. +sub no_tagged_fields { + return 1; +} + +sub one_msg { + my ($sock, $test, $seqno) = @_; + my $resp; + + ok(write_msg({seqno => $seqno}, $test->{msg}, $sock), "send $test->{id}"); + ok($resp = <$sock>, "read $test->{id}"); + chomp($resp); + ok(verify_cksum($resp), "checksum $test->{id}"); + like($resp, $test->{pat}, "match leader $test->{id}"); + TODO: { + local $TODO = "$test->{id} field tests not written yet" + unless $test->{fields}; + + ok($test->{fields} && &{$test->{fields}}($resp), "tagged fields $test->{id}"); + } +} + +sub run_sip_tests { + my ($sock, $seqno); + + $Sip::error_detection = 1; + $/ = "\r"; + + $sock = new IO::Socket::INET(PeerAddr => 'localhost:5300', + Type => SOCK_STREAM); + BAIL_OUT('failed to create connection to server') unless $sock; + + $seqno = 1; + + plan tests => scalar @_ * 5; + foreach my $test (@_) { + one_msg($sock, $test, $seqno++); + } +} + +1;