Imported Upstream version 3.1.0
[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
22 use lib "@amperldir@";
23 use Amanda::Feature;
24 use Amanda::Debug;
25 use Installcheck;
26
27 # put the debug messages somewhere
28 Amanda::Debug::dbopen("installcheck");
29 Installcheck::log_test_output();
30
31 # some round-trip tests
32 for my $str (qw(
33                 0
34                 00
35                 000
36                 0000
37                 ff
38                 ffff
39                 000f
40                 00ff
41                 0fff
42                 abaa
43                 aaaaaa
44                 aaaaaaaa
45                 aaaaaaaaaa
46                 aaaaaaaaaaaaaa
47                 aaaaaaaaaaaaaaa
48                 aaaaaaaaaaaaaaaaaa
49                 aaaaaaaaaaaaaaaaaaa
50                 aaaaaaaaaaaaaaaaaaaaaa
51                 aaaaaaaaaaaaaaaaaaaaaaa
52                 aaaaaaaaaaaaaaaaaaaaaaaaaaaa
53                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
54                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
55                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
56                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
57                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
58                 )) {
59     # (note that odd-length strings will trigger a warning)
60     my $feat = Amanda::Feature::Set->from_string($str);
61     my $str2 = $feat->as_string();
62     my $feat2 = Amanda::Feature::Set->from_string($str2);
63     my $str3 = $feat2->as_string();
64     is($str2, $str3, "round-trip '$str' -> '$str2'")
65 }
66
67 # check the various constructors
68 like((Amanda::Feature::Set->old())->as_string(),
69     qr/^[0-9a-f]+$/,
70     "old constructor");
71 like((Amanda::Feature::Set->mine())->as_string(),
72     qr/^[0-9a-f]+$/,
73     "mine constructor");
74
75 # and some bit flags
76 my $feat = Amanda::Feature::Set->mine();
77 ok($feat->has($Amanda::Feature::fe_amrecover_feedme_tape),
78     "'mine' features include fe_amrecover_feedme_tape");
79 $feat->remove($Amanda::Feature::fe_amrecover_feedme_tape);
80 ok(!$feat->has($Amanda::Feature::fe_amrecover_feedme_tape),
81     "fe_amrecover_feedme_tape removed");
82
83 $feat = Amanda::Feature::Set->old();
84 ok(!$feat->has($Amanda::Feature::fe_req_xml),
85     "old set does not have fe_req_xml");
86 $feat->add($Amanda::Feature::fe_req_xml);
87 ok($feat->has($Amanda::Feature::fe_req_xml),
88     "fe_req_xml added");
89