| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
if (not $ENV{'ONLINE_TEST'}) { |
| 6 |
plan tests => 16; |
| 7 |
} else { |
| 8 |
plan tests => 23; |
| 9 |
} |
| 10 |
|
| 11 |
my $q; |
| 12 |
my $result; |
| 13 |
|
| 14 |
use Finance::Quote; |
| 15 |
ok(1, "Finance::Quote loaded"); |
| 16 |
|
| 17 |
if ( $ENV{'ONLINE_TEST'}) { |
| 18 |
|
| 19 |
$q = Finance::Quote->new('YahooJSON'); |
| 20 |
ok( $q, "specific module constructor"); |
| 21 |
|
| 22 |
$result = $q->fetch("yahoo_json", "IBM"); |
| 23 |
ok( (ref $result eq "HASH" and exists $result->{'IBM','success'}), "check fetch on specific module"); |
| 24 |
|
| 25 |
$result = $q->fetch("usa", "IBM"); |
| 26 |
ok( !defined $result, "check fetch on wrong specific module"); |
| 27 |
|
| 28 |
$q = Finance::Quote->new(); |
| 29 |
ok( $q, "bare constructor"); |
| 30 |
|
| 31 |
$result = $q->fetch("usa", "IBM"); |
| 32 |
ok( (ref $result eq "HASH" and exists $result->{'IBM','success'}), "check fetch on specific module"); |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
$q = Finance::Quote->new(); |
| 37 |
|
| 38 |
ok( $q->B_to_billions("1.234B") eq "1234000000", "B_to_billions check"); |
| 39 |
ok( $q->decimal_shiftup("6.789", 2) eq "678.9", "decimal_shiftup test"); |
| 40 |
|
| 41 |
ok( $q->get_failover(), "check default failover"); |
| 42 |
$q->set_failover(0); |
| 43 |
ok( !$q->get_failover(), "check set/get failover"); |
| 44 |
|
| 45 |
$q = Finance::Quote->new(failover => 0); |
| 46 |
ok( !$q->get_failover(), "check failover for named argument constructor"); |
| 47 |
|
| 48 |
$q = Finance::Quote->new(); |
| 49 |
ok( !defined $q->get_fetch_currency(), "default currency is not defined"); |
| 50 |
|
| 51 |
$q->set_fetch_currency('aud'); |
| 52 |
ok( 'aud' eq $q->get_fetch_currency(), "check set/get currency"); |
| 53 |
|
| 54 |
$q = Finance::Quote->new(fetch_currency => 'usd'); |
| 55 |
ok( 'usd' eq $q->get_fetch_currency(), "check named parameter fetch_currency"); |
| 56 |
|
| 57 |
$q = Finance::Quote->new(); |
| 58 |
ok( 0 == @{$q->get_required_labels()}, "check default required labels"); |
| 59 |
|
| 60 |
my $labels = ['close', 'isodate', 'last']; |
| 61 |
$q->set_required_labels($labels); |
| 62 |
ok( join(",", sort @{$labels}) eq join(",", @{$q->get_required_labels()}), "check set/get required_labels"); |
| 63 |
|
| 64 |
if ( $ENV{'ONLINE_TEST'}) { |
| 65 |
$result = $q->fetch("yahoo_json", "IBM"); |
| 66 |
ok( (ref $result eq "HASH" and exists $result->{'IBM','success'}), "check fetch on specific module"); |
| 67 |
} |
| 68 |
|
| 69 |
$q = Finance::Quote->new(required_labels => ['does-not-exist']); |
| 70 |
ok( 'does-not-exist' eq join(",", @{$q->get_required_labels()}), "check set/get required_labels"); |
| 71 |
|
| 72 |
if ( $ENV{'ONLINE_TEST'}) { |
| 73 |
$result = $q->fetch("usa", "IBM"); |
| 74 |
ok( (ref $result eq "HASH" and !%{$result}), "check required_labels is enforeced"); |
| 75 |
} |
| 76 |
|
| 77 |
$q = Finance::Quote->new(); |
| 78 |
ok( !defined $q->get_timeout(), "check default timeout"); |
| 79 |
$q->set_timeout(123); |
| 80 |
ok( 123 == $q->get_timeout(), "check set/get timeout"); |
| 81 |
$q = Finance::Quote->new(timeout => 456); |
| 82 |
ok( 456 == $q->get_timeout(), "check timeout as named parameter"); |
| 83 |
|
| 84 |
print ref $q->get_user_agent(), "\n"; |
| 85 |
ok( 'LWP::UserAgent' eq ref $q->get_user_agent(), "check get_user_agent"); |