9936cbfc9022bb14a3280674ce5b3cd577a37134
[debian/amanda] / installcheck / Amanda_Header.pl
1 # Copyright (c) 2009 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 => 7;
20 use strict;
21
22 use lib "@amperldir@";
23 use Amanda::Header;
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 # Not much to test, but we can at least exercise the constructor and destructor,
32 # and the SWIG getters and setters:
33 ok(my $hdr = Amanda::Header->new(), "can create a dumpfile_t");
34 is($hdr->{'datestamp'}, '', "newly created dumpfile_t has empty datestamp");
35 ok($hdr->{'name'} = "TAPE17", "can write to a string in the header");
36 is($hdr->{'name'}, "TAPE17", "..and get it back");
37
38 # set some other attributes so to_string will work
39 $hdr->{'type'} = $Amanda::Header::F_TAPESTART;
40 $hdr->{'datestamp'} = '20090102030405';
41
42 my $block = $hdr->to_string(32768, 32768);
43 like($block,
44      qr/^AMANDA: TAPESTART DATE 20090102030405 TAPE TAPE17/,
45      "generated header looks OK");
46 is(length($block), 32768, "generated header has correct length");
47
48 $hdr = Amanda::Header->from_string($block);
49 is($hdr->{'name'}, "TAPE17",
50    "from_string gives a reasonable-looking object");
51