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/>.
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";
38 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
43 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
47 qr
= quvi_resolve_new(q
, URL
);
48 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
51 g_assert(quvi_resolve_forwarded(qr
) == QUVI_TRUE
);
52 g_assert_cmpstr(quvi_resolve_destination_url(qr
), ==, DST
);
54 quvi_resolve_free(qr
);
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";
71 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
76 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
80 qr
= quvi_resolve_new(q
, URL
);
81 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
84 g_assert(quvi_resolve_forwarded(qr
) == QUVI_TRUE
);
85 g_assert_cmpstr(quvi_resolve_destination_url(qr
), ==, DST
);
87 quvi_resolve_free(qr
);
92 static void test_resolve_nodst()
94 static const gchar URL
[] = "http://www.youtube.com/";
99 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
104 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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
);
118 static void test_resolve_nodst_t_param()
120 static const gchar URL
[] =
121 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
126 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
131 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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
);
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
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";
181 if (chk_internet() == FALSE
|| chk_skip(__func__
) == TRUE
)
186 g_assert_cmpint(quvi_errcode(q
), ==, QUVI_OK
);
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
);
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
);
206 g_test_add_func("/quvi/resolve (3)", test_resolve_3
);
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: */