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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (show annotations)
Sun Nov 25 18:51:26 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1659 byte(s)
 r266@brr:  dpavlin | 2007-11-25 19:50:35 +0100
 - first pass with Devel::LeakTrace::Fast
 - remove DBM::Deep store
 - CWMP::Queue now supports dir and clean args
 - create new parser for each request

1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $debug = shift @ARGV;
6
7 use Test::More tests => 32;
8 use Data::Dump qw/dump/;
9 use Cwd qw/abs_path/;
10 use lib 'lib';
11
12 #use Devel::LeakTrace::Fast;
13
14 BEGIN {
15 use_ok('CWMP::Store');
16 use_ok('CWMP::Store::YAML');
17 use_ok('CWMP::Store::JSON');
18 }
19
20 ok(my $abs_path = abs_path($0), "abs_path");
21 $abs_path =~ s!/[^/]*$!/!; #!fix-vim
22
23 my $path = "$abs_path/var/";
24
25 sub test_store {
26 my $module = shift;
27
28 diag "testing store plugin $module";
29
30 ok( my $store = CWMP::Store->new({
31 debug => $debug,
32 module => $module,
33 path => $path,
34 clean => 1,
35 }), 'new' );
36 isa_ok( $store, 'CWMP::Store' );
37
38 cmp_ok( $store->path, 'eq', $path, 'path' );
39
40 my $state = {
41 foo => 'bar',
42 DeviceID => {
43 SerialNumber => 123456,
44 },
45 };
46
47 cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' );
48
49 ok( $store->update_state( $state ), 'update_state new' );
50
51 ok( my $store_state = $store->get_state( 123456 ), 'get_state' );
52
53 isa_ok( $state, 'HASH' );
54 isa_ok( $store_state, 'HASH' );
55
56 if ( $debug ) {
57
58 diag "store_state = ",dump( $store_state );
59
60 }
61
62 is_deeply( $state, $store_state, 'state ID same as uid' );
63
64 ok( $store->update_state( {
65 DeviceID => {
66 SerialNumber => 123456,
67 },
68 baz => 12345
69 } ), 'update_state existing' );
70
71 $state->{baz} = 12345;
72
73 is_deeply( $store->get_state( 123456 ), $state, 'get_state' );
74
75 is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' );
76
77 ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' );
78
79 is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' );
80
81 }
82
83 # now test all stores
84
85 test_store('YAML');
86 test_store('JSON');
87

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26