test_media_select: Replace URL, update patterns
[libquvi.git] / tests / quvi.c
blobb85c45b59a7694fa146d66d106b7d4fbb7177fd8
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 <stdlib.h>
24 #include <glib.h>
25 #include <quvi.h>
27 #include "tests.h"
29 static void test_quvi_core()
31 gpointer p;
32 quvi_t q;
33 glong n;
35 if (chk_skip(__func__) == TRUE)
36 return;
38 q = quvi_new();
39 g_assert(q != NULL);
40 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
41 g_assert_cmpstr(quvi_errmsg(q), ==, "Not an error");
42 g_assert_cmpint(quvi_ok(q), ==, QUVI_TRUE);
44 /* quvi_get */
46 n = 0;
47 quvi_get(q, QUVI_INFO_RESPONSE_CODE-1, &n);
48 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
49 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
50 g_assert_cmpint(n, ==, 0);
52 p = NULL;
53 quvi_get(q, QUVI_INFO_RESPONSE_CODE-1, &p);
54 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
55 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
56 g_assert(p == NULL);
58 n = 0;
59 quvi_get(q, QUVI_INFO_RESPONSE_CODE+1, &n);
60 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
61 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
62 g_assert_cmpint(n, ==, 0);
64 p = NULL;
65 quvi_get(q, QUVI_INFO_CURL_HANDLE, &p);
66 g_assert_cmpint(quvi_ok(q), ==, QUVI_TRUE);
67 g_assert(p != NULL);
69 p = NULL;
70 quvi_get(q, QUVI_INFO_CURL_HANDLE+1, &p);
71 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
72 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
73 g_assert(p == NULL);
75 /* quvi_set */
77 quvi_set(q, QUVI_OPTION_CALLBACK_STATUS-1, 0);
78 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
79 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
81 quvi_set(q, QUVI_OPTION_AUTOPROXY+1, 0);
82 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
83 g_assert_cmpint(quvi_ok(q), ==, QUVI_FALSE);
85 quvi_free(q);
88 static void test_version()
90 if (chk_skip(__func__) == TRUE)
91 return;
93 if (g_test_trap_fork(0,
94 G_TEST_TRAP_SILENCE_STDOUT|G_TEST_TRAP_SILENCE_STDERR))
96 g_print("%s", quvi_version(QUVI_VERSION));
97 g_printerr("%s", quvi_version(QUVI_VERSION_SCRIPTS));
98 exit(0);
100 g_test_trap_assert_passed();
101 g_test_trap_assert_stdout("v?.?.?*");
102 g_test_trap_assert_stderr("v?.?*");
104 g_assert_cmpstr(quvi_version(QUVI_VERSION_SCRIPTS+1),
105 ==, quvi_version(QUVI_VERSION));
107 g_assert_cmpstr(quvi_version(QUVI_VERSION-1),
108 ==, quvi_version(QUVI_VERSION));
111 static void test_file_ext()
113 struct lookup_s
115 gchar *input;
116 gchar *output;
119 static const struct lookup_s l[] =
121 {"video/x-flv", "flv"},
122 {"audio/mpeg", "mp3"},
123 {"video/mp4", "mp4"},
124 {"foo", "flv"},
125 {NULL, NULL}
128 quvi_file_ext_t qfe;
129 quvi_t q;
130 gint i;
132 if (chk_skip(__func__) == TRUE)
133 return;
135 q = quvi_new();
136 g_assert(q != NULL);
137 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
138 g_assert_cmpint(quvi_ok(q), ==, QUVI_TRUE);
140 i = 0;
141 while (l[i].input != NULL)
143 qfe = quvi_file_ext_new(q, l[i].input);
144 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
145 g_assert_cmpint(quvi_ok(q), ==, QUVI_TRUE);
146 g_assert_cmpstr(l[i].output, ==, quvi_file_ext_get(qfe));
147 quvi_file_ext_free(qfe);
148 ++i;
150 quvi_free(q);
153 gint main(gint argc, gchar **argv)
155 g_test_init(&argc, &argv, NULL);
156 g_test_add_func("/quvi (core)", test_quvi_core);
157 g_test_add_func("/quvi/version", test_version);
158 g_test_add_func("/quvi/file_ext", test_file_ext);
159 return (g_test_run());
162 /* vim: set ts=2 sw=2 tw=72 expandtab: */