From f91f5cdca44058cc7d6ccf1b4da173423d9db8a0 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Wed, 8 May 2013 01:15:36 +0300 Subject: [PATCH] tests: Add a test for media/ardmediathek.lua Signed-off-by: Toni Gundogdu --- tests/media/ardmediathek.mk | 6 ++ tests/media/media_ardmediathek.c | 129 +++++++++++++++++++++++++++++++++++++++ tests/media/tests.mk | 1 + 3 files changed, 136 insertions(+) create mode 100644 tests/media/ardmediathek.mk create mode 100644 tests/media/media_ardmediathek.c diff --git a/tests/media/ardmediathek.mk b/tests/media/ardmediathek.mk new file mode 100644 index 0000000..704c996 --- /dev/null +++ b/tests/media/ardmediathek.mk @@ -0,0 +1,6 @@ +TEST_PROGS+=media_ardmediathek +media_ardmediathek_SOURCES=media/media_ardmediathek.c +media_ardmediathek_CPPFLAGS=$(testsuite_cppflags) +media_ardmediathek_LDFLAGS=$(testsuite_ldflags) +media_ardmediathek_LDADD=$(testsuite_ldadd) +media_ardmediathek_CFLAGS=$(AM_CFLAGS) diff --git a/tests/media/media_ardmediathek.c b/tests/media/media_ardmediathek.c new file mode 100644 index 0000000..f68f4ac --- /dev/null +++ b/tests/media/media_ardmediathek.c @@ -0,0 +1,129 @@ +/* libquvi-scripts + * Copyright (C) 2013 Toni Gundogdu + * + * This file is part of libquvi-scripts . + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General + * Public License along with this program. If not, see + * . + */ + +/* + * NOTE + * + * Media hosted at ardmediathek.de will reportedly expire after a few + * weeks. This test attempts to work around this by trying to find a + * media URL from the website that can be used to test the media script. + * + * The front page will not contain any media URLs unless javascript is + * enabled. We cannot emulate js so, instead, we fetch the "Neueste + * Clips" which should media URLs. + */ + +#include "config.h" + +#include +#include +#include + +#include "tests.h" + +static const gchar WWW[] = "http://www.ardmediathek.de"; + +static gchar *fetch_neueste_clips_page() +{ + static const gchar PATTERN[] = + "href=\"(.*)\" title=\".*\" data-xtclib=\"Neueste\\+Clips\""; + + gchar *p, *u, *s; + capture_t c; + + p = fetch(WWW); + g_assert(p != NULL); + + c = capture_new(p, PATTERN, 0); + g_assert(c != NULL); + + g_assert(capture_matches(c) == TRUE); + s = capture_fetch(c, 1); + + capture_free(c); + g_free(p); + + u = g_strdup_printf("%s%s", WWW, s); + g_free(s); + + p = fetch(u); + g_free(u); + + return (p); +} + +static void test_media_ardmediathek() +{ + static const gchar PATTERN[] = "href=\"(.*documentId=.*)\" class"; + + struct qm_test_opts_s o; + gchar *p, *u, *r; + capture_t c; + GSList *l; + + memset(&o, 0, sizeof(o)); + + /* Normally done in qm_test, due to fetch-parse, do it here. */ + + if (chk_skip(__func__) == TRUE) + return; + + p = fetch_neueste_clips_page(); + g_assert(p != NULL); + + l = NULL; + u = NULL; + + c = capture_new(p, PATTERN, 0); + g_assert(c != NULL); + + while (capture_matches(c) == TRUE) + { + r = capture_fetch(c, 1); + l = g_slist_prepend(l, g_strdup_printf("%s%s", WWW, r)); + capture_next(c); + g_free(r); + } + l = g_slist_reverse(l); + g_assert_cmpint(g_slist_length(l), >, 0); + + /* Pick a random URL from the stack. */ + { + const gint32 n = g_random_int_range(0, g_slist_length(l)); + u = (gchar*) g_slist_nth_data(l, n); + } + g_assert(u != NULL); + + g_test_message("media URL=%s", u); + qm_test(__func__, u, NULL, &o); + + slist_free_full(l, (GFunc) g_free); + capture_free(c); + g_free(p); +} + +gint main(gint argc, gchar **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_add_func("/media/ardmediathek", test_media_ardmediathek); + return (g_test_run()); +} + +/* vim: set ts=2 sw=2 tw=72 expandtab: */ diff --git a/tests/media/tests.mk b/tests/media/tests.mk index 11a9859..1126ab6 100644 --- a/tests/media/tests.mk +++ b/tests/media/tests.mk @@ -1,4 +1,5 @@ include $(top_srcdir)/tests/media/academicearth.mk +include $(top_srcdir)/tests/media/ardmediathek.mk include $(top_srcdir)/tests/media/arte.mk include $(top_srcdir)/tests/media/audioboo.mk include $(top_srcdir)/tests/media/bikeradar.mk -- 2.11.4.GIT