2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28 static void test_playlist()
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_nosupport()
176 static const gchar URL
[] = "http://example.com/";
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_ERROR_NO_SUPPORT
);
196 g_assert(qp
!= NULL
);
198 quvi_playlist_get(qp
, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL
, &s
);
199 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
200 g_assert_cmpstr(s
, ==, "");
202 quvi_playlist_get(qp
, QUVI_PLAYLIST_PROPERTY_TITLE
, &s
);
203 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
204 g_assert_cmpstr(s
, ==, "");
206 quvi_playlist_get(qp
, QUVI_PLAYLIST_PROPERTY_ID
, &s
);
207 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
208 g_assert_cmpstr(s
, ==, "");
210 quvi_playlist_free(qp
);
214 gint
main(gint argc
, gchar
**argv
)
216 g_test_init(&argc
, &argv
, NULL
);
217 g_test_add_func("/quvi/playlist", test_playlist
);
218 g_test_add_func("/quvi/playlist (short)", test_playlist_short
);
219 g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport
);
220 return (g_test_run());
223 /* vim: set ts=2 sw=2 tw=72 expandtab: */