common/: Use socket.url
[libquvi-scripts.git] / tests / lib / qp_test.c
blobeb323a92c87e539bd85acb3d576008e8f91b04f0
1 /* libquvi-scripts
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
17 * 02110-1301 USA
20 #include "config.h"
22 #include <string.h>
23 #include <glib.h>
24 #include <quvi.h>
26 #include "tests.h"
28 /* Test playlist properties. The 'e' parameter may be NULL, in which
29 * case the test for the exact values (e.g. ID) will be skipped. */
30 void qp_test(const gchar *func, const gchar *url,
31 const qp_test_exact_t e, const qp_test_opts_t o)
33 quvi_playlist_t qp;
34 quvi_t q;
35 gint c;
37 if (chk_skip(func) == TRUE)
38 return;
40 q = quvi_new();
41 g_assert(q != NULL);
42 g_assert_cmpint(qerr(q), ==, QUVI_OK);
44 chk_verbose(q);
46 qp = quvi_playlist_new(q, url);
47 g_test_message("errmsg=%s", quvi_errmsg(q));
48 g_assert_cmpint(qerr(q), ==, QUVI_OK);
49 g_assert(qp != NULL);
51 if (chk_complete())
53 g_test_message("TEST_LEVEL=complete");
55 /* Exact values. */
57 if (e != NULL)
59 if (e->id != NULL)
60 qp_cmp_s(QUVI_PLAYLIST_PROPERTY_ID, e->id);
63 /* Optional. */
65 if (o->s_len_gt0.thumbnail_url == TRUE)
66 qp_chk_l(QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL);
68 if (o->s_len_gt0.title == TRUE)
69 qp_chk_l(QUVI_PLAYLIST_PROPERTY_TITLE);
71 /* Media. */
73 c = 0;
74 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
76 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_URL);
78 /* Optional. */
80 if (o->gt0.media.duration_ms == TRUE)
81 qp_chk_gt0(QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS);
83 if (o->s_len_gt0.media.title == TRUE)
84 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE);
86 ++c;
88 g_assert_cmpint(c, >, 0);
90 else
92 g_test_message("TEST_LEVEL=basic");
94 /* Must return >0 media URLs. */
96 for (c=0; quvi_playlist_media_next(qp) == QUVI_TRUE; ++c);
97 g_assert_cmpint(c, >, 0);
99 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_URL);
102 quvi_playlist_free(qp);
103 quvi_free(q);
106 /* vim: set ts=2 sw=2 tw=72 expandtab: */