Imported Upstream version 3.2.0
[debian/amanda] / installcheck / Amanda_NDMP.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 => 11;
20 use IO::Socket;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use Installcheck;
26 use Installcheck::Mock;
27 use Amanda::NDMP qw( :constants );
28
29 my $ndmp = Installcheck::Mock::NdmpServer->new();
30 my $nc;
31
32 Amanda::Debug::dbopen("installcheck");
33
34 $nc = Amanda::NDMP::NDMPConnection->new("127.0.0.1", $ndmp->{'port'},
35                                     "ndmp", "ndmp", "md5");
36 ok($nc, "constructor creates an object");
37 is($nc->err_code(), 0, "and no error is set");
38
39 $nc->set_verbose(1);
40
41 # can't test the scsi_* methods in the general case, because we have nothing to talk
42 # to -- but they were tested once, never fear!
43
44 ok($nc->tape_open($ndmp->{'drive'}, $NDMP9_TAPE_RDWR_MODE),
45     "tape_open");
46
47 # the stringification maps here are for old perls, which don't do well
48 # with Math::BigInt and is_deeply.
49
50 is_deeply([ map { "$_" } $nc->tape_write("ab"x8) ], ['1', '16'],
51     "tape_write");
52
53 is_deeply([ map { "$_" } $nc->tape_write("cd"x8) ], ['1', '16'],
54     "tape_write");
55
56 is_deeply([ map { "$_" } $nc->tape_mtio($NDMP9_MTIO_EOF, 1) ], ['1', '0'],
57     "tape_mtio (eof)");
58
59 is_deeply([ map { "$_" } $nc->tape_mtio($NDMP9_MTIO_REW, 1) ], ['1', '0'],
60     "tape_mtio (rewind)");
61
62 is_deeply([ map { "$_" } $nc->tape_read(32) ], ['1', "ab"x8], "tape_read");
63 is_deeply([ map { "$_" } $nc->tape_read(32) ], ['1', "cd"x8], "tape_read");
64
65 is_deeply([ map { "$_" } $nc->tape_get_state() ], ['1', '0', '0', '2'], "tape_get_state");
66
67 ok($nc->tape_close(),
68     "tape_close");
69
70 $ndmp->cleanup();