File: 06_compression.t

package info (click to toggle)
libxml-dumper-perl 0.71-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 152 kB
  • ctags: 21
  • sloc: perl: 503; makefile: 49; xml: 3
file content (60 lines) | stat: -rw-r--r-- 1,273 bytes parent folder | download
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
use strict;
use warnings;

use Test;
use XML::Dumper;

BEGIN { plan tests => 1 }

our $COMPRESSION_AVAILABLE;

INIT {
	eval { require Compress::Zlib; };
	if( $@ ) {
		$COMPRESSION_AVAILABLE = 0;
	} else {
		$COMPRESSION_AVAILABLE = 1;
	}
}

sub check( $ );

check "Gzip Compression";

# ============================================================
sub check( $ ) {
# ============================================================
# Richard Evans provided gzip header signature test code
# (twice, cuz I lost it the first time), 22 Jul 2003
# ------------------------------------------------------------
	my $test = shift;

	if( not $COMPRESSION_AVAILABLE ) {
		skip( 1, 'Compress::Zlib not installed; compression feature disabled' );
		return;
	}

	my $gz = Compress::Zlib::gzopen( 't/data/compression.xml.gz', 'rb' );
	my @xml;
	my $buffer;
	while( $gz->gzread( $buffer ) > 0 ) {
		push @xml, $buffer;
	}
	$gz->gzclose();
	my $xml = join '', @xml;
	my $perl = xml2pl( 't/data/compression.xml.gz' );
	my $roundtrip_xml = pl2xml( $perl );

	if( xml_compare( $xml, $roundtrip_xml )) {
		ok( 1 );
		return;
	}

	print STDERR
		"\nTest for $test failed: data doesn't match!\n\n" . 
		"Got:\n----\n'$xml'\n----\n".
		"Came up with:\n----\n'$roundtrip_xml'\n----\n";

	ok( 0 );
}