4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 11; |
use Test::More tests => 12; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
use Cwd qw/abs_path/; |
10 |
|
use File::Slurp; |
11 |
use blib; |
use blib; |
12 |
|
|
13 |
BEGIN { |
BEGIN { |
14 |
use_ok('CWMP::Response'); |
use_ok('CWMP::Response'); |
15 |
} |
} |
16 |
|
|
17 |
#ok( my $xml = join("",<DATA>), 'xml' ); |
ok(my $abs_path = abs_path($0), "abs_path"); |
18 |
#diag $xml if $debug; |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
19 |
|
|
20 |
ok( my $response = CWMP::Response->new({ debug => $debug }), 'new' ); |
ok( my $response = CWMP::Response->new({ debug => $debug }), 'new' ); |
21 |
isa_ok( $response, 'CWMP::Response' ); |
isa_ok( $response, 'CWMP::Response' ); |
22 |
|
|
23 |
sub is_like { |
sub check_response { |
24 |
my ( $command, $template_xml ) = @_; |
my $command = shift || die "no command?"; |
25 |
|
|
26 |
ok( my $xml = $response->$command({ ID => 42 }), $command ); |
ok( my $xml = $response->$command({ ID => 42 }), "generate response for $command" ); |
27 |
diag $xml if $debug; |
|
28 |
chomp( $xml ); |
my $file = "$abs_path/response/$command.xml"; |
29 |
chomp( $template_xml ); |
|
30 |
like( $xml, qr{^\Q$template_xml\E$}, $command . ' xml' ); |
if ( ! -e $file ) { |
31 |
|
diag "creating $file"; |
32 |
|
write_file( $file, $xml ); |
33 |
|
} |
34 |
|
|
35 |
|
my $template_xml = read_file( $file ) || die "can't read template xml $file: $!"; |
36 |
|
|
37 |
|
is( $xml, $template_xml, "compare $command" ); |
38 |
} |
} |
39 |
|
|
40 |
is_like( 'InformResponse', <<__SOAP__ |
check_response( 'InformResponse' ); |
41 |
<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
check_response( 'GetRPCMethods' ); |
42 |
<soap:Header> |
check_response( 'Reboot' ); |
43 |
<cwmp:ID mustUnderstand="1">42</cwmp:ID> |
check_response( 'GetParameterNames' ); |
|
<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests> |
|
|
</soap:Header> |
|
|
<soap:Body> |
|
|
<cwmp:InformResponse> |
|
|
<cwmp:MaxEnvelopes>1</cwmp:MaxEnvelopes> |
|
|
</cwmp:InformResponse> |
|
|
</soap:Body> |
|
|
</soap:Envelope> |
|
|
__SOAP__ |
|
|
); |
|
|
|
|
|
is_like( 'GetRPCMethods', <<__SOAP__ |
|
|
<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
|
|
<soap:Header> |
|
|
<cwmp:ID mustUnderstand="1">42</cwmp:ID> |
|
|
<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests> |
|
|
</soap:Header> |
|
|
<soap:Body> |
|
|
<GetRPCMethods /> |
|
|
</soap:Body> |
|
|
</soap:Envelope> |
|
|
__SOAP__ |
|
|
); |
|
|
|
|
|
is_like( 'Reboot', <<__SOAP__ |
|
|
<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
|
|
<soap:Header> |
|
|
<cwmp:ID mustUnderstand="1">42</cwmp:ID> |
|
|
<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests> |
|
|
</soap:Header> |
|
|
<soap:Body> |
|
|
<Reboot /> |
|
|
</soap:Body> |
|
|
</soap:Envelope> |
|
|
__SOAP__ |
|
|
); |
|
|
|
|
|
is_like( 'GetParameterNames', <<__SOAP__ |
|
|
<soap:Envelope xmlns:cwmp="urn:dslforum-org:cwmp-1-0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> |
|
|
<soap:Header> |
|
|
<cwmp:ID mustUnderstand="1">42</cwmp:ID> |
|
|
<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests> |
|
|
</soap:Header> |
|
|
<soap:Body> |
|
|
<cwmp:GetParameterNames> |
|
|
<cwmp:ParameterPath></cwmp:ParameterPath> |
|
|
<cwmp:NextLevel>0</cwmp:NextLevel> |
|
|
</cwmp:GetParameterNames> |
|
|
</soap:Body> |
|
|
</soap:Envelope> |
|
|
__SOAP__ |
|
|
); |
|