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
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";
37 if (chk_internet() == FALSE
)
40 if (chk_skip(__func__
) == TRUE
)
45 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
49 qr
= quvi_resolve_new(q
, URL
);
50 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
53 g_assert(quvi_resolve_forwarded(qr
) == QUVI_TRUE
);
54 g_assert_cmpstr(quvi_resolve_destination_url(qr
), ==, DST
);
56 quvi_resolve_free(qr
);
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";
72 if (chk_internet() == FALSE
)
75 if (chk_skip(__func__
) == TRUE
)
80 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
84 qr
= quvi_resolve_new(q
, URL
);
85 g_assert_cmpint(qerr_m(q
, URL
), ==, QUVI_OK
);
88 g_assert(quvi_resolve_forwarded(qr
) == QUVI_TRUE
);
89 g_assert_cmpstr(quvi_resolve_destination_url(qr
), ==, DST
);
91 quvi_resolve_free(qr
);
95 static void test_resolve_nodst()
97 static const gchar URL
[] = "http://www.iana.org/domains/example/";
102 if (chk_internet() == FALSE
)
105 if (chk_skip(__func__
) == TRUE
)
110 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
124 static void test_resolve_nodst_t_param()
126 static const gchar URL
[] =
127 "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
132 if (chk_internet() == FALSE
)
135 if (chk_skip(__func__
) == TRUE
)
140 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
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";
171 if (chk_internet() == FALSE
)
174 if (chk_skip(__func__
) == TRUE
)
179 g_assert_cmpint(qerr(q
), ==, QUVI_OK
);
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
);
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: */