tests: Add lib/qs_test.c
[libquvi-scripts.git] / tests / lib / tests.h
blobb7c13882ee032ebcd97e32b0ee7b6799970ab2ca
1 /* libquvi-scripts
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #ifndef tests_h
21 #define tests_h
23 /* qerr.c */
25 glong qerr(quvi_t);
27 /* env.c */
29 gboolean chk_env(const gchar*, const gchar*);
30 gboolean chk_skip(const gchar*);
31 void chk_verbose(quvi_t);
32 gboolean chk_complete();
33 gboolean chk_fixme();
34 gboolean chk_nsfw();
36 /* Media. */
38 struct qm_test_exact_s
40 const gchar *title;
41 const gchar *id;
43 typedef struct qm_test_exact_s *qm_test_exact_t;
45 struct qm_test_opts_s
47 struct /* String value length >0 */
49 struct /* stream */
51 struct /* video */
53 gboolean encoding;
54 } video;
55 struct /* audio */
57 gboolean encoding;
58 } audio;
59 gboolean container;
60 } stream;
61 } s_len_gt0;
62 struct /* >0 (numeric) */
64 struct /* stream */
66 struct /* video */
68 gboolean bitrate_kbit_s;
69 gboolean height;
70 gboolean width;
71 } video;
72 struct
74 gboolean bitrate_kbit_s;
75 } audio;
76 } stream;
77 gboolean start_time_ms;
78 gboolean duration_ms;
79 } gt0;
81 typedef struct qm_test_opts_s *qm_test_opts_t;
83 /* Compare media property string values. */
84 #define qm_cmp_s(qmp, e)\
85 do {\
86 gchar *s = NULL;\
87 quvi_media_get(qm, qmp, &s);\
88 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
89 g_assert(s != NULL);\
90 g_test_message("%s=%s", #qmp, s);\
91 g_assert_cmpstr(s, ==, e);\
92 } while (0)
94 /* Media property string value length >0 */
95 #define qm_chk_l(qmp)\
96 do {\
97 gchar *s = NULL;\
98 quvi_media_get(qm, qmp, &s);\
99 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
100 g_assert(s != NULL);\
101 g_test_message("%s=%s", #qmp, s);\
102 g_assert_cmpint(strlen(s), >, 0);\
103 } while (0)
105 /* Media property value (double) >0 */
106 #define qm_chk_gt0(qmp)\
107 do {\
108 gdouble v = 0;\
109 quvi_media_get(qm, qmp, &v);\
110 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
111 g_test_message("%s=%g", #qmp, v);\
112 g_assert_cmpfloat(v, >, 0);\
113 } while (0)
115 void qm_test(const gchar*, const gchar*,
116 const qm_test_exact_t, const qm_test_opts_t);
118 /* Playlist. */
120 struct qp_test_exact_s
122 const gchar *id;
124 typedef struct qp_test_exact_s *qp_test_exact_t;
126 struct qp_test_opts_s
128 struct
130 struct
132 gboolean title;
133 } media;
134 gboolean thumbnail_url;
135 gboolean title;
136 } s_len_gt0;
137 struct
139 struct
141 gboolean duration_ms;
142 } media;
143 } gt0;
145 typedef struct qp_test_opts_s *qp_test_opts_t;
147 /* Compare playlist property string values. */
148 #define qp_cmp_s(qpp, e)\
149 do {\
150 gchar *s = NULL;\
151 quvi_playlist_get(qp, qpp, &s);\
152 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
153 g_assert(s != NULL);\
154 g_test_message("%s=%s", #qpp, s);\
155 g_assert_cmpstr(s, ==, e);\
156 } while (0)
158 /* Playist property string value length >0 */
159 #define qp_chk_l(qpp)\
160 do {\
161 gchar *s = NULL;\
162 quvi_playlist_get(qp, qpp, &s);\
163 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
164 g_assert(s != NULL);\
165 g_test_message("%s=%s", #qpp, s);\
166 g_assert_cmpint(strlen(s), >, 0);\
167 } while (0)
169 /* Media property value (double) >0 */
170 #define qp_chk_gt0(qpp)\
171 do {\
172 gdouble v = 0;\
173 quvi_playlist_get(qp, qpp, &v);\
174 g_assert_cmpint(qerr(q), ==, QUVI_OK);\
175 g_test_message("%s=%g", #qpp, v);\
176 g_assert_cmpfloat(v, >, 0);\
177 } while (0)
179 void qp_test(const gchar*, const gchar*,
180 const qp_test_exact_t, const qp_test_opts_t);
182 /* Scan. */
184 struct qs_test_exact_s
186 const gchar *url;
187 const gint n; /* Expected no. of returned media URLs. */
189 typedef struct qs_test_exact_s *qs_test_exact_t;
191 void qs_test(const gchar*, qs_test_exact_t);
193 /* Other. */
195 gboolean match(const gchar*, const gchar*);
196 gchar *capture(const gchar*, const gchar*);
197 gchar *fetch(const gchar*);
199 #endif /* tests_h */
201 /* vim: set ts=2 sw=2 tw=72 expandtab: */