FIX: tests: Use quvi_errcode instead of qerr
[libquvi-scripts.git] / tests / lib / qsub_test.c
blob6c626524c1285115ab65df9e2d25e1269f5bada3
1 /* libquvi-scripts
2 * Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi-scripts <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 void _test_basic(const gchar *func, const gchar *url,
30 qsub_test_opts_t o, quvi_t q, quvi_subtitle_t qsub)
32 quvi_subtitle_type_t qst;
33 quvi_subtitle_lang_t qsl;
34 gint t,l;
36 /* Must return >0 subtitle types. */
38 for (t=0; (qst = quvi_subtitle_type_next(qsub)) != NULL; ++t)
40 gdouble type;
42 /* Must set the type properties. */
44 qsub_chk_type_gt0(QUVI_SUBTITLE_TYPE_PROPERTY_FORMAT);
45 qsub_chk_type_gt0(QUVI_SUBTITLE_TYPE_PROPERTY_TYPE);
47 quvi_subtitle_type_get(qst, QUVI_SUBTITLE_TYPE_PROPERTY_TYPE, &type);
49 /* Must return >0 subtitle langs. */
51 for (l=0; (qsl = quvi_subtitle_lang_next(qst)) != NULL; ++l)
53 /* Must set the lang properties. */
55 qsub_chk_lang_l(QUVI_SUBTITLE_LANG_PROPERTY_CODE);
56 qsub_chk_lang_l(QUVI_SUBTITLE_LANG_PROPERTY_URL);
57 qsub_chk_lang_l(QUVI_SUBTITLE_LANG_PROPERTY_ID);
60 * YouTube provides these properties for CCs only. If additional
61 * subtitle scripts are introduced, this needs to be reworked.
63 if (type == QUVI_SUBTITLE_TYPE_CC)
65 if (o->lang.s_len_gt0.translated == TRUE)
66 qsub_chk_lang_l(QUVI_SUBTITLE_LANG_PROPERTY_TRANSLATED);
68 if (o->lang.s_len_gt0.original == TRUE)
69 qsub_chk_lang_l(QUVI_SUBTITLE_LANG_PROPERTY_ORIGINAL);
72 g_assert_cmpint(l, >, 0);
74 g_assert_cmpint(t, >, 0);
78 * Test subtitle properties.
80 void qsub_test(const gchar *func, const gchar *url, qsub_test_opts_t o)
82 quvi_subtitle_t qsub;
83 quvi_t q;
85 if (chk_skip(func) == TRUE)
86 return;
88 q = quvi_new();
89 g_assert(q != NULL);
90 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
92 chk_verbose(q);
94 qsub = quvi_subtitle_new(q, url);
95 g_test_message("errmsg=%s", quvi_errmsg(q));
96 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
97 g_assert(qsub != NULL);
99 /* Both levels are identical. */
100 if (chk_complete())
102 g_test_message("TEST_LEVEL=complete");
103 _test_basic(func, url, o, q, qsub);
105 else
107 g_test_message("TEST_LEVEL=basic");
108 _test_basic(func, url, o, q, qsub);
110 quvi_subtitle_free(qsub);
111 quvi_free(q);
114 /* vim: set ts=2 sw=2 tw=72 expandtab: */