FIX: tests: Use quvi_errcode instead of qerr
[libquvi-scripts.git] / tests / lib / tests.h
blob9da18e5942dbe0ac18f26170f9d53f968d52d6d1
1 /* libquvi-scripts
2 * Copyright (C) 2012,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 #ifndef tests_h
22 #define tests_h
24 /* env.c */
26 gboolean chk_env(const gchar*, const gchar*);
27 gboolean chk_skip(const gchar*);
28 void chk_verbose(gpointer);
29 gboolean chk_geoblocked();
30 gboolean chk_complete();
31 gboolean chk_fixme();
32 gboolean chk_nsfw();
34 /* Media. */
36 struct qm_test_exact_s
38 const gchar *title;
39 const gchar *id;
41 typedef struct qm_test_exact_s *qm_test_exact_t;
43 struct qm_test_opts_s
45 struct /* String value length >0 */
47 struct /* stream */
49 struct /* video */
51 gboolean encoding;
52 } video;
53 struct /* audio */
55 gboolean encoding;
56 } audio;
57 gboolean container;
58 } stream;
59 } s_len_gt0;
60 struct /* >0 (numeric) */
62 struct /* stream */
64 struct /* video */
66 gboolean bitrate_kbit_s;
67 gboolean height;
68 gboolean width;
69 } video;
70 struct
72 gboolean bitrate_kbit_s;
73 } audio;
74 } stream;
75 gboolean start_time_ms;
76 gboolean duration_ms;
77 } gt0;
79 typedef struct qm_test_opts_s *qm_test_opts_t;
81 /* Compare media property string values. */
82 #define qm_cmp_s(qmp, e)\
83 do {\
84 gchar *s = NULL;\
85 quvi_media_get(qm, qmp, &s);\
86 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
87 g_assert(s != NULL);\
88 g_test_message("%s=%s", #qmp, s);\
89 g_assert_cmpstr(s, ==, e);\
90 } while (0)
92 /* Media property string value length >0 */
93 #define qm_chk_l(qmp)\
94 do {\
95 gchar *s = NULL;\
96 quvi_media_get(qm, qmp, &s);\
97 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
98 g_assert(s != NULL);\
99 g_test_message("%s=%s", #qmp, s);\
100 g_assert_cmpint(strlen(s), >, 0);\
101 } while (0)
103 /* Media property value (double) >0 */
104 #define qm_chk_gt0(qmp)\
105 do {\
106 gdouble v = 0;\
107 quvi_media_get(qm, qmp, &v);\
108 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
109 g_test_message("%s=%g", #qmp, v);\
110 g_assert_cmpfloat(v, >, 0);\
111 } while (0)
113 void qm_test(const gchar*, const gchar*,
114 const qm_test_exact_t, const qm_test_opts_t);
116 /* Playlist. */
118 struct qp_test_exact_s
120 const gchar *id;
122 typedef struct qp_test_exact_s *qp_test_exact_t;
124 struct qp_test_opts_s
126 struct
128 struct
130 gboolean title;
131 } media;
132 gboolean thumbnail_url;
133 gboolean title;
134 } s_len_gt0;
135 struct
137 struct
139 gboolean duration_ms;
140 } media;
141 } gt0;
143 typedef struct qp_test_opts_s *qp_test_opts_t;
145 /* Compare playlist property string values. */
146 #define qp_cmp_s(qpp, e)\
147 do {\
148 gchar *s = NULL;\
149 quvi_playlist_get(qp, qpp, &s);\
150 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
151 g_assert(s != NULL);\
152 g_test_message("%s=%s", #qpp, s);\
153 g_assert_cmpstr(s, ==, e);\
154 } while (0)
156 /* Playlist property string value length >0 */
157 #define qp_chk_l(qpp)\
158 do {\
159 gchar *s = NULL;\
160 quvi_playlist_get(qp, qpp, &s);\
161 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
162 g_assert(s != NULL);\
163 g_test_message("%s=%s", #qpp, s);\
164 g_assert_cmpint(strlen(s), >, 0);\
165 } while (0)
167 /* Playlist property value (double) >0 */
168 #define qp_chk_gt0(qpp)\
169 do {\
170 gdouble v = 0;\
171 quvi_playlist_get(qp, qpp, &v);\
172 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
173 g_test_message("%s=%g", #qpp, v);\
174 g_assert_cmpfloat(v, >, 0);\
175 } while (0)
177 void qp_test(const gchar*, const gchar*,
178 const qp_test_exact_t, const qp_test_opts_t);
180 /* Scan. */
182 struct qs_test_exact_s
184 const gchar *url;
185 const gint n; /* Expected no. of returned media URLs. */
187 typedef struct qs_test_exact_s *qs_test_exact_t;
189 void qs_test(const gchar*, qs_test_exact_t);
191 /* Subtitle. */
193 /* Subtitle type property value (double) length >0 */
194 #define qsub_chk_type_gt0(qsp)\
195 do {\
196 gdouble v = 0;\
197 quvi_subtitle_type_get(qst, qsp, &v);\
198 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
199 g_test_message("%s=%g", #qsp, v);\
200 g_assert_cmpfloat(v, >, 0);\
201 } while (0)
203 /* Subtitle lang property string value >0 */
204 #define qsub_chk_lang_l(qsp)\
205 do {\
206 gchar *s = NULL;\
207 quvi_subtitle_lang_get(qsl, qsp, &s);\
208 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);\
209 g_assert(s != NULL);\
210 g_test_message("%s=%s", #qsp, s);\
211 g_assert_cmpint(strlen(s), >, 0);\
212 } while (0)
214 struct qsub_test_opts_s
216 struct
218 struct
220 gboolean format;
221 gboolean type;
222 } gt0;
223 } type;
224 struct
226 struct
228 gboolean translated;
229 gboolean original;
230 gboolean code;
231 gboolean url;
232 gboolean id;
233 } s_len_gt0;
234 } lang;
237 typedef struct qsub_test_opts_s *qsub_test_opts_t;
239 void qsub_test(const gchar*, const gchar*, qsub_test_opts_t);
241 /* Other. */
243 struct capture_s
245 GMatchInfo *m;
246 GRegex *re;
247 GError *e;
250 typedef struct capture_s *capture_t;
252 capture_t capture_new(const gchar*, const gchar*, const GRegexCompileFlags);
253 gchar *capture_fetch(capture_t, const gint);
254 gboolean capture_matches(capture_t);
255 gboolean capture_next(capture_t);
256 void capture_free(capture_t);
258 gboolean match(const gchar*, const gchar*);
259 gchar *fetch(const gchar*);
261 void slist_free_full(GSList*, const GFunc);
263 #endif /* tests_h */
265 /* vim: set ts=2 sw=2 tw=72 expandtab: */