re-enable all_parameteres collection of first connect
[perl-cwmp.git] / t / 05-store.t
index e458d42..0cac16f 100755 (executable)
@@ -4,63 +4,84 @@ use warnings;
 
 my $debug = shift @ARGV;
 
-use Test::More tests => 18;
+use Test::More tests => 32;
 use Data::Dump qw/dump/;
 use Cwd qw/abs_path/;
 use lib 'lib';
 
+#use Devel::LeakTrace::Fast;
+
 BEGIN {
        use_ok('CWMP::Store');
-       use_ok('CWMP::Store::DBMDeep');
+       use_ok('CWMP::Store::YAML');
+       use_ok('CWMP::Store::JSON');
 }
 
 ok(my $abs_path = abs_path($0), "abs_path");
 $abs_path =~ s!/[^/]*$!/!;     #!fix-vim
 
-my $path = "$abs_path/var/state.db";
+my $path = "$abs_path/var/";
+
+sub test_store {
+       my $module = shift;
+
+       diag "testing store plugin $module";
 
-unlink $path if -e $path;
+       ok( my $store = CWMP::Store->new({
+               debug => $debug,
+               module => $module,
+               path => $path,
+               clean => 1,
+       }), 'new' );
+       isa_ok( $store, 'CWMP::Store' );
 
-ok( my $store = CWMP::Store->new({
-       debug => $debug,
-#      module => 'DBMDeep',
-       module => 'YAML',
-       path => $path,
-}), 'new' );
-isa_ok( $store, 'CWMP::Store' );
+       cmp_ok( $store->path, 'eq', $path, 'path' );
 
-cmp_ok( $store->path, 'eq', $path, 'path' );
+       my $state = {
+               foo => 'bar',
+               DeviceID => {
+                       SerialNumber => 123456,
+               },
+       };
 
-my $state = {
-       foo => 'bar',
-       DeviceID => {
-               SerialNumber => 123456,
-       },
-};
+       cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' );
 
-cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' );
+       ok( $store->update_state( $state ), 'update_state new' );
 
-ok( $store->update_state( ID => 42, $state ), 'update_state new' );
+       ok( my $store_state = $store->get_state( 123456 ), 'get_state' );
 
-ok( my $store_state = $store->state( ID => '42'), 'db->get' );
+       isa_ok( $state, 'HASH' );
+       isa_ok( $store_state, 'HASH' );
 
-is_deeply( $store_state, $state, 'state ID' );
+       if ( $debug ) {
 
-ok( $store_state = $store->state( uid =>  123456 ), 'db->get' );
+               diag "store_state = ",dump( $store_state );
+       
+       }
 
-is_deeply( $store_state, $state, 'state uid' );
+       is_deeply( $state, $store_state, 'state ID same as uid' );
 
-ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' );
+       $state = {
+               DeviceID => {
+                       SerialNumber => 123456,
+               },
+               baz => 12345 
+       };
 
-$state->{baz} = 12345;
+       ok( $store->set_state( 123456, $state ), 'set_state' );
 
-is_deeply( $store->state( ID => 42 ), $state, 'store->state ID' );
+       is_deeply( $store->get_state( 123456 ), $state, 'get_state' );
 
-is_deeply( $store->state( uid => 123456 ), $state, 'store->state uid' );
+       is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' );
 
-is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' );
+       ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' );
+
+       is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' );
+
+}
 
-ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' );
+# now test all stores
 
-is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' );
+test_store('YAML');
+test_store('JSON');