/[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

Diff of /google/trunk/t/05-store.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 156 by dpavlin, Sat Oct 27 22:54:28 2007 UTC revision 227 by dpavlin, Sun Nov 25 18:51:26 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4    
5  my $debug = shift @ARGV;  my $debug = shift @ARGV;
6    
7  use Test::More tests => 18;  use Test::More tests => 32;
8  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
9  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
10  use lib 'lib';  use lib 'lib';
11    
12    #use Devel::LeakTrace::Fast;
13    
14  BEGIN {  BEGIN {
15          use_ok('CWMP::Store');          use_ok('CWMP::Store');
16          use_ok('CWMP::Store::DBMDeep');          use_ok('CWMP::Store::YAML');
17            use_ok('CWMP::Store::JSON');
18  }  }
19    
20  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
# Line 19  $abs_path =~ s!/[^/]*$!/!;     #!fix-vim Line 22  $abs_path =~ s!/[^/]*$!/!;     #!fix-vim
22    
23  my $path = "$abs_path/var/";  my $path = "$abs_path/var/";
24    
25  unlink $path if -e $path;  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  ok( my $store = CWMP::Store->new({          cmp_ok( $store->path, 'eq', $path, 'path' );
         debug => $debug,  
 #       module => 'DBMDeep',  
         module => 'YAML',  
         path => $path,  
 }), 'new' );  
 isa_ok( $store, 'CWMP::Store' );  
39    
40  cmp_ok( $store->path, 'eq', $path, 'path' );          my $state = {
41                    foo => 'bar',
42                    DeviceID => {
43                            SerialNumber => 123456,
44                    },
45            };
46    
47  my $state = {          cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' );
         foo => 'bar',  
         DeviceID => {  
                 SerialNumber => 123456,  
         },  
 };  
48    
49  cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' );          ok( $store->update_state( $state ), 'update_state new' );
50    
51  ok( $store->update_state( ID => 42, $state ), 'update_state new' );          ok( my $store_state = $store->get_state( 123456 ), 'get_state' );
52    
53  ok( my $store_state = $store->state( ID => '42'), 'db->get' );          isa_ok( $state, 'HASH' );
54            isa_ok( $store_state, 'HASH' );
55    
56  is_deeply( $store_state, $state, 'state ID' );          if ( $debug ) {
57    
58  ok( $store_state = $store->state( uid =>  123456 ), 'db->get' );                  diag "store_state = ",dump( $store_state );
59            
60            }
61    
62  is_deeply( $store_state, $state, 'state uid' );          is_deeply( $state, $store_state, 'state ID same as uid' );
63    
64  ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' );          ok( $store->update_state( {
65                    DeviceID => {
66                            SerialNumber => 123456,
67                    },
68                    baz => 12345
69            } ), 'update_state existing' );
70    
71  $state->{baz} = 12345;          $state->{baz} = 12345;
72    
73  is_deeply( $store->state( ID => 42 ), $state, 'store->state ID' );          is_deeply( $store->get_state( 123456 ), $state, 'get_state' );
74    
75  is_deeply( $store->state( uid => 123456 ), $state, 'store->state uid' );          is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' );
76    
77  is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' );          ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' );
78    
79            is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' );
80    
81    }
82    
83  ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' );  # now test all stores
84    
85  is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' );  test_store('YAML');
86    test_store('JSON');
87    

Legend:
Removed from v.156  
changed lines
  Added in v.227

  ViewVC Help
Powered by ViewVC 1.1.26