Blame tests/resolve.c

Packit 3ff1e7
/* libquvi
Packit 3ff1e7
 * Copyright (C) 2012  Toni Gundogdu <legatvs@gmail.com>
Packit 3ff1e7
 *
Packit 3ff1e7
 * This file is part of libquvi <http://quvi.sourceforge.net/>.
Packit 3ff1e7
 *
Packit 3ff1e7
 * This program is free software: you can redistribute it and/or
Packit 3ff1e7
 * modify it under the terms of the GNU Affero General Public
Packit 3ff1e7
 * License as published by the Free Software Foundation, either
Packit 3ff1e7
 * version 3 of the License, or (at your option) any later version.
Packit 3ff1e7
 *
Packit 3ff1e7
 * This program is distributed in the hope that it will be useful,
Packit 3ff1e7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 3ff1e7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 3ff1e7
 * GNU Affero General Public License for more details.
Packit 3ff1e7
 *
Packit 3ff1e7
 * You should have received a copy of the GNU Affero General
Packit 3ff1e7
 * Public License along with this program.  If not, see
Packit 3ff1e7
 * <http://www.gnu.org/licenses/>.
Packit 3ff1e7
 */
Packit 3ff1e7
Packit 3ff1e7
#include "config.h"
Packit 3ff1e7
Packit 3ff1e7
#include <glib.h>
Packit 3ff1e7
#include <quvi.h>
Packit 3ff1e7
Packit 3ff1e7
#include "tests.h"
Packit 3ff1e7
Packit 3ff1e7
static void test_resolve_core()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://is.gd/9lrXf8";
Packit 3ff1e7
Packit 3ff1e7
  static const gchar DST[] =
Packit 3ff1e7
    "http://www.collegehumor.com/video/6781885/batman-blows-his-cover";
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_t qr;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
Packit 3ff1e7
    return;
Packit 3ff1e7
Packit 3ff1e7
  q = quvi_new();
Packit 3ff1e7
  g_assert(q != NULL);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
Packit 3ff1e7
  chk_verbose(q);
Packit 3ff1e7
Packit 3ff1e7
  qr = quvi_resolve_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qr != NULL);
Packit 3ff1e7
Packit 3ff1e7
  g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
Packit 3ff1e7
  g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_free(qr);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
#ifdef _1 /* Comment out until a new one with >1 redirections is found. */
Packit 3ff1e7
static void test_resolve_3()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://is.gd/gQ4pYW";
Packit 3ff1e7
Packit 3ff1e7
  static const gchar DST[] =
Packit 3ff1e7
    "http://www.thefirearmblog.com/blog/2012/06/11/shooting-drones/"
Packit 3ff1e7
    "?utm_source=feedburner&utm_medium=feed&utm_campaign="
Packit 3ff1e7
    "Feed%3A+TheFirearmBlog+%28The+Firearm+Blog%29";
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_t qr;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
Packit 3ff1e7
    return;
Packit 3ff1e7
Packit 3ff1e7
  q = quvi_new();
Packit 3ff1e7
  g_assert(q != NULL);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
Packit 3ff1e7
  chk_verbose(q);
Packit 3ff1e7
Packit 3ff1e7
  qr = quvi_resolve_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qr != NULL);
Packit 3ff1e7
Packit 3ff1e7
  g_assert(quvi_resolve_forwarded(qr) == QUVI_TRUE);
Packit 3ff1e7
  g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_free(qr);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
#endif /* _1 */
Packit 3ff1e7
Packit 3ff1e7
static void test_resolve_nodst()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://www.youtube.com/";
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_t qr;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
Packit 3ff1e7
    return;
Packit 3ff1e7
Packit 3ff1e7
  q = quvi_new();
Packit 3ff1e7
  g_assert(q != NULL);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
Packit 3ff1e7
  chk_verbose(q);
Packit 3ff1e7
Packit 3ff1e7
  qr = quvi_resolve_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qr != NULL);
Packit 3ff1e7
Packit 3ff1e7
  g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_free(qr);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
static void test_resolve_nodst_t_param()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] =
Packit 3ff1e7
    "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_t qr;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
Packit 3ff1e7
    return;
Packit 3ff1e7
Packit 3ff1e7
  q = quvi_new();
Packit 3ff1e7
  g_assert(q != NULL);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
