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/>.
29 static void test_playlist_core()
31 static const gchar URL
[] =
32 "http://soundcloud.com/thelittleidiot/sets/destroyed/";
39 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
44 g_assert_cmpint(qerr(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(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
);
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);
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);
113 g_assert_cmpint(i
, >, 1);
116 quvi_playlist_free(qp
);
120 static void test_playlist_short()
122 static const gchar URL
[] = "http://is.gd/BjbpVn";
128 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
133 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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");
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);
162 g_assert_cmpint(i
, >, 1);
165 quvi_playlist_free(qp
);
169 static void test_playlist_escaped_url()
171 static const gchar URL
[] =
172 "http://youtube.com/watch%3Fv%3Dp5o7gBKHwtk%26list%3DPL954CCC04F8437E14%26feature%3Dplcp";
177 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
182 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
194 static void test_playlist_nosupport()
196 static const gchar URL
[] = "http://example.com/";
202 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
207 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
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: */