1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use warnings; |
4 |
|
5 |
my $debug = shift @ARGV; |
6 |
|
7 |
use Test::More tests => 14; |
8 |
use Data::Dump qw/dump/; |
9 |
use Cwd qw/abs_path/; |
10 |
use lib 'lib'; |
11 |
|
12 |
BEGIN { |
13 |
use_ok('CWMP::Store'); |
14 |
} |
15 |
|
16 |
ok(my $abs_path = abs_path($0), "abs_path"); |
17 |
$abs_path =~ s!/[^/]*$!/!; #!fix-vim |
18 |
|
19 |
my $path = "$abs_path/var/state.db"; |
20 |
|
21 |
unlink $path if -e $path; |
22 |
|
23 |
ok( my $store = CWMP::Store->new({ |
24 |
debug => $debug, |
25 |
path => $path, |
26 |
}), 'new' ); |
27 |
isa_ok( $store, 'CWMP::Store' ); |
28 |
|
29 |
cmp_ok( $store->path, 'eq', $path, 'path' ); |
30 |
|
31 |
my $state = { |
32 |
foo => 'bar', |
33 |
DeviceID => { |
34 |
SerialNumber => 123456, |
35 |
}, |
36 |
}; |
37 |
|
38 |
cmp_ok( $store->ID_to_uid( 42, $state ), 'eq', 123456, 'ID_to_uid' ); |
39 |
|
40 |
ok( $store->update_state( 42, $state ), 'update_state new' ); |
41 |
|
42 |
ok( my $store_state = $store->state('42'), 'db->get' ); |
43 |
|
44 |
is_deeply( $store_state, $state, 'state' ); |
45 |
|
46 |
ok( $store->update_state( 42, { baz => 12345 } ), 'update_state existing' ); |
47 |
|
48 |
$state->{baz} = 12345; |
49 |
|
50 |
is_deeply( $store->state(42), $state, 'store->state' ); |
51 |
|
52 |
is_deeply( [ $store->known_CPE ], [ 123456 ], 'known_CPE' ); |
53 |
|
54 |
ok( $store->update_state( 11, { DeviceID => { SerialNumber => 99999 } } ), 'new device' ); |
55 |
|
56 |
is_deeply( [ $store->known_CPE ], [ 123456, 99999 ], 'known_CPE' ); |
57 |
|