tests: test_resolve_nodst: Update URL
[libquvi.git] / tests / resolve.c
blob426f05effbcaddc82d6e924171a0a6d618be1378
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 #ifdef _1 /* Comment out until a new one with >1 redirections is found. */
59 static void test_resolve_3()
61 static const gchar URL[] = "http://is.gd/gQ4pYW";
63 static const gchar DST[] =
64 "http://www.thefirearmblog.com/blog/2012/06/11/shooting-drones/"
65 "?utm_source=feedburner&utm_medium=feed&utm_campaign="
66 "Feed%3A+TheFirearmBlog+%28The+Firearm+Blog%29";
68 quvi_resolve_t qr;
69 quvi_t q;
71 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
72 return;
74 q = quvi_new();
75 g_assert(q != NULL);
76 g_assert_cmpint(qerr(q), ==, QUVI_OK);
78 chk_verbose(q);
80 qr = quvi_resolve_new(q, URL);
81 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
82 g_assert(qr != NULL);
84 g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
85 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
87 quvi_resolve_free(qr);
88 quvi_free(q);
90 #endif /* _1 */
92 static void test_resolve_nodst()
94 static const gchar URL[] = "http://www.youtube.com/";
96 quvi_resolve_t qr;
97 quvi_t q;
99 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
100 return;
102 q = quvi_new();
103 g_assert(q != NULL);
104 g_assert_cmpint(qerr(q), ==, QUVI_OK);
106 chk_verbose(q);
108 qr = quvi_resolve_new(q, URL);
109 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
110 g_assert(qr != NULL);
112 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
114 quvi_resolve_free(qr);
115 quvi_free(q);
118 static void test_resolve_nodst_t_param()
120 static const gchar URL[] =
121 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
123 quvi_resolve_t qr;
124 quvi_t q;
126 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
127 return;
129 q = quvi_new();
130 g_assert(q != NULL);
131 g_assert_cmpint(qerr(q), ==, QUVI_OK);
133 chk_verbose(q);
135 qr = quvi_resolve_new(q, URL);
136 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
137 g_assert(qr != NULL);
140 * [UPDATE] 2012-11-19: g00gle servers no longer strip the #t param
141 * The description below no longer applies, although we still test
142 * this, in case this changes back.
144 * [ISSUE] g00gle servers redirect to the media URL stripping #t
145 * g00gle servers redirect to the media URL stripping the #t
146 * parameter. The library should not be fooled by this trickery.
147 * The workaround is implemented in libquvi-scripts
148 * (resolve_redirections.lua).
150 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
152 quvi_resolve_free(qr);
153 quvi_free(q);
156 /* [UPDATE] 2012-11-19: g00gle servers now seem to redirect to
157 * the media URL without stripping the #t parameter. The test has been
158 * modified to test that shortened URLs redirect to the expected media
159 * URL.
161 * [ISSUE] #t parameter is lost with shortened URLs
162 * Shortened Y0uTube media URLs with the #t parameter do not work
163 * with the library. The test below should redirect to
164 * http://www.youtube.com/watch?v=G4evlxq34og
165 * missing the #t parameter, see the above test for the description.
167 static void test_resolve_shortened_with_t_param()
169 static const gchar URL[] = "http://is.gd/TRWtNf";
170 /* http://www.youtube.com/watch?v=G4evlxq34og#t=3m20 */
172 static const gchar DST[] =
173 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
174 #ifdef _1 /* [UPDATE] 2012-11-19: See above */
175 "http://www.youtube.com/watch?v=G4evlxq34og";
176 #endif
178 quvi_resolve_t qr;
179 quvi_t q;
181 if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
182 return;
184 q = quvi_new();
185 g_assert(q != NULL);
186 g_assert_cmpint(qerr(q), ==, QUVI_OK);
188 chk_verbose(q);
190 qr = quvi_resolve_new(q, URL);
191 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
192 g_assert(qr != NULL);
194 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_TRUE);
195 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
197 quvi_resolve_free(qr);
198 quvi_free(q);
201 gint main(gint argc, gchar **argv)
203 g_test_init(&argc, &argv, NULL);
204 g_test_add_func("/quvi/resolve (core)", test_resolve_core);
205 #ifdef _1
206 g_test_add_func("/quvi/resolve (3)", test_resolve_3);
207 #endif
208 g_test_add_func("/quvi/resolve (nodst)", test_resolve_nodst);
209 g_test_add_func("/quvi/resolve (nodst #t param)",
210 test_resolve_nodst_t_param);
211 g_test_add_func("/quvi/resolve (short URL with #t param)",
212 test_resolve_shortened_with_t_param);
213 return (g_test_run());
216 /* vim: set ts=2 sw=2 tw=72 expandtab: */