5 my $debug = shift @ARGV;
7 use Test::More tests => 153;
8 use Data::Dump qw/dump/;
12 use File::Path qw/rmtree mkpath/;
18 use_ok('CWMP::Server');
19 use_ok('CWMP::Store');
20 use_ok('CWMP::Request');
26 $SIG{ALRM} = sub { die; };
30 ok(my $abs_path = abs_path($0), "abs_path");
31 $abs_path =~ s!/[^/]*$!/!; #!fix-vim
33 my $store_path = "$abs_path/var/";
34 my $store_module = 'YAML';
36 rmtree $store_path if -e $store_path;
37 ok( mkpath $store_path, "mkpath $store_path" );
39 ok( my $server = CWMP::Server->new({
44 module => $store_module,
51 isa_ok( $server, 'CWMP::Server' );
58 } elsif (defined($pid)) {
66 sleep 1; # so server can start
73 ok( $s = Net::HTTP->new(Host => "localhost:$port"), 'CPE client' );
79 diag "CPE disconnect";
81 ok( $s->write_request(
84 'Content-Type' => 'text/xml',
86 my ($code, $mess, %h) = $s->read_response_headers;
89 return $code == 200 ? 1 : 0;
95 ok( -e $path, $path );
97 cpe_disconnect if $path =~ m/Inform/;
100 ok( $s->write_request(
102 'Transfer-Encoding' => 'chunked',
104 'Content-Type' => 'text/xml',
105 ), 'write_request' );
107 my $xml = read_file( $path );
110 my $chunk_size = 5000;
112 foreach my $part ( 0 .. int( length($xml) / $chunk_size ) ) {
113 my $chunk = substr( $xml, $part * $chunk_size, $chunk_size );
114 ok( $s->write_chunk( $chunk ), "chunk $part " . length($chunk) . " bytes" );
116 ok( $s->write_chunk_eof, 'write_chunk_eof' );
118 my($code, $mess, %h) = $s->read_response_headers;
122 my $n = $s->read_entity_body($buf, 1024);
123 die "read failed: $!" unless defined $n;
128 ok( my $store = CWMP::Store->new({ module => $store_module, path => $store_path, debug => $debug }), 'another store' );
130 my $state = LoadFile( "$path.yml" );
132 $path =~ s!/[^/]+$!!; #!vim
133 ok( my $uid = $store->state_to_uid( LoadFile( "$path/Inform.yml" ) ), 'state_to_uid' );
135 ok( my $store_state = $store->current_store->get_state( $uid ), 'get_state' );
140 foreach my $k ( keys %$state ) {
141 if ( defined( $store_state->{$k} ) ) {
142 $s->{$k} = $store_state->{$k};
144 die "store_state doesn't have $k: ",dump( $store_state );
148 is_deeply( $s, $state, 'store->current_store->get_state' );
155 my $path = $File::Find::name;
156 return unless -f $path;
157 return if $path =~ m/\.yml$/;
159 test_request( $path );
161 ok( ! $@, "request $path" );
165 ok( cpe_disconnect, 'cpe_disconnect' );
167 diag "shutdown server";
169 ok( kill(9,$pid), 'kill ' . $pid );
171 ok( waitpid($pid,0), 'waitpid' );