7940f0536dc8bd31b8639339b1456b9f07318b39
[debian/amanda] / installcheck / Amanda_Feature.pl
1 # Copyright (c) 2010 Zmanda, Inc.  All Rights Reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
6 #
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
10 # for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 #
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 31;
20 use strict;
21 use warnings;
22
23 use lib "@amperldir@";
24 use Amanda::Feature;
25 use Amanda::Debug;
26 use Installcheck;
27
28 # put the debug messages somewhere
29 Amanda::Debug::dbopen("installcheck");
30 Installcheck::log_test_output();
31
32 # some round-trip tests
33 for my $str (qw(
34                 0
35                 00
36                 000
37                 0000
38                 ff
39                 ffff
40                 000f
41                 00ff
42                 0fff
43                 abaa
44                 aaaaaa
45                 aaaaaaaa
46                 aaaaaaaaaa
47                 aaaaaaaaaaaaaa
48                 aaaaaaaaaaaaaaa
49                 aaaaaaaaaaaaaaaaaa
50                 aaaaaaaaaaaaaaaaaaa
51                 aaaaaaaaaaaaaaaaaaaaaa
52                 aaaaaaaaaaaaaaaaaaaaaaa
53                 aaaaaaaaaaaaaaaaaaaaaaaaaaaa
54                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
55                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
56                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
57                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
58                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
59                 )) {
60     # (note that odd-length strings will trigger a warning)
61     my $feat = Amanda::Feature::Set->from_string($str);
62     my $str2 = $feat->as_string();
63     my $feat2 = Amanda::Feature::Set->from_string($str2);
64     my $str3 = $feat2->as_string();
65     is($str2, $str3, "round-trip '$str' -> '$str2'")
66 }
67
68 # check the various constructors
69 like((Amanda::Feature::Set->old())->as_string(),
70     qr/^[0-9a-f]+$/,
71     "old constructor");
72 like((Amanda::Feature::Set->mine())->as_string(),
73     qr/^[0-9a-f]+$/,
74     "mine constructor");
75
76 # and some bit flags
77 my $feat = Amanda::Feature::Set->mine();
78 ok($feat->has($Amanda::Feature::fe_amrecover_feedme_tape),
79     "'mine' features include fe_amrecover_feedme_tape");
80 $feat->remove($Amanda::Feature::fe_amrecover_feedme_tape);
81 ok(!$feat->has($Amanda::Feature::fe_amrecover_feedme_tape),
82     "fe_amrecover_feedme_tape removed");
83
84 $feat = Amanda::Feature::Set->old();
85 ok(!$feat->has($Amanda::Feature::fe_req_xml),
86     "old set does not have fe_req_xml");
87 $feat->add($Amanda::Feature::fe_req_xml);
88 ok($feat->has($Amanda::Feature::fe_req_xml),
89     "fe_req_xml added");
90