d532ea1049080d29839f0d291da62462e761b7ef
[videosite.git] / videosite-test.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5 use File::Spec;
6 use File::Basename;
7 use Module::Load;
8 use Cwd qw(realpath);
9 use Carp;
10
11 $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
12
13 my $debug = 0;
14 my $success = 0;
15 my $fail = 0;
16 my $notest = 0;
17
18 push(@INC, dirname(realpath($0)));
19 load 'libvideosite';
20
21 unless(libvideosite::register_api({
22     _debug => sub { return $debug },
23 })) {
24     die("Error registering API: $libvideosite::error");
25 }
26
27 unless(libvideosite::init()) {
28     die("Could not init libvideosite: $libvideosite::error");
29 }
30
31 select(STDOUT);
32 $| = 1;
33 printf("Doing self tests:\n");
34 foreach my $g (libvideosite::_grabbers()) {
35     my $r;
36
37     if (@ARGV) {
38         my $found;
39
40         # If there are grabber names given on the command line check
41         # the current name against that list and skip if not present
42         $found = grep { $_ eq $g->{'NAME'} } @ARGV;
43
44         if ($found == 0) {
45             next;
46         }
47     }
48
49     printf("  %s...", $g->{'NAME'});
50     $r = $g->_selftest();
51     if(defined($r)) {
52         if ($r == 1) {
53             printf(" OK\n");
54             $success++;
55         } else {
56             printf(" no self test\n");
57             $notest++;
58         }
59     } else {
60         $fail++;
61     }
62 }
63
64 printf("\n\n%d succeeded\n%d failed\n%d not testable\n", $success, $fail, $notest);