lintian doesn't like orphan packages with uploaders...
[debian/amanda] / installcheck / Amanda_Config_FoldingHash.pl
1 # Copyright (c) 2009-2012 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20 use Test::More tests => 22;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use Amanda::Config::FoldingHash;
26 use Data::Dumper;
27
28 my $h = Amanda::Config::FoldingHash->new();
29 ok(!(exists $h->{'key'}), "key doesn't exist in new hash");
30 is_deeply([sort(keys(%$h))], [], "hash starts out with no keys");
31
32 $h->{'key'} = 3;
33 ok((exists $h->{'key'}), "key exists after assignment");
34 is($h->{'key'}, 3, "can fetch value stored in simple key");
35 is($h->{'kEy'}, 3, "can fetch value stored in key via fold");
36
37 $h->{'key'} = 4;
38 is($h->{'key'}, 4, "updating the one key works");
39 is_deeply([sort(keys(%$h))], [sort(qw(key))], "hash now has the one key");
40
41 delete $h->{'key'};
42 ok(!(exists $h->{'key'}), "key doesn't exist after deletion");
43 is($h->{'key'}, undef, "got undef fetching deleted key");
44
45 $h->{'kEY'} = 20;
46 ok((exists $h->{'kEY'}), "unfolded key exists after assignment");
47 ok((exists $h->{'key'}), "folded key exists after assignment");
48 is($h->{'key'}, 20, "can fetch value stored in folded key");
49 is_deeply([sort(keys(%$h))], [sort(qw(key))], "key is folded in list");
50
51 $h->{'key'} = 92;
52 is($h->{'key'}, 92, "updated folded key");
53
54 $h->{'Key'} = 37;
55 is($h->{'key'}, 37, "updated key via fold");
56
57 $h->{'_some-OTHER_kEy_'} = undef;
58 ok((exists $h->{'_some-OTHER_kEy_'}), "longer key exists after assigning undef");
59 ok((exists $h->{'-some-other-key-'}), "longer folded key exists too");
60 ok((exists $h->{'-SOME_other_key_'}), "longer key exists via fold");
61 is_deeply([sort(keys(%$h))], [sort(qw(key -some-other-key-))], "keys list as folded");
62
63 delete $h->{'KeY'};
64 ok(!(exists $h->{'key'}), "key doesn't exist after deletion via fold");
65 is($h->{'key'}, undef, "got undef fetching folded deleted key");
66
67 for my $k (qw(_ __ a-B Cf_ __g-h i__j-k L)) {
68     $h->{$k} = $k;
69 }
70
71 is_deeply([sort(keys(%$h))], [sort(qw(-some-other-key- - -- a-b cf- --g-h i--j-k l))],
72    "various keys are listed as folded");
73