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/>.
29 static void test_playlist_core()
31 static const gchar URL
[] =
32 "http://soundcloud.com/volt-icarus2-otherupload/sets/bgm/";
39 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
44 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
48 qp
= quvi_playlist_new(q
, URL
);
49 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
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 "
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
);
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);
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 "
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);
121 g_assert_cmpint(i
, >, 1);
124 quvi_playlist_free(qp
);
128 static void test_playlist_short()
130 static const gchar URL
[] = "http://is.gd/3oNTko";
136 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
141 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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");
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);
170 g_assert_cmpint(i
, >, 1);
173 quvi_playlist_free(qp
);
177 static void test_playlist_escaped_url()
179 static const gchar URL
[] =
180 "http://www.youtube.com/playlist%3Flist%3DPLlbnzwCkgkTBBXWz595XaKs_kkXek0gQP%26";
185 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
190 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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
);
202 static void test_playlist_nosupport()
204 static const gchar URL
[] = "http://example.com/";
210 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
215 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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
);
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: */