test_scan_core: Replace test URL
[libquvi.git] / tests / scan.c
blob608888b61f9405b1fe47570bdbfc7ce4f8ec8725
1 /* libquvi
2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <string.h>
24 #include <glib.h>
25 #include <quvi.h>
27 #include "tests.h"
29 static quvi_t new_q()
31 quvi_t q = quvi_new();
32 g_assert(q != NULL);
33 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
34 chk_verbose(q);
35 return (q);
38 static void chk_results(quvi_scan_t qs)
40 const gchar *s;
41 gint i = 0;
42 while ((s = quvi_scan_next_media_url(qs)) != NULL)
44 g_assert_cmpint(strlen(s), >, 0);
45 ++i;
47 g_assert_cmpint(i, >=, 1);
50 static void test_scan_core()
52 static const gchar URL[] =
53 "http://screenrant.com/superman-man-steel-trailer/";
55 quvi_scan_t qs;
56 quvi_t q;
58 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
59 return;
61 q = new_q();
63 qs = quvi_scan_new(q, URL);
64 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
65 g_assert(qs != NULL);
66 chk_results(qs);
68 quvi_scan_free(qs);
69 quvi_free(q);
72 static void test_scan_short()
74 static const gchar URL[] = "http://is.gd/yUeWit";
76 quvi_scan_t qs;
77 quvi_t q;
79 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
80 return;
82 q = new_q();
84 qs = quvi_scan_new(q, URL);
85 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
86 g_assert(qs != NULL);
87 chk_results(qs);
89 quvi_scan_free(qs);
90 quvi_free(q);
93 static void test_scan_noresults()
95 static const gchar URL[] = "http://example.com/";
97 quvi_scan_t qs;
98 quvi_t q;
100 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
101 return;
103 q = new_q();
105 qs = quvi_scan_new(q, URL);
106 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
107 g_assert(qs != NULL);
108 g_assert(quvi_scan_next_media_url(qs) == NULL);
110 quvi_scan_free(qs);
111 quvi_free(q);
114 struct user_data_s
116 gint n;
119 typedef struct user_data_s *user_data_t;
121 static QuviError status_cb(glong status_type, gpointer data,
122 gpointer user_data)
124 user_data_t u = (user_data_t) user_data;
125 g_assert(user_data != NULL);
126 ++u->n;
127 return (QUVI_OK);
130 static void test_scan_userdata()
132 static const gchar URL[] = "http://is.gd/yUeWit";
134 struct user_data_s u;
135 quvi_scan_t qs;
136 quvi_t q;
138 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
139 return;
141 q = new_q();
142 u.n = 0;
144 quvi_set(q, QUVI_OPTION_CALLBACK_STATUS, (quvi_callback_status) status_cb);
145 quvi_set(q, QUVI_OPTION_CALLBACK_STATUS_USERDATA, &u);
147 g_assert_cmpint(u.n, ==, 0);
148 qs = quvi_scan_new(q, URL);
149 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
150 g_assert(qs != NULL);
152 quvi_scan_free(qs);
153 quvi_free(q);
155 g_assert_cmpint(u.n, >, 0);
158 gint main(gint argc, gchar **argv)
160 g_test_init(&argc, &argv, NULL);
161 g_test_add_func("/quvi/scan (core)", test_scan_core);
162 g_test_add_func("/quvi/scan (short)", test_scan_short);
163 g_test_add_func("/quvi/scan (noresults)", test_scan_noresults);
164 g_test_add_func("/quvi/scan (userdata)", test_scan_userdata);
165 return (g_test_run());
168 /* vim: set ts=2 sw=2 tw=72 expandtab: */