test_media_select: Replace URL, update patterns
[libquvi.git] / tests / http_metainfo.c
blob9aac7c0cfb55538b5acaacc74e5f897866444eae
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <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 #define chk_len(p)\
30 do {\
31 gchar *s = NULL;\
32 quvi_http_metainfo_get(qv, p, &s);\
33 g_assert(s != NULL);\
34 g_test_message("%s=%s", #p, s);\
35 g_assert_cmpint(strlen(s), >, 1);\
36 } while (0)
38 #define chk_val(p)\
39 do {\
40 gdouble n = 0;\
41 quvi_http_metainfo_get(qv, p, &n);\
42 g_test_message("%s=%f", #p, n);\
43 g_assert_cmpfloat(n, >, 0);\
44 } while (0)
46 static void test_http_metainfo()
48 static const gchar URL[] = "http://is.gd/SKyg8m";
50 quvi_http_metainfo_t qv;
51 quvi_t q;
52 gchar *v;
54 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
55 return;
57 q = quvi_new();
58 g_assert(q != NULL);
59 g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
61 chk_verbose(q);
63 qv = quvi_http_metainfo_new(q, URL);
64 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
65 g_assert(qv != NULL);
67 quvi_http_metainfo_get(qv, QUVI_HTTP_METAINFO_PROPERTY_FILE_EXTENSION-1,&v);
68 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
70 quvi_http_metainfo_get(qv, QUVI_HTTP_METAINFO_PROPERTY_LENGTH_BYTES+1, &v);
71 g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
73 chk_len(QUVI_HTTP_METAINFO_PROPERTY_FILE_EXTENSION);
74 chk_len(QUVI_HTTP_METAINFO_PROPERTY_CONTENT_TYPE);
76 chk_val(QUVI_HTTP_METAINFO_PROPERTY_LENGTH_BYTES);
78 quvi_http_metainfo_free(qv);
79 quvi_free(q);
82 gint main(gint argc, gchar **argv)
84 g_test_init(&argc, &argv, NULL);
85 g_test_add_func("/quvi/http_metainfo", test_http_metainfo);
86 return (g_test_run());
89 /* vim: set ts=2 sw=2 tw=72 expandtab: */