/[cwmp]/google/trunk/t/30-server.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

Contents of /google/trunk/t/30-server.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 223 - (show annotations)
Sat Nov 24 02:17:40 2007 UTC (16 years, 5 months ago) by dpavlin
File MIME type: application/x-troff
File size: 6866 byte(s)
 r257@brr:  dpavlin | 2007-11-24 03:16:39 +0100
 massive amount of tweaks including replacement of YAML with YAML::Syck
 and scoping all over the place

1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $debug = shift @ARGV;
6
7 use Test::More tests => 20;
8 use Data::Dump qw/dump/;
9 use Cwd qw/abs_path/;
10 use blib;
11
12 BEGIN {
13 use_ok('Net::HTTP');
14 use_ok('CWMP::Server');
15 use_ok('CWMP::Store');
16 }
17
18 my $port = 4242;
19
20 eval {
21 $SIG{ALRM} = sub { die; };
22 alarm 30;
23 };
24
25 ok(my $abs_path = abs_path($0), "abs_path");
26 $abs_path =~ s!/[^/]*$!/!; #!fix-vim
27
28 my $store_path = "$abs_path/var/";
29 #my $store_module = 'DBMDeep';
30 my $store_module = 'YAML';
31
32 ok( my $server = CWMP::Server->new({
33 debug => $debug,
34 port => $port,
35 session => {
36 store => {
37 module => $store_module,
38 path => $store_path,
39 clean => 1,
40 },
41 create_dump => 0,
42 }
43 }), 'new' );
44 isa_ok( $server, 'CWMP::Server' );
45
46 my $pid;
47
48 if ( $pid = fork ) {
49 ok( $pid, 'fork ');
50 diag "forked $pid";
51 } elsif (defined($pid)) {
52 # child
53 $server->run;
54 exit;
55 } else {
56 die "can't fork";
57 }
58
59 sleep 1; # so server can start
60
61 ok( my $s = Net::HTTP->new(Host => "localhost:$port"), 'client' );
62 $s->keep_alive( 1 );
63
64 ok( $s->write_request(
65 POST => '/',
66 'Transfer-Encoding' => 'chunked',
67 'SOAPAction' => '',
68 'Content-Type' => 'text/xml',
69 ), 'write_request' );
70
71 foreach my $chunk (qq{
72
73 <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">
74 <soapenv:Header>
75 <cwmp:ID soapenv:mustUnderstand="1">1_THOM_TR69_ID</cwmp:ID>
76 </soapenv:Header>
77 <soapenv:Body>
78 <cwmp:Inform>
79 <DeviceId>
80 <Manufacturer>THOMSON</Manufacturer>
81 <OUI>00147F</OUI>
82 <ProductClass>SpeedTouch 780</ProductClass>
83 <SerialNumber>CP0644JTHJ4</SerialNumber>
84 </DeviceId>
85 <Event soap:arrayType="cwmp:EventStruct[03]">
86 <EventStruct>
87 <EventCode>0 BOOTSTRAP</EventCode>
88 <CommandKey></CommandKey>
89 </EventStruct>
90 <EventStruct>
91 <Event},qq{Code>1 BOOT</EventCode>
92 <CommandKey></CommandKey>
93 </EventStruct>
94 <EventStruct>
95 <EventCode>4 VALUE CHANGE</EventCode>
96 <CommandKey></CommandKey>
97 </EventStruct>
98 </Event>
99 <MaxEnvelopes>2</MaxEnvelopes>
100 <CurrentTime>1970-01-01T00:04:33Z</CurrentTime>
101 <RetryCount>01</RetryCount>},qq{
102 <ParameterList soap:arrayType="cwmp:ParameterValueStruct[12]">
103 <ParameterValueStruct>
104 <Name>InternetGatewayDevice.DeviceSummary</Name>
105 <Value xsi:type="xsd:string">InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)</Value>
106 </ParameterValueStruct>
107 <ParameterValueStruct>
108 <Name>}, qq{
109 InternetGatewayDevice.DeviceInfo.SpecVersion</Name>
110 <Value xsi:type="xsd:string">1.1</Value>
111 </ParameterValueStruct>
112 <ParameterValueStruct>
113 <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>
114 <Value xsi:type="xsd:string">BANT-R</Value>
115 </ParameterValueStruct>
116 <ParameterValueStruct>
117 <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>
118 <Value xsi:type="xsd:string">6.2.15.5</Value>
119 </ParameterValueStruct>
120 <ParameterValueStruct>
121 <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>
122 <Value xsi:type="xsd:string"></Value>
123 </ParameterValueStruct>
124 <ParameterValueStruct>
125 <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name</Name>
126 <Value xsi:type="xsd:string">Routed PPPoE on 0/35 and 8/35</Value>
127 </ParameterValueStruct>
128 <ParameterValueStruct>
129 <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version</Name>
130 <Value xsi:type="xsd:string"></Value>
131 </ParameterValueStruct>
132 <ParameterValueStruct>
133 <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date</Name>
134 <Value xsi:type="xsd:dateTime">0000-00-00T00:00:00</Value>
135 </ParameterValueStruct>
136 <ParameterValueStruct>
137 <Name>InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description</Name>
138 <Value xsi:type="xsd:string">Factory Defaults</Value>
139 </ParameterValueStruct>
140 <ParameterValueStruct>
141 <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>
142 <Value}, qq{ xsi:type="xsd:string">http://192.168.1.254:51005/</Value>
143 </ParameterValueStruct>
144 <ParameterValueStruct>
145 <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>
146 <Value xsi:type="xsd:string"></Value>
147 </ParameterValueStruct>
148 <ParameterValueStruct>
149 <Name>.ExternalIPAddress</Name>
150 <Value xsi:type="xsd:string">192.168.1.254</Value>
151 </ParameterValueStruct>
152 </ParameterList>
153 </cwmp:Inform>
154 </soapenv:Body>
155 </soapenv:Envelope>
156 } ) {
157 ok( $s->write_chunk( $chunk ), "chunk " . length($chunk) . " bytes" );
158 }
159 ok( $s->write_chunk_eof, 'write_chunk_eof' );
160
161 sleep 1;
162
163 ok( my $store = CWMP::Store->new({ module => $store_module, path => $store_path, debug => $debug }), 'another store' );
164
165 my $state = {
166 CurrentTime => "1970-01-01T00:04:33Z",
167 DeviceID => {
168 Manufacturer => "THOMSON",
169 OUI => "00147F",
170 ProductClass => "SpeedTouch 780",
171 SerialNumber => "CP0644JTHJ4",
172 },
173 EventStruct => ["0 BOOTSTRAP", "1 BOOT", "4 VALUE CHANGE"],
174 ID => "1_THOM_TR69_ID",
175 MaxEnvelopes => 2,
176 # NoMoreRequests => undef,
177 Parameter => {
178 "\nInternetGatewayDevice.DeviceInfo.SpecVersion" => "1.1",
179 ".ExternalIPAddress" => "192.168.1.254",
180 "InternetGatewayDevice.DeviceInfo.HardwareVersion" => "BANT-R",
181 "InternetGatewayDevice.DeviceInfo.ProvisioningCode" => undef,
182 "InternetGatewayDevice.DeviceInfo.SoftwareVersion" => "6.2.15.5",
183 "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Date" => "0000-00-00T00:00:00",
184 "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Description" => "Factory Defaults",
185 "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Name" => "Routed PPPoE on 0/35 and 8/35",
186 "InternetGatewayDevice.DeviceInfo.VendorConfigFile.1.Version" => undef,
187 "InternetGatewayDevice.DeviceSummary" => "InternetGatewayDevice:1.1[] (Baseline:1, EthernetLAN:1, ADSLWAN:1, Bridging:1, Time:1, WiFiLAN:1)",
188 "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" => "http://192.168.1.254:51005/",
189 "InternetGatewayDevice.ManagementServer.ParameterKey" => undef,
190 },
191 RetryCount => "01",
192 _dispatch => "InformResponse",
193 };
194
195 ok( my $store_state = $store->current_store->get_state( 'CP0644JTHJ4' ), 'get_state' );
196
197 is_deeply( $store_state, $state, 'store->current_store->get_state' );
198
199 diag "shutdown server";
200
201 ok( kill(9,$pid), 'kill ' . $pid );
202
203 ok( waitpid($pid,0), 'waitpid' );
204

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26