<commit_before>/* libquvi
 * Copyright (C) 2012  <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include "config.h"

#include <string.h>
#include <glib.h>
#include <quvi.h>

#include "tests.h"

static void test_playlist()
{
  static const gchar URL[] =
    "http://soundcloud.com/thelittleidiot/sets/destroyed/";

  quvi_playlist_t qp;
  gdouble n;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert(qp != NULL);

  /* Boundary check: the first -1 */
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID-1, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);

  /* Boundary check: the last +1 */
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS+1, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");

  /* This should advance the current media pointer to the first media
   * item in the returned list. */
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "The Broken Places"); /* First media title. */

  /* This should continue from the 2nd item, not the 1st in the list. */
  quvi_playlist_media_next(qp);

  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "Be The One"); /* Second media title. */

  quvi_playlist_media_reset(qp);

  {
    gint i = 0;
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
      {
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpfloat(n, >, 0);

        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);

        if (i == 0)
          {
            /* Confirm that this is the first item, the call to
             * quvi_playlist_reset earlier should have reset the
             * current location. */
            g_assert_cmpstr(s, ==, "The Broken Places");
          }

        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);

        ++i;
      }
    g_assert_cmpint(i, >, 1);
  }

  quvi_playlist_free(qp);
  quvi_free(q);
}

static void test_playlist_short()
{
  static const gchar URL[] = "http://is.gd/BjbpVn";

  quvi_playlist_t qp;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert(qp != NULL);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");

  {
    gint i = 0;
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
      {
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);
        ++i;
      }
    g_assert_cmpint(i, >, 1);
  }

  quvi_playlist_free(qp);
  quvi_free(q);
}

static void test_playlist_nosupport()
{
  static const gchar URL[] = "http://example.com/";

  quvi_playlist_t qp;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_NO_SUPPORT);
  g_assert(qp != NULL);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "");

  quvi_playlist_free(qp);
  quvi_free(q);
}

gint main(gint argc, gchar **argv)
{
  g_test_init(&argc, &argv, NULL);
  g_test_add_func("/quvi/playlist", test_playlist);
  g_test_add_func("/quvi/playlist (short)", test_playlist_short);
  g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
  return (g_test_run());
}

/* vim: set ts=2 sw=2 tw=72 expandtab: */<commit_msg>tests: Update tests/playlist.c<commit_after>/* libquvi
 * Copyright (C) 2012  <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#include "config.h"

#include <string.h>
#include <glib.h>
#include <quvi.h>

#include "tests.h"

static void test_playlist()
{
  static const gchar URL[] =
    "http://soundcloud.com/thelittleidiot/sets/destroyed/";

  quvi_playlist_t qp;
  gdouble n;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert(qp != NULL);

  /* Boundary check: the first -1 */
  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL-1, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);

  /* Boundary check: the last +1 */
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS+1, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_INVALID_ARG);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpint(strlen(s), >, 0);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");

  /* This should advance the current media pointer to the first media
   * item in the returned list. */
  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "The Broken Places"); /* First media title. */

  /* This should continue from the 2nd item, not the 1st in the list. */
  quvi_playlist_media_next(qp);

  quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "Be The One"); /* Second media title. */

  quvi_playlist_media_reset(qp);

  {
    gint i = 0;
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
      {
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_DURATION_MS, &n);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpfloat(n, >, 0);

        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_TITLE, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);

        if (i == 0)
          {
            /* Confirm that this is the first item, the call to
             * quvi_playlist_reset earlier should have reset the
             * current location. */
            g_assert_cmpstr(s, ==, "The Broken Places");
          }

        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);

        ++i;
      }
    g_assert_cmpint(i, >, 1);
  }

  quvi_playlist_free(qp);
  quvi_free(q);
}

static void test_playlist_short()
{
  static const gchar URL[] = "http://is.gd/BjbpVn";

  quvi_playlist_t qp;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert(qp != NULL);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpint(strlen(s), >, 0);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "thelittleidiot_destroyed");

  {
    gint i = 0;
    while (quvi_playlist_media_next(qp) == QUVI_TRUE)
      {
        quvi_playlist_get(qp, QUVI_PLAYLIST_MEDIA_PROPERTY_URL, &s);
        g_assert_cmpint(qerr(q), ==, QUVI_OK);
        g_assert_cmpint(strlen(s), >, 0);
        ++i;
      }
    g_assert_cmpint(i, >, 1);
  }

  quvi_playlist_free(qp);
  quvi_free(q);
}

static void test_playlist_nosupport()
{
  static const gchar URL[] = "http://example.com/";

  quvi_playlist_t qp;
  quvi_t q;
  gchar *s;

  if (chk_internet() == FALSE)
    return;

  if (chk_skip(__func__) == TRUE)
    return;

  q = quvi_new();
  g_assert(q != NULL);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);

  chk_verbose(q);

  qp = quvi_playlist_new(q, URL);
  g_assert_cmpint(qerr(q), ==, QUVI_ERROR_NO_SUPPORT);
  g_assert(qp != NULL);

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_THUMBNAIL_URL, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "");

  quvi_playlist_get(qp, QUVI_PLAYLIST_PROPERTY_ID, &s);
  g_assert_cmpint(qerr(q), ==, QUVI_OK);
  g_assert_cmpstr(s, ==, "");

  quvi_playlist_free(qp);
  quvi_free(q);
}

gint main(gint argc, gchar **argv)
{
  g_test_init(&argc, &argv, NULL);
  g_test_add_func("/quvi/playlist", test_playlist);
  g_test_add_func("/quvi/playlist (short)", test_playlist_short);
  g_test_add_func("/quvi/playlist (nosupport)", test_playlist_nosupport);
  return (g_test_run());
}

/* vim: set ts=2 sw=2 tw=72 expandtab: */
{'fraction_non_alphanumeric': 0.1375125467652158, 'fraction_numerical': 0.006569942513003011, 'mean_word_length': 3.8863129736959428, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2592724', 'n_tokens_mistral': 4534, 'n_tokens_neox': 4434, 'n_words': 894}