1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/* libquvi
* Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
*
* This file is part of libquvi <http://quvi.sourceforge.net/>.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General
* Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <glib.h>
#include <quvi.h>
#include "tests.h"
static void test_resolve_core()
{
static const gchar URL[] = "http://is.gd/9lrXf8";
static const gchar DST[] =
"http://www.collegehumor.com/video/6781885/batman-blows-his-cover";
quvi_resolve_t qr;
quvi_t q;
if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
return;
q = quvi_new();
g_assert(q != NULL);
g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
chk_verbose(q);
qr = quvi_resolve_new(q, URL);
g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
g_assert(qr != NULL);
g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
quvi_resolve_free(qr);
quvi_free(q);
}
#ifdef _1 /* Comment out until a new one with >1 redirections is found. */
static void test_resolve_3()
{
static const gchar URL[] = "http://is.gd/gQ4pYW";
static const gchar DST[] =
"http://www.thefirearmblog.com/blog/2012/06/11/shooting-drones/"
"?utm_source=feedburner&utm_medium=feed&utm_campaign="
"Feed%3A+TheFirearmBlog+%28The+Firearm+Blog%29";
quvi_resolve_t qr;
quvi_t q;
if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
return;
q = quvi_new();
g_assert(q != NULL);
g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
chk_verbose(q);
qr = quvi_resolve_new(q, URL);
g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
g_assert(qr != NULL);
g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
quvi_resolve_free(qr);
quvi_free(q);
}
#endif /* _1 */
static void test_resolve_nodst()
{
static const gchar URL[] = "http://www.youtube.com/";
quvi_resolve_t qr;
quvi_t q;
if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
return;
q = quvi_new();
g_assert(q != NULL);
g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
chk_verbose(q);
qr = quvi_resolve_new(q, URL);
g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
g_assert(qr != NULL);
g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
quvi_resolve_free(qr);
quvi_free(q);
}
static void test_resolve_nodst_t_param()
{
static const gchar URL[] =
"http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
quvi_resolve_t qr;
quvi_t q;
if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
return;
q = quvi_new();
g_assert(q != NULL);
g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
chk_verbose(q);
qr = quvi_resolve_new(q, URL);
g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
g_assert(qr != NULL);
/*
* [UPDATE] 2012-11-19: g00gle servers no longer strip the #t param
* The description below no longer applies, although we still test
* this, in case this changes back.
*
* [ISSUE] g00gle servers redirect to the media URL stripping #t
* g00gle servers redirect to the media URL stripping the #t
* parameter. The library should not be fooled by this trickery.
* The workaround is implemented in libquvi-scripts
* (resolve_redirections.lua).
*/
g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
quvi_resolve_free(qr);
quvi_free(q);
}
/* [UPDATE] 2012-11-19: g00gle servers now seem to redirect to
* the media URL without stripping the #t parameter. The test has been
* modified to test that shortened URLs redirect to the expected media
* URL.
*
* [ISSUE] #t parameter is lost with shortened URLs
* Shortened Y0uTube media URLs with the #t parameter do not work
* with the library. The test below should redirect to
* http://www.youtube.com/watch?v=G4evlxq34og
* missing the #t parameter, see the above test for the description.
*/
static void test_resolve_shortened_with_t_param()
{
static const gchar URL[] = "http://is.gd/TRWtNf";
/* http://www.youtube.com/watch?v=G4evlxq34og#t=3m20 */
static const gchar DST[] =
"http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
#ifdef _1 /* [UPDATE] 2012-11-19: See above */
"http://www.youtube.com/watch?v=G4evlxq34og";
#endif
quvi_resolve_t qr;
quvi_t q;
if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
return;
q = quvi_new();
g_assert(q != NULL);
g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
chk_verbose(q);
qr = quvi_resolve_new(q, URL);
g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
g_assert(qr != NULL);
g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_TRUE);
g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
quvi_resolve_free(qr);
quvi_free(q);
}
gint main(gint argc, gchar **argv)
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/quvi/resolve (core)", test_resolve_core);
#ifdef _1
g_test_add_func("/quvi/resolve (3)", test_resolve_3);
#endif
g_test_add_func("/quvi/resolve (nodst)", test_resolve_nodst);
g_test_add_func("/quvi/resolve (nodst #t param)",
test_resolve_nodst_t_param);
g_test_add_func("/quvi/resolve (short URL with #t param)",
test_resolve_shortened_with_t_param);
return (g_test_run());
}
/* vim: set ts=2 sw=2 tw=72 expandtab: */
|