4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 4; |
use Test::More tests => 24; |
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::Request'); |
use_ok('CWMP::Request'); |
15 |
} |
} |
16 |
|
|
17 |
ok( my $xml = join("",<DATA>), 'xml' ); |
my @models = ( qw/SpeedTouch-706/ ); |
18 |
|
|
19 |
diag $xml if $debug; |
ok( $#models, 'got models' ); |
20 |
|
|
21 |
ok( my $state = CWMP::Request->parse( $xml ), 'parse' ); |
ok(my $abs_path = abs_path($0), "abs_path"); |
22 |
|
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
23 |
|
|
24 |
|
sub file_is_deeply { |
25 |
|
my ( $path ) = @_; |
26 |
|
|
27 |
|
ok( my $xml = read_file( $path ), "read_file( $path )" ); |
28 |
|
|
29 |
|
diag $xml if $debug; |
30 |
|
|
31 |
|
ok( my $state = CWMP::Request->parse( $xml ), 'parse' ); |
32 |
|
|
33 |
|
my $dump_path = $path; |
34 |
|
$dump_path =~ s/\.xml/\.pl/; |
35 |
|
|
36 |
|
write_file( $dump_path, dump( $state ) ) unless ( -e $dump_path ); |
37 |
|
|
38 |
|
diag "$path ? $dump_path"; |
39 |
|
|
40 |
|
my $hash = read_file( $dump_path ), "read_file( $dump_path )"; |
41 |
|
ok ( $hash = eval "$hash", 'eval' ); |
42 |
|
|
43 |
|
is_deeply( $state, $hash, 'same' ); |
44 |
|
} |
45 |
|
|
46 |
|
foreach my $model ( @models ) { |
47 |
|
|
48 |
|
my $dir = "$abs_path/$model/"; |
49 |
|
opendir(DIR, $dir) || die "can't opendir $dir: $!"; |
50 |
|
my @xmls = map { "$dir/$_" } grep { /\.xml$/ && -f "$dir/$_" } readdir(DIR); |
51 |
|
closedir DIR; |
52 |
|
|
53 |
|
diag "got ", $#xmls + 1, " xml tests"; |
54 |
|
|
55 |
|
ok( $#xmls, "xmls" ); |
56 |
|
|
57 |
|
foreach my $xml_path ( @xmls ) { |
58 |
|
ok ( $xml_path, 'xml path' ); |
59 |
|
file_is_deeply( $xml_path ); |
60 |
|
} |
61 |
|
} |
62 |
|
|
|
is_deeply( $state, { |
|
|
CurrentTime => "1970-01-01T00:04:33Z", |
|
|
DeviceID => { |
|
|
Manufacturer => "THOMSON", |
|
|
OUI => "00147F", |
|
|
ProductClass => "SpeedTouch 780", |
|
|
SerialNumber => "CP0644JTHJ4", |
|
|
}, |
|
|
EventStruct => ["0 BOOTSTRAP", "1 BOOT", "4 VALUE CHANGE"], |
|
|
ID => "1_THOM_TR69_ID", |
|
|
MaxEnvelopes => 2, |
|
|
Parameter => { |
|
|
".ExternalIPAddress" => "192.168.1.254", |
|
|
"InternetGatewayDevice.DeviceInfo.HardwareVersion" => "BANT-R", |
|
|
"InternetGatewayDevice.DeviceInfo.ProvisioningCode" => undef, |
|
|
"InternetGatewayDevice.DeviceInfo.SoftwareVersion" => "6.2.15.5", |
|
|
"InternetGatewayDevice.DeviceInfo.SpecVersion" => "1.1", |
|
|
"InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date" => "0000-00-00T00:00:00", |
|
|
"InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description" => "Factory Defaults", |
|
|
"InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name" => "Routed PPPoE on 0/35 and 8/35", |
|
|
"InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version" => undef, |
|
|
"InternetGatewayDevice.DeviceSummary" => "InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)", |
|
|
"InternetGatewayDevice.ManagementServer.ConnectionRequestURL" => "http://192.168.1.254:51005/", |
|
|
"InternetGatewayDevice.ManagementServer.ParameterKey" => undef, |
|
|
}, |
|
|
RetryCount => "01", |
|
|
}, 'state' ); |
|
|
|
|
|
diag dump( $state ) if $debug; |
|
|
|
|
|
|
|
|
__DATA__ |
|
|
<soapenv:Envelope soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0"> |
|
|
<soapenv:Header> |
|
|
<cwmp:ID soapenv:mustUnderstand="1">1_THOM_TR69_ID</cwmp:ID> |
|
|
</soapenv:Header> |
|
|
<soapenv:Body> |
|
|
<cwmp:Inform> |
|
|
<DeviceId> |
|
|
<Manufacturer>THOMSON</Manufacturer> |
|
|
<OUI>00147F</OUI> |
|
|
<ProductClass>SpeedTouch 780</ProductClass> |
|
|
<SerialNumber>CP0644JTHJ4</SerialNumber> |
|
|
</DeviceId> |
|
|
<Event soap:arrayType="cwmp:EventStruct[03]"> |
|
|
<EventStruct> |
|
|
<EventCode>0 BOOTSTRAP</EventCode> |
|
|
<CommandKey></CommandKey> |
|
|
</EventStruct> |
|
|
<EventStruct> |
|
|
<EventCode>1 BOOT</EventCode> |
|
|
<CommandKey></CommandKey> |
|
|
</EventStruct> |
|
|
<EventStruct> |
|
|
<EventCode>4 VALUE CHANGE</EventCode> |
|
|
<CommandKey></CommandKey> |
|
|
</EventStruct> |
|
|
</Event> |
|
|
<MaxEnvelopes>2</MaxEnvelopes> |
|
|
<CurrentTime>1970-01-01T00:04:33Z</CurrentTime> |
|
|
<RetryCount>01</RetryCount> |
|
|
<ParameterList soap:arrayType="cwmp:ParameterValueStruct[12]"> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceSummary</Name> |
|
|
<Value xsi:type="xsd:string">InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name> |
|
|
<Value xsi:type="xsd:string">1.1</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name> |
|
|
<Value xsi:type="xsd:string">BANT-R</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name> |
|
|
<Value xsi:type="xsd:string">6.2.15.5</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name> |
|
|
<Value xsi:type="xsd:string"></Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name</Name> |
|
|
<Value xsi:type="xsd:string">Routed PPPoE on 0/35 and 8/35</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version</Name> |
|
|
<Value xsi:type="xsd:string"></Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date</Name> |
|
|
<Value xsi:type="xsd:dateTime">0000-00-00T00:00:00</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description</Name> |
|
|
<Value xsi:type="xsd:string">Factory Defaults</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name> |
|
|
<Value xsi:type="xsd:string">http://192.168.1.254:51005/</Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name> |
|
|
<Value xsi:type="xsd:string"></Value> |
|
|
</ParameterValueStruct> |
|
|
<ParameterValueStruct> |
|
|
<Name>.ExternalIPAddress</Name> |
|
|
<Value xsi:type="xsd:string">192.168.1.254</Value> |
|
|
</ParameterValueStruct> |
|
|
</ParameterList> |
|
|
</cwmp:Inform> |
|
|
</soapenv:Body> |
|
|
</soapenv:Envelope> |
|