Merge branch 'tg/next__media_port_ted.lua' into next
[libquvi-scripts.git] / tests / lib / qm_test.c
blob4493f4e036f0d407abe51735b5a27e20c748fb7e
1 /* libquvi-scripts
2 * Copyright (C) 2012 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 media properties. The 'e' parameter may be NULL, in which case
30 * the test for exact values (e.g. title and ID) will be skipped. */
31 void qm_test(const gchar *func, const gchar *url,
32 const qm_test_exact_t e, const qm_test_opts_t o)
34 quvi_media_t qm;
35 quvi_t q;
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 qm = quvi_media_new(q, url);
47 g_test_message("errmsg=%s", quvi_errmsg(q));
48 g_assert_cmpint(qerr(q), ==, QUVI_OK);
49 g_assert(qm != NULL);
51 if (chk_complete())
53 gint c;
55 g_test_message("TEST_LEVEL=complete");
57 /* Exact values. */
59 if (e != NULL)
61 if (e->title != NULL)
62 qm_cmp_s(QUVI_MEDIA_PROPERTY_TITLE, e->title);
64 if (e->id != NULL)
65 qm_cmp_s(QUVI_MEDIA_PROPERTY_ID, e->id);
68 /* Thumbnail, expected, but check length only. */
70 qm_chk_l(QUVI_MEDIA_PROPERTY_THUMBNAIL_URL);
72 /* Optional. */
74 if (o->gt0.duration_ms == TRUE)
75 qm_chk_gt0(QUVI_MEDIA_PROPERTY_DURATION_MS);
77 if (o->gt0.start_time_ms== TRUE)
78 qm_chk_gt0(QUVI_MEDIA_PROPERTY_START_TIME_MS);
80 /* Streams. */
82 for (c=0; quvi_media_stream_next(qm) == QUVI_TRUE; ++c);
83 g_assert_cmpint(c, >, 0);
85 while (quvi_media_stream_next(qm) == QUVI_TRUE)
87 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_URL);
89 if (c >1) /* Must have a stream ID, when there are >1 streams. */
90 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_ID);
92 /* Optional. */
94 if (o->s_len_gt0.stream.container == TRUE)
95 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_CONTAINER);
97 /* Optional: Video. */
99 if (o->gt0.stream.video.bitrate_kbit_s == TRUE)
100 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_BITRATE_KBIT_S);
102 if (o->gt0.stream.video.height == TRUE)
103 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT);
105 if (o->gt0.stream.video.width == TRUE)
106 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH);
108 if (o->s_len_gt0.stream.video.encoding == TRUE)
109 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_ENCODING);
111 /* Optional: Audio. */
113 if (o->gt0.stream.audio.bitrate_kbit_s == TRUE)
114 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_BITRATE_KBIT_S);
116 if (o->s_len_gt0.stream.audio.encoding == TRUE)
117 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_ENCODING);
120 else
122 g_test_message("TEST_LEVEL=basic");
124 /* Must return >0 media streams. */
126 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_URL);
129 quvi_media_free(qm);
130 quvi_free(q);
133 /* vim: set ts=2 sw=2 tw=72 expandtab: */