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/>.
25 #include <curl/curl.h>
29 static const gchar URL
[] =
30 "http://www.gaskrank.tv/tv/motorrad-oldtimer/1928-henderson-deluxe-alt-und--19115.htm";
32 static const gchar URL_SHORT
[] = "http://is.gd/jg9P5c";
33 static const gchar URL_NOSUP
[] = "http://example.com/";
34 static const gchar URL_INV
[] = "foobar";
36 static void test_supports_online()
41 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
46 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
50 r
= quvi_supports(q
, URL
,
51 QUVI_SUPPORTS_MODE_OFFLINE
-1, /* Defaults to online. */
52 QUVI_SUPPORTS_TYPE_MEDIA
);
53 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
54 g_assert_cmpint(r
, ==, QUVI_TRUE
);
56 r
= quvi_supports(q
, URL
,
57 QUVI_SUPPORTS_MODE_ONLINE
+1, /* Defaults to online */
58 QUVI_SUPPORTS_TYPE_MEDIA
);
59 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
60 g_assert_cmpint(r
, ==, QUVI_TRUE
);
62 r
= quvi_supports(q
, URL
,
63 QUVI_SUPPORTS_MODE_ONLINE
,
65 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
66 g_assert_cmpint(r
, ==, QUVI_TRUE
);
68 r
= quvi_supports(q
, URL
,
69 QUVI_SUPPORTS_MODE_ONLINE
,
70 QUVI_SUPPORTS_TYPE_MEDIA
);
71 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
72 g_assert_cmpint(r
, ==, QUVI_TRUE
);
74 r
= quvi_supports(q
, URL_SHORT
,
75 QUVI_SUPPORTS_MODE_ONLINE
,
76 QUVI_SUPPORTS_TYPE_MEDIA
);
77 g_assert_cmpint(qerr_m(q
, URL_SHORT
), ==, QUVI_OK
);
78 g_assert_cmpint(r
, ==, QUVI_TRUE
);
80 r
= quvi_supports(q
, URL
/* Media URL */,
81 QUVI_SUPPORTS_MODE_ONLINE
,
82 QUVI_SUPPORTS_TYPE_PLAYLIST
/*!*/);
83 g_assert_cmpint(r
, ==, QUVI_FALSE
);
84 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_ERROR_NO_SUPPORT
);
86 r
= quvi_supports(q
, URL_NOSUP
,
87 QUVI_SUPPORTS_MODE_ONLINE
,
88 QUVI_SUPPORTS_TYPE_ANY
);
89 g_assert_cmpint(r
, ==, QUVI_FALSE
);
90 g_assert_cmpint(qerr_m(q
, URL_NOSUP
), ==, QUVI_ERROR_NO_SUPPORT
);
92 r
= quvi_supports(q
, URL_INV
,
93 QUVI_SUPPORTS_MODE_ONLINE
,
94 QUVI_SUPPORTS_TYPE_ANY
);
95 g_assert_cmpint(r
, ==, QUVI_FALSE
);
96 g_assert_cmpint(qerr_m(q
, URL_INV
), ==, QUVI_ERROR_CALLBACK
);
101 static void test_supports_offline()
106 if (chk_skip(__func__
) == TRUE
)
111 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
113 r
= quvi_supports(q
, URL
,
114 QUVI_SUPPORTS_MODE_OFFLINE
,
115 QUVI_SUPPORTS_TYPE_ANY
);
116 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
117 g_assert_cmpint(r
, ==, QUVI_TRUE
);
119 r
= quvi_supports(q
, URL
/* Media URL */,
120 QUVI_SUPPORTS_MODE_OFFLINE
,
121 QUVI_SUPPORTS_TYPE_PLAYLIST
/*!*/);
122 g_assert_cmpint(r
, ==, QUVI_FALSE
);
123 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_ERROR_NO_SUPPORT
);
125 r
= quvi_supports(q
, URL_SHORT
,
126 QUVI_SUPPORTS_MODE_OFFLINE
,
127 QUVI_SUPPORTS_TYPE_ANY
);
128 g_assert_cmpint(r
, ==, QUVI_FALSE
);
129 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_ERROR_NO_SUPPORT
);
131 r
= quvi_supports(q
, URL_NOSUP
,
132 QUVI_SUPPORTS_MODE_OFFLINE
,
133 QUVI_SUPPORTS_TYPE_ANY
);
134 g_assert_cmpint(r
, ==, QUVI_FALSE
);
135 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_ERROR_NO_SUPPORT
);
137 r
= quvi_supports(q
, URL_INV
,
138 QUVI_SUPPORTS_MODE_OFFLINE
,
139 QUVI_SUPPORTS_TYPE_ANY
);
140 g_assert_cmpint(r
, ==, QUVI_FALSE
);
141 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_ERROR_NO_SUPPORT
);
146 static void test_supports_net_err()
152 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
157 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
161 /* Simulate a network error. See also quvi_supports C API
164 quvi_get(q
, QUVI_INFO_CURL_HANDLE
, &c
);
166 curl_easy_setopt(c
, CURLOPT_PROXY
, "http://localhost:12345");
168 r
= quvi_supports(q
, URL
, QUVI_SUPPORTS_MODE_ONLINE
,
169 QUVI_SUPPORTS_TYPE_ANY
);
170 g_assert_cmpint(r
, ==, QUVI_FALSE
);
171 g_assert_cmpint(qerr_m(q
, URL
), !=, QUVI_ERROR_NO_SUPPORT
);
172 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_ERROR_CALLBACK
);
177 gint
main(gint argc
, gchar
**argv
)
179 g_test_init(&argc
, &argv
, NULL
);
180 g_test_add_func("/quvi/supports (online)", test_supports_online
);
181 g_test_add_func("/quvi/supports (offline)", test_supports_offline
);
182 g_test_add_func("/quvi/supports (network error)", test_supports_net_err
);
183 return (g_test_run());
186 /* vim: set ts=2 sw=2 tw=72 expandtab: */