tests: Use quvi_errcode instead of QUVI_INFO_ERROR_CODE
[libquvi.git] / tests / playlist.c
blob2e56e653476d7ba00ace1e847c80a071621513a2
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 void test_playlist_core()
31 static const gchar URL[] =
32 "http://soundcloud.com/volt-icarus2-otherupload/sets/bgm/";
34 quvi_playlist_t qp;
35 gdouble n;
36 quvi_t q;
37 gchar *s;
39 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
40 return;
42 q = quvi_new();
43 g_assert(q != NULL);
44 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
46 chk_verbose(q);
48 qp = quvi_playlist_new(q, URL);
49 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
50 g_assert(qp != NULL);
52 /* Boundary check: the first -1 */
53 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL-1, &s);
54 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
56 /* Boundary check: the last +1 */
57 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS+1, &s);
58 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
60 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
61 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
62 g_assert_cmpint(strlen(s), >, 0);
64 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
65 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
66 g_assert_cmpstr(s, ==, "허스키익스프레스bgm");
68 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
69 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
70 g_assert_cmpstr(s, ==, "volt-icarus2-otherupload_bgm");
72 /* This should advance the current media pointer to the first media
73 * item in the returned list. */
74 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
75 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
76 /* First media title. */
77 g_assert_cmpstr(s, ==,
78 "은빛설원의 노래(Song of silver snowy)_Husky "
79 "Express Main bgm");
81 /* This should continue from the 2nd item, not the 1st in the list. */
82 quvi_playlist_media_next(qp);
84 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
85 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
86 /* Second media title. */
87 g_assert_cmpstr(s, ==,
88 "햇살을 가르며Hike(Hike bisecting the "
89 "sunshine)_Husky Express bgm");
91 quvi_playlist_media_reset(qp);
94 gint i = 0;
95 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
97 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
98 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
99 g_assert_cmpfloat(n, >, 0);
101 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
102 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
103 g_assert_cmpint(strlen(s), >, 0);
105 if (i == 0)
107 /* Confirm that this is the first item, the call to
108 * quvi_playlist_reset earlier should have reset the
109 * current location. */
110 g_assert_cmpstr(s, ==,
111 "은빛설원의 노래(Song of silver snowy)_Husky "
112 "Express Main bgm");
115 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
116 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
117 g_assert_cmpint(strlen(s), >, 0);
119 ++i;
121 g_assert_cmpint(i, >, 1);
124 quvi_playlist_free(qp);
125 quvi_free(q);
128 static void test_playlist_short()
130 static const gchar URL[] = "http://is.gd/3oNTko";
132 quvi_playlist_t qp;
133 quvi_t q;
134 gchar *s;
136 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
137 return;
139 q = quvi_new();
140 g_assert(q != NULL);
141 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
143 chk_verbose(q);
145 qp = quvi_playlist_new(q, URL);
146 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
147 g_assert(qp != NULL);
149 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
150 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
151 g_assert_cmpint(strlen(s), >, 0);
153 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
154 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
155 g_assert_cmpstr(s, ==, "허스키익스프레스bgm");
157 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
158 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
159 g_assert_cmpstr(s, ==, "volt-icarus2-otherupload_bgm");
162 gint i = 0;
163 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
165 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
166 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
167 g_assert_cmpint(strlen(s), >, 0);
168 ++i;
170 g_assert_cmpint(i, >, 1);
173 quvi_playlist_free(qp);
174 quvi_free(q);
177 static void test_playlist_escaped_url()
179 static const gchar URL[] =
180 "http://www.youtube.com/playlist%3Flist%3DPLlbnzwCkgkTBBXWz595XaKs_kkXek0gQP%26";
182 quvi_playlist_t qp;
183 quvi_t q;
185 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
186 return;
188 q = quvi_new();
189 g_assert(q != NULL);
190 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
192 chk_verbose(q);
194 qp = quvi_playlist_new(q, URL);
195 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
196 g_assert(qp != NULL);
198 quvi_playlist_free(qp);
199 quvi_free(q);
202 static void test_playlist_nosupport()
204 static const gchar URL[] = "http://example.com/";
206 quvi_playlist_t qp;
207 quvi_t q;
208 gchar *s;
210 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
211 return;
213 q = quvi_new();
214 g_assert(q != NULL);
215 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
217 chk_verbose(q);
219 qp = quvi_playlist_new(q, URL);
220 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_ERROR_NO_SUPPORT);
221 g_assert(qp != NULL);
223 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
224 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
225 g_assert_cmpstr(s, ==, "");
227 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
228 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
229 g_assert_cmpstr(s, ==, "");
231 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
232 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
233 g_assert_cmpstr(s, ==, "");
235 quvi_playlist_free(qp);
236 quvi_free(q);
239 gint main(gint argc, gchar **argv)
241 g_test_init(&argc, &argv, NULL);
242 g_test_add_func("/quvi/playlist (core)", test_playlist_core);
243 g_test_add_func("/quvi/playlist (short)", test_playlist_short);
244 g_test_add_func("/quvi/playlist (escaped URL)", test_playlist_escaped_url);
245 g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
246 return (g_test_run());
249 /* vim: set ts=2 sw=2 tw=72 expandtab: */