5 my $debug = shift @ARGV;
7 use Test::More tests => 73;
8 use Data::Dump qw/dump/;
14 use_ok('CWMP::Request');
17 my @models = ( qw/SpeedTouch-706 SpeedTouch-780/ );
19 ok( $#models + 1, 'got models' );
21 ok(my $abs_path = abs_path($0), "abs_path");
22 $abs_path =~ s!/[^/]*$!/!; #!fix-vim
30 ok( my $xml = read_file( $path ), "read_file( $path )" );
34 ok( my $trigger = $path2method->{$path}, "path2method($path)" );
36 CWMP::Request->add_trigger( name => $trigger, callback => sub {
37 my ( $self, $state ) = @_;
38 $triggers_count->{$trigger}++;
39 ok( $state, "called trigger $trigger" );
42 ok( my $state = CWMP::Request->parse( $xml ), 'parse' );
44 my $dump_path = $path;
45 $dump_path =~ s/\.xml/\.pl/;
47 write_file( $dump_path, dump( $state ) ) unless ( -e $dump_path );
49 diag "$path ? $dump_path" if $debug;
51 ok( my $hash = read_file( $dump_path ), "read_file( $dump_path )" );
52 ok ( $hash = eval "$hash", 'eval' );
54 is_deeply( $state, $hash, 'same' );
57 foreach my $model ( @models ) {
59 my $dir = "$abs_path/$model/";
60 opendir(DIR, $dir) || die "can't opendir $dir: $!";
64 $method =~ s/\.xml$//;
65 $path2method->{$path} = $method;
67 } grep { /\.xml$/ && -f "$dir/$_" } readdir(DIR);
70 diag "$model has ", $#xmls + 1, " xml tests";
74 foreach my $xml_path ( @xmls ) {
75 ok ( $xml_path, 'xml path' );
76 file_is_deeply( $xml_path );
80 diag "triggers_count = ",dump( $triggers_count ) if $debug;