tests/playlist.c: Add test_playlist_escaped_url
[libquvi.git] / tests / playlist.c
blobc8612410704d7791311f6deb3f33800849f04c44
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA
20 #include "config.h"
22 #include <string.h>
23 #include <glib.h>
24 #include <quvi.h>
26 #include "tests.h"
28 static void test_playlist()
30 static const gchar URL[] =
31 "http://soundcloud.com/thelittleidiot/sets/destroyed/";
33 quvi_playlist_t qp;
34 gdouble n;
35 quvi_t q;
36 gchar *s;
38 if (chk_internet() == FALSE)
39 return;
41 if (chk_skip(__func__) == TRUE)
42 return;
44 q = quvi_new();
45 g_assert(q != NULL);
46 g_assert_cmpint(qerr(q), ==, QUVI_OK);
48 chk_verbose(q);
50 qp = quvi_playlist_new(q, URL);
51 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
52 g_assert(qp != NULL);
54 /* Boundary check: the first -1 */
55 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL-1, &s);
56 g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);
58 /* Boundary check: the last +1 */
59 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS+1, &s);
60 g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);
62 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
63 g_assert_cmpint(qerr(q), ==, QUVI_OK);
64 g_assert_cmpint(strlen(s), >, 0);
66 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
67 g_assert_cmpint(qerr(q), ==, QUVI_OK);
68 g_assert_cmpstr(s, ==, "Destroyed");
70 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
71 g_assert_cmpint(qerr(q), ==, QUVI_OK);
72 g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");
74 /* This should advance the current media pointer to the first media
75 * item in the returned list. */
76 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
77 g_assert_cmpint(qerr(q), ==, QUVI_OK);
78 g_assert_cmpstr(s, ==, "The Broken Places"); /* First media title. */
80 /* This should continue from the 2nd item, not the 1st in the list. */
81 quvi_playlist_media_next(qp);
83 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
84 g_assert_cmpint(qerr(q), ==, QUVI_OK);
85 g_assert_cmpstr(s, ==, "Be The One"); /* Second media title. */
87 quvi_playlist_media_reset(qp);
90 gint i = 0;
91 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
93 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
94 g_assert_cmpint(qerr(q), ==, QUVI_OK);
95 g_assert_cmpfloat(n, >, 0);
97 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
98 g_assert_cmpint(qerr(q), ==, QUVI_OK);
99 g_assert_cmpint(strlen(s), >, 0);
101 if (i == 0)
103 /* Confirm that this is the first item, the call to
104 * quvi_playlist_reset earlier should have reset the
105 * current location. */
106 g_assert_cmpstr(s, ==, "The Broken Places");
109 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
110 g_assert_cmpint(qerr(q), ==, QUVI_OK);
111 g_assert_cmpint(strlen(s), >, 0);
113 ++i;
115 g_assert_cmpint(i, >, 1);
118 quvi_playlist_free(qp);
119 quvi_free(q);
122 static void test_playlist_short()
124 static const gchar URL[] = "http://is.gd/BjbpVn";
126 quvi_playlist_t qp;
127 quvi_t q;
128 gchar *s;
130 if (chk_internet() == FALSE)
131 return;
133 if (chk_skip(__func__) == TRUE)
134 return;
136 q = quvi_new();
137 g_assert(q != NULL);
138 g_assert_cmpint(qerr(q), ==, QUVI_OK);
140 chk_verbose(q);
142 qp = quvi_playlist_new(q, URL);
143 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
144 g_assert(qp != NULL);
146 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
147 g_assert_cmpint(qerr(q), ==, QUVI_OK);
148 g_assert_cmpint(strlen(s), >, 0);
150 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
151 g_assert_cmpint(qerr(q), ==, QUVI_OK);
152 g_assert_cmpstr(s, ==, "Destroyed");
154 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
155 g_assert_cmpint(qerr(q), ==, QUVI_OK);
156 g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");
159 gint i = 0;
160 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
162 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
163 g_assert_cmpint(qerr(q), ==, QUVI_OK);
164 g_assert_cmpint(strlen(s), >, 0);
165 ++i;
167 g_assert_cmpint(i, >, 1);
170 quvi_playlist_free(qp);
171 quvi_free(q);
174 static void test_playlist_escaped_url()
176 static const gchar URL[] =
177 "http://youtube.com/watch%3Fv%3Dp5o7gBKHwtk%26list%3DPL954CCC04F8437E14%26feature%3Dplcp";
179 quvi_playlist_t qp;
180 quvi_t q;
182 if (chk_internet() == FALSE)
183 return;
185 if (chk_skip(__func__) == TRUE)
186 return;
188 q = quvi_new();
189 g_assert(q != NULL);
190 g_assert_cmpint(qerr(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)
211 return;
213 if (chk_skip(__func__) == TRUE)
214 return;
216 q = quvi_new();
217 g_assert(q != NULL);
218 g_assert_cmpint(qerr(q), ==, QUVI_OK);
220 chk_verbose(q);
222 qp = quvi_playlist_new(q, URL);
223 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_ERROR_NO_SUPPORT);
224 g_assert(qp != NULL);
226 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
227 g_assert_cmpint(qerr(q), ==, QUVI_OK);
228 g_assert_cmpstr(s, ==, "");
230 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
231 g_assert_cmpint(qerr(q), ==, QUVI_OK);
232 g_assert_cmpstr(s, ==, "");
234 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
235 g_assert_cmpint(qerr(q), ==, QUVI_OK);
236 g_assert_cmpstr(s, ==, "");
238 quvi_playlist_free(qp);
239 quvi_free(q);
242 gint main(gint argc, gchar **argv)
244 g_test_init(&argc, &argv, NULL);
245 g_test_add_func("/quvi/playlist", test_playlist);
246 g_test_add_func("/quvi/playlist (short)", test_playlist_short);
247 g_test_add_func("/quvi/playlist (escaped URL)", test_playlist_escaped_url);
248 g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
249 return (g_test_run());
252 /* vim: set ts=2 sw=2 tw=72 expandtab: */