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