File: interop-io-string.pl

package info (click to toggle)
libio-compress-lzma-perl 2.213-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 848 kB
  • sloc: perl: 7,361; makefile: 13
file content (149 lines) | stat: -rw-r--r-- 3,154 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use lib 't';
use strict;
#use warnings;
use bytes;

use Test::More ;
use CompTestUtils;

BEGIN {

    eval { require IO::String ;  import IO::String; 1 }
        or plan(skip_all => "IO::String not installed");

    # use Test::NoWarnings, if available
    my $extra = 0 ;
    $extra = 1
        if eval { require Test::NoWarnings ;  import Test::NoWarnings; 1 };

    plan tests => 4 + $extra ;
}


sub run
{

    my $CompressClass   = identify();
    my $UncompressClass = getInverse($CompressClass);
    my $Error           = getErrorRef($CompressClass);
    my $UnError         = getErrorRef($UncompressClass);
    my $TopFuncName     = getTopFuncName($CompressClass);
    my $Func            = getTopFuncRef($CompressClass);
    my $FuncInverse     = getTopFuncRef($UncompressClass);

    {
        use IO::String;
        #use IO::Scalar;
        #use IO::Wrap;
        #use IO::All;

        my $content = "hello world" ;
        my $string = $content;
        my $StrFH = new IO::String $string;

        #my $StrFH = new IO::Scalar \$string;
        #my $fh = new IO::String $string;
        #my $StrFH = wraphandle($fh);

        #my $lex = new LexFile my $filename ;
        #writeFile($filename, $content);
        #my $StrFH = io "$filename";

        ok $StrFH, "Created IO::String Object";

        my $outStr;
        my $out = \$outStr;
        ok $Func->($StrFH, $out), "Compressed"
            or diag $$Error ;

        my $got;
        ok $FuncInverse->($out, \$got), "Uncompressed"
            or diag $$UnError ;
        is $got, $content, "got expected content";
    }



#    if (0)
#    {
#        my $content = "hello world" ;
#        my $string = $content;
#        my $StrFH = new IO::String $string;
#
#        use File::Copy qw(cp);
#        #my $lex = new LexFile my $filename ;
#        #my $filename = "/tmp/freddy";
#        my $lex1 = new LexFile my $filename, my $filename1, my $filename2 ;
#        writeFile($filename1, "hello moto\n");
#
#        my $x =  $CompressClass->new($filename);
#        cp $StrFH, $x;
#
#        #my $y =  $UncompressClass->new($filename1);
#        #cp $y => $filename2;
#
#        #is readFile($filename2), "hello moto\n", "expected content";
#    }
}

1;

__END__


sub readWithBzip2
{
    my $file = shift ;

    my $comp = "$BZIP2 -dc" ;

    open F, "$comp $file |";
    local $/;
    $_[0] = <F>;
    close F;

    return $? ;
}

sub getBzip2Info
{
    my $file = shift ;
}

sub writeWithBzip2
{
    my $file = shift ;
    my $content = shift ;
    my $options = shift || '';

    unlink $file ;
    my $bzip2 = "$BZIP2 -c $options >$file" ;

    open F, "| $bzip2" ;
    print F $content ;
    close F ;

    return $? ;
}


{
    title "Test interop with $BZIP2" ;

    my $file = 'a.bz2';
    my $file1 = 'b.bz2';
    my $lex = new LexFile $file, $file1;
    my $content = "hello world\n" ;
    my $got;

    is writeWithBzip2($file, $content), 0, "writeWithBzip2 ok";

    bunzip2 $file => \$got ;
    is $got, $content;


    bzip2 \$content => $file1;
    $got = '';
    is readWithBzip2($file1, $got), 0, "readWithBzip2 returns 0";
    is $got, $content, "got content";
}