tests: Use quvi_errcode instead of QUVI_INFO_ERROR_CODE
[libquvi.git] / tests / script.c
blob2af5e779135266deba305766ce31d73cba302ecf
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 gint count(const quvi_t q, const QuviScriptType t)
31 gint c = 0;
32 while (quvi_script_next(q, t) == QUVI_TRUE)
33 ++c;
34 return (c);
37 static gsize len(const quvi_t q,
38 const QuviScriptType t,
39 const QuviScriptProperty p)
41 gchar *s = NULL;
43 quvi_script_get(q, t, p, &s);
44 g_assert(s != NULL);
46 return (strlen(s));
49 static void test_script()
51 QuviScriptType t;
52 quvi_t q;
54 if (chk_skip(__func__) == TRUE)
55 return;
57 q = quvi_new();
58 g_assert(q != NULL);
59 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
61 /* Properties. */
62 for (t=QUVI_SCRIPT_TYPE_PLAYLIST; t<QUVI_SCRIPT_TYPE_SCAN+1; ++t)
64 g_assert_cmpint(count(q, t), >=, 1);
66 while (quvi_script_next(q, t) == QUVI_TRUE)
68 /* Shared with all scripts. */
69 g_assert_cmpint(len(q, t, QUVI_SCRIPT_PROPERTY_FILEPATH), >, 0);
70 g_assert_cmpint(len(q, t, QUVI_SCRIPT_PROPERTY_FILENAME), >, 0);
71 g_assert_cmpint(len(q, t, QUVI_SCRIPT_PROPERTY_SHA1), >, 0);
73 /* Media script specific. */
74 if (t == QUVI_SCRIPT_TYPE_MEDIA || t == QUVI_SCRIPT_TYPE_PLAYLIST)
75 g_assert_cmpint(len(q, t, QUVI_SCRIPT_PROPERTY_DOMAINS),>,0);
79 /* Boundaries */
81 /* Script type. */
83 const gint c = count(q, QUVI_SCRIPT_TYPE_MEDIA);
85 g_assert_cmpint(c, ==, count(q, QUVI_SCRIPT_TYPE_SUBTITLE_EXPORT-1));
86 g_assert_cmpint(c, ==, count(q, QUVI_SCRIPT_TYPE_SCAN+1));
89 /* Property. Do this last (quvi_script_next is called once). */
91 gchar *s;
93 t = QUVI_SCRIPT_TYPE_MEDIA;
94 g_assert(quvi_script_next(q, t) == QUVI_TRUE);
96 quvi_script_get(q, t, QUVI_SCRIPT_PROPERTY_EXPORT_FORMAT-1, &s);
97 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
99 quvi_script_get(q, t, QUVI_SCRIPT_PROPERTY_SHA1+1, &s);
100 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
103 quvi_free(q);
106 gint main(gint argc, gchar **argv)
108 g_test_init(&argc, &argv, NULL);
109 g_test_add_func("/quvi/script", test_script);
110 return (g_test_run());
113 /* vim: set ts=2 sw=2 tw=72 expandtab: */