=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/t/network_tests.t,v retrieving revision 1.4 retrieving revision 1.15 diff -u -r1.4 -r1.15 --- HOPE/Net-OpenAMD/t/network_tests.t 2010/06/27 01:52:33 1.4 +++ HOPE/Net-OpenAMD/t/network_tests.t 2010/07/17 13:10:48 1.15 @@ -1,27 +1,30 @@ #!perl package NetworkTests; -# $AFresh1: network_tests.t,v 1.3 2010/06/26 16:50:40 andrew Exp $ +# $AFresh1: network_tests.t,v 1.14 2010/07/17 11:46:47 andrew Exp $ use strict; use warnings; use Test::More; +use Test::Deep; use Net::OpenAMD; +#use Data::Dumper; + if ( !caller() ) { if ( $ENV{'NETWORK_TESTS'} ) { - - # plan tests => ??; + plan tests => 14; } else { - plan skip_all => "Set env NETWORK_TESTS to test"; + plan skip_all => + 'Network test. Set $ENV{NETWORK_TESTS} to a true value to run.'; } my $amd = Net::OpenAMD->new(); run_tests($amd); - done_testing(); + #done_testing(); } 1; @@ -29,78 +32,127 @@ sub run_tests { my ($amd) = @_; + my @interests = ( + "new tech", "activism", + "radio", "lockpicking", + "crypto", "privacy", + "ethics", "telephones", + "social engineering", "hacker spaces", + "hardware hacking", "nostalgia", + "communities", "science", + "government", "network security", + "malicious software", "pen testing", + "web", "niche hacks", + "media" + ); + my %cmp = ( + single_line => re('^[^\n]+$'), + multi_line => re('(?xms:^.*$)'), + digits => re('^\d+$'), + track => any( 'Lovelace', 'Tesla', 'Bell', 'Hooper' ), + area => any('Engressia'), + interests => any(@interests), + all_interests => bag(@interests), + coordinate => re('^\d{1,2}\.\d+$'), + boolean => any( 'True', 'False' ), + ); + + $cmp{user} = [ + $cmp{single_line}, + superhashof( + { name => $cmp{single_line}, + + #interests => array_each( $cmp{interests} ), + #x => $cmp{coordinate}, + #y => $cmp{coordinate}, + } + ), + ]; + + $cmp{speaker} = [ + $cmp{single_line}, + { name => $cmp{single_line}, + bio => $cmp{multi_line}, + } + ]; + + $cmp{location} = superhashof( + { #area => $cmp{area}, + user => $cmp{single_line}, + + #button => $cmp{boolean}, + x => $cmp{coordinate}, + y => $cmp{coordinate}, + + #time => $cmp{single_line}, + } + ); + my %tests = ( location => [ { args => undef, - expect => [ - { 'y' => '83.1452331542969', - 'area' => 'Engressia', - 'time' => 2387, - 'user' => 12983, - 'x' => '46.7369918823242', - 'button' => 'False' - } - ], + expect => array_each( $cmp{location} ), }, + { args => { user => 'user0' }, + expect => qr/^Invalid \s JSON|$/xms, + }, + { args => { user => 'user0', limit => 5 }, + expect => qr/^Invalid \s JSON|$/xms, + }, + { args => { area => 'Lovelace' }, + expect => array_each( $cmp{location} ), + }, ], speakers => [ { args => undef, - expect => [ - { 'name' => 'Johnny', - 'bio' => 'Johnny\'s bio' - }, - ], + expect => array_each( $cmp{speaker} ), }, + { args => { name => 'The Cheshire Catalyst' }, + expect => array_each( $cmp{speaker} ), + }, ], talks => [ { args => undef, - expect => [ - { 'speakers' => [ 'Judas', 'JohnnyX' ], - 'interests' => [ 'media', 'crypto' ], - 'time' => '2008/7/18 13:00:00', - 'track' => 'Hooper', - 'title' => 'Ancient Egyptian Music and DRM', - 'abstract' => - 'A discussion of the development of musical notation, which was designed as a means of reproducing music while making it impossible for the general public to perform without permission.' + expect => array_each( + { abstract => $cmp{multi_line}, + speakers => array_each( $cmp{single_line} ), + time => $cmp{single_line}, + title => $cmp{single_line}, + track => $cmp{track}, } - ], + ), }, + { args => { interests => 'lockpicking' }, + expect => array_each( + { abstract => $cmp{multi_line}, + speakers => array_each( $cmp{single_line} ), + time => $cmp{single_line}, + title => $cmp{single_line}, + track => $cmp{track}, + + # interests => 'lockpicking', + } + ), + }, ], interests => [ { args => undef, - expect => [ - 'new tech', 'activism', - 'radio', 'lockpicking', - 'crypto', 'privacy', - 'ethics', 'telephones', - 'social engineering', 'hacker spaces', - 'hardware hacking', 'nostalgia', - 'communities', 'science', - 'government', 'network security', - 'malicious software', 'pen testing', - 'web', 'niche hacks', - 'media', - ], + expect => $cmp{all_interests}, }, ], users => [ { args => undef, - expect => [ - { 'name' => 'JohnnyX', - 'x' => '32.54091324', - 'y' => '54.10958384', - 'interests' => [ - 'new tech', 'radio', - 'lockpicking', 'crypto', - 'telephones', 'social engineering', - 'hacker spaces', 'hardware hacking', - 'nostalgia', 'communities', - 'science', 'network security', - 'malicious software', 'pen testing' - ], - } - ] + expect => array_each( $cmp{user} ), }, + { args => { user => 'user0' }, + expect => array_each( $cmp{user} ), + }, + { args => { user => 'user0', limit => 20 }, + expect => array_each( $cmp{user} ), + }, + { args => { interests => 'lockpicking' }, + expect => array_each( $cmp{user} ), + }, ], stats => [ { args => undef, @@ -118,8 +170,14 @@ like( $@, $test->{expect}, "AMD->$method($test->{args})" ); } elsif ( ref $test->{expect} ) { - is( $@, '', "AMD->$method($test->{args})" ); - is_deeply( $result, $test->{expect}, 'got expected result' ); + if ($@) { + is( $@, '', "AMD->$method($test->{args})" ); + } + else { + cmp_deeply( $result, $test->{expect}, + "AMD->$method($test->{args}) - " + . 'got expected result' ); + } } else { is( $@, $test->{expect}, "AMD->$method($test->{args})" );