1#!perl 2 3use strict; 4use warnings; 5use Test::More tests => 16; 6use File::Temp qw/tempfile/; 7 8BEGIN { use_ok( 'WWW::Curl::Easy' ); } 9 10my $url = $ENV{CURL_TEST_URL} || "http://www.google.com"; 11 12# Init the curl session 13my $curl = WWW::Curl::Easy->new(); 14ok($curl, 'Curl session initialize returns something'); 15ok(ref($curl) eq 'WWW::Curl::Easy', 'Curl session looks like an object from the WWW::Curl::Easy module'); 16 17ok(! $curl->setopt(CURLOPT_NOPROGRESS, 0), "Setting CURLOPT_NOPROGRESS"); 18ok(! $curl->setopt(CURLOPT_FOLLOWLOCATION, 1), "Setting CURLOPT_FOLLOWLOCATION"); 19ok(! $curl->setopt(CURLOPT_TIMEOUT, 30), "Setting CURLOPT_TIMEOUT"); 20 21my $head = tempfile(); 22ok(! $curl->setopt(CURLOPT_WRITEHEADER, $head), "Setting CURLOPT_WRITEHEADER"); 23 24my $body = tempfile(); 25ok(! $curl->setopt(CURLOPT_FILE,$body), "Setting CURLOPT_FILE"); 26 27ok(! $curl->setopt(CURLOPT_URL, $url), "Setting CURLOPT_URL"); 28 29my @myheaders; 30$myheaders[0] = "Server: www"; 31$myheaders[1] = "User-Agent: Perl interface for libcURL"; 32ok(! $curl->setopt(CURLOPT_HTTPHEADER, \@myheaders), "Setting CURLOPT_HTTPHEADER"); 33 34ok(! $curl->setopt(CURLOPT_PROGRESSDATA,"making progress!"), "Setting CURLOPT_PROGRESSDATA"); 35 36my $progress_called = 0; 37my $last_dlnow = 0; 38sub prog_callb 39{ 40 my ($clientp,$dltotal,$dlnow,$ultotal,$ulnow)=@_; 41 $last_dlnow=$dlnow; 42 $progress_called++; 43 return 0; 44} 45 46ok (! $curl->setopt(CURLOPT_PROGRESSFUNCTION, \&prog_callb), "Setting CURLOPT_PROGRESSFUNCTION"); 47 48ok (! $curl->setopt(CURLOPT_NOPROGRESS, 0), "Turning progress meter back on"); 49 50ok (! $curl->perform(), "Performing perform"); 51 52ok ($progress_called, "Progress callback called"); 53 54ok ($last_dlnow, "Last downloaded chunk non-zero"); 55