FIX: tests: Use quvi_errcode instead of qerr
[libquvi-scripts.git] / tests / lib / qp_test.c
blob9e9b9a528003db661ca9e6d1bca7c9ca9233055e
1 /* libquvi-scripts
2 * Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi-scripts <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/>.
21 #include "config.h"
23 #include <string.h>
24 #include <glib.h>
25 #include <quvi.h>
27 #include "tests.h"
29 /* Test playlist properties. The 'e' parameter may be NULL, in which
30 * case the test for the exact values (e.g. ID) will be skipped. */
31 void qp_test(const gchar *func, const gchar *url,
32 const qp_test_exact_t e, const qp_test_opts_t o)
34 quvi_playlist_t qp;
35 quvi_t q;
36 gint c;
38 if (chk_skip(func) == TRUE)
39 return;
41 q = quvi_new();
42 g_assert(q != NULL);
43 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
45 chk_verbose(q);
47 qp = quvi_playlist_new(q, url);
48 g_test_message("errmsg=%s", quvi_errmsg(q));
49 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
50 g_assert(qp != NULL);
52 if (chk_complete())
54 g_test_message("TEST_LEVEL=complete");
56 /* Exact values. */
58 if (e != NULL)
60 if (e->id != NULL)
61 qp_cmp_s(QUVI_PLAYLIST_PROPERTY_ID, e->id);
64 /* Optional. */
66 if (o->s_len_gt0.thumbnail_url == TRUE)
67 qp_chk_l(QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL);
69 if (o->s_len_gt0.title == TRUE)
70 qp_chk_l(QUVI_PLAYLIST_PROPERTY_TITLE);
72 /* Media. */
74 c = 0;
75 while (quvi_playlist_media_next(qp) == QUVI_TRUE)
77 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_URL);
79 /* Optional. */
81 if (o->gt0.media.duration_ms == TRUE)
82 qp_chk_gt0(QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS);
84 if (o->s_len_gt0.media.title == TRUE)
85 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE);
87 ++c;
89 g_assert_cmpint(c, >, 0);
91 else
93 g_test_message("TEST_LEVEL=basic");
95 /* Must return >0 media URLs. */
97 for (c=0; quvi_playlist_media_next(qp) == QUVI_TRUE; ++c)
99 qp_chk_l(QUVI_PLAYLIST_MEDIA_PROPERTY_URL);
101 g_assert_cmpint(c, >, 0);
104 quvi_playlist_free(qp);
105 quvi_free(q);
108 /* vim: set ts=2 sw=2 tw=72 expandtab: */