File: 04refloop.t

package info (click to toggle)
libnet-ldap-perl 1%3A0.6500%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,660 kB
  • ctags: 731
  • sloc: perl: 15,059; sh: 76; makefile: 5
file content (56 lines) | stat: -rw-r--r-- 1,001 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
#!perl

use Test::More;

use Net::LDAP qw(LDAP_UNAVAILABLE);

my $devnull = eval { require File::Spec; File::Spec->devnull } || "/dev/null";


(-e $devnull)
? plan tests => 5
: plan skip_all => 'no null device';


$::destroy = 0;
{
  my $ldap = Net::LDAP::Dummy->new("host", async => 1);
  $ldap->bind; # create an internal ref loop
  note(explain($ldap->inner))  if $ENV{TEST_VERBOSE};
}
ok($::destroy, '');

my $ref;
my $mesg;
$::destroy = 0;
{
  my $ldap = Net::LDAP::Dummy->new("host", async => 1);
  $mesg = $ldap->bind; # create an internal ref loop
  $ref = $ldap->inner->outer;
  is($ref == $ldap, '');
}
ok(!$::destroy, '');

$ref = undef;
ok($mesg->code == LDAP_UNAVAILABLE, '');

undef $mesg;
ok($::destroy, '');


package Net::LDAP::Dummy;

use IO::File;

BEGIN { @ISA = qw(Net::LDAP); }

sub connect_ldap {
  my $ldap = shift;
  $ldap->{net_ldap_socket} = IO::File->new("+> $devnull");
}

sub DESTROY {
  my $self = shift;
  $::destroy = 1 unless tied(%$self);
  $self->SUPER::DESTROY;
}