4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 17; |
use Test::More tests => 47; |
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'); |
17 |
|
use_ok('CWMP::Store::YAML'); |
18 |
|
use_ok('CWMP::Store::JSON'); |
19 |
} |
} |
20 |
|
|
21 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
22 |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
23 |
|
|
24 |
my $path = "$abs_path/var/state.db"; |
my $path = "$abs_path/var/"; |
25 |
|
|
26 |
|
sub test_store { |
27 |
|
my $module = shift; |
28 |
|
|
29 |
|
diag "testing store plugin $module"; |
30 |
|
|
31 |
|
ok( my $store = CWMP::Store->new({ |
32 |
|
debug => $debug, |
33 |
|
module => $module, |
34 |
|
path => $path, |
35 |
|
clean => 1, |
36 |
|
}), 'new' ); |
37 |
|
isa_ok( $store, 'CWMP::Store' ); |
38 |
|
|
39 |
unlink $path if -e $path; |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
40 |
|
|
41 |
ok( my $store = CWMP::Store->new({ |
my $state = { |
42 |
debug => $debug, |
foo => 'bar', |
43 |
path => $path, |
DeviceID => { |
44 |
}), 'new' ); |
SerialNumber => 123456, |
45 |
isa_ok( $store, 'CWMP::Store' ); |
}, |
46 |
|
}; |
47 |
|
|
48 |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' ); |
49 |
|
|
50 |
my $state = { |
ok( $store->update_state( $state ), 'update_state new' ); |
|
foo => 'bar', |
|
|
DeviceID => { |
|
|
SerialNumber => 123456, |
|
|
}, |
|
|
}; |
|
51 |
|
|
52 |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
ok( my $store_state = $store->get_state( 123456 ), 'get_state' ); |
53 |
|
|
54 |
ok( $store->update_state( ID => 42, $state ), 'update_state new' ); |
isa_ok( $state, 'HASH' ); |
55 |
|
isa_ok( $store_state, 'HASH' ); |
56 |
|
|
57 |
ok( my $store_state = $store->state( ID => '42'), 'db->get' ); |
if ( $debug ) { |
58 |
|
|
59 |
is_deeply( $store_state, $state, 'state ID' ); |
diag "store_state = ",dump( $store_state ); |
60 |
|
|
61 |
|
} |
62 |
|
|
63 |
ok( $store_state = $store->state( uid => 123456 ), 'db->get' ); |
is_deeply( $state, $store_state, 'state ID same as uid' ); |
64 |
|
|
65 |
is_deeply( $store_state, $state, 'state uid' ); |
ok( $store->update_state( { |
66 |
|
DeviceID => { |
67 |
|
SerialNumber => 123456, |
68 |
|
}, |
69 |
|
baz => 12345 |
70 |
|
} ), 'update_state existing' ); |
71 |
|
|
72 |
ok( $store->update_state( ID => 42, { baz => 12345 } ), 'update_state existing' ); |
$state->{baz} = 12345; |
73 |
|
|
74 |
$state->{baz} = 12345; |
is_deeply( $store->get_state( 123456 ), $state, 'get_state' ); |
75 |
|
|
76 |
is_deeply( $store->state( ID => 42 ), $state, 'store->state ID' ); |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
77 |
|
|
78 |
is_deeply( $store->state( uid => 123456 ), $state, 'store->state uid' ); |
ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
79 |
|
|
80 |
is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' ); |
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
81 |
|
|
82 |
|
undef $store; |
83 |
|
|
84 |
|
} |
85 |
|
|
86 |
ok( $store->update_state( ID => 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
# now test all stores |
87 |
|
|
88 |
is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' ); |
test_store('DBMDeep'); |
89 |
|
test_store('YAML'); |
90 |
|
test_store('JSON'); |
91 |
|
|