summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2022-07-25 08:07:46 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2022-07-25 08:07:46 +0900
commitbac347c3605b37a1839937a689e380303a9085a4 (patch)
tree9cda36fd2c11df9aaa40660149bf688ce66d14ce /t
parent3d7755f418633e4b2eda8c8a4b1ae156ec1b65ed (diff)
downloadperl-WWW-Curl-bac347c3605b37a1839937a689e380303a9085a4.tar.gz
perl-WWW-Curl-bac347c3605b37a1839937a689e380303a9085a4.tar.bz2
perl-WWW-Curl-bac347c3605b37a1839937a689e380303a9085a4.zip
Imported Upstream version 4.11upstream/4.11
Diffstat (limited to 't')
-rw-r--r--t/00constants.t3
-rw-r--r--t/01basic.t15
-rw-r--r--t/08ssl.t6
-rw-r--r--t/13slowleak.t1
-rw-r--r--t/18twinhandles.t5
-rw-r--r--t/19multi.t74
6 files changed, 93 insertions, 11 deletions
diff --git a/t/00constants.t b/t/00constants.t
index fba9aba..fa30132 100644
--- a/t/00constants.t
+++ b/t/00constants.t
@@ -1,8 +1,9 @@
#!perl
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 3;
BEGIN { use_ok( 'WWW::Curl::Easy' ); }
ok (CURLOPT_URL == 10000+2, "Constant loaded ok");
+ok (CURLE_URL_MALFORMAT, "CURLE_ error constant can be used");
diff --git a/t/01basic.t b/t/01basic.t
index 5b4d175..58fdf4d 100644
--- a/t/01basic.t
+++ b/t/01basic.t
@@ -2,14 +2,14 @@
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 18;
use File::Temp qw/tempfile/;
BEGIN { use_ok( 'WWW::Curl::Easy' ); }
my $url = $ENV{CURL_TEST_URL} || "http://www.google.com";
-my $memfile = '';
+
# Init the curl session
my $curl = WWW::Curl::Easy->new();
ok($curl, 'Curl session initialize returns something');
@@ -18,6 +18,8 @@ ok(ref($curl) eq 'WWW::Curl::Easy', 'Curl session looks like an object from the
ok(! $curl->setopt(CURLOPT_NOPROGRESS, 1), "Setting CURLOPT_NOPROGRESS");
ok(! $curl->setopt(CURLOPT_FOLLOWLOCATION, 1), "Setting CURLOPT_FOLLOWLOCATION");
ok(! $curl->setopt(CURLOPT_TIMEOUT, 30), "Setting CURLOPT_TIMEOUT");
+ok(! $curl->setopt(CURLOPT_ENCODING, undef), "Setting CURLOPT_ENCODING to undef");
+ok(! $curl->setopt(CURLOPT_RESUME_FROM_LARGE, 0), "Setting CURLOPT_RESUME_FROM_LARGE to 0");
$curl->setopt(CURLOPT_HEADER, 1);
my $head = tempfile();
@@ -33,6 +35,7 @@ $myheaders[0] = "Server: www";
$myheaders[1] = "User-Agent: Perl interface for libcURL";
ok(! $curl->setopt(CURLOPT_HTTPHEADER, \@myheaders), "Setting CURLOPT_HTTPHEADER");
+$curl->setopt(CURLOPT_COOKIEFILE, "");
my $retcode = $curl->perform();
ok(! $retcode, "Curl return code ok");
@@ -43,6 +46,14 @@ my $realurl = $curl->getinfo(CURLINFO_EFFECTIVE_URL);
ok( $realurl, "getinfo returns CURLINFO_EFFECTIVE_URL");
my $httpcode = $curl->getinfo(CURLINFO_HTTP_CODE);
ok( $httpcode, "getinfo returns CURLINFO_HTTP_CODE");
+
+SKIP: {
+ skip "Only testing cookies against google.com", 2 unless $url eq "http://www.google.com";
+ my $cookies = $curl->getinfo(CURLINFO_COOKIELIST);
+ is(ref $cookies, "ARRAY", "Returned array reference");
+ ok(@$cookies > 0, "Got 1 or more cookies");
+}
+
#diag ("Bytes: $bytes");
#diag ("realurl: $realurl");
#diag ("httpcode: $httpcode");
diff --git a/t/08ssl.t b/t/08ssl.t
index 28759e5..7374e06 100644
--- a/t/08ssl.t
+++ b/t/08ssl.t
@@ -10,10 +10,6 @@ use WWW::Curl::Easy;
# site-url, verifypeer(0,1), verifyhost(0,2), result(0=ok, 1=fail), result-openssl0.9.5
my $url_list=[
- [ 'https://65.205.248.243/', 0, 0, 0 , 0 ], # www.thawte.com
-# [ 'https://65.205.248.243/', 0, 2, 1 , 1 ], # www.thawte.com
- [ 'https://65.205.249.60/', 0, 0, 0 , 0 ], # www.verisign.com
-# [ 'https://65.205.249.60/', 0, 2, 1 , 1 ], # www.verisign.com
[ 'https://www.microsoft.com/', 0, 0, 0 , 0 ],
[ 'https://www.microsoft.com/', 0, 0, 0 , 0 ],
[ 'https://www.verisign.com/', 1, 2, 0 , 0 ], # verisign have had broken ssl - do this first
@@ -32,7 +28,7 @@ my $url_list=[
];
-if (&WWW::Curl::Easy::version() !~ /ssl/i) {
+if (&WWW::Curl::Easy::version() !~ /ssl|nss/i) {
plan skip_all => 'libcurl was compiled without ssl support, skipping ssl tests';
} else {
plan tests => scalar(@{$url_list})+7;
diff --git a/t/13slowleak.t b/t/13slowleak.t
index 1bfbb21..c02bd6f 100644
--- a/t/13slowleak.t
+++ b/t/13slowleak.t
@@ -40,4 +40,3 @@ if ($retcode == 0) {
}
-WWW::Curl::Easy::global_cleanup; #noop
diff --git a/t/18twinhandles.t b/t/18twinhandles.t
index 10423d3..5b0b86b 100644
--- a/t/18twinhandles.t
+++ b/t/18twinhandles.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More tests => 12;
BEGIN { use_ok( 'WWW::Curl::Easy' ); }
@@ -39,11 +39,12 @@ for my $handle ($curl1,$curl2) {
}
-ok(! $curl1->setopt(CURLOPT_URL, "error:bad-url"), "Setting deliberately bad url succeeds - should return error on perform"); # deliberate error
+ok(! $curl1->setopt(CURLOPT_URL, "zxxypz://whoa"), "Setting deliberately bad protocol succeeds - should return error on perform"); # deliberate error
ok(! $curl2->setopt(CURLOPT_URL, $url), "Setting OK url");
my $code1=$curl1->perform();
ok($code1 != 0, "Curl1 handle fails as expected");
+ok($code1 == CURLE_UNSUPPORTED_PROTOCOL, "Curl1 handle fails with the correct error");
my $code2=$curl2->perform();
ok($code2 == 0, "Curl2 handle succeeds");
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");