Packit 3ff1e7
  chk_verbose(q);
Packit 3ff1e7
Packit 3ff1e7
  qr = quvi_resolve_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qr != NULL);
Packit 3ff1e7
Packit 3ff1e7
  /*
Packit 3ff1e7
   * [UPDATE] 2012-11-19: g00gle servers no longer strip the #t param
Packit 3ff1e7
   * The description below no longer applies, although we still test
Packit 3ff1e7
   * this, in case this changes back.
Packit 3ff1e7
   *
Packit 3ff1e7
   * [ISSUE] g00gle servers redirect to the media URL stripping #t
Packit 3ff1e7
   * g00gle servers redirect to the media URL stripping the #t
Packit 3ff1e7
   * parameter. The library should not be fooled by this trickery.
Packit 3ff1e7
   * The workaround is implemented in libquvi-scripts
Packit 3ff1e7
   * (resolve_redirections.lua).
Packit 3ff1e7
   */
Packit 3ff1e7
  g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_FALSE);
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_free(qr);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
/* [UPDATE] 2012-11-19: g00gle servers now seem to redirect to
Packit 3ff1e7
 * the media URL without stripping the #t parameter. The test has been
Packit 3ff1e7
 * modified to test that shortened URLs redirect to the expected media
Packit 3ff1e7
 * URL.
Packit 3ff1e7
 *
Packit 3ff1e7
 * [ISSUE] #t parameter is lost with shortened URLs
Packit 3ff1e7
 * Shortened Y0uTube media URLs with the #t parameter do not work
Packit 3ff1e7
 * with the library. The test below should redirect to
Packit 3ff1e7
 *   http://www.youtube.com/watch?v=G4evlxq34og
Packit 3ff1e7
 * missing the #t parameter, see the above test for the description.
Packit 3ff1e7
 */
Packit 3ff1e7
static void test_resolve_shortened_with_t_param()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://is.gd/TRWtNf";
Packit 3ff1e7
  /* http://www.youtube.com/watch?v=G4evlxq34og#t=3m20 */
Packit 3ff1e7
Packit 3ff1e7
  static const gchar DST[] =
Packit 3ff1e7
    "http://www.youtube.com/watch?v=G4evlxq34og#t=3m20";
Packit 3ff1e7
#ifdef _1 /* [UPDATE] 2012-11-19: See above */
Packit 3ff1e7
    "http://www.youtube.com/watch?v=G4evlxq34og";
Packit 3ff1e7
#endif
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_t qr;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
Packit 3ff1e7
  if (chk_internet() == FALSE || chk_skip(__func__) == TRUE)
Packit 3ff1e7
    return;
Packit 3ff1e7
Packit 3ff1e7
  q = quvi_new();
Packit 3ff1e7
  g_assert(q != NULL);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
Packit 3ff1e7
  chk_verbose(q);
Packit 3ff1e7
Packit 3ff1e7
  qr = quvi_resolve_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qr != NULL);
Packit 3ff1e7
Packit 3ff1e7
  g_assert_cmpint(quvi_resolve_forwarded(qr), ==, QUVI_TRUE);
Packit 3ff1e7
  g_assert_cmpstr(quvi_resolve_destination_url(qr), ==, DST);
Packit 3ff1e7
Packit 3ff1e7
  quvi_resolve_free(qr);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
gint main(gint argc, gchar **argv)
Packit 3ff1e7
{
Packit 3ff1e7
  g_test_init(&argc, &argv, NULL);
Packit 3ff1e7
  g_test_add_func("/quvi/resolve (core)", test_resolve_core);
Packit 3ff1e7
#ifdef _1
Packit 3ff1e7
  g_test_add_func("/quvi/resolve (3)", test_resolve_3);
Packit 3ff1e7
#endif
Packit 3ff1e7
  g_test_add_func("/quvi/resolve (nodst)", test_resolve_nodst);
Packit 3ff1e7
  g_test_add_func("/quvi/resolve (nodst #t param)",
Packit 3ff1e7
                  test_resolve_nodst_t_param);
Packit 3ff1e7
  g_test_add_func("/quvi/resolve (short URL with #t param)",
Packit 3ff1e7
                  test_resolve_shortened_with_t_param);
Packit 3ff1e7
  return (g_test_run());
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
/* vim: set ts=2 sw=2 tw=72 expandtab: */