summaryrefslogtreecommitdiff
path: root/t/05progress.t
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-12 15:16:01 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-12 15:16:01 +0900
commit0034f59c7ed77eb8f8fe1ec082749d8520e3412e (patch)
tree6b318e64217938d6cd8ca074214778d2db99de84 /t/05progress.t
parent3555375b5b187f5eb25bc6673e2479d54f20ada3 (diff)
downloadperl-WWW-Curl-tizen_2.1.tar.gz
perl-WWW-Curl-tizen_2.1.tar.bz2
perl-WWW-Curl-tizen_2.1.zip
Diffstat (limited to 't/05progress.t')
-rw-r--r--t/05progress.t54
1 files changed, 54 insertions, 0 deletions
diff --git a/t/05progress.t b/t/05progress.t
new file mode 100644
index 0000000..52129ea
--- /dev/null
+++ b/t/05progress.t
@@ -0,0 +1,54 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More tests => 16;
+use File::Temp qw/tempfile/;
+
+BEGIN { use_ok( 'WWW::Curl::Easy' ); }
+
+my $url = $ENV{CURL_TEST_URL} || "http://www.google.com";
+
+# Init the curl session
+my $curl = WWW::Curl::Easy->new();
+ok($curl, 'Curl session initialize returns something');
+ok(ref($curl) eq 'WWW::Curl::Easy', 'Curl session looks like an object from the WWW::Curl::Easy module');
+
+ok(! $curl->setopt(CURLOPT_NOPROGRESS, 0), "Setting CURLOPT_NOPROGRESS");
+ok(! $curl->setopt(CURLOPT_FOLLOWLOCATION, 1), "Setting CURLOPT_FOLLOWLOCATION");
+ok(! $curl->setopt(CURLOPT_TIMEOUT, 30), "Setting CURLOPT_TIMEOUT");
+
+my $head = tempfile();
+ok(! $curl->setopt(CURLOPT_WRITEHEADER, $head), "Setting CURLOPT_WRITEHEADER");
+
+my $body = tempfile();
+ok(! $curl->setopt(CURLOPT_FILE,$body), "Setting CURLOPT_FILE");
+
+ok(! $curl->setopt(CURLOPT_URL, $url), "Setting CURLOPT_URL");
+
+my @myheaders;
+$myheaders[0] = "Server: www";
+$myheaders[1] = "User-Agent: Perl interface for libcURL";
+ok(! $curl->setopt(CURLOPT_HTTPHEADER, \@myheaders), "Setting CURLOPT_HTTPHEADER");
+
+ok(! $curl->setopt(CURLOPT_PROGRESSDATA,"making progress!"), "Setting CURLOPT_PROGRESSDATA");
+
+my $progress_called = 0;
+my $last_dlnow = 0;
+sub prog_callb
+{
+ my ($clientp,$dltotal,$dlnow,$ultotal,$ulnow)=@_;
+ $last_dlnow=$dlnow;
+ $progress_called++;
+ return 0;
+}
+
+ok (! $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&prog_callb), "Setting CURLOPT_PROGRESSFUNCTION");
+
+ok (! $curl->setopt(CURLOPT_NOPROGRESS, 0), "Turning progress meter back on");
+
+ok (! $curl->perform(), "Performing perform");
+
+ok ($progress_called, "Progress callback called");
+
+ok ($last_dlnow, "Last downloaded chunk non-zero");