quvi_supports: Handle QUVI_SUPPORTS_TYPE_SUBTITLE
[libquvi.git] / tests / playlist.c
blob5483d6f096d5eeb48d98963c905e6ecb0009ef46
1 /* libquvi
2 * Copyright (C) 2012 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/thelittleidiot/sets/destroyed/";
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(qerr(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(qerr(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(qerr(q), ==, QUVI_ERROR_INVALID_ARG);
60 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
61 g_assert_cmpint(qerr(q), ==, QUVI_OK);
62 g_assert_cmpint(strlen(s), >, 0);
64 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
65 g_assert_cmpint(qerr(q), ==, QUVI_OK);
66 g_assert_cmpstr(s, ==, "Destroyed");
68 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
69 g_assert_cmpint(qerr(q), ==, QUVI_OK);
70 g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");
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(qerr(q), ==, QUVI_OK);
76 g_assert_cmpstr(s, ==, "The Broken Places"); /* First media title. */
78 /* This should continue from the 2nd item, not the 1st in the list. */
79 quvi_playlist_media_next(qp);
81 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
82 g_assert_cmpint(qerr(q), ==, QUVI_OK);
83 g_assert_cmpstr(s, ==, "Be The One"); /* Second media title. */
85 quvi_playlist_media_reset(qp);
88 gint i = 0;
89 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
91 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
92 g_assert_cmpint(qerr(q), ==, QUVI_OK);
93 g_assert_cmpfloat(n, >, 0);
95 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
96 g_assert_cmpint(qerr(q), ==, QUVI_OK);
97 g_assert_cmpint(strlen(s), >, 0);
99 if (i == 0)
101 /* Confirm that this is the first item, the call to
102 * quvi_playlist_reset earlier should have reset the
103 * current location. */
104 g_assert_cmpstr(s, ==, "The Broken Places");
107 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
108 g_assert_cmpint(qerr(q), ==, QUVI_OK);
109 g_assert_cmpint(strlen(s), >, 0);
111 ++i;
113 g_assert_cmpint(i, >, 1);
116 quvi_playlist_free(qp);
117 quvi_free(q);
120 static void test_playlist_short()
122 static const gchar URL[] = "http://is.gd/BjbpVn";
124 quvi_playlist_t qp;
125 quvi_t q;
126 gchar *s;
128 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
129 return;
131 q = quvi_new();
132 g_assert(q != NULL);
133 g_assert_cmpint(qerr(q), ==, QUVI_OK);
135 chk_verbose(q);
137 qp = quvi_playlist_new(q, URL);
138 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
139 g_assert(qp != NULL);
141 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
142 g_assert_cmpint(qerr(q), ==, QUVI_OK);
143 g_assert_cmpint(strlen(s), >, 0);
145 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
146 g_assert_cmpint(qerr(q), ==, QUVI_OK);
147 g_assert_cmpstr(s, ==, "Destroyed");
149 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
150 g_assert_cmpint(qerr(q), ==, QUVI_OK);
151 g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");
154 gint i = 0;
155 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
157 quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
158 g_assert_cmpint(qerr(q), ==, QUVI_OK);
159 g_assert_cmpint(strlen(s), >, 0);
160 ++i;
162 g_assert_cmpint(i, >, 1);
165 quvi_playlist_free(qp);
166 quvi_free(q);
169 static void test_playlist_escaped_url()
171 static const gchar URL[] =
172 "http://youtube.com/watch%3Fv%3Dp5o7gBKHwtk%26list%3DPL954CCC04F8437E14%26feature%3Dplcp";
174 quvi_playlist_t qp;
175 quvi_t q;
177 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
178 return;
180 q = quvi_new();
181 g_assert(q != NULL);
182 g_assert_cmpint(qerr(q), ==, QUVI_OK);
184 chk_verbose(q);
186 qp = quvi_playlist_new(q, URL);
187 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
188 g_assert(qp != NULL);
190 quvi_playlist_free(qp);
191 quvi_free(q);
194 static void test_playlist_nosupport()
196 static const gchar URL[] = "http://example.com/";
198 quvi_playlist_t qp;
199 quvi_t q;
200 gchar *s;
202 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
203 return;
205 q = quvi_new();
206 g_assert(q != NULL);
207 g_assert_cmpint(qerr(q), ==, QUVI_OK);
209 chk_verbose(q);
211 qp = quvi_playlist_new(q, URL);
212 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_ERROR_NO_SUPPORT);
213 g_assert(qp != NULL);
215 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
216 g_assert_cmpint(qerr(q), ==, QUVI_OK);
217 g_assert_cmpstr(s, ==, "");
219 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
220 g_assert_cmpint(qerr(q), ==, QUVI_OK);
221 g_assert_cmpstr(s, ==, "");
223 quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
224 g_assert_cmpint(qerr(q), ==, QUVI_OK);
225 g_assert_cmpstr(s, ==, "");
227 quvi_playlist_free(qp);
228 quvi_free(q);
231 gint main(gint argc, gchar **argv)
233 g_test_init(&argc, &argv, NULL);
234 g_test_add_func("/quvi/playlist (core)", test_playlist_core);
235 g_test_add_func("/quvi/playlist (short)", test_playlist_short);
236 g_test_add_func("/quvi/playlist (escaped URL)", test_playlist_escaped_url);
237 g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
238 return (g_test_run());
241 /* vim: set ts=2 sw=2 tw=72 expandtab: */