Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (61 sloc) 1.895 kb
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
#!/usr/bin/perl

# Test the serialization of XML structures to filehandles

use strict;
use vars qw($dir $fh $file $tmpfile $md5_able $faux_req $faux_res $ofh $data);

use RPC::XML ':all';

use Test;
use File::Spec;
use IO::File;

(undef, $dir, undef) = File::Spec->splitpath($0);
$file = File::Spec->catfile($dir, 'svsm_text.gif');
$tmpfile = File::Spec->catfile($dir, "__tmp__${$}__");

BEGIN
{
    eval "use Digest::MD5";
    $md5_able = $@ ? 0 : 1;

    plan tests => 8;
}

END
{
    unlink $tmpfile;
}

die "Could not open $file for reading: $!"
    unless $fh = IO::File->new("< $file");

$faux_req = RPC::XML::request->new('test',
RPC_STRING 'string',
RPC_INT 10,
RPC_I4 20,
RPC_BOOLEAN 1,
[ qw(a b c) ],
{ one => 2 },
RPC_BASE64 $fh);

# This is a good place to test the length() method, while we're at it
ok(length($faux_req->as_string), $faux_req->length);

die "Could not open $tmpfile for read/write: $!"
    unless $ofh = IO::File->new("+> $tmpfile");
$ofh->autoflush(1);

$faux_req->serialize($ofh);
ok(1); # Just happy we made it this far.

ok(-s $ofh, length($faux_req->as_string));

$ofh->seek(0, 0);
$data = '';
read($ofh, $data, -s $ofh);

ok($data, $faux_req->as_string);

# Done with these for now
$ofh->close; unlink $tmpfile;
$fh->close;

die "Could not open $tmpfile for read/write: $!"
    unless $ofh = IO::File->new("+> $tmpfile");
$ofh->autoflush(1);

$faux_res = RPC::XML::response->new(RPC::XML::fault->new(1, 'test'));

# This is a good place to test the length() method, while we're at it
ok(length($faux_res->as_string), $faux_res->length);

$faux_res->serialize($ofh);
ok(1); # Again, this means that all the triggered calls managed to not die

ok(-s $ofh, length($faux_res->as_string));

$ofh->seek(0, 0);
$data = '';
read($ofh, $data, -s $ofh);

ok($data, $faux_res->as_string);

$ofh->close;

exit;
Something went wrong with that request. Please try again.