From 7d17c3a4e25ac98e258fd8529804bfce00a90cb7 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Wed, 27 Jul 2011 00:44:40 +0300 Subject: [PATCH] Rewrite tests --- t/00_use.t | 28 ++++++++++ t/01_codes.t | 73 +++++++++++++++++++++++++ t/02_Media_defaults.t | 45 ++++++++++++++++ t/03_Options_defaults.t | 48 +++++++++++++++++ t/04_Query_defaults.t | 42 +++++++++++++++ t/05_Url_defaults.t | 43 +++++++++++++++ t/Query.t | 36 +++++++++++++ t/Support.t | 45 ++++++++++++++++ t/WWW-Quvi-Defaults.t | 126 -------------------------------------------- t/WWW-Quvi-Query.t | 42 --------------- t/{WWW-Quvi-Pod.t => pod.t} | 0 t/version.t | 38 +++++++++++++ 12 files changed, 398 insertions(+), 168 deletions(-) create mode 100644 t/00_use.t create mode 100644 t/01_codes.t create mode 100644 t/02_Media_defaults.t create mode 100644 t/03_Options_defaults.t create mode 100644 t/04_Query_defaults.t create mode 100644 t/05_Url_defaults.t create mode 100644 t/Query.t create mode 100644 t/Support.t delete mode 100644 t/WWW-Quvi-Defaults.t delete mode 100644 t/WWW-Quvi-Query.t rename t/{WWW-Quvi-Pod.t => pod.t} (100%) create mode 100644 t/version.t diff --git a/t/00_use.t b/t/00_use.t new file mode 100644 index 0000000..f3bdae1 --- /dev/null +++ b/t/00_use.t @@ -0,0 +1,28 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More tests => 1; + +BEGIN { use_ok('WWW::Quvi') }; + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/01_codes.t b/t/01_codes.t new file mode 100644 index 0000000..1682257 --- /dev/null +++ b/t/01_codes.t @@ -0,0 +1,73 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +my @return = ( + WWW::Quvi::OK, + WWW::Quvi::Mem, + WWW::Quvi::BadHandle, + WWW::Quvi::InvArg, + WWW::Quvi::CurlInit, + WWW::Quvi::Last, + WWW::Quvi::AbortedByCallback, + WWW::Quvi::LuaInit, + WWW::Quvi::NoLuaWebsite, + WWW::Quvi::NoLuaUtil, + WWW::Quvi::NoSupport, + WWW::Quvi::CallbackError, + WWW::Quvi::IconvError, + WWW::Quvi::LuaError +); + +my @proto = ( + WWW::Quvi::ProtoHttp, + WWW::Quvi::ProtoMms, + WWW::Quvi::ProtoRtsp, + WWW::Quvi::ProtoRtmp, + WWW::Quvi::ProtoAll +); + +plan tests => scalar @return + scalar @proto; + +my $n = -1; +foreach (@return) { + is($_, ++$n); +# diag "$_,$n\n"; + $n = 0x40 if $n == WWW::Quvi::NoLuaUtil; +} + +$n = 1; +foreach (@proto) { + is($_, $n); +# diag "$_,$n\n"; + if ($n == WWW::Quvi::ProtoRtmp) { + $n = 0x1|0x2|0x4|0x8; + } + else { + $n = $n << 1; + } +} + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/02_Media_defaults.t b/t/02_Media_defaults.t new file mode 100644 index 0000000..53bffca --- /dev/null +++ b/t/02_Media_defaults.t @@ -0,0 +1,45 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +my %h = ( + start_time => '', + page_url => '', + title => '', + host => '', + id => '', + ok => 0, +); + +plan tests => keys(%h) + 1; + +my $m = new WWW::Quvi::Media; +isa_ok($m, 'WWW::Quvi::Media'); + +for my $k (keys %h) { + is($m->{$k}, $h{$k}); # Test default. +} + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/03_Options_defaults.t b/t/03_Options_defaults.t new file mode 100644 index 0000000..1e10931 --- /dev/null +++ b/t/03_Options_defaults.t @@ -0,0 +1,48 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +my %h = ( + user_agent => '', + http_proxy => '', + format => 'default', + verify => 1, + verbose_libcurl => 0, + resolve => 1, + category => WWW::Quvi::ProtoHttp +); + +plan tests => keys(%h)*2 + 1; + +my $o = new WWW::Quvi::Options; +isa_ok($o, 'WWW::Quvi::Options'); + +for my $k (keys %h) { + is($o->{$k}, $h{$k}); # Test default. + $o->{$k} = '1'; # Test set. + is($o->{$k}, 1); +} + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/04_Query_defaults.t b/t/04_Query_defaults.t new file mode 100644 index 0000000..118915d --- /dev/null +++ b/t/04_Query_defaults.t @@ -0,0 +1,42 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +my %h = ( + last_error => '', + quvi_code => 0, + resp_code => -1 +); + +plan tests => keys(%h) + 1; + +my $q = new WWW::Quvi::Query; +isa_ok($q, 'WWW::Quvi::Query'); + +for my $k (keys %h) { + is($q->{$k}, $h{$k}); # Test default. +} + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/05_Url_defaults.t b/t/05_Url_defaults.t new file mode 100644 index 0000000..dad7ba2 --- /dev/null +++ b/t/05_Url_defaults.t @@ -0,0 +1,43 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +my %h = ( + content_type => '', + length_bytes => -1, + file_suffix => '', + url => '' +); + +plan tests => keys(%h) + 1; + +my $u = new WWW::Quvi::Url; +isa_ok($u, 'WWW::Quvi::Url'); + +for my $k (keys %h) { + is($u->{$k}, $h{$k}); # Test default. +} + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/Query.t b/t/Query.t new file mode 100644 index 0000000..b6c7cf3 --- /dev/null +++ b/t/Query.t @@ -0,0 +1,36 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More; +use WWW::Quvi; + +$ENV{HAVE_INTERNET} + ? plan tests => 1 + : plan skip_all => 'Set HAVE_INTERNET to enable'; + +my $u = "http://www.dailymotion.com/video/xdpig1_city-of-scars_shortfilms"; +my $q = new WWW::Quvi::Query; +my $m = $q->parse($u, new WWW::Quvi::Options); +is($m->{ok}, 1) or diag $q->{last_error}; + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/Support.t b/t/Support.t new file mode 100644 index 0000000..13d01f9 --- /dev/null +++ b/t/Support.t @@ -0,0 +1,45 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More tests => 6; +use WWW::Quvi; + +my $q = new WWW::Quvi::Query; +isa_ok($q, 'WWW::Quvi::Query'); + +# Next (supported) website. + +my ($rc, $domain, $formats) = $q->next_website; +is($rc, WWW::Quvi::OK); +like($domain, qr{^\w+.\w+$}); +like($formats, qr{^\w+(?:|)}); + +# Supported. + +$rc = $q->supported('http://dai.ly/foobar'); +is($rc, WWW::Quvi::OK); + +$rc = $q->supported('http://foo.bar'); +is($rc, WWW::Quvi::NoSupport); + +# vim: set ts=2 sw=2 tw=72 expandtab: diff --git a/t/WWW-Quvi-Defaults.t b/t/WWW-Quvi-Defaults.t deleted file mode 100644 index a284d55..0000000 --- a/t/WWW-Quvi-Defaults.t +++ /dev/null @@ -1,126 +0,0 @@ - -use warnings; -use strict; - -use Test::More tests => 40; -BEGIN { use_ok('WWW::Quvi') }; - -# Version. - -like (&WWW::Quvi::version, qr{^\d+.\d+$}); - -like (&WWW::Quvi::version(WWW::Quvi::ModuleVersion), qr{^\d+.\d+$}); - -like ( - &WWW::Quvi::version(WWW::Quvi::libquviVersion), qr{^\d+.\d+.\d+$}); - -like ( - &WWW::Quvi::version(WWW::Quvi::libquviVersionLong), - qr{^\d+.\d+.\d+.* built on \d+.\d+.\d+ .* (.*)$} -); - -# Options. - -my $opts = new WWW::Quvi::Options; -isa_ok ($opts, 'WWW::Quvi::Options'); - -is ($opts->{user_agent}, ""); -is ($opts->{http_proxy}, ""); -is ($opts->{format}, "default"); -is ($opts->{verify}, 1); -is ($opts->{verbose_libcurl}, ""); -is ($opts->{shortened}, 1); -is ($opts->{category}, WWW::Quvi::ProtoHttp); - -$opts->{user_agent} = "Mozilla/5.0"; -is ($opts->{user_agent}, "Mozilla/5.0"); - -$opts->{http_proxy} = "http://foo:1234"; -is ($opts->{http_proxy}, "http://foo:1234"); - -$opts->{format} = "hd"; -is ($opts->{format}, "hd"); - -$opts->{verify} = 0; -is ($opts->{verify}, ""); - -$opts->{verbose_libcurl} = 1; -is ($opts->{verbose_libcurl}, 1); - -$opts->{shortened} = 0; -is ($opts->{shortened}, ""); - -$opts->{category} = WWW::Quvi::ProtoMms; -is ($opts->{category}, WWW::Quvi::ProtoMms); - -# Url. - -my $l = new WWW::Quvi::Url; -isa_ok ($l, 'WWW::Quvi::Url'); - -is ($l->{content_type}, ""); -is ($l->{file_suffix}, ""); -is ($l->{length_bytes}, -1); -is ($l->{url}, ""); - -# Media. - -my $v = new WWW::Quvi::Media; -isa_ok ($v, 'WWW::Quvi::Media'); - -is ($v->{title}, ""); -is ($v->{host}, ""); -is ($v->{url}, ""); -is ($v->{id}, ""); -is ($v->{ok}, ""); -is ($v->{start_time}, ""); - -# Query. - -my $q = new WWW::Quvi::Query; -isa_ok ($q, 'WWW::Quvi::Query'); - -is ($q->{last_error}, ""); -is ($q->{quvi_code}, 0); -is ($q->{resp_code}, -1); - -# Websites. - -my ($rc, $domain, $formats) = $q->next_website; -is ($rc, WWW::Quvi::OK); -like ($domain, qr{^\w+.\w+$}); -like ($formats, qr{^\w+(?:|)}); - -# Supported. - -$rc = $q->supported ("http://dai.ly"); -is ($rc, WWW::Quvi::OK); - -# QUVIcode aliases. - -my @QUVIcode = { - WWW::Quvi::OK, - WWW::Quvi::Mem, - WWW::Quvi::BadHandle, - WWW::Quvi::InvArg, - WWW::Quvi::CurlInit, - WWW::Quvi::Last, - WWW::Quvi::AbortedByCallback, - WWW::Quvi::LuaInit, - WWW::Quvi::NoLuaWebsite, - WWW::Quvi::NoSupport, - WWW::Quvi::CallbackError, - WWW::Quvi::IconvError, - WWW::Quvi::LuaError, -}; - -# QUVIcategory aliases. - -my @QUVIcategory = { - WWW::Quvi::ProtoHttp, - WWW::Quvi::ProtoMms, - WWW::Quvi::ProtoRtsp, - WWW::Quvi::ProtoRtmp, - WWW::Quvi::ProtoAll, -0xffff # Pad to prevent "Odd number of elements in anonymous hash" warning -}; diff --git a/t/WWW-Quvi-Query.t b/t/WWW-Quvi-Query.t deleted file mode 100644 index 11da161..0000000 --- a/t/WWW-Quvi-Query.t +++ /dev/null @@ -1,42 +0,0 @@ - -use warnings; -use strict; - -use Test::More; - -$ENV{HAVE_INTERNET} - ? plan tests => 16 - : plan skip_all => 'Set HAVE_INTERNET to enable these tests'; - -use_ok('WWW::Quvi'); - -my $opts = new WWW::Quvi::Options; - -my $q = new WWW::Quvi::Query; -isa_ok ($q, 'WWW::Quvi::Query'); - -my $url = -"http://www.funnyordie.com/videos/eec0f64fc5/between-two-ferns-with-zach-galifianakis-bruce-willis"; - -my $v = $q->parse ($url, $opts); -isa_ok ($v, 'WWW::Quvi::Video'); - -is ($v->{ok}, 1); -is ($v->{title}, "Between Two Ferns with Zach Galifianakis: Bruce Willis"); -is ($v->{url}, $url); -is ($v->{host}, "funnyordie"); -is ($v->{id}, "eec0f64fc5"); -is ($v->{link}->{url}, "http://videos0.ordienetworks.com/videos/eec0f64fc5/iphone_wifi.mp4"); -is ($v->{link}->{content_type}, "video/mp4"); -is ($v->{link}->{length_bytes}, 16235486); -is ($v->{link}->{file_suffix}, "mp4"); - -is ($q->{resp_code}, 200); -is ($q->{quvi_code}, 0); - -$opts->{http_proxy} = "http://localhost:1234"; - -# Should fail. Assumes localhost isn't running an HTTP proxy at 1234. -$v = $q->parse ($url, $opts); -isa_ok ($v, "WWW::Quvi::Video"); -is ($v->{ok}, ""); diff --git a/t/WWW-Quvi-Pod.t b/t/pod.t similarity index 100% rename from t/WWW-Quvi-Pod.t rename to t/pod.t diff --git a/t/version.t b/t/version.t new file mode 100644 index 0000000..7a5808e --- /dev/null +++ b/t/version.t @@ -0,0 +1,38 @@ + +# WWW::Quvi +# Copyright (C) 2011 Toni Gundogdu +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. +# + +use warnings; +use strict; + +use Test::More tests => 4; +use WWW::Quvi; + +# Version. + +like(&WWW::Quvi::version, qr{^\d+.\d+$}); + +like(&WWW::Quvi::version(WWW::Quvi::ModuleVersion), qr{^\d+.\d+$}); + +like(&WWW::Quvi::version(WWW::Quvi::libquviVersion), qr{^\d+.\d+.\d+$}); + +like(&WWW::Quvi::version(WWW::Quvi::libquviVersionLong), + qr{^\d+.\d+.\d+.* built on \d+.\d+.\d+ .* (.*)$}); + +# vim: set ts=2 sw=2 tw=72 expandtab: -- 2.11.4.GIT