Blame tests/check/gst/gsturi.c

Packit a6ee4b
/* GStreamer unit tests for GstURI
Packit a6ee4b
 *
Packit a6ee4b
 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
#ifdef HAVE_CONFIG_H
Packit a6ee4b
#include "config.h"
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#ifndef GST_REMOVE_DEPRECATED
Packit a6ee4b
#undef GST_DISABLE_DEPRECATED
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#include <gst/check/gstcheck.h>
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_protocol_case)
Packit a6ee4b
{
Packit a6ee4b
  GstElement *element;
Packit a6ee4b
  GError *err = NULL;
Packit a6ee4b
Packit a6ee4b
  element = gst_element_make_from_uri (GST_URI_SRC, "file:///foo/bar", NULL,
Packit a6ee4b
      &err;;
Packit a6ee4b
Packit a6ee4b
  /* no element? probably no registry, bail out */
Packit a6ee4b
  if (element == NULL && err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL) {
Packit a6ee4b
    g_error_free (err);
Packit a6ee4b
    return;
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  gst_object_unref (element);
Packit a6ee4b
  element = gst_element_make_from_uri (GST_URI_SRC, "FILE:///foo/bar", NULL,
Packit a6ee4b
      NULL);
Packit a6ee4b
  fail_unless (element != NULL,
Packit a6ee4b
      "Got source for 'file://' URI but not for 'FILE://' URI");
Packit a6ee4b
  gst_object_unref (element);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_uri_get_location)
Packit a6ee4b
{
Packit a6ee4b
  gchar *l;
Packit a6ee4b
Packit a6ee4b
  /* URI with no location should return empty string */
Packit a6ee4b
  l = gst_uri_get_location ("dvd://");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l, "");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
Packit a6ee4b
  /* URI with hostname */
Packit a6ee4b
  l = gst_uri_get_location ("smb://supercomputer/path/to/file");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l, "supercomputer/path/to/file");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
Packit a6ee4b
  /* URI */
Packit a6ee4b
  l = gst_uri_get_location ("file:///path/to/file");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l, "/path/to/file");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
Packit a6ee4b
  /* unescaping */
Packit a6ee4b
  l = gst_uri_get_location ("file:///path/to/some%20file");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l, "/path/to/some file");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
#ifndef GST_REMOVE_DEPRECATED
Packit a6ee4b
GST_START_TEST (test_gst_uri_construct)
Packit a6ee4b
{
Packit a6ee4b
  gchar *l = NULL;
Packit a6ee4b
Packit a6ee4b
  /* URI with no protocol or empty protocol should return empty string */
Packit a6ee4b
  ASSERT_CRITICAL (l = gst_uri_construct (NULL, "/path/to/file"));
Packit a6ee4b
  fail_unless (l == NULL);
Packit a6ee4b
  ASSERT_CRITICAL (l = gst_uri_construct ("", "/path/to/file"));
Packit a6ee4b
  fail_unless (l == NULL);
Packit a6ee4b
Packit a6ee4b
  /* URI with no location should return empty string */
Packit a6ee4b
  ASSERT_CRITICAL (l = gst_uri_construct ("protocol", NULL));
Packit a6ee4b
  fail_unless (l == NULL);
Packit a6ee4b
Packit a6ee4b
  /* check the protocol for validity */
Packit a6ee4b
  l = gst_uri_construct ("protocol1234567890+-.", "somefile");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l, "protocol1234567890+-.://somefile");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
Packit a6ee4b
  /* check the location for correct handling */
Packit a6ee4b
  l = gst_uri_construct ("aprotocol",
Packit a6ee4b
      "/path+ to/some/file%d?akey=aval&key2=val2");
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "aprotocol:///path%2B%20to/some/file%25d?akey=aval&key2=val2");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#ifdef G_OS_WIN32
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_win32_uri)
Packit a6ee4b
{
Packit a6ee4b
  gchar *uri, *l;
Packit a6ee4b
Packit a6ee4b
  uri = g_strdup ("file:///c:/my%20music/foo.ogg");
Packit a6ee4b
  l = gst_uri_get_location (uri);
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  /* fail_unless_equals_string will screw up here in the failure case
Packit a6ee4b
   * because the string constant will be appended to the printf format
Packit a6ee4b
   * message string and contains a '%', that's why we use fail_unless here */
Packit a6ee4b
  fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
Packit a6ee4b
      "wrong location '%s' returned for URI '%s'", l, uri);
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  g_free (uri);
Packit a6ee4b
Packit a6ee4b
  /* make sure the other variant with two slashes before the C: (which was
Packit a6ee4b
   * needed before because of a bug in _get_location()) still works */
