File: 01base.t

package info (click to toggle)
libfilesys-smbclient-perl 3.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 384 kB
  • sloc: perl: 757; ansic: 84; makefile: 8
file content (127 lines) | stat: -rwxr-xr-x 3,300 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl -w

use Test::More;
use Filesys::SmbClient;
use strict;
use diagnostics;

plan tests=>19;

my $loaded = 1;
ok($loaded,"Load module");

my $buffer = "A test of write call\n";
my $buffer2 = "buffer of 1234\n";

SKIP: {
  skip "No server defined for test at perl Makefile.PL", 18 if (!-e ".c");
if (-e ".c") {
  use POSIX;
  my $ok = 0;
  open(F,".c") || die "Can't read .c\n";
  my $l = <F>; chomp($l); 
  my @l = split(/\t/, $l);
  my %param = 
    (
     username  => $l[3],
     password  => $l[4],
     workgroup => $l[2],
     debug     =>  0,
#     flags     => SMBCCTX_FLAG_NO_AUTO_ANONYMOUS_LOGON
    );
  my $smb = new Filesys::SmbClient(%param);
  my $server = "smb://$l[0]/$l[1]";

  # Create a directory
  ok($smb->mkdir("$server/toto",'0666'),"Create directory")
    or diag("With $!");

  # Create a existent directory
  ok(!$smb->mkdir("$server/toto",'0666'),"Create existent directory");

  # Write a file
  my $fd = $smb->open(">$server/toto/test",0666);
  if ($fd) {
    $ok = 1 if ($smb->write($fd,$buffer));
  }
  $smb->close($fd);
  ok($ok,"Create file");
  $ok=0;

  # Rename a file
  ok($smb->rename("$server/toto/test","$server/toto/tata"),"Rename file")
    or diag("With $!");

  # Stat a file
  my @tab = $smb->stat("$server/toto/tata");
  ok($#tab != 0,"Stat file ") or diag("With $!");

  # Stat a non-existent file
  @tab = $smb->stat("smb://jupidsdsdster/soft/lala");
  ok($#tab == 0,"Stat non-existent file") or diag("With $!");

  # Read a file
  my $buf;
  $fd = $smb->open("$server/toto/tata",'0666');
  while (my $l= $smb->read($fd,50)) {$buf.=$l; }
  if (!$buf) { ok(0, "Read file"); }
  else {
    ok(length($buf) == length($buffer),"Read file")
      or diag("read ",length($buf)," bytes)");
  }
  $smb->close($fd);

  # Directory
  # Read a directory
  $fd = $smb->opendir("$server/toto"); 
  my @a;
  if ($fd) {	
    foreach my $n ($smb->readdir($fd)) {push(@a,$n);}
    $ok = 1 if ($#a==2);
    $smb->close($fd);
  }
  ok($ok,"Read short directory"); $ok=0;

  # Read long info on a directory
  undef @a;
  $fd = $smb->opendir("$server/toto");
  if ($fd) {	
    while (my $f = $smb->readdir_struct($fd)) { push(@a,$f); }
    $ok = 1 if ($#a==2);
    $smb->close($fd);
  }
  ok($ok,"Read long directory");

  # Unlink a file
  ok($smb->unlink("$server/toto/tata"),"Unlink file")
    or diag("With $!");

  # Unlink a non-existent file
  ok(!$smb->unlink("$server/toto/tatarr"),"Unlink non-existent file");

  ok($smb->mkdir("$server/toto/tate",'0666'),"Create directory")
    or diag("With $!");

  ok($smb->mkdir("$server/toto/tate/titi",'0666'),"Create directory")
    or diag("With $!");

  ok($smb->rmdir_recurse("$server/toto/tate",'0666'),
     "Rmdir entire directory") or diag("With $!");

  # Erase this directory
  ok($smb->rmdir("$server/toto/"),"Rm directory") or diag("With $!");

  # Erase non-existent directory
  ok(!$smb->rmdir("$server/totoarr/"),"Rm non-existent directory");

  # Rename a non-existent file
  ok(!$smb->rename("$server/toto/testrr","$server/toto/tata"),
     "Rename non-existent file");

  print "There is a .c file in this directory with info about your params \n",
        "for you SMB server test. Think to remove it if you have finish \n",
	  "with test.\n\n";

  ok( $smb->shutdown(0), "shutdown");
}
}