2 # Copyright (C) 2010 Toni Gundogdu.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 use POSIX
":sys_wait_h";
24 use File
::Basename
qw(basename);
27 use vars
qw(@ISA @EXPORT @EXPORT_OK);
29 our @ISA = qw(Exporter);
31 our @EXPORT_OK = qw(run run_t pod_checks check_codeset);
33 my $QUVI_PATH = "@top_builddir@/src/quvi";
34 $ENV{QUVI_BASEDIR
} = "@top_srcdir@/share";
36 # Exit test if NO_INTERNET is set.
38 if ($ENV{NO_INTERNET
}) {
39 print STDERR
"SKIP: No internet. Unset NO_INTERNET to enable.\n";
44 # Remove these from the args: we use them for
45 # default "flv" runs only.
50 qw(--page-title --video-id --file-length --file-suffix);
55 foreach my $arg (@args) {
62 push @tmp, $arg if !$skip;
69 # Wraps "-t -f $fmt", parses quvi --support output, and
70 # tests all host supported formats.
74 my @args = ("--no-shortened", "-t", @_);
75 my @formats = parse_formats
($_[0]);
79 $rc = run
( ("-f", $_, @args) );
81 @args = remove_checks
(@args);
87 # Runs quvi with the given options. Checks and
88 # parses the supported environment variables.
90 my @args = ( $QUVI_PATH, @_ );
91 my $extra = $ENV{QUVI_TEST_OPTIONS
};
93 @args = ( @args, split( /\s+/, $extra ) )
103 printf "\nTEST: %s\nRUN: ", basename
($0);
104 print qq/"$_"/ . " " foreach @args;
111 elsif ( $child == 0 ) {
112 exit( system(@args) >> 8 );
119 my $result = waitpid( $child, 0 );
121 if ( $result == -1 ) {
122 die "no more processes to wait: pid $child not found";
124 elsif ( $result == 0 ) {
126 # $child is still running.
129 elsif ( $result != $child ) {
130 die "got invalid pid $result (expected $child)";
136 if ( WIFEXITED
($status) ) {
137 $rc = WEXITSTATUS
($status);
138 print STDERR
"-> child: normal termination ($rc)\n";
141 elsif ( WIFSIGNALED
($status) ) {
142 $rc = WTERMSIG
($status);
143 print STDERR
"-> child: abnormal termination ($rc)\n";
146 elsif ( WIFSTOPPED
($status) ) {
147 $rc = WSTOPSIG
($status);
148 print STDERR
"-> child: stopped ($rc)\n";
156 # Parses quvi --support output. First argument is
157 # expected to be the host id, e.g. "youtube".
159 my $output = `$QUVI_PATH --support`;
162 if ($output =~ /$host\.(?:\w+\s+|\s+)(.*)/i) {
168 # Check the pod markup.
170 require Pod
::Checker
;
171 my $rc = Pod
::Checker
::podchecker
("@top_srcdir@/man1/quvi.1.pod");
175 # Returns current locale codeset. Terminates if codeset
176 # is not matched to UTF-8/16/32.
180 require I18N
::Langinfo
;
181 I18N
::Langinfo
->import( qw(langinfo CODESET) );
182 $cs = langinfo
( CODESET
() );
185 if ($@
) { $skip = 1; }
186 else { if ($cs !~ /^utf/i) { $skip = 1; } }
188 print STDERR
"SKIP: No utf-8 (or utf-16, utf-32) locale codeset.\n";