4 |
|
|
5 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
6 |
|
|
7 |
use Test::More tests => 14; |
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 |
|
cmp_ok( $store->path, 'eq', $path, 'path' ); |
40 |
|
|
41 |
unlink $path if -e $path; |
my $state = { |
42 |
|
foo => 'bar', |
43 |
|
DeviceID => { |
44 |
|
SerialNumber => 123456, |
45 |
|
}, |
46 |
|
}; |
47 |
|
|
48 |
ok( my $store = CWMP::Store->new({ |
cmp_ok( $store->state_to_uid( $state ), 'eq', 123456, 'state_to_uid' ); |
|
debug => $debug, |
|
|
path => $path, |
|
|
}), 'new' ); |
|
|
isa_ok( $store, 'CWMP::Store' ); |
|
49 |
|
|
50 |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
ok( $store->update_state( $state ), 'update_state new' ); |
51 |
|
|
52 |
my $state = { |
ok( my $store_state = $store->get_state( 123456 ), 'get_state' ); |
|
foo => 'bar', |
|
|
DeviceID => { |
|
|
SerialNumber => 123456, |
|
|
}, |
|
|
}; |
|
53 |
|
|
54 |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
isa_ok( $state, 'HASH' ); |
55 |
|
isa_ok( $store_state, 'HASH' ); |
56 |
|
|
57 |
ok( $store->update_state( 42, $state ), 'update_state new' ); |
if ( $debug ) { |
58 |
|
|
59 |
ok( my $store_state = $store->state('42'), 'db->get' ); |
diag "store_state = ",dump( $store_state ); |
60 |
|
|
61 |
|
} |
62 |
|
|
63 |
is_deeply( $store_state, $state, 'state' ); |
is_deeply( $state, $store_state, 'state ID same as uid' ); |
64 |
|
|
65 |
ok( $store->update_state( 42, { baz => 12345 } ), 'update_state existing' ); |
ok( $store->update_state( { |
66 |
|
DeviceID => { |
67 |
|
SerialNumber => 123456, |
68 |
|
}, |
69 |
|
baz => 12345 |
70 |
|
} ), 'update_state existing' ); |
71 |
|
|
72 |
$state->{baz} = 12345; |
$state->{baz} = 12345; |
73 |
|
|
74 |
is_deeply( $store->state(42), $state, 'store->state' ); |
is_deeply( $store->get_state( 123456 ), $state, 'get_state' ); |
75 |
|
|
76 |
is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' ); |
is_deeply( [ $store->all_uids ], [ 123456 ], 'all_uids' ); |
77 |
|
|
78 |
|
ok( $store->update_state( { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
79 |
|
|
80 |
|
is_deeply( [ $store->all_uids ], [ 123456, 99999 ], 'all_uids' ); |
81 |
|
|
82 |
|
undef $store; |
83 |
|
|
84 |
|
} |
85 |
|
|
86 |
ok( $store->update_state( 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 |
|
|