diff options
Diffstat (limited to 't/19multi.t')
-rw-r--r-- | t/19multi.t | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/t/19multi.t b/t/19multi.t new file mode 100644 index 0000000..1e11ac3 --- /dev/null +++ b/t/19multi.t @@ -0,0 +1,74 @@ +#!perl + +use strict; +use warnings; +use Test::More tests => 16; +use WWW::Curl::Easy; +use WWW::Curl::Multi; +use File::Temp qw/tempfile/; + +my $header = tempfile(); +my $header2 = tempfile(); +my $body = tempfile(); +my $body2 = tempfile(); + +my $url = $ENV{CURL_TEST_URL} || "http://www.google.com"; + +sub fhbits { + my $fhlist = shift; + my $bits = ''; + for (@{$fhlist}) { + vec($bits,$_,1) = 1; + } + return $bits; +} + +sub action_wait { + my $curlm = shift; + my ($re, $wr, $err) = $curlm->fdset; + my ($rin, $win, $ein, $rout, $wout, $eout); + $rin = $win = $ein = ''; + $rin = fhbits($re); + $win = fhbits($wr); + $ein = $rin | $win; + my ($nfound,$timeleft) = select($rin, $win, $ein, 1); +} + + my $curl = new WWW::Curl::Easy; + $curl->setopt( CURLOPT_URL, $url); + ok(! $curl->setopt(CURLOPT_WRITEHEADER, $header), "Setting CURLOPT_WRITEHEADER"); + ok(! $curl->setopt(CURLOPT_WRITEDATA,$body), "Setting CURLOPT_WRITEDATA"); + + my $curl2 = new WWW::Curl::Easy; + $curl2->setopt( CURLOPT_URL, $url); + ok(! $curl2->setopt(CURLOPT_WRITEHEADER, $header2), "Setting CURLOPT_WRITEHEADER"); + ok(! $curl2->setopt(CURLOPT_WRITEDATA,$body2), "Setting CURLOPT_WRITEDATA"); + + my $curlm = new WWW::Curl::Multi; + my @fds = $curlm->fdset; + ok( @fds == 3 && ref($fds[0]) && ref($fds[1]) && ref($fds[2]), "fdset returns 3 references"); + ok( ! @{$fds[0]} && ! @{$fds[1]} && !@{$fds[2]} , "The three returned arrayrefs are empty"); + $curlm->perform; + @fds = $curlm->fdset; + ok( ! @{$fds[0]} && ! @{$fds[1]} && !@{$fds[2]} , "The three returned arrayrefs are still empty after perform"); + $curlm->add_handle($curl); + @fds = $curlm->fdset; + ok( ! @{$fds[0]} && ! @{$fds[1]} && !@{$fds[2]} , "The three returned arrayrefs are still empty after perform and add_handle"); + $curlm->perform; + @fds = $curlm->fdset; + ok( @{$fds[0]} == 1 || @{$fds[1]} == 1, "The read or write fdset contains one fd"); + $curlm->add_handle($curl2); + @fds = $curlm->fdset; + ok(@{$fds[0]} == 1 || @{$fds[1]} == 1, "The read or write fdset still only contains one fd"); + $curlm->perform; + @fds = $curlm->fdset; + ok( @{$fds[0]} == 2 || @{$fds[1]} == 2, "The read or write fdset contains two fds"); + while ($curlm->perform) { + action_wait($curlm); + } + @fds = $curlm->fdset; + ok( ! @{$fds[0]} && ! @{$fds[1]} && !@{$fds[2]} , "The three returned arrayrefs are empty after we have no active transfers"); + ok($header, "Header reply exists from first handle"); + ok($body, "Body reply exists from second handle"); + ok($header2, "Header reply exists from second handle"); + ok($body2, "Body reply exists from second handle"); |