summaryrefslogtreecommitdiff
path: root/t/04abort-test.t
diff options
context:
space:
mode:
Diffstat (limited to 't/04abort-test.t')
-rw-r--r--t/04abort-test.t36
1 files changed, 36 insertions, 0 deletions
diff --git a/t/04abort-test.t b/t/04abort-test.t
new file mode 100644
index 0000000..c653c49
--- /dev/null
+++ b/t/04abort-test.t
@@ -0,0 +1,36 @@
+#!perl
+
+use strict;
+use warnings;
+use Test::More tests => 8;
+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');
+
+$curl->setopt(CURLOPT_NOPROGRESS, 1);
+$curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
+$curl->setopt(CURLOPT_TIMEOUT, 30);
+
+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 $body_abort_called = 0;
+sub body_abort_callback { $body_abort_called++; return -1 };
+
+$curl->setopt(CURLOPT_WRITEFUNCTION, \&body_abort_callback);
+
+ok( $curl->perform(), "Request fails, Abort succeeds");
+
+ok( $body_abort_called, "Abort function was invoked");