shlist

share and manage lists between multiple people
Log | Files | Refs

commit 1c272647cc57dfd95d2f8c277a61f87d2bf3b471
parent 89154444ada1f21b0f0d605f79b87899d03346b1
Author: kyle <kyle@getaddrinfo.net>
Date:   Sat, 21 Nov 2015 16:57:29 -0700

test: rename testlib.pm to test.pm

- do this for consistency with test.mk, test.sh

Diffstat:
Mtests/add_friend/test.pl | 6++----
Mtests/double_register/test.pl | 2+-
Mtests/new_device/test.pl | 2+-
Mtests/new_device_bad_phnum/test.pl | 2+-
Mtests/new_list/test.pl | 2+-
Mtests/new_list_bad_devid/test.pl | 2+-
Mtests/new_list_missing_name/test.pl | 2+-
Mtests/payload_size_zero/test.pl | 2+-
Mtests/payload_too_large/test.pl | 2+-
Atests/test.pm | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtests/testlib.pm | 74--------------------------------------------------------------------------
Mtests/two_lists_same_name/test.pl | 2+-
12 files changed, 85 insertions(+), 87 deletions(-)

diff --git a/tests/add_friend/test.pl b/tests/add_friend/test.pl @@ -1,13 +1,11 @@ #!/usr/bin/perl -I../ - use strict; use warnings; - -use testlib; +use test; # this test: # - gets a new device id -# - then adds a new friend +# - adds a new friend my $sock = new_socket(); send_msg($sock, 0, "4038675309"); diff --git a/tests/double_register/test.pl b/tests/double_register/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -I../ use strict; use warnings; -use testlib; +use test; my $sock = new_socket(); send_msg($sock, $msg_num{new_device}, "4038675309"); diff --git a/tests/new_device/test.pl b/tests/new_device/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -I../ use strict; use warnings; -use testlib; +use test; my $sock = new_socket(); send_msg($sock, $msg_num{new_device}, "4038675309"); diff --git a/tests/new_device_bad_phnum/test.pl b/tests/new_device_bad_phnum/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -I../ use strict; use warnings; -use testlib; +use test; # send a new device message with a bad phone number my $sock = new_socket(); diff --git a/tests/new_list/test.pl b/tests/new_list/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; # this test: # - gets a new device id diff --git a/tests/new_list_bad_devid/test.pl b/tests/new_list_bad_devid/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; # this test: # - gets a new device id diff --git a/tests/new_list_missing_name/test.pl b/tests/new_list_missing_name/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; # this test: # - gets a new device id diff --git a/tests/payload_size_zero/test.pl b/tests/payload_size_zero/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; my $sock = new_socket(); send_msg($sock, 0, ""); diff --git a/tests/payload_too_large/test.pl b/tests/payload_too_large/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; my $sock = new_socket(); diff --git a/tests/test.pm b/tests/test.pm @@ -0,0 +1,74 @@ +package test; +use strict; +use warnings; + +use Exporter qw(import); +use IO::Socket; + +require "msgs.pl"; +our (%msg_num, @msg_str, @msg_func, $protocol_ver); + +our @EXPORT = qw(new_socket fail send_msg recv_msg %msg_num); + +sub fail { + print shift; + exit 1; +} + +sub new_socket +{ + if (! defined $ENV{PORT}) { + fail "$0: error, test needs PORT environment variable set\n"; + exit 1; + } + + my $sock = new IO::Socket::INET( + LocalHost => '127.0.0.1', + PeerHost => '127.0.0.1', + PeerPort => $ENV{PORT}, + Proto => 'tcp' + ); + + die "error: new socket: $!\n" unless $sock; + return $sock; +} + +sub send_msg +{ + my ($sock, $type, $contents) = @_; + + # send away + print $sock pack("nn", $type, length($contents)); + print $sock $contents; +} + +sub recv_msg +{ + my ($sock) = @_; + + # wait for response + my ($metadata, $type, $size); + my $bread = read($sock, $metadata, 4); + unless (defined $bread) { + fail "read(): $!\n"; + } + if ($bread != 4) { + fail "read() returned $bread instead of 4!"; + } + unless (($type, $size) = unpack("nn", $metadata)) { + fail "error unpacking metadata"; + } + + # XXX: do msg type upper bounds checking here + fail "bad message size not 0 <= $size < 1024" if ($size < 0 || $size > 1023); + + my $data; + if ((my $bread = read($sock, $data, $size)) != $size) { + fail "read() returned $bread instead of $size!"; + } + + # caller should validate this is the expected type + return ($type, $data, $size); +} + +1; diff --git a/tests/testlib.pm b/tests/testlib.pm @@ -1,74 +0,0 @@ -package testlib; -use strict; -use warnings; - -use Exporter qw(import); -use IO::Socket; - -require "msgs.pl"; -our (%msg_num, @msg_str, @msg_func, $protocol_ver); - -our @EXPORT = qw(new_socket fail send_msg recv_msg %msg_num); - -sub fail { - print shift; - exit 1; -} - -sub new_socket -{ - if (! defined $ENV{PORT}) { - fail "$0: error, test needs PORT environment variable set\n"; - exit 1; - } - - my $sock = new IO::Socket::INET( - LocalHost => '127.0.0.1', - PeerHost => '127.0.0.1', - PeerPort => $ENV{PORT}, - Proto => 'tcp' - ); - - die "error: new socket: $!\n" unless $sock; - return $sock; -} - -sub send_msg -{ - my ($sock, $type, $contents) = @_; - - # send away - print $sock pack("nn", $type, length($contents)); - print $sock $contents; -} - -sub recv_msg -{ - my ($sock) = @_; - - # wait for response - my ($metadata, $type, $size); - my $bread = read($sock, $metadata, 4); - unless (defined $bread) { - fail "read(): $!\n"; - } - if ($bread != 4) { - fail "read() returned $bread instead of 4!"; - } - unless (($type, $size) = unpack("nn", $metadata)) { - fail "error unpacking metadata"; - } - - # XXX: do msg type upper bounds checking here - fail "bad message size not 0 <= $size < 1024" if ($size < 0 || $size > 1023); - - my $data; - if ((my $bread = read($sock, $data, $size)) != $size) { - fail "read() returned $bread instead of $size!"; - } - - # caller should validate this is the expected type - return ($type, $data, $size); -} - -1; diff --git a/tests/two_lists_same_name/test.pl b/tests/two_lists_same_name/test.pl @@ -3,7 +3,7 @@ use strict; use warnings; -use testlib; +use test; # this test: # - gets a new device id