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
28 static void test_playlist_core()
30 static const gchar URL
[] =
31 "http://soundcloud.com/thelittleidiot/sets/destroyed/";
38 if (chk_internet() == FALSE
)
41 if (chk_skip(__func__
) == TRUE
)
46 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
50 qp
= quvi_playlist_new(q
, URL
);
51 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
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
);
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);
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);
115 g_assert_cmpint(i
, >, 1);
118 quvi_playlist_free(qp
);
122 static void test_playlist_short()
124 static const gchar URL
[] = "http://is.gd/BjbpVn";
130 if (chk_internet() == FALSE
)
133 if (chk_skip(__func__
) == TRUE
)
138 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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");
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);
167 g_assert_cmpint(i
, >, 1);
170 quvi_playlist_free(qp
);
174 static void test_playlist_escaped_url()
176 static const gchar URL
[] =
177 "http://youtube.com/watch%3Fv%3Dp5o7gBKHwtk%26list%3DPL954CCC04F8437E14%26feature%3Dplcp";
182 if (chk_internet() == FALSE
)
185 if (chk_skip(__func__
) == TRUE
)
190 g_assert_cmpint(qerr(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
)
213 if (chk_skip(__func__
) == TRUE
)
218 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
242 gint
main(gint argc
, gchar
**argv
)
244 g_test_init(&argc
, &argv
, NULL
);
245 g_test_add_func("/quvi/playlist (core)", test_playlist_core
);
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: */