/[cwmp]/google/trunk/t/10-request.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /google/trunk/t/10-request.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 200 - (hide annotations)
Wed Nov 14 19:23:32 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1708 byte(s)
 r212@brr:  dpavlin | 2007-11-14 20:23:06 +0100
 added Class::Trigger based triggers on SOAP requests from CPE

1 dpavlin 31 #!/usr/bin/perl
2     use strict;
3     use warnings;
4    
5     my $debug = shift @ARGV;
6    
7 dpavlin 200 use Test::More tests => 73;
8 dpavlin 31 use Data::Dump qw/dump/;
9 dpavlin 58 use Cwd qw/abs_path/;
10     use File::Slurp;
11 dpavlin 31 use blib;
12    
13     BEGIN {
14     use_ok('CWMP::Request');
15     }
16    
17 dpavlin 69 my @models = ( qw/SpeedTouch-706 SpeedTouch-780/ );
18 dpavlin 31
19 dpavlin 60 ok( $#models + 1, 'got models' );
20 dpavlin 31
21 dpavlin 58 ok(my $abs_path = abs_path($0), "abs_path");
22     $abs_path =~ s!/[^/]*$!/!; #!fix-vim
23 dpavlin 31
24 dpavlin 200 my $path2method;
25     my $triggers_count;
26    
27 dpavlin 58 sub file_is_deeply {
28     my ( $path ) = @_;
29 dpavlin 31
30 dpavlin 58 ok( my $xml = read_file( $path ), "read_file( $path )" );
31 dpavlin 31
32 dpavlin 58 diag $xml if $debug;
33 dpavlin 31
34 dpavlin 200 ok( my $trigger = $path2method->{$path}, "path2method($path)" );
35    
36     CWMP::Request->add_trigger( name => $trigger, callback => sub {
37     my ( $self, $state ) = @_;
38     $triggers_count->{$trigger}++;
39     ok( $state, "called trigger $trigger" );
40     });
41    
42 dpavlin 58 ok( my $state = CWMP::Request->parse( $xml ), 'parse' );
43    
44     my $dump_path = $path;
45     $dump_path =~ s/\.xml/\.pl/;
46    
47     write_file( $dump_path, dump( $state ) ) unless ( -e $dump_path );
48    
49 dpavlin 63 diag "$path ? $dump_path" if $debug;
50 dpavlin 58
51 dpavlin 63 ok( my $hash = read_file( $dump_path ), "read_file( $dump_path )" );
52 dpavlin 58 ok ( $hash = eval "$hash", 'eval' );
53    
54     is_deeply( $state, $hash, 'same' );
55     }
56    
57     foreach my $model ( @models ) {
58    
59     my $dir = "$abs_path/$model/";
60     opendir(DIR, $dir) || die "can't opendir $dir: $!";
61 dpavlin 200 my @xmls = map {
62     my $path = "$dir/$_";
63     my $method = $_;
64     $method =~ s/\.xml$//;
65     $path2method->{$path} = $method;
66     $path;
67     } grep { /\.xml$/ && -f "$dir/$_" } readdir(DIR);
68 dpavlin 58 closedir DIR;
69    
70 dpavlin 69 diag "$model has ", $#xmls + 1, " xml tests";
71 dpavlin 58
72     ok( $#xmls, "xmls" );
73    
74     foreach my $xml_path ( @xmls ) {
75     ok ( $xml_path, 'xml path' );
76     file_is_deeply( $xml_path );
77     }
78     }
79    
80 dpavlin 200 diag "triggers_count = ",dump( $triggers_count ) if $debug;
81    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26