4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 7; |
use Test::More tests => 14; |
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 ); |
my $state = { |
27 |
diag $xml if $debug; |
ID => 42, |
28 |
chomp( $xml ); |
}; |
29 |
chomp( $template_xml ); |
|
30 |
like( $xml, qr{^\Q$template_xml\E$}, $command . ' xml' ); |
diag "check_response $command",dump( 'state', @_ ) if $debug; |
31 |
|
ok( my $xml = $response->$command( $state, @_ ), "generate response $command" . dump(@_) ); |
32 |
|
|
33 |
|
my $file = "$abs_path/response/$command.xml"; |
34 |
|
|
35 |
|
if ( ! -e $file ) { |
36 |
|
diag "creating $file"; |
37 |
|
write_file( $file, $xml ); |
38 |
|
} |
39 |
|
|
40 |
|
my $template_xml = read_file( $file ) || die "can't read template xml $file: $!"; |
41 |
|
|
42 |
|
is( $xml, $template_xml, "compare $command" ); |
43 |
} |
} |
44 |
|
|
45 |
is_like( 'Inform', <<__SOAP__ |
check_response( 'InformResponse' ); |
46 |
<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' ); |
47 |
<soap:Header> |
check_response( 'Reboot' ); |
48 |
<cwmp:ID mustUnderstand="1">42</cwmp:ID> |
check_response( 'GetParameterNames', 'InternetGatewayDevice.DeviceInfo.SerialNumber' ); |
49 |
<cwmp:NoMoreRequests>0</cwmp:NoMoreRequests> |
check_response( 'GetParameterValues', 'InternetGatewayDevice.DeviceInfo.SerialNumber', 'InternetGatewayDevice.DeviceInfo.VendorConfigFile.' ); |
|
</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__ |
|
|
); |
|