Update NEWS for v0.9.20131130
[libquvi-scripts.git] / tests / media / media_arte.c
blob0fc1a3d4661ece2896d9290f19da13c535c900ea
1 /* libquvi-scripts
2 * Copyright (C) 2013 Mohamed El Morabity <melmorabity@fedoraproject.org>
3 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
5 * This file is part of libquvi-scripts <http://quvi.sourceforge.net>.
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public
9 * License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General
18 * Public License along with this program. If not, see
19 * <http://www.gnu.org/licenses/>.
23 * NOTE: Media hosted at videos.arte.tv expire after some time. For this
24 * test, we need to fetch the front page and parse a test media URL from
25 * it.
28 #include "config.h"
30 #include <string.h>
31 #include <glib.h>
32 #include <quvi.h>
34 #include "tests.h"
36 static const gchar PATTERN[] = "\"url\":\"(.*?)\"";
37 static const gchar WWW[] = "http://www.arte.tv/guide/fr/plus7.json";
39 static void test_media_arte()
41 struct qm_test_opts_s o;
42 gchar *p, *u, *r;
43 capture_t c;
44 GSList *l;
46 if (chk_geoblocked() == FALSE)
47 return;
49 memset(&o, 0, sizeof(o));
51 /* Normally done in qm_test, due to fetch-parse, do it here. */
53 if (chk_skip(__func__) == TRUE)
54 return;
56 p = fetch(WWW);
57 g_assert(p != NULL);
59 l = NULL;
60 u = NULL;
62 c = capture_new(p, PATTERN, 0);
63 g_assert(c != NULL);
65 while (capture_matches(c) == TRUE)
67 r = capture_fetch(c, 1);
68 l = g_slist_prepend(l, g_strdup_printf("http://www.arte.tv%s", r));
69 capture_next(c);
70 g_free(r);
72 l = g_slist_reverse(l);
73 g_assert_cmpint(g_slist_length(l), >, 0);
75 /* Pick a random URL from the stack. */
77 const gint32 n = g_random_int_range(0, g_slist_length(l));
78 u = (gchar*) g_slist_nth_data(l, n);
80 g_assert(u != NULL);
82 g_test_message("media URL=%s", u);
83 qm_test(__func__, u, NULL, &o);
85 slist_free_full(l, (GFunc) g_free);
86 capture_free(c);
87 g_free(p);
90 gint main(gint argc, gchar **argv)
92 g_test_init(&argc, &argv, NULL);
93 g_test_add_func("/media/arte", test_media_arte);
94 return (g_test_run());
97 /* vim: set ts=2 sw=2 tw=72 expandtab: */