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

Contents of /google/trunk/t/05-store.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 162 - (show annotations)
Sat Oct 27 22:55:45 2007 UTC (16 years, 7 months ago) by dpavlin
File MIME type: application/x-troff
File size: 1693 byte(s)
 r147@llin (orig r146):  dpavlin | 2007-10-28 00:43:25 +0200
 - added clean parametar to stores to start with empty database
 - much less chatty without debug
 - test both existing store plugins
 - finish API rename in CWMP::Store, version bump [0.05]

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26