Imported Upstream version 3.2.0
[debian/amanda] / installcheck / Amanda_Header.pl
1 # Copyright (c) 2009, 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 => 55;
20 use strict;
21 use warnings;
22
23 use lib "@amperldir@";
24 use Amanda::Header;
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 # Test all of the setters and getters, as well as to_string and from_string, by
33 # constructing a header and converting it to a string and back.  This is a little
34 # tricky, because of the various restrictions on combinations of fields in the
35 # header, so we use multple headers.
36
37 my $hdr1 = Amanda::Header->new();
38 $hdr1->{'type'} = $Amanda::Header::F_DUMPFILE;
39 $hdr1->{'datestamp'} = '20090102030405';
40 $hdr1->{'dumplevel'} = 6;
41 $hdr1->{'compressed'} = 1;
42 $hdr1->{'encrypted'} = 1;
43 $hdr1->{'comp_suffix'} = '.TEENSY';
44 $hdr1->{'encrypt_suffix'} = 'E';
45 $hdr1->{'name'} = 'schlitz';
46 $hdr1->{'disk'} = '/pbr';
47 $hdr1->{'program'} = 'GNUTAR';
48 $hdr1->{'application'} = 'amnot';
49 $hdr1->{'srvcompprog'} = 'scp';
50 $hdr1->{'srv_encrypt'} = 'se';
51 $hdr1->{'recover_cmd'} = 'rec |';
52 $hdr1->{'uncompress_cmd'} = 'unc |';
53 $hdr1->{'decrypt_cmd'} = 'dec |';
54 $hdr1->{'srv_decrypt_opt'} = '-dos';
55 $hdr1->{'cont_filename'} = '/path/to/cont';
56 $hdr1->{'dle_str'} = "D\nL\nE";
57 $hdr1->{'is_partial'} = 1;
58 $hdr1->{'blocksize'} = 32000;
59 $hdr1->{'orig_size'} = 10240;
60
61 my $hdr2 = Amanda::Header->new();
62 $hdr2->{'type'} = $Amanda::Header::F_SPLIT_DUMPFILE;
63 $hdr2->{'datestamp'} = '20090102030405';
64 $hdr2->{'dumplevel'} = 6;
65 $hdr2->{'compressed'} = 1;
66 $hdr2->{'encrypted'} = 1;
67 $hdr2->{'comp_suffix'} = '.TEENSY';
68 $hdr2->{'encrypt_suffix'} = 'E';
69 $hdr2->{'name'} = 'schlitz';
70 $hdr2->{'disk'} = '/pbr';
71 $hdr2->{'program'} = 'GNUTAR';
72 $hdr2->{'application'} = 'amnot';
73 $hdr2->{'clntcompprog'} = 'ccp';
74 $hdr2->{'clnt_encrypt'} = 'ce';
75 $hdr2->{'recover_cmd'} = 'rec |';
76 $hdr2->{'uncompress_cmd'} = 'unc |';
77 $hdr2->{'decrypt_cmd'} = 'dec |';
78 $hdr2->{'clnt_decrypt_opt'} = '-doc';
79 $hdr2->{'cont_filename'} = '/path/to/cont';
80 $hdr2->{'dle_str'} = "D\nL\nE";
81 $hdr2->{'is_partial'} = 1;
82 $hdr2->{'partnum'} = 13;
83 $hdr2->{'totalparts'} = 14;
84 $hdr2->{'blocksize'} = 32000;
85 $hdr2->{'orig_size'} = 10240;
86
87 my $hdr3 = Amanda::Header->new();
88 $hdr3->{'type'} = $Amanda::Header::F_TAPESTART;
89 $hdr3->{'name'} = 'TAPE17';
90 $hdr3->{'datestamp'} = '20090102030405';
91
92 my $string1 = $hdr1->to_string(32768, 32768);
93 my $string2 = $hdr2->to_string(65536, 65536);
94 my $string3 = $hdr3->to_string(32768, 32768);
95
96 is(length($string1), 32768, "generated header 1 has correct length");
97 is(length($string2), 65536, "generated header 2 has correct length");
98
99 like($string3,
100      qr/^AMANDA: TAPESTART DATE 20090102030405 TAPE TAPE17/,
101      "generated tapestart header looks OK");
102
103 $hdr1 = Amanda::Header->from_string($string1);
104 $hdr2 = Amanda::Header->from_string($string2);
105 $hdr3 = Amanda::Header->from_string($string3);
106
107 is($hdr1->{'type'}, $Amanda::Header::F_DUMPFILE, "'type' for hdr1");
108 is($hdr1->{'datestamp'}, '20090102030405', "'datestamp' for hdr1");
109 is($hdr1->{'dumplevel'}, 6, "'dumplevel' for hdr1");
110 is($hdr1->{'compressed'}, 1, "'compressed' for hdr1");
111 is($hdr1->{'encrypted'}, 1, "'encrypted' for hdr1");
112 is($hdr1->{'comp_suffix'}, '.TEENSY', "'comp_suffix' for hdr1");
113 is($hdr1->{'encrypt_suffix'}, 'E', "'encrypt_suffix' for hdr1");
114 is($hdr1->{'name'}, 'schlitz', "'name' for hdr1");
115 is($hdr1->{'disk'}, '/pbr', "'disk' for hdr1");
116 is($hdr1->{'program'}, 'GNUTAR', "'program' for hdr1");
117 is($hdr1->{'application'}, 'amnot', "'application' for hdr1");
118 is($hdr1->{'srvcompprog'}, 'scp', "'srvcompprog' for hdr1");
119 is($hdr1->{'srv_encrypt'}, 'se', "'srv_encrypt' for hdr1");
120 is($hdr1->{'recover_cmd'}, 'rec |', "'recover_cmd' for hdr1");
121 is($hdr1->{'uncompress_cmd'}, 'unc |', "'uncompress_cmd' for hdr1");
122 is($hdr1->{'decrypt_cmd'}, 'dec |', "'decrypt_cmd' for hdr1");
123 is($hdr1->{'srv_decrypt_opt'}, '-dos', "'srv_decrypt_opt' for hdr1");
124 is($hdr1->{'cont_filename'}, '/path/to/cont', "'cont_filename' for hdr1");
125 is($hdr1->{'dle_str'}, "D\nL\nE", "'dle_str' for hdr0");
126 is($hdr1->{'is_partial'}, 1, "'is_partial' for hdr1");
127 # no partnum for F_DUMPFILE
128 # no numparts for F_DUMPFILE
129 is($hdr1->{'blocksize'}, 0, "'blocksize' for hdr1 (not re-read; defaults to 0)");
130 is($hdr1->{'orig_size'}, 10240, "'orig_size' for hdr1");
131
132 is($hdr2->{'type'}, $Amanda::Header::F_SPLIT_DUMPFILE, "'type' for hdr2");
133 is($hdr2->{'datestamp'}, '20090102030405', "'datestamp' for hdr2");
134 is($hdr2->{'dumplevel'}, 6, "'dumplevel' for hdr2");
135 is($hdr2->{'compressed'}, 1, "'compressed' for hdr2");
136 is($hdr2->{'encrypted'}, 1, "'encrypted' for hdr2");
137 is($hdr2->{'comp_suffix'}, '.TEENSY', "'comp_suffix' for hdr2");
138 is($hdr2->{'encrypt_suffix'}, 'E', "'encrypt_suffix' for hdr2");
139 is($hdr2->{'name'}, 'schlitz', "'name' for hdr2");
140 is($hdr2->{'disk'}, '/pbr', "'disk' for hdr2");
141 is($hdr2->{'program'}, 'GNUTAR', "'program' for hdr2");
142 is($hdr2->{'application'}, 'amnot', "'application' for hdr2");
143 is($hdr2->{'clntcompprog'}, 'ccp', "'clntcompprog' for hdr2");
144 is($hdr2->{'clnt_encrypt'}, 'ce', "'clnt_encrypt' for hdr2");
145 is($hdr2->{'recover_cmd'}, 'rec |', "'recover_cmd' for hdr2");
146 is($hdr2->{'uncompress_cmd'}, 'unc |', "'uncompress_cmd' for hdr2");
147 is($hdr2->{'decrypt_cmd'}, 'dec |', "'decrypt_cmd' for hdr2");
148 is($hdr2->{'clnt_decrypt_opt'}, '-doc', "'clnt_decrypt_opt' for hdr2");
149 is($hdr2->{'cont_filename'}, '/path/to/cont', "'cont_filename' for hdr2");
150 is($hdr2->{'dle_str'}, "D\nL\nE", "'dle_str' for hdr0");
151 is($hdr2->{'is_partial'}, 1, "'is_partial' for hdr2");
152 is($hdr2->{'partnum'}, 13, "'partnum' for hdr2");
153 is($hdr2->{'totalparts'}, 14, "'totalparts' for hdr2");
154 is($hdr2->{'blocksize'}, 0, "'blocksize' for hdr2 (not re-read; defaults to 0)");
155 is($hdr2->{'orig_size'}, 10240, "'orig_size' for hdr2");
156
157 is($hdr3->{'type'}, $Amanda::Header::F_TAPESTART, "'type' for hdr3");
158 is($hdr3->{'datestamp'}, "20090102030405", "'datestamp' for F_TAPESTART");
159 is($hdr3->{'name'}, "TAPE17", "'name' for F_TAPESTART");
160
161 # test out the other methods
162
163 # debug_dump just shouldn't crash, please
164 $hdr1->debug_dump();
165 $hdr2->debug_dump();
166 $hdr3->debug_dump();
167
168 is($hdr1->summary(),
169       "FILE: date 20090102030405 host schlitz disk /pbr lev 6 comp .TEENSY "
170     . "program GNUTAR server_custom_compress scp server_encrypt se "
171     . "server_decrypt_option -dos",
172     "hdr1 summary");
173 is($hdr2->summary(),
174       "split dumpfile: date 20090102030405 host schlitz disk /pbr part 13/14 lev 6 comp .TEENSY "
175     . "program GNUTAR client_custom_compress ccp client_encrypt ce "
176     . "client_decrypt_option -doc",
177     "hdr2 summary");
178 is($hdr3->summary(),
179     "start of tape: date 20090102030405 label TAPE17",
180     "hdr3 summary");