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