Packit a6ee4b
  uri = g_strdup ("file://c:/my%20music/foo.ogg");
Packit a6ee4b
  l = gst_uri_get_location (uri);
Packit a6ee4b
  fail_unless (l != NULL);
Packit a6ee4b
  /* fail_unless_equals_string will screw up here in the failure case
Packit a6ee4b
   * because the string constant will be appended to the printf format
Packit a6ee4b
   * message string and contains a '%', that's why we use fail_unless here */
Packit a6ee4b
  fail_unless (g_str_equal (l, "c:/my music/foo.ogg"),
Packit a6ee4b
      "wrong location '%s' returned for URI '%s'", l, uri);
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  g_free (uri);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
#endif /* G_OS_WIN32 */
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_uri_misc)
Packit a6ee4b
{
Packit a6ee4b
  /* require at least two characters for the protocol */
Packit a6ee4b
  fail_if (gst_uri_is_valid ("B:\\foo.txt"));
Packit a6ee4b
  fail_if (gst_uri_is_valid ("B:/foo.txt"));
Packit a6ee4b
  fail_if (gst_uri_is_valid ("B://foo.txt"));
Packit a6ee4b
  fail_if (gst_uri_is_valid ("B:foo.txt"));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("fd://0"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("AB:\\foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("AB:/foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("AB://foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("AB:foo.txt"));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABC:/foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABC://foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABC:foo.txt"));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABCD:/foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABCD://foo.txt"));
Packit a6ee4b
  fail_unless (gst_uri_is_valid ("ABCD:foo.txt"));
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_element_make_from_uri)
Packit a6ee4b
{
Packit a6ee4b
  GstElement *element;
Packit a6ee4b
  GError *err = NULL;
Packit a6ee4b
Packit a6ee4b
  element = gst_element_make_from_uri (GST_URI_SRC, "foo://", NULL, NULL);
Packit a6ee4b
  fail_unless (element == NULL);
Packit a6ee4b
Packit a6ee4b
  element = gst_element_make_from_uri (GST_URI_SRC, "foo://", NULL, &err;;
Packit a6ee4b
  fail_unless (element == NULL);
Packit a6ee4b
  fail_unless (err != NULL);
Packit a6ee4b
  fail_unless (err->code == GST_URI_ERROR_UNSUPPORTED_PROTOCOL);
Packit a6ee4b
  g_error_free (err);
Packit a6ee4b
  err = NULL;
Packit a6ee4b
Packit a6ee4b
  if (gst_registry_check_feature_version (gst_registry_get (), "filesrc",
Packit a6ee4b
          GST_VERSION_MAJOR, GST_VERSION_MINOR, GST_VERSION_MICRO)) {
Packit a6ee4b
    element = gst_element_make_from_uri (GST_URI_SRC, "file://host/foo", NULL,
Packit a6ee4b
        &err;;
Packit a6ee4b
    fail_unless (element == NULL);
Packit a6ee4b
    fail_unless (err != NULL);
Packit a6ee4b
    fail_unless (err->code == GST_URI_ERROR_BAD_URI);
Packit a6ee4b
    g_error_free (err);
Packit a6ee4b
    err = NULL;
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
/* Taken from the GNet unit test and extended with other URIs:
Packit a6ee4b
 * https://git.gnome.org/browse/archive/gnet/plain/tests/check/gnet/gneturi.c
Packit a6ee4b
 */
Packit a6ee4b
struct QueryValue
Packit a6ee4b
{
Packit a6ee4b
  const gchar *key;
Packit a6ee4b
  const gchar *value;
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
struct URITest
Packit a6ee4b
{
Packit a6ee4b
  const gchar *str;
Packit a6ee4b
  struct
Packit a6ee4b
  {
Packit a6ee4b
    const gchar *scheme;
Packit a6ee4b
    const gchar *userinfo;
Packit a6ee4b
    const gchar *host;
Packit a6ee4b
    gint port;
Packit a6ee4b
    const gchar *path;
Packit a6ee4b
    /* needs to be updated if more than 10 */
Packit a6ee4b
    struct QueryValue query[10];
Packit a6ee4b
    const gchar *fragment;
Packit a6ee4b
  } uri;
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
static const struct URITest tests[] = {
Packit a6ee4b
  /* VALID URIS.  PARSING AND PRINTING OF THESE SHOULD NOT CHANGE */
Packit a6ee4b
Packit a6ee4b
  /* scheme/path */
Packit a6ee4b
  {"scheme:",
Packit a6ee4b
      {"scheme", NULL, NULL, GST_URI_NO_PORT, NULL, {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme:path",
Packit a6ee4b
      {"scheme", NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"path",
Packit a6ee4b
      {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"/path",
Packit a6ee4b
      {NULL, NULL, NULL, GST_URI_NO_PORT, "/path", {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  /* hostname/port */
Packit a6ee4b
  {"scheme://hostname/path",
Packit a6ee4b
        {"scheme", NULL, "hostname", GST_URI_NO_PORT, "/path", {{NULL, NULL}},
Packit a6ee4b
          NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123/path",
Packit a6ee4b
      {"scheme", NULL, "hostname", 123, "/path", {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  /* ipv6 hostname/port */
Packit a6ee4b
  {"scheme://[01:23:45:67:89:ab:cd:ef]/path",
Packit a6ee4b
        {"scheme", NULL, "01:23:45:67:89:ab:cd:ef", GST_URI_NO_PORT, "/path",
Packit a6ee4b
          {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://[01:23:45:67:89:ab:cd:ef]:123/path",
Packit a6ee4b
        {"scheme", NULL, "01:23:45:67:89:ab:cd:ef", 123, "/path", {{NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  /* query/fragment */
Packit a6ee4b
  {"path?query",
Packit a6ee4b
        {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
  {"path?query=value",
Packit a6ee4b
        {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", "value"}, {NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"path?query#fragment",
Packit a6ee4b
        {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"path?query=value#fragment",
Packit a6ee4b
        {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{"query", "value"}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme:path?query#fragment",
Packit a6ee4b
        {"scheme", NULL, NULL, GST_URI_NO_PORT, "path", {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  /* full */
Packit a6ee4b
  {"scheme://hostname:123/path?query#fragment",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, "/path", {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123/path?query=value#fragment",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, "/path", {{"query", "value"}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123?query",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, NULL, {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123?query=value",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, NULL, {{"query", "value"}, {NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123?query#fragment",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, NULL, {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://hostname:123?query=value#fragment",
Packit a6ee4b
        {"scheme", NULL, "hostname", 123, NULL, {{"query", "value"}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  /* user/pass */
Packit a6ee4b
  {"scheme://userinfo@hostname",
Packit a6ee4b
        {"scheme", "userinfo", "hostname", GST_URI_NO_PORT, NULL, {{NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://userinfo@hostname:123/path?query#fragment",
Packit a6ee4b
        {"scheme", "userinfo", "hostname", 123, "/path", {{"query", NULL},
Packit a6ee4b
              {NULL, NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://user:pass@hostname",
Packit a6ee4b
        {"scheme", "user:pass", "hostname", GST_URI_NO_PORT, NULL, {{NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://user:pass@hostname:123/path?query#fragment",
Packit a6ee4b
        {"scheme", "user:pass", "hostname", 123, "/path", {{"query", NULL},
Packit a6ee4b
              {NULL, NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  /* FUNNY URIS.  PARSING AND PRINTING OF THESE MAY CHANGE */
Packit a6ee4b
Packit a6ee4b
  {"scheme:hostname:123/path?query#fragment",
Packit a6ee4b
        {"scheme", NULL, NULL, GST_URI_NO_PORT, "hostname:123/path", {{"query",
Packit a6ee4b
                  NULL}, {NULL, NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  {"scheme://:pass@hostname:123/path?query#fragment",
Packit a6ee4b
        {"scheme", ":pass", "hostname", 123, "/path", {{"query", NULL}, {NULL,
Packit a6ee4b
                  NULL}}, "fragment"}},
Packit a6ee4b
Packit a6ee4b
  /* Skip initial white space */
Packit a6ee4b
  {" \f\n\r\t\vscheme:",
Packit a6ee4b
      {"scheme", NULL, NULL, GST_URI_NO_PORT, NULL, {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  {" \f\n\r\t\vpath",
Packit a6ee4b
      {NULL, NULL, NULL, GST_URI_NO_PORT, "path", {{NULL, NULL}}, NULL}},
Packit a6ee4b
Packit a6ee4b
  /* file URI */
Packit a6ee4b
  {"file://host/home/joe/foo.txt",
Packit a6ee4b
        {"file", NULL, "host", GST_URI_NO_PORT, "/home/joe/foo.txt", {{NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
  {"file:///home/joe/foo.txt",
Packit a6ee4b
        {"file", NULL, NULL, GST_URI_NO_PORT, "/home/joe/foo.txt", {{NULL,
Packit a6ee4b
                  NULL}}, NULL}},
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
static const gchar *unparsable_uri_tests[] = {
Packit a6ee4b
  /* Path not started correctly */
Packit a6ee4b
  "scheme://hostname:123path?query#fragment",
Packit a6ee4b
Packit a6ee4b
  /* Brackets that don't close */
Packit a6ee4b
  "scheme://[01:23:45:67:89:ab:cd:ef:123/path",
Packit a6ee4b
Packit a6ee4b
  /* IPv6 hostname without brackets */
Packit a6ee4b
  "scheme://01:23:45:67:89:ab:cd:ef:123/path",
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_parsing)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *uri;
Packit a6ee4b
  GList *list;
Packit a6ee4b
  gchar *tmp_str;
Packit a6ee4b
  guint i, j;
Packit a6ee4b
Packit a6ee4b
  for (i = 0; i < G_N_ELEMENTS (tests); i++) {
Packit a6ee4b
    GST_DEBUG ("Testing URI '%s'", tests[i].str);
Packit a6ee4b
Packit a6ee4b
    uri = gst_uri_from_string (tests[i].str);
Packit a6ee4b
    fail_unless (uri != NULL);
Packit a6ee4b
    fail_unless_equals_string (gst_uri_get_scheme (uri), tests[i].uri.scheme);
Packit a6ee4b
    fail_unless_equals_string (gst_uri_get_userinfo (uri),
Packit a6ee4b
        tests[i].uri.userinfo);
Packit a6ee4b
    fail_unless_equals_string (gst_uri_get_host (uri), tests[i].uri.host);
Packit a6ee4b
    fail_unless_equals_int (gst_uri_get_port (uri), tests[i].uri.port);
Packit a6ee4b
    tmp_str = gst_uri_get_path (uri);
Packit a6ee4b
    fail_unless_equals_string (tmp_str, tests[i].uri.path);
Packit a6ee4b
    g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
    for (j = 0; j < 10; j++) {
Packit a6ee4b
      if (!tests[i].uri.query[j].key)
Packit a6ee4b
        break;
Packit a6ee4b
Packit a6ee4b
      if (tests[i].uri.query[j].value) {
Packit a6ee4b
        fail_unless_equals_string (gst_uri_get_query_value (uri,
Packit a6ee4b
                tests[i].uri.query[j].key), tests[i].uri.query[j].value);
Packit a6ee4b
      } else {
Packit a6ee4b
        fail_unless (gst_uri_query_has_key (uri, tests[i].uri.query[j].key));
Packit a6ee4b
      }
Packit a6ee4b
    }
Packit a6ee4b
    list = gst_uri_get_query_keys (uri);
Packit a6ee4b
    fail_unless_equals_int (j, g_list_length (list));
Packit a6ee4b
    g_list_free (list);
Packit a6ee4b
    gst_uri_unref (uri);
Packit a6ee4b
  }
Packit a6ee4b
Packit a6ee4b
  for (i = 0; i < G_N_ELEMENTS (unparsable_uri_tests); i++) {
Packit a6ee4b
    GST_DEBUG ("Testing unparsable URI '%s'", unparsable_uri_tests[i]);
Packit a6ee4b
Packit a6ee4b
    uri = gst_uri_from_string (unparsable_uri_tests[i]);
Packit a6ee4b
    fail_unless (uri == NULL);
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
static const struct URITest url_presenting_tests[] = {
Packit a6ee4b
  /* check all URI elements present */
Packit a6ee4b
  {.uri = {"scheme", "user:pass", "host", 1234, "/path/to/dir",
Packit a6ee4b
          {{"query", NULL}, {"key", "value"}}, "fragment"},
Packit a6ee4b
      .str =
Packit a6ee4b
#if GLIB_CHECK_VERSION(2, 59, 0)
Packit a6ee4b
      "scheme://user:pass@host:1234/path/to/dir?key=value&query#fragment"},
Packit a6ee4b
#else
Packit a6ee4b
      "scheme://user:pass@host:1234/path/to/dir?query&key=value#fragment"},
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
  /* IPv6 literal should render in square brackets */
Packit a6ee4b
  {.uri = {"scheme", "user:pass", "12:34:56:78:9a:bc:de:f0", 1234,
Packit a6ee4b
          "/path/to/dir", {{"query", "value"}}, "fragment"},
Packit a6ee4b
      .str =
Packit a6ee4b
      "scheme://user:pass@[12:34:56:78:9a:bc:de:f0]:1234/path/to/dir?query=value#fragment"},
Packit a6ee4b
};
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_presenting)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *uri;
Packit a6ee4b
  gchar *result;
Packit a6ee4b
  guint i, j;
Packit a6ee4b
Packit a6ee4b
  for (i = 0; i < G_N_ELEMENTS (url_presenting_tests); i++) {
Packit a6ee4b
    uri = gst_uri_new (url_presenting_tests[i].uri.scheme,
Packit a6ee4b
        url_presenting_tests[i].uri.userinfo,
Packit a6ee4b
        url_presenting_tests[i].uri.host,
Packit a6ee4b
        url_presenting_tests[i].uri.port,
Packit a6ee4b
        url_presenting_tests[i].uri.path,
Packit a6ee4b
        NULL, url_presenting_tests[i].uri.fragment);
Packit a6ee4b
    fail_unless (uri != NULL);
Packit a6ee4b
    for (j = 0; j < 10; j++) {
Packit a6ee4b
      if (!url_presenting_tests[i].uri.query[j].key)
Packit a6ee4b
        break;
Packit a6ee4b
Packit a6ee4b
      fail_unless (gst_uri_set_query_value (uri,
Packit a6ee4b
              url_presenting_tests[i].uri.query[j].key,
Packit a6ee4b
              url_presenting_tests[i].uri.query[j].value));
Packit a6ee4b
    }
Packit a6ee4b
Packit a6ee4b
    result = gst_uri_to_string (uri);
Packit a6ee4b
    fail_unless_equals_string (result, url_presenting_tests[i].str);
Packit a6ee4b
    g_free (result);
Packit a6ee4b
    gst_uri_unref (uri);
Packit a6ee4b
  }
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_normalization)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *url;
Packit a6ee4b
  gchar *tmp_str;
Packit a6ee4b
Packit a6ee4b
  url =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("ScHeMe://User:P%61ss@HOST.%63om:1234/path/./from/../to%7d/item%2dobj?qu%65ry=something#fr%61gment");
Packit a6ee4b
  fail_unless (gst_uri_normalize (url));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_userinfo (url), "User:Pass");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url), "host.com");
Packit a6ee4b
  tmp_str = gst_uri_get_path (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/path/to}/item-obj");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  fail_unless (gst_uri_query_has_key (url, "query"));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_query_value (url, "query"),
Packit a6ee4b
      "something");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_fragment (url), "fragment");
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_joining)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *base, *rel, *joined;
Packit a6ee4b
  gchar *l;
Packit a6ee4b
Packit a6ee4b
  base =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("http://example.com/path/to/dir/filename.html#fragment");
Packit a6ee4b
Packit a6ee4b
  /* test change of fragment only */
Packit a6ee4b
  rel = gst_uri_from_string ("#new_frag");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/filename.html#new_frag");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test addition of new query string */
Packit a6ee4b
  rel = gst_uri_from_string ("?key=val");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/filename.html?key=val");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test new base filename */
Packit a6ee4b
  rel = gst_uri_from_string ("new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test relative file same directory */
Packit a6ee4b
  rel = gst_uri_from_string ("./new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test relative file parent directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test relative file grandparent directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../../new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/path/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test relative file root directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../../../new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test relative file beyond root directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../../../../new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test add subdirectory */
Packit a6ee4b
  rel = gst_uri_from_string ("subdir/new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/subdir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test change directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../subdir/new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/subdir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  gst_uri_unref (base);
Packit a6ee4b
Packit a6ee4b
  /* change base for path ending in directory */
Packit a6ee4b
  base = gst_uri_from_string ("http://example.com/path/to/dir/");
Packit a6ee4b
Packit a6ee4b
  /* test adding file to directory */
Packit a6ee4b
  rel = gst_uri_from_string ("new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test adding file to directory using relative path */
Packit a6ee4b
  rel = gst_uri_from_string ("./new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l,
Packit a6ee4b
      "http://example.com/path/to/dir/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test filename in parent directory */
Packit a6ee4b
  rel = gst_uri_from_string ("../new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test path ending in '../' */
Packit a6ee4b
  rel = gst_uri_from_string ("one/two/../");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test path ending in '..' Result should be the same as when ending in '../' */
Packit a6ee4b
  rel = gst_uri_from_string ("one/two/..");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "http://example.com/path/to/dir/one/");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  /* test replace with absolute */
Packit a6ee4b
  rel = gst_uri_from_string ("https://ssl.example.com/new_filename.xml");
Packit a6ee4b
  joined = gst_uri_join (base, rel);
Packit a6ee4b
  l = gst_uri_to_string (joined);
Packit a6ee4b
  fail_unless_equals_string (l, "https://ssl.example.com/new_filename.xml");
Packit a6ee4b
  g_free (l);
Packit a6ee4b
  gst_uri_unref (joined);
Packit a6ee4b
  gst_uri_unref (rel);
Packit a6ee4b
Packit a6ee4b
  gst_uri_unref (base);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_equality)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *url1, *url2;
Packit a6ee4b
Packit a6ee4b
  url1 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("ScHeMe://User:Pass@HOST.com:1234/path/./from/../to%7d/item%2dobj?query=something#fragment");
Packit a6ee4b
Packit a6ee4b
  /* equal */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (gst_uri_equal (url1, url2));
Packit a6ee4b
  fail_unless (gst_uri_equal (url2, url1));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different fragment */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#different-fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different query */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=different-something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different path */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/different-item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different port */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:4321/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different host */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@different-host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different userinfo */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://Different-User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different scheme */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("different+scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no scheme) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("//User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no userinfo) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://host.com:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no host) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@:1234/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no port) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com/path/to%7D/item-obj?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no path) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234?query=something#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no query) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj#fragment");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* different (no fragment) */
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_from_string
Packit a6ee4b
      ("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  /* compare two NULL uris */
Packit a6ee4b
  fail_unless (gst_uri_equal (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  /* compare same object */
Packit a6ee4b
  fail_unless (gst_uri_equal (url1, url1));
Packit a6ee4b
Packit a6ee4b
  /* compare one NULL and one non-NULL uri */
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, NULL));
Packit a6ee4b
  fail_unless (!gst_uri_equal (NULL, url1));
Packit a6ee4b
Packit a6ee4b
  gst_uri_unref (url1);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_constructors)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *url1, *url2;
Packit a6ee4b
  gchar *tmp_str;
Packit a6ee4b
  GHashTable *tmp_table;
Packit a6ee4b
Packit a6ee4b
  url1 =
Packit a6ee4b
      gst_uri_new ("scheme", "userinfo", "hostname", 1234, "/path/to/file",
Packit a6ee4b
      "query", "fragment");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url1), "scheme");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_userinfo (url1), "userinfo");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url1), "hostname");
Packit a6ee4b
  fail_unless (gst_uri_get_port (url1) == 1234);
Packit a6ee4b
  tmp_str = gst_uri_get_path (url1);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/path/to/file");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  tmp_table = gst_uri_get_query_table (url1);
Packit a6ee4b
  fail_unless (g_hash_table_size (tmp_table) == 1);
Packit a6ee4b
  fail_unless (g_hash_table_contains (tmp_table, "query"));
Packit a6ee4b
  fail_unless (g_hash_table_lookup (tmp_table, "query") == NULL);
Packit a6ee4b
  g_hash_table_unref (tmp_table);
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_fragment (url1), "fragment");
Packit a6ee4b
  tmp_str = gst_uri_to_string (url1);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "scheme://userinfo@hostname:1234/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  url2 =
Packit a6ee4b
      gst_uri_new_with_base (url1, NULL, NULL, NULL, GST_URI_NO_PORT,
Packit a6ee4b
      "new_file", NULL, NULL);
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
Packit a6ee4b
  fail_unless (gst_uri_get_port (url2) == 1234);
Packit a6ee4b
  tmp_str = gst_uri_get_path (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/path/to/new_file");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  fail_unless (gst_uri_get_query_table (url2) == NULL);
Packit a6ee4b
  fail_unless (gst_uri_get_fragment (url2) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "scheme://userinfo@hostname:1234/path/to/new_file");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  url2 = gst_uri_from_string_with_base (url1, "/a/new/path/to/file");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
Packit a6ee4b
  fail_unless (gst_uri_get_port (url2) == 1234);
Packit a6ee4b
  tmp_str = gst_uri_get_path (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/a/new/path/to/file");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  fail_unless (gst_uri_get_query_table (url2) == NULL);
Packit a6ee4b
  fail_unless (gst_uri_get_fragment (url2) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "scheme://userinfo@hostname:1234/a/new/path/to/file");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  url2 = gst_uri_from_string_with_base (url1, "http://foobar.com/bla");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url2), "http");
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url2), "foobar.com");
Packit a6ee4b
  fail_unless (gst_uri_get_port (url2) == 0);
Packit a6ee4b
  tmp_str = gst_uri_get_path (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/bla");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  fail_unless (gst_uri_get_query_table (url2) == NULL);
Packit a6ee4b
  fail_unless (gst_uri_get_fragment (url2) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url2);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "http://foobar.com/bla");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  url2 = gst_uri_copy (url1);
Packit a6ee4b
  fail_unless (gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_set_query_value (url2, "key", "value");
Packit a6ee4b
  fail_unless (!gst_uri_equal (url1, url2));
Packit a6ee4b
  gst_uri_unref (url2);
Packit a6ee4b
Packit a6ee4b
  gst_uri_unref (url1);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_get_set)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *url;
Packit a6ee4b
  gchar *tmp_str;
Packit a6ee4b
  GList *tmp_list;
Packit a6ee4b
Packit a6ee4b
  url = gst_uri_from_string ("scheme://hostname/path/to/file?query#fragment");
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_scheme (url, "new+scheme"));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_scheme (url), "new+scheme");
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "new+scheme://hostname/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_scheme (url, NULL));
Packit a6ee4b
  fail_unless (gst_uri_get_scheme (url) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_scheme (NULL, "fail"));
Packit a6ee4b
  fail_unless (gst_uri_set_scheme (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_userinfo (url, "username:password"));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_userinfo (url), "username:password");
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//username:password@hostname/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_userinfo (url, NULL));
Packit a6ee4b
  fail_unless (gst_uri_get_userinfo (url) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_userinfo (NULL, "fail"));
Packit a6ee4b
  fail_unless (gst_uri_set_userinfo (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_host (url, NULL));
Packit a6ee4b
  fail_unless (gst_uri_get_host (url) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str, "/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_host (url, "example.com"));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_host (url), "example.com");
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_host (NULL, "fail"));
Packit a6ee4b
  fail_unless (gst_uri_set_host (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_port (url, 12345));
Packit a6ee4b
  fail_unless (gst_uri_get_port (url) == 12345);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com:12345/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_port (url, GST_URI_NO_PORT));
Packit a6ee4b
  fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_port (NULL, 1234));
Packit a6ee4b
  fail_unless (gst_uri_set_port (NULL, GST_URI_NO_PORT));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_append_path_segment (url, "here"));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/here?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_append_path_segment (NULL, "fail"));
Packit a6ee4b
  fail_unless (gst_uri_append_path_segment (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_append_path (url, "../there"));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/here/../there?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_append_path (NULL, "fail"));
Packit a6ee4b
  fail_unless (gst_uri_append_path (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  gst_uri_normalize (url);
Packit a6ee4b
Packit a6ee4b
  tmp_list = gst_uri_get_path_segments (url);
Packit a6ee4b
  fail_unless (tmp_list != NULL);
Packit a6ee4b
  tmp_list = g_list_append (tmp_list, g_strdup ("segment"));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
  fail_unless (gst_uri_set_path_segments (url, tmp_list));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  tmp_list = g_list_append (NULL, g_strdup ("test"));
Packit a6ee4b
  fail_unless (!gst_uri_set_path_segments (NULL, tmp_list));
Packit a6ee4b
  fail_unless (gst_uri_set_path_segments (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_query_value (url, "key", "value"));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
#if GLIB_CHECK_VERSION(2, 59, 0)
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?key=value&query#fragment");
Packit a6ee4b
#else
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query&key=value#fragment");
Packit a6ee4b
#endif
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_query_value (url, "key", NULL));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
#if GLIB_CHECK_VERSION(2, 59, 0)
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?key&query#fragment");
Packit a6ee4b
#else
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query&key#fragment");
Packit a6ee4b
#endif
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_query_value (NULL, "key", "value"));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_remove_query_key (url, "key"));
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query#fragment");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_remove_query_key (url, "key"));
Packit a6ee4b
  fail_unless (!gst_uri_remove_query_key (NULL, "key"));
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_fragment (url, NULL));
Packit a6ee4b
  fail_unless (gst_uri_get_fragment (url) == NULL);
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (gst_uri_set_fragment (url, "tag"));
Packit a6ee4b
  fail_unless_equals_string (gst_uri_get_fragment (url), "tag");
Packit a6ee4b
  tmp_str = gst_uri_to_string (url);
Packit a6ee4b
  fail_unless_equals_string (tmp_str,
Packit a6ee4b
      "//example.com/path/to/file/there/segment?query#tag");
Packit a6ee4b
  g_free (tmp_str);
Packit a6ee4b
Packit a6ee4b
  fail_unless (!gst_uri_set_fragment (NULL, "can't set if no URI"));
Packit a6ee4b
  fail_unless (gst_uri_set_fragment (NULL, NULL));
Packit a6ee4b
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
GST_START_TEST (test_url_get_media_fragment_table)
Packit a6ee4b
{
Packit a6ee4b
  GstUri *url;
Packit a6ee4b
  gchar *val;
Packit a6ee4b
  GHashTable *table;
Packit a6ee4b
Packit a6ee4b
  /* Examples at https://www.w3.org/TR/media-frags/#processing-media-fragment-uri */
Packit a6ee4b
Packit a6ee4b
  /* TEST "t=1" */
Packit a6ee4b
  url = gst_uri_from_string ("http://foo/var/file#t=1");
Packit a6ee4b
  table = gst_uri_get_media_fragment_table (url);
Packit a6ee4b
  fail_unless (table);
Packit a6ee4b
  fail_unless (g_hash_table_size (table) == 1);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless_equals_string ("1", val);
Packit a6ee4b
  g_hash_table_unref (table);
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
Packit a6ee4b
  /* NOTE: Media Fragments URI 1.0 (W3C) is saying that
Packit a6ee4b
   * "Multiple occurrences of the same dimension: only the last valid occurrence
Packit a6ee4b
   *  of a dimension (e.g. t=10 in #t=2&t=10) is interpreted and all previous
Packit a6ee4b
   *  occurrences (valid or invalid) SHOULD be ignored by the user agent"
Packit a6ee4b
   */
Packit a6ee4b
  /* TEST "t=1&t=2" */
Packit a6ee4b
  url = gst_uri_from_string ("http://foo/var/file#t=1&t=2");
Packit a6ee4b
  table = gst_uri_get_media_fragment_table (url);
Packit a6ee4b
  fail_unless (table);
Packit a6ee4b
  fail_unless (g_hash_table_size (table) == 1);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless_equals_string ("2", val);
Packit a6ee4b
  g_hash_table_unref (table);
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
Packit a6ee4b
  /* TEST "a=b=c" */
Packit a6ee4b
  url = gst_uri_from_string ("http://foo/var/file#a=b=c");
Packit a6ee4b
  table = gst_uri_get_media_fragment_table (url);
Packit a6ee4b
  fail_unless (table);
Packit a6ee4b
  fail_unless (g_hash_table_size (table) == 1);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless_equals_string ("b=c", val);
Packit a6ee4b
  g_hash_table_unref (table);
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
Packit a6ee4b
  /* TEST "a&b=c" */
Packit a6ee4b
  url = gst_uri_from_string ("http://foo/var/file#a&b=c");
Packit a6ee4b
  table = gst_uri_get_media_fragment_table (url);
Packit a6ee4b
  fail_unless (table);
Packit a6ee4b
  fail_unless (g_hash_table_size (table) == 2);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "a", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless (val == NULL);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "b", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless_equals_string ("c", val);
Packit a6ee4b
  g_hash_table_unref (table);
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
Packit a6ee4b
  /* TEST "%74=%6ept%3A%310" */
Packit a6ee4b
  url = gst_uri_from_string ("http://foo/var/file#%74=%6ept%3A%310");
Packit a6ee4b
  table = gst_uri_get_media_fragment_table (url);
Packit a6ee4b
  fail_unless (table);
Packit a6ee4b
  fail_unless (g_hash_table_size (table) == 1);
Packit a6ee4b
  fail_unless (g_hash_table_lookup_extended (table, "t", NULL,
Packit a6ee4b
          (gpointer) & val));
Packit a6ee4b
  fail_unless_equals_string ("npt:10", val);
Packit a6ee4b
  g_hash_table_unref (table);
Packit a6ee4b
  gst_uri_unref (url);
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_END_TEST;
Packit a6ee4b
Packit a6ee4b
static Suite *
Packit a6ee4b
gst_uri_suite (void)
Packit a6ee4b
{
Packit a6ee4b
  Suite *s = suite_create ("GstURI");
Packit a6ee4b
  TCase *tc_chain = tcase_create ("uri");
Packit a6ee4b
Packit a6ee4b
  tcase_set_timeout (tc_chain, 20);
Packit a6ee4b
Packit a6ee4b
  suite_add_tcase (s, tc_chain);
Packit a6ee4b
  tcase_add_test (tc_chain, test_protocol_case);
Packit a6ee4b
  tcase_add_test (tc_chain, test_uri_get_location);
Packit a6ee4b
#ifndef GST_REMOVE_DEPRECATED
Packit a6ee4b
  tcase_add_test (tc_chain, test_gst_uri_construct);
Packit a6ee4b
#endif
Packit a6ee4b
  tcase_add_test (tc_chain, test_uri_misc);
Packit a6ee4b
  tcase_add_test (tc_chain, test_element_make_from_uri);
Packit a6ee4b
#ifdef G_OS_WIN32
Packit a6ee4b
  tcase_add_test (tc_chain, test_win32_uri);
Packit a6ee4b
#endif
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_parsing);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_presenting);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_normalization);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_joining);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_equality);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_constructors);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_get_set);
Packit a6ee4b
  tcase_add_test (tc_chain, test_url_get_media_fragment_table);
Packit a6ee4b
Packit a6ee4b
  return s;
Packit a6ee4b
}
Packit a6ee4b
Packit a6ee4b
GST_CHECK_MAIN (gst_uri);