LIBQUVI_SHOW_SCRIPT: Output script path if URL was accepted
[libquvi.git] / tests / resolve.c
blob1cff9182091620f3d4ebe07b5ae57ad4acf6e0e7
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; 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 <glib.h>
23 #include <quvi.h>
25 #include "tests.h"
27 static void test_resolve()
29 static const gchar URL[] = "http://is.gd/9lrXf8";
31 static const gchar DST[] =
32 "http://www.collegehumor.com/video/6781885/batman-blows-his-cover";
34 quvi_resolve_t qr;
35 quvi_t q;
37 if (chk_internet() == FALSE)
38 return;
40 if (chk_skip(__func__) == TRUE)
41 return;
43 q = quvi_new();
44 g_assert(q != NULL);
45 g_assert_cmpint(qerr(q), ==, QUVI_OK);
47 chk_verbose(q);
49 qr = quvi_resolve_new(q, URL);
50 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
51 g_assert(qr != NULL);
53 g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
54 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
56 quvi_resolve_free(qr);
57 quvi_free(q);
60 static void test_resolve_3()
62 static const gchar URL[] = "http://is.gd/gQ4pYW";
64 static const gchar DST[] =
65 "http://www.thefirearmblog.com/blog/2012/06/11/shooting-drones/"
66 "?utm_source=feedburner&utm_medium=feed&utm_campaign="
67 "Feed%3A+TheFirearmBlog+%28The+Firearm+Blog%29";
69 quvi_resolve_t qr;
70 quvi_t q;
72 if (chk_internet() == FALSE)
73 return;
75 if (chk_skip(__func__) == TRUE)
76 return;
78 q = quvi_new();
79 g_assert(q != NULL);
80 g_assert_cmpint(qerr(q), ==, QUVI_OK);
82 chk_verbose(q);
84 qr = quvi_resolve_new(q, URL);
85 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
86 g_assert(qr != NULL);
88 g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
89 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
91 quvi_resolve_free(qr);
92 quvi_free(q);
95 static void test_resolve_nodst()
97 static const gchar URL[] = "http://www.iana.org/domains/example/";
99 quvi_resolve_t qr;
100 quvi_t q;
102 if (chk_internet() == FALSE)
103 return;
105 if (chk_skip(__func__) == TRUE)
106 return;
108 q = quvi_new();
109 g_assert(q != NULL);
110 g_assert_cmpint(qerr(q), ==, QUVI_OK);
112 chk_verbose(q);
114 qr = quvi_resolve_new(q, URL);
115 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
116 g_assert(qr != NULL);
118 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
120 quvi_resolve_free(qr);
121 quvi_free(q);
124 static void test_resolve_nodst_t_param()
126 static const gchar URL[] =
127 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
129 quvi_resolve_t qr;
130 quvi_t q;
132 if (chk_internet() == FALSE)
133 return;
135 if (chk_skip(__func__) == TRUE)
136 return;
138 q = quvi_new();
139 g_assert(q != NULL);
140 g_assert_cmpint(qerr(q), ==, QUVI_OK);
142 chk_verbose(q);
144 qr = quvi_resolve_new(q, URL);
145 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
146 g_assert(qr != NULL);
148 /* g00gle servers redirect to the media URL stripping the #t
149 * parameter. The library should not be fooled by this trickery. */
150 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
152 quvi_resolve_free(qr);
153 quvi_free(q);
156 /* Known limitation: Shortened Y0uTube media URLs with the #t parameter
157 * do not work with the library. The test below should redirect to
158 * "http://www.youtube.com/watch?v=G4evlxq34og", missing the #t
159 * parameter, see the above example for the explanation. */
160 static void test_resolve_shortened_with_t_param()
162 static const gchar URL[] = "http://is.gd/TRWtNf";
163 /* http://www.youtube.com/watch?v=G4evlxq34og#t=3m20 */
165 static const gchar DST[] =
166 "http://www.youtube.com/watch?v=G4evlxq34og";
168 quvi_resolve_t qr;
169 quvi_t q;
171 if (chk_internet() == FALSE)
172 return;
174 if (chk_skip(__func__) == TRUE)
175 return;
177 q = quvi_new();
178 g_assert(q != NULL);
179 g_assert_cmpint(qerr(q), ==, QUVI_OK);
181 chk_verbose(q);
183 qr = quvi_resolve_new(q, URL);
184 g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
185 g_assert(qr != NULL);
187 g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_TRUE);
188 g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
190 quvi_resolve_free(qr);
191 quvi_free(q);
194 gint main(gint argc, gchar **argv)
196 g_test_init(&argc, &argv, NULL);
197 g_test_add_func("/quvi/resolve", test_resolve);
198 g_test_add_func("/quvi/resolve (3)", test_resolve_3);
199 g_test_add_func("/quvi/resolve (nodst)", test_resolve_nodst);
200 g_test_add_func("/quvi/resolve (nodst #t param)",
201 test_resolve_nodst_t_param);
202 g_test_add_func("/quvi/resolve (short URL with #t param)",
203 test_resolve_shortened_with_t_param);
204 return (g_test_run());
207 /* vim: set ts=2 sw=2 tw=72 expandtab: */