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