File: 05dsml.t

package info (click to toggle)
libnet-ldap-perl 1%3A0.4400-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,484 kB
  • sloc: perl: 13,645; sh: 16; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (2)
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

BEGIN {
  require "t/common.pl";
}

unless (eval { require XML::SAX::Base; 1}) {
  print "1..0 # XML::SAX::Base not installed\n";
  exit;
}

unless (eval { require XML::SAX::Writer; 1}) {
  print "1..0 # XML::SAX::Writer not installed\n";
  exit;
}

require Net::LDAP::LDIF;
require Net::LDAP::DSML;

print "1..1\n";

my $infile   = "data/00-in.ldif";
my $outfile1 = "$TEMPDIR/05-out1.dsml";
my $cmpfile1 = "data/05-cmp.dsml";

my $ldif = Net::LDAP::LDIF->new($infile,"r");

@entry = $ldif->read;

open(FH,">$outfile1");
binmode FH;
my $dsml = Net::LDAP::DSML->new(output => \*FH,pretty_print => 1);

$dsml->write_entry($_) for @entry;

$dsml->end_dsml;
close(FH);

# postprocess generated DSML file for more flexible comparison
# (don't rely on unpatched XML::SAX::Writer [e.g. Debian])
{
open(FH, "+<$outfile1");
binmode FH;
local $/;	# slurp mode
my $txt = <FH>;

$txt =~ s/>\n[\n\t ]+/>\n/g;	# remove empty lines & leading spaces after tags
$txt =~ s/\"/'/g;	# convert " to ' in tag attribute values

seek(FH, 0, 0);
print FH $txt;
truncate(FH, length($txt));
close(FH);
}

ok(!compare($cmpfile1,$outfile1), $cmpfile1);