Updated with Tizen:Base source codes
[toolchains/perl-WWW-Curl.git] / t / 04abort-test.t
1 #!perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 8;
6 use File::Temp qw/tempfile/;
7
8 BEGIN { use_ok( 'WWW::Curl::Easy' ); }
9
10 my $url = $ENV{CURL_TEST_URL} || "http://www.google.com";
11
12 # Init the curl session
13 my $curl = WWW::Curl::Easy->new();
14 ok($curl, 'Curl session initialize returns something');
15 ok(ref($curl) eq 'WWW::Curl::Easy', 'Curl session looks like an object from the WWW::Curl::Easy module');
16
17 $curl->setopt(CURLOPT_NOPROGRESS, 1);
18 $curl->setopt(CURLOPT_FOLLOWLOCATION, 1);
19 $curl->setopt(CURLOPT_TIMEOUT, 30);
20
21 my $head = tempfile();
22 ok(! $curl->setopt(CURLOPT_WRITEHEADER, $head), "Setting CURLOPT_WRITEHEADER");
23
24 my $body = tempfile();
25 ok(! $curl->setopt(CURLOPT_FILE,$body), "Setting CURLOPT_FILE");
26
27 ok(! $curl->setopt(CURLOPT_URL, $url), "Setting CURLOPT_URL");
28
29 my $body_abort_called = 0;
30 sub body_abort_callback { $body_abort_called++; return -1 };
31
32 $curl->setopt(CURLOPT_WRITEFUNCTION, \&body_abort_callback);
33
34 ok( $curl->perform(), "Request fails, Abort succeeds");
35
36 ok( $body_abort_called, "Abort function was invoked");