quvi_supports: Handle QUVI_SUPPORTS_TYPE_SUBTITLE
[libquvi.git] / tests / resolve.c
blob71d675a7e912dadabb7e1b9c9f9863f62d2efe4b
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 <glib.h>
24 #include <quvi.h>
26 #include "tests.h"
28 static void test_resolve_core()
30 static const gchar URL[] = "http://is.gd/9lrXf8";
32 static const gchar DST[] =
33 "http://www.collegehumor.com/video/6781885/batman-blows-his-cover";
35 quvi_resolve_t qr;
36 quvi_t q;
38 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
39 return;
41 q = quvi_new();
42 g_assert(q != NULL);
43 g_assert_cmpint(qerr(q), ==, QUVI_OK);
45 chk_verbose(q);
47 qr = quvi_resolve_new(q, URL);
48 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
49 g_assert(qr != NULL);
51 g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
52 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
54 quvi_resolve_free(qr);
55 quvi_free(q);
58 static void test_resolve_3()
60 static const gchar URL[] = "http://is.gd/gQ4pYW";
62 static const gchar DST[] =
63 "http://www.thefirearmblog.com/blog/2012/06/11/shooting-drones/"
64 "?utm_source=feedburner&utm_medium=feed&utm_campaign="
65 "Feed%3A+TheFirearmBlog+%28The+Firearm+Blog%29";
67 quvi_resolve_t qr;
68 quvi_t q;
70 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
71 return;
73 q = quvi_new();
74 g_assert(q != NULL);
75 g_assert_cmpint(qerr(q), ==, QUVI_OK);
77 chk_verbose(q);
79 qr = quvi_resolve_new(q, URL);
80 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
81 g_assert(qr != NULL);
83 g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
84 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
86 quvi_resolve_free(qr);
87 quvi_free(q);
90 static void test_resolve_nodst()
92 static const gchar URL[] = "http://www.iana.org/domains/example";
94 quvi_resolve_t qr;
95 quvi_t q;
97 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
98 return;
100 q = quvi_new();
101 g_assert(q != NULL);
102 g_assert_cmpint(qerr(q), ==, QUVI_OK);
104 chk_verbose(q);
106 qr = quvi_resolve_new(q, URL);
107 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
108 g_assert(qr != NULL);
110 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
112 quvi_resolve_free(qr);
113 quvi_free(q);
116 static void test_resolve_nodst_t_param()
118 static const gchar URL[] =
119 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
121 quvi_resolve_t qr;
122 quvi_t q;
124 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
125 return;
127 q = quvi_new();
128 g_assert(q != NULL);
129 g_assert_cmpint(qerr(q), ==, QUVI_OK);
131 chk_verbose(q);
133 qr = quvi_resolve_new(q, URL);
134 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
135 g_assert(qr != NULL);
138 * [UPDATE] 2012-11-19: g00gle servers no longer strip the #t param
139 * The description below no longer applies, although we still test
140 * this, in case this changes back.
142 * [ISSUE] g00gle servers redirect to the media URL stripping #t
143 * g00gle servers redirect to the media URL stripping the #t
144 * parameter. The library should not be fooled by this trickery.
145 * The workaround is implemented in libquvi-scripts
146 * (resolve_redirections.lua).
148 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
150 quvi_resolve_free(qr);
151 quvi_free(q);
154 /* [UPDATE] 2012-11-19: g00gle servers now seem to redirect to
155 * the media URL without stripping the #t parameter. The test has been
156 * modified to test that shortened URLs redirect to the expected media
157 * URL.
159 * [ISSUE] #t parameter is lost with shortened URLs
160 * Shortened Y0uTube media URLs with the #t parameter do not work
161 * with the library. The test below should redirect to
162 * http://www.youtube.com/watch?v=G4evlxq34og
163 * missing the #t parameter, see the above test for the description.
165 static void test_resolve_shortened_with_t_param()
167 static const gchar URL[] = "http://is.gd/TRWtNf";
168 /* http://www.youtube.com/watch?v=G4evlxq34og#t=3m20 */
170 static const gchar DST[] =
171 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
172 #ifdef _1 /* [UPDATE] 2012-11-19: See above */
173 "http://www.youtube.com/watch?v=G4evlxq34og";
174 #endif
176 quvi_resolve_t qr;
177 quvi_t q;
179 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
180 return;
182 q = quvi_new();
183 g_assert(q != NULL);
184 g_assert_cmpint(qerr(q), ==, QUVI_OK);
186 chk_verbose(q);
188 qr = quvi_resolve_new(q, URL);
189 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
190 g_assert(qr != NULL);
192 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_TRUE);
193 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
195 quvi_resolve_free(qr);
196 quvi_free(q);
199 gint main(gint argc, gchar **argv)
201 g_test_init(&argc, &argv, NULL);
202 g_test_add_func("/quvi/resolve (core)", test_resolve_core);
203 g_test_add_func("/quvi/resolve (3)", test_resolve_3);
204 g_test_add_func("/quvi/resolve (nodst)", test_resolve_nodst);
205 g_test_add_func("/quvi/resolve (nodst #t param)",
206 test_resolve_nodst_t_param);
207 g_test_add_func("/quvi/resolve (short URL with #t param)",
208 test_resolve_shortened_with_t_param);
209 return (g_test_run());
212 /* vim: set ts=2 sw=2 tw=72 expandtab: */