LIBQUVI_SHOW_SCRIPT: Output script path if URL was accepted
[libquvi.git] / tests / scan.c
blobadca331c453d2811651bdd0927bffd57684e1f87
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (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, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include "config.h"
22 #include <string.h>
23 #include <glib.h>
24 #include <quvi.h>
26 #include "tests.h"
28 static quvi_t new_q()
30 quvi_t q = quvi_new();
31 g_assert(q != NULL);
32 g_assert_cmpint(qerr(q), ==, QUVI_OK);
33 chk_verbose(q);
34 return (q);
37 static void chk_results(quvi_scan_t qs)
39 const gchar *s;
40 gint i = 0;
41 while ((s = quvi_scan_next_media_url(qs)) != NULL)
43 g_assert_cmpint(strlen(s), >, 0);
44 ++i;
46 g_assert_cmpint(i, >=, 1);
49 static void test_scan()
51 static const gchar URL[] =
52 "http://www.fangoria.com/index.php/home/all-news/1-latest-news/"
53 "6981-new-qprometheusq-trailer-has-landed";
55 quvi_scan_t qs;
56 quvi_t q;
58 if (chk_internet() == FALSE)
59 return;
61 if (chk_skip(__func__) == TRUE)
62 return;
64 q = new_q();
66 qs = quvi_scan_new(q, URL);
67 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
68 g_assert(qs != NULL);
69 chk_results(qs);
71 quvi_scan_free(qs);
72 quvi_free(q);
75 static void test_scan_short()
77 static const gchar URL[] = "http://is.gd/gQ4pYW";
79 quvi_scan_t qs;
80 quvi_t q;
82 if (chk_internet() == FALSE)
83 return;
85 if (chk_skip(__func__) == TRUE)
86 return;
88 q = new_q();
90 qs = quvi_scan_new(q, URL);
91 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
92 g_assert(qs != NULL);
93 chk_results(qs);
95 quvi_scan_free(qs);
96 quvi_free(q);
99 static void test_scan_noresults()
101 static const gchar URL[] = "http://example.com/";
103 quvi_scan_t qs;
104 quvi_t q;
106 if (chk_internet() == FALSE)
107 return;
109 if (chk_skip(__func__) == TRUE)
110 return;
112 q = new_q();
114 qs = quvi_scan_new(q, URL);
115 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
116 g_assert(qs != NULL);
117 g_assert(quvi_scan_next_media_url(qs) == NULL);
119 quvi_scan_free(qs);
120 quvi_free(q);
123 gint main(gint argc, gchar **argv)
125 g_test_init(&argc, &argv, NULL);
126 g_test_add_func("/quvi/scan", test_scan);
127 g_test_add_func("/quvi/scan (short)", test_scan_short);
128 g_test_add_func("/quvi/scan (noresults)", test_scan_noresults);
129 return (g_test_run());
132 /* vim: set ts=2 sw=2 tw=72 expandtab: */