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

google/t/05-store.t revision 85 by dpavlin, Fri Jun 22 18:36:09 2007 UTC google/trunk/t/05-store.t 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 => 10;  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::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");
21  $abs_path =~ s!/[^/]*$!/!;      #!fix-vim  $abs_path =~ s!/[^/]*$!/!;      #!fix-vim
22    
23  my $path = "$abs_path/var/state.db";  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  unlink $path if -e $path;          ok( my $store_state = $store->get_state( 123456 ), 'get_state' );
52    
53  ok( my $store = CWMP::Store->new({          isa_ok( $state, 'HASH' );
54          debug => $debug,          isa_ok( $store_state, 'HASH' );
         path => $path,  
 }), 'new' );  
 isa_ok( $store, 'CWMP::Store' );  
55    
56  cmp_ok( $store->path, 'eq', $path, 'path' );          if ( $debug ) {
57    
58  ok( $store->update_state( 42, { foo => 'bar' } ), 'update_state new' );                  diag "store_state = ",dump( $store_state );
59            
60            }
61    
62  ok( my $state = $store->state('42'), 'db->get' );          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  is_deeply( $state, { foo => 'bar' }, 'state' );  # now test all stores
84    
85  ok( $store->update_state( 42, { baz => 12345 } ), 'update_state existing' );  test_store('YAML');
86    test_store('JSON');
87    
 is_deeply( $store->state(42), { foo => 'bar', baz => 12345 }, 'store->state' );  

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

  ViewVC Help
Powered by ViewVC 1.1.26