[BACK]Return to network_tests.t CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / t

Annotation of HOPE/Net-OpenAMD/t/network_tests.t, Revision 1.14

1.1       andrew      1: #!perl
                      2: package NetworkTests;
1.2       andrew      3:
1.14    ! andrew      4: # $AFresh1: network_tests.t,v 1.13 2010/07/14 01:54:03 andrew Exp $
1.1       andrew      5:
                      6: use strict;
                      7: use warnings;
                      8:
                      9: use Test::More;
1.9       andrew     10: use Test::Deep;
1.1       andrew     11: use Net::OpenAMD;
1.11      andrew     12:
                     13: #use Data::Dumper;
1.1       andrew     14:
1.2       andrew     15: if ( !caller() ) {
                     16:     if ( $ENV{'NETWORK_TESTS'} ) {
1.14    ! andrew     17:         plan tests => 14;
1.1       andrew     18:     }
                     19:     else {
1.6       andrew     20:         plan skip_all =>
                     21:             'Network test.  Set $ENV{NETWORK_TESTS} to a true value to run.';
1.1       andrew     22:     }
                     23:
1.14    ! andrew     24:     my $amd = Net::OpenAMD->new();
1.9       andrew     25:     run_tests($amd);
                     26:
                     27:     #done_testing();
                     28: }
                     29:
                     30: 1;
                     31:
                     32: sub run_tests {
                     33:     my ($amd) = @_;
                     34:
                     35:     my @interests = (
                     36:         "new tech",           "activism",
                     37:         "radio",              "lockpicking",
                     38:         "crypto",             "privacy",
                     39:         "ethics",             "telephones",
                     40:         "social engineering", "hacker spaces",
                     41:         "hardware hacking",   "nostalgia",
                     42:         "communities",        "science",
                     43:         "government",         "network security",
                     44:         "malicious software", "pen testing",
                     45:         "web",                "niche hacks",
                     46:         "media"
                     47:     );
                     48:     my %cmp = (
                     49:         single_line   => re('^[^\n]+$'),
1.10      andrew     50:         multi_line    => re('(?xms:^.*$)'),
1.9       andrew     51:         digits        => re('^\d+$'),
                     52:         track         => any( 'Lovelace', 'Tesla', 'Bell', 'Hooper' ),
                     53:         area          => any('Engressia'),
                     54:         interests     => any(@interests),
                     55:         all_interests => bag(@interests),
1.14    ! andrew     56:         coordinate    => re('^\d{1,2}\.\d+$'),
1.9       andrew     57:         boolean => any( 'True', 'False' ),
                     58:     );
                     59:
1.11      andrew     60:     $cmp{user} = [
                     61:         $cmp{single_line},
1.13      andrew     62:         superhashof(
                     63:             {   name => $cmp{single_line},
1.11      andrew     64:
1.13      andrew     65:                 #interests => array_each( $cmp{interests} ),
                     66:                 #x         => $cmp{coordinate},
                     67:                 #y         => $cmp{coordinate},
                     68:             }
                     69:         ),
1.11      andrew     70:     ];
                     71:
                     72:     $cmp{speaker} = [
                     73:         $cmp{single_line},
                     74:         {   name => $cmp{single_line},
                     75:             bio  => $cmp{multi_line},
                     76:         }
                     77:     ];
1.9       andrew     78:
1.13      andrew     79:     $cmp{location} = superhashof(
1.14    ! andrew     80:         {   #area => $cmp{area},
        !            81:             user => $cmp{single_line},
1.13      andrew     82:
                     83:             #button => $cmp{boolean},
                     84:             x => $cmp{coordinate},
                     85:             y => $cmp{coordinate},
                     86:
                     87:             #time   => $cmp{single_line},
                     88:         }
                     89:     );
                     90:
1.2       andrew     91:     my %tests = (
                     92:         location => [
                     93:             {   args   => undef,
1.13      andrew     94:                 expect => array_each( $cmp{location} ),
1.2       andrew     95:             },
1.10      andrew     96:             {   args   => { user => 'user0' },
1.14    ! andrew     97:                 expect => qr/^Invalid \s JSON/xms,
1.8       andrew     98:             },
1.13      andrew     99:             {   args   => { user => 'user0', limit => 5 },
1.14    ! andrew    100:                 expect => qr/^Invalid \s JSON/xms,
1.11      andrew    101:             },
1.14    ! andrew    102:             {   args   => { area => 'Lovelace' },
        !           103:                 expect => array_each( $cmp{location} ),
1.11      andrew    104:             },
1.2       andrew    105:         ],
                    106:         speakers => [
                    107:             {   args   => undef,
1.11      andrew    108:                 expect => array_each( $cmp{speaker} ),
                    109:             },
                    110:             {   args => { name => 'The Cheshire Catalyst' },
                    111:                 expect => array_each( $cmp{speaker} ),
1.2       andrew    112:             },
                    113:         ],
                    114:         talks => [
                    115:             {   args   => undef,
1.9       andrew    116:                 expect => array_each(
1.10      andrew    117:                     {   abstract => $cmp{multi_line},
                    118:                         speakers => array_each( $cmp{single_line} ),
                    119:                         time     => $cmp{single_line},
                    120:                         title    => $cmp{single_line},
                    121:                         track    => $cmp{track},
1.9       andrew    122:                     }
                    123:                 ),
1.2       andrew    124:             },
1.11      andrew    125:             {   args   => { interests => 'lockpicking' },
                    126:                 expect => array_each(
                    127:                     {   abstract => $cmp{multi_line},
                    128:                         speakers => array_each( $cmp{single_line} ),
                    129:                         time     => $cmp{single_line},
                    130:                         title    => $cmp{single_line},
                    131:                         track    => $cmp{track},
                    132:
                    133:                         # interests => 'lockpicking',
                    134:                     }
                    135:                 ),
                    136:             },
1.2       andrew    137:         ],
                    138:         interests => [
                    139:             {   args   => undef,
1.9       andrew    140:                 expect => $cmp{all_interests},
1.2       andrew    141:             },
                    142:         ],
                    143:         users => [
                    144:             {   args   => undef,
1.11      andrew    145:                 expect => array_each( $cmp{user} ),
                    146:             },
                    147:             {   args   => { user => 'user0' },
                    148:                 expect => array_each( $cmp{user} ),
                    149:             },
                    150:             {   args   => { user => 'user0', limit => 20 },
                    151:                 expect => array_each( $cmp{user} ),
                    152:             },
                    153:             {   args   => { interests => 'lockpicking' },
                    154:                 expect => array_each( $cmp{user} ),
1.2       andrew    155:             },
                    156:         ],
                    157:         stats => [
                    158:             {   args   => undef,
1.4       andrew    159:                 expect => qr/^Unused \s feature/xms,
1.2       andrew    160:             },
                    161:         ],
                    162:     );
                    163:
1.9       andrew    164:     foreach my $method ( keys %tests ) {
                    165:         foreach my $test ( @{ $tests{$method} } ) {
1.2       andrew    166:             no warnings 'uninitialized';
                    167:             my $result;
                    168:             eval { $result = $amd->$method( $test->{args} ) };
1.4       andrew    169:             if ( ref $test->{expect} eq 'Regexp' ) {
                    170:                 like( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    171:             }
                    172:             elsif ( ref $test->{expect} ) {
1.14    ! andrew    173:                 if ($@) {
        !           174:                     is( $@, '', "AMD->$method($test->{args})" );
        !           175:                 }
        !           176:                 else {
        !           177:                     cmp_deeply( $result, $test->{expect},
        !           178:                               "AMD->$method($test->{args}) - "
        !           179:                             . 'got expected result' );
        !           180:                 }
1.4       andrew    181:             }
                    182:             else {
                    183:                 is( $@, $test->{expect}, "AMD->$method($test->{args})" );
                    184:             }
1.2       andrew    185:         }
                    186:     }
1.1       andrew    187: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>