common/: Use socket.url
[libquvi-scripts.git] / tests / lib / qm_test.c
blob6d01f37f289dd60d097f537aa6392e3ab2891050
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 media properties. The 'e' parameter may be NULL, in which case
29 * the test for exact values (e.g. title and ID) will be skipped. */
30 void qm_test(const gchar *func, const gchar *url,
31 const qm_test_exact_t e, const qm_test_opts_t o)
33 quvi_media_t qm;
34 quvi_t q;
36 if (chk_skip(func) == TRUE)
37 return;
39 q = quvi_new();
40 g_assert(q != NULL);
41 g_assert_cmpint(qerr(q), ==, QUVI_OK);
43 chk_verbose(q);
45 qm = quvi_media_new(q, url);
46 g_test_message("errmsg=%s", quvi_errmsg(q));
47 g_assert_cmpint(qerr(q), ==, QUVI_OK);
48 g_assert(qm != NULL);
50 if (chk_complete())
52 gint c;
54 g_test_message("TEST_LEVEL=complete");
56 /* Exact values. */
58 if (e != NULL)
60 if (e->title != NULL)
61 qm_cmp_s(QUVI_MEDIA_PROPERTY_TITLE, e->title);
63 if (e->id != NULL)
64 qm_cmp_s(QUVI_MEDIA_PROPERTY_ID, e->id);
67 /* Thumbnail, expected, but check length only. */
69 qm_chk_l(QUVI_MEDIA_PROPERTY_THUMBNAIL_URL);
71 /* Optional. */
73 if (o->gt0.duration_ms == TRUE)
74 qm_chk_gt0(QUVI_MEDIA_PROPERTY_DURATION_MS);
76 if (o->gt0.start_time_ms== TRUE)
77 qm_chk_gt0(QUVI_MEDIA_PROPERTY_START_TIME_MS);
79 /* Streams. */
81 for (c=0; quvi_media_stream_next(qm) == QUVI_TRUE; ++c);
82 g_assert_cmpint(c, >, 0);
84 while (quvi_media_stream_next(qm) == QUVI_TRUE)
86 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_URL);
88 if (c >1) /* Must have a stream ID, when there are >1 streams. */
89 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_ID);
91 /* Optional. */
93 if (o->s_len_gt0.stream.container == TRUE)
94 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_CONTAINER);
96 /* Optional: Video. */
98 if (o->gt0.stream.video.bitrate_kbit_s == TRUE)
99 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_BITRATE_KBIT_S);
101 if (o->gt0.stream.video.height == TRUE)
102 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_HEIGHT);
104 if (o->gt0.stream.video.width == TRUE)
105 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_WIDTH);
107 if (o->s_len_gt0.stream.video.encoding == TRUE)
108 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_VIDEO_ENCODING);
110 /* Optional: Audio. */
112 if (o->gt0.stream.audio.bitrate_kbit_s == TRUE)
113 qm_chk_gt0(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_BITRATE_KBIT_S);
115 if (o->s_len_gt0.stream.audio.encoding == TRUE)
116 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_AUDIO_ENCODING);
119 else
121 g_test_message("TEST_LEVEL=basic");
123 /* Must return >0 media streams. */
125 qm_chk_l(QUVI_MEDIA_STREAM_PROPERTY_URL);
128 quvi_media_free(qm);
129 quvi_free(q);
132 /* vim: set ts=2 sw=2 tw=72 expandtab: */