Blame tests/playlist.c

Packit 3ff1e7
/* libquvi
Packit 3ff1e7
 * Copyright (C) 2012,2013  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 <string.h>
Packit 3ff1e7
#include <glib.h>
Packit 3ff1e7
#include <quvi.h>
Packit 3ff1e7
Packit 3ff1e7
#include "tests.h"
Packit 3ff1e7
Packit 3ff1e7
static void test_playlist_core()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] =
Packit 3ff1e7
    "http://soundcloud.com/volt-icarus2-otherupload/sets/bgm/";
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_t qp;
Packit 3ff1e7
  gdouble n;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
  gchar *s;
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
  qp = quvi_playlist_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qp != NULL);
Packit 3ff1e7
Packit 3ff1e7
  /* Boundary check: the first -1 */
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL-1, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
Packit 3ff1e7
Packit 3ff1e7
  /* Boundary check: the last +1 */
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS+1, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_ERROR_INVALID_ARG);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpint(strlen(s), >, 0);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "허스키익스프레스bgm");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "volt-icarus2-otherupload_bgm");
Packit 3ff1e7
Packit 3ff1e7
  /* This should advance the current media pointer to the first media
Packit 3ff1e7
   * item in the returned list. */
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  /* First media title. */
Packit 3ff1e7
  g_assert_cmpstr(s, ==,
Packit 3ff1e7
                  "은빛설원의 노래(Song of silver snowy)_Husky "
Packit 3ff1e7
                  "Express Main bgm");
Packit 3ff1e7
Packit 3ff1e7
  /* This should continue from the 2nd item, not the 1st in the list. */
Packit 3ff1e7
  quvi_playlist_media_next(qp);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  /* Second media title. */
Packit 3ff1e7
  g_assert_cmpstr(s, ==,
Packit 3ff1e7
                  "햇살을 가르며Hike(Hike bisecting the "
Packit 3ff1e7
                  "sunshine)_Husky Express bgm");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_media_reset(qp);
Packit 3ff1e7
Packit 3ff1e7
  {
Packit 3ff1e7
    gint i = 0;
Packit 3ff1e7
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
Packit 3ff1e7
      {
Packit 3ff1e7
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
Packit 3ff1e7
        g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
        g_assert_cmpfloat(n, >, 0);
Packit 3ff1e7
Packit 3ff1e7
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
Packit 3ff1e7
        g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
        g_assert_cmpint(strlen(s), >, 0);
Packit 3ff1e7
Packit 3ff1e7
        if (i == 0)
Packit 3ff1e7
          {
Packit 3ff1e7
            /* Confirm that this is the first item, the call to
Packit 3ff1e7
             * quvi_playlist_reset earlier should have reset the
Packit 3ff1e7
             * current location. */
Packit 3ff1e7
            g_assert_cmpstr(s, ==,
Packit 3ff1e7
                            "은빛설원의 노래(Song of silver snowy)_Husky "
Packit 3ff1e7
                            "Express Main bgm");
Packit 3ff1e7
          }
Packit 3ff1e7
Packit 3ff1e7
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
Packit 3ff1e7
        g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
        g_assert_cmpint(strlen(s), >, 0);
Packit 3ff1e7
Packit 3ff1e7
        ++i;
Packit 3ff1e7
      }
Packit 3ff1e7
    g_assert_cmpint(i, >, 1);
Packit 3ff1e7
  }
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_free(qp);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
static void test_playlist_short()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://is.gd/3oNTko";
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_t qp;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
  gchar *s;
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
  qp = quvi_playlist_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qp != NULL);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpint(strlen(s), >, 0);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "허스키익스프레스bgm");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "volt-icarus2-otherupload_bgm");
Packit 3ff1e7
Packit 3ff1e7
  {
Packit 3ff1e7
    gint i = 0;
Packit 3ff1e7
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
Packit 3ff1e7
      {
Packit 3ff1e7
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
Packit 3ff1e7
        g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
        g_assert_cmpint(strlen(s), >, 0);
Packit 3ff1e7
        ++i;
Packit 3ff1e7
      }
Packit 3ff1e7
    g_assert_cmpint(i, >, 1);
Packit 3ff1e7
  }
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_free(qp);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
static void test_playlist_escaped_url()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] =
Packit 3ff1e7
    "http://www.youtube.com/playlist%3Flist%3DPLlbnzwCkgkTBBXWz595XaKs_kkXek0gQP%26";
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_t qp;
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
  qp = quvi_playlist_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_OK);
Packit 3ff1e7
  g_assert(qp != NULL);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_free(qp);
Packit 3ff1e7
  quvi_free(q);
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
static void test_playlist_nosupport()
Packit 3ff1e7
{
Packit 3ff1e7
  static const gchar URL[] = "http://example.com/";
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_t qp;
Packit 3ff1e7
  quvi_t q;
Packit 3ff1e7
  gchar *s;
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
  qp = quvi_playlist_new(q, URL);
Packit 3ff1e7
  g_assert_cmpint(qerr_m(q, URL), ==, QUVI_ERROR_NO_SUPPORT);
Packit 3ff1e7
  g_assert(qp != NULL);
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_TITLE, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
Packit 3ff1e7
  g_assert_cmpint(quvi_errcode(q), ==, QUVI_OK);
Packit 3ff1e7
  g_assert_cmpstr(s, ==, "");
Packit 3ff1e7
Packit 3ff1e7
  quvi_playlist_free(qp);
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/playlist (core)", test_playlist_core);
Packit 3ff1e7
  g_test_add_func("/quvi/playlist (short)", test_playlist_short);
Packit 3ff1e7
  g_test_add_func("/quvi/playlist (escaped URL)", test_playlist_escaped_url);
Packit 3ff1e7
  g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
Packit 3ff1e7
  return (g_test_run());
Packit 3ff1e7
}
Packit 3ff1e7
Packit 3ff1e7
/* vim: set ts=2 sw=2 tw=72 expandtab: */