Blame tests/check/libs/profile.c

Packit 971217
/* GStreamer unit test for gstprofile
Packit 971217
 *
Packit 971217
 * Copyright (C) <2009> Edward Hervey <edward.hervey@collabora.co.uk>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <glib.h>
Packit 971217
#include <glib/gstdio.h>
Packit 971217
#include <gst/check/gstcheck.h>
Packit 971217
Packit 971217
#include <gst/pbutils/encoding-profile.h>
Packit 971217
#include <gst/pbutils/encoding-target.h>
Packit 971217
Packit 971217
#ifdef G_OS_UNIX
Packit 971217
#include <unistd.h>             /* For R_OK etc. */
Packit 971217
#endif
Packit 971217
Packit 971217
static inline gboolean
Packit 971217
gst_caps_is_equal_unref (GstCaps * caps1, GstCaps * caps2)
Packit 971217
{
Packit 971217
  gboolean ret;
Packit 971217
Packit 971217
  ret = gst_caps_is_equal (caps1, caps2);
Packit 971217
  gst_caps_unref (caps1);
Packit 971217
Packit 971217
  return ret;
Packit 971217
}
Packit 971217
Packit 971217
#define CHECK_PROFILE(profile, name, description, format, preset, presence, restriction) \
Packit 971217
  {									\
Packit 971217
  fail_if(profile == NULL);						\
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_name (profile), name); \
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_description (profile), description); \
Packit 971217
  fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_format (profile), format)); \
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_preset (profile), preset); \
Packit 971217
  fail_unless_equals_int (gst_encoding_profile_get_presence (profile), presence); \
Packit 971217
  if (restriction) \
Packit 971217
    fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_restriction (profile), restriction)); \
Packit 971217
  }
Packit 971217
Packit 971217
GST_START_TEST (test_profile_creation)
Packit 971217
{
Packit 971217
  GstEncodingProfile *encprof;
Packit 971217
  GstEncodingAudioProfile *audioprof;
Packit 971217
  GstEncodingVideoProfile *videoprof;
Packit 971217
  GstCaps *ogg, *vorbis, *theora;
Packit 971217
  GstCaps *test1, *test2;
Packit 971217
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  theora = gst_caps_new_empty_simple ("video/x-theora");
Packit 971217
Packit 971217
  encprof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
Packit 971217
      "ogg-theora-vorbis", "dumb-profile", ogg, (gchar *) "dumb-preset");
Packit 971217
  CHECK_PROFILE (encprof, "ogg-theora-vorbis", "dumb-profile", ogg,
Packit 971217
      "dumb-preset", 0, NULL);
Packit 971217
Packit 971217
  audioprof = gst_encoding_audio_profile_new (vorbis, (gchar *) "HQ", NULL, 0);
Packit 971217
  CHECK_PROFILE ((GstEncodingProfile *) audioprof, NULL, NULL, vorbis, "HQ", 0,
Packit 971217
      NULL);
Packit 971217
Packit 971217
  videoprof = gst_encoding_video_profile_new (theora, (gchar *) "HQ", NULL, 0);
Packit 971217
  CHECK_PROFILE ((GstEncodingProfile *) videoprof, NULL, NULL, theora, "HQ",
Packit 971217
      0, NULL);
Packit 971217
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (
Packit 971217
          (GstEncodingContainerProfile *) encprof,
Packit 971217
          (GstEncodingProfile *) audioprof));
Packit 971217
  fail_unless (gst_encoding_container_profile_add_profile (
Packit 971217
          (GstEncodingContainerProfile *) encprof,
Packit 971217
          (GstEncodingProfile *) videoprof));
Packit 971217
Packit 971217
  /* Test caps */
Packit 971217
  test1 = gst_caps_from_string ("video/x-theora; audio/x-vorbis");
Packit 971217
  test2 = gst_encoding_profile_get_input_caps (encprof);
Packit 971217
  fail_unless (gst_caps_is_equal (test1, test2));
Packit 971217
  gst_caps_unref (test1);
Packit 971217
  gst_caps_unref (test2);
Packit 971217
Packit 971217
  gst_encoding_profile_unref (encprof);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
  gst_caps_unref (theora);
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_profile_input_caps)
Packit 971217
{
Packit 971217
  GstEncodingProfile *sprof;
Packit 971217
  GstCaps *vorbis;
Packit 971217
  GstCaps *out, *restriction, *test1;
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
Packit 971217
  /* Simple case, no restriction */
Packit 971217
  sprof = (GstEncodingProfile *)
Packit 971217
      gst_encoding_audio_profile_new (vorbis, NULL, NULL, 0);
Packit 971217
  fail_if (sprof == NULL);
Packit 971217
Packit 971217
  out = gst_encoding_profile_get_input_caps (sprof);
Packit 971217
  fail_if (out == NULL);
Packit 971217
  fail_unless (gst_caps_is_equal (out, vorbis));
Packit 971217
  gst_caps_unref (out);
Packit 971217
  gst_encoding_profile_unref (sprof);
Packit 971217
Packit 971217
  /* One simple restriction */
Packit 971217
  restriction = gst_caps_from_string ("audio/x-raw,channels=2,rate=44100");
Packit 971217
  test1 = gst_caps_from_string ("audio/x-vorbis,channels=2,rate=44100");
Packit 971217
  fail_if (restriction == NULL);
Packit 971217
Packit 971217
  sprof = (GstEncodingProfile *)
Packit 971217
      gst_encoding_audio_profile_new (vorbis, NULL, restriction, 0);
Packit 971217
  fail_if (sprof == NULL);
Packit 971217
Packit 971217
  out = gst_encoding_profile_get_input_caps (sprof);
Packit 971217
  fail_if (out == NULL);
Packit 971217
  GST_DEBUG ("got caps %" GST_PTR_FORMAT, out);
Packit 971217
  fail_unless (gst_caps_is_equal (out, test1));
Packit 971217
  gst_caps_unref (out);
Packit 971217
  gst_caps_unref (restriction);
Packit 971217
  gst_caps_unref (test1);
Packit 971217
  gst_encoding_profile_unref (sprof);
Packit 971217
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_target_naming)
Packit 971217
{
Packit 971217
  GstEncodingTarget *target;
Packit 971217
Packit 971217
  gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
Packit 971217
Packit 971217
  /* NULL values */
Packit 971217
  ASSERT_CRITICAL (target = gst_encoding_target_new (NULL, NULL, NULL, NULL));
Packit 971217
  fail_if (target != NULL);
Packit 971217
  ASSERT_CRITICAL (target =
Packit 971217
      gst_encoding_target_new ("donkey", NULL, NULL, NULL));
Packit 971217
  fail_if (target != NULL);
Packit 971217
  ASSERT_CRITICAL (target =
Packit 971217
      gst_encoding_target_new (NULL, "donkey", NULL, NULL));
Packit 971217
  fail_if (target != NULL);
Packit 971217
  ASSERT_CRITICAL (target =
Packit 971217
      gst_encoding_target_new (NULL, NULL, "donkey", NULL));
Packit 971217
  fail_if (target != NULL);
Packit 971217
Packit 971217
  /* Name and Category validation */
Packit 971217
Packit 971217
  /* empty non-NULL strings */
Packit 971217
  fail_if (gst_encoding_target_new ("", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "", "description", NULL) != NULL);
Packit 971217
Packit 971217
  /* don't start with a lower case ASCII character */
Packit 971217
  fail_if (gst_encoding_target_new ("A", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("3", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("-", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("!", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new (" ", "valid", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "A", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "3", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "-", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "!", "description", NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", " ", "description", NULL) != NULL);
Packit 971217
Packit 971217
  /* Starting with anything else is valid */
Packit 971217
  target = gst_encoding_target_new ("a", "valid", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
  target = gst_encoding_target_new ("z", "valid", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
  target = gst_encoding_target_new ("valid", "a", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
  target = gst_encoding_target_new ("valid", "z", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
Packit 971217
  /* only inner valid characters are lower-case ASCII letters *OR* digits *OR* hyphens */
Packit 971217
  fail_if (gst_encoding_target_new ("aA", "valid", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("a!", "valid", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("space donkeys", "valid", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("howaboutùnicode", "valid", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "aA", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
  fail_if (gst_encoding_target_new ("valid", "a!", "description",
Packit 971217
          NULL) != NULL);
Packit 971217
Packit 971217
  target =
Packit 971217
      gst_encoding_target_new ("donkey-4-ever", "valid", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
  target =
Packit 971217
      gst_encoding_target_new ("valid", "donkey-4-ever", "description", NULL);
Packit 971217
  fail_if (target == NULL);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static GstEncodingTarget *
Packit 971217
create_saveload_target (const gchar * targetname)
Packit 971217
{
Packit 971217
  GstEncodingTarget *target;
Packit 971217
  GstEncodingProfile *profile, *sprof;
Packit 971217
  GstCaps *caps, *caps2;
Packit 971217
Packit 971217
  GST_DEBUG ("Creating target");
Packit 971217
Packit 971217
  target = gst_encoding_target_new (targetname, "herding",
Packit 971217
      "Plenty of pony glitter profiles", NULL);
Packit 971217
  caps = gst_caps_from_string ("animal/x-pony");
Packit 971217
  profile =
Packit 971217
      (GstEncodingProfile *) gst_encoding_container_profile_new ("pony",
Packit 971217
      "I don't want a description !", caps, NULL);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
  gst_encoding_target_add_profile (target, profile);
Packit 971217
Packit 971217
  caps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
Packit 971217
  caps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
Packit 971217
  sprof =
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, caps2,
Packit 971217
      1);
Packit 971217
  gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
Packit 971217
      profile, sprof);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
  gst_caps_unref (caps2);
Packit 971217
Packit 971217
  caps = gst_caps_from_string ("video/x-glitter,sparkling=True");
Packit 971217
  caps2 =
Packit 971217
      gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
Packit 971217
  sprof = (GstEncodingProfile *)
Packit 971217
      gst_encoding_video_profile_new (caps, "seriously glittery", caps2, 0);
Packit 971217
  gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
Packit 971217
      sprof, TRUE);
Packit 971217
  gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
Packit 971217
      profile, sprof);
Packit 971217
  gst_caps_unref (caps);
Packit 971217
  gst_caps_unref (caps2);
Packit 971217
Packit 971217
  return target;
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_target_profile)
Packit 971217
{
Packit 971217
  GstEncodingTarget *target;
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
Packit 971217
  target = create_saveload_target ("myponytarget");
Packit 971217
Packit 971217
  /* NULL isn't a valid profile name */
Packit 971217
  ASSERT_CRITICAL (gst_encoding_target_get_profile (target, NULL));
Packit 971217
Packit 971217
  /* try finding a profile that doesn't exist */
Packit 971217
  fail_if (gst_encoding_target_get_profile (target,
Packit 971217
          "no-really-does-not-exist"));
Packit 971217
Packit 971217
  /* try finding a profile that exists */
Packit 971217
  prof = gst_encoding_target_get_profile (target, "pony");
Packit 971217
  fail_if (prof == NULL);
Packit 971217
Packit 971217
  gst_encoding_profile_unref (prof);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_saving_profile)
Packit 971217
{
Packit 971217
  GstEncodingTarget *orig, *loaded = NULL;
Packit 971217
  GstEncodingProfile *proforig, *profloaded;
Packit 971217
  gchar *profile_file_name;
Packit 971217
Packit 971217
  /* Create and store a target */
Packit 971217
  orig = create_saveload_target ("myponytarget2");
Packit 971217
  GST_DEBUG ("Saving target 'myponytarget2'");
Packit 971217
  fail_unless (gst_encoding_target_save (orig, NULL));
Packit 971217
Packit 971217
  /* Check we can load it */
Packit 971217
  profile_file_name =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", "myponytarget2.gep", NULL);
Packit 971217
  GST_DEBUG ("Loading target from '%s'", profile_file_name);
Packit 971217
  loaded = gst_encoding_target_load_from_file (profile_file_name, NULL);
Packit 971217
  fail_unless (loaded != NULL);
Packit 971217
  g_free (profile_file_name);
Packit 971217
Packit 971217
  GST_DEBUG ("Checking targets are equal");
Packit 971217
  /* Check targets are identical */
Packit 971217
  /* 1. at the target level */
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_name (orig),
Packit 971217
      gst_encoding_target_get_name (loaded));
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_category (orig),
Packit 971217
      gst_encoding_target_get_category (loaded));
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_description (orig),
Packit 971217
      gst_encoding_target_get_description (loaded));
Packit 971217
  fail_unless_equals_int (g_list_length ((GList *)
Packit 971217
          gst_encoding_target_get_profiles (loaded)), 1);
Packit 971217
Packit 971217
  /* 2. at the profile level */
Packit 971217
  profloaded =
Packit 971217
      (GstEncodingProfile *) gst_encoding_target_get_profiles (loaded)->data;
Packit 971217
  proforig =
Packit 971217
      (GstEncodingProfile *) gst_encoding_target_get_profiles (orig)->data;
Packit 971217
Packit 971217
  fail_unless_equals_int (G_TYPE_FROM_INSTANCE (profloaded),
Packit 971217
      G_TYPE_FROM_INSTANCE (proforig));
Packit 971217
  GST_DEBUG ("Comparing loaded:%p to original:%p", profloaded, proforig);
Packit 971217
  fail_unless (gst_encoding_profile_is_equal (profloaded, proforig));
Packit 971217
Packit 971217
  gst_encoding_target_unref (orig);
Packit 971217
  gst_encoding_target_unref (loaded);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static void
Packit 971217
test_individual_target (GstEncodingTarget * target)
Packit 971217
{
Packit 971217
  GstEncodingProfile *prof;
Packit 971217
  GstCaps *tmpcaps, *tmpcaps2;
Packit 971217
  GstEncodingProfile *sprof1, *sprof2;
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the target properties");
Packit 971217
  /* Check the target  */
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_name (target),
Packit 971217
      "myponytarget");
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_category (target),
Packit 971217
      "herding");
Packit 971217
  fail_unless_equals_string (gst_encoding_target_get_description (target),
Packit 971217
      "Plenty of pony glitter profiles");
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the number of profiles the target contains");
Packit 971217
  fail_unless_equals_int (g_list_length ((GList *)
Packit 971217
          gst_encoding_target_get_profiles (target)), 1);
Packit 971217
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the container profile");
Packit 971217
  /* Check the profile */
Packit 971217
  prof = (GstEncodingProfile *) gst_encoding_target_get_profiles (target)->data;
Packit 971217
  tmpcaps = gst_caps_from_string ("animal/x-pony");
Packit 971217
  CHECK_PROFILE (prof, "pony", "I don't want a description !", tmpcaps, NULL, 0,
Packit 971217
      0);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the container profile has 2 stream profiles");
Packit 971217
  /* Check the stream profiles */
Packit 971217
  fail_unless_equals_int (g_list_length ((GList *)
Packit 971217
          gst_encoding_container_profile_get_profiles (
Packit 971217
              (GstEncodingContainerProfile *) prof)), 2);
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the container profile has the audio/x-pony-song stream");
Packit 971217
  tmpcaps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
Packit 971217
  tmpcaps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
Packit 971217
  sprof1 =
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (tmpcaps, NULL,
Packit 971217
      tmpcaps2, 1);
Packit 971217
  fail_unless (gst_encoding_container_profile_contains_profile (
Packit 971217
          (GstEncodingContainerProfile *) prof, sprof1));
Packit 971217
  gst_encoding_profile_unref (sprof1);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
  gst_caps_unref (tmpcaps2);
Packit 971217
Packit 971217
  GST_DEBUG ("Checking the container profile has the video//x-glitter stream");
Packit 971217
  tmpcaps = gst_caps_from_string ("video/x-glitter,sparkling=True");
Packit 971217
  tmpcaps2 =
Packit 971217
      gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
Packit 971217
  sprof2 = (GstEncodingProfile *)
Packit 971217
      gst_encoding_video_profile_new (tmpcaps, "seriously glittery", tmpcaps2,
Packit 971217
      0);
Packit 971217
  gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
Packit 971217
      sprof2, TRUE);
Packit 971217
  fail_unless (gst_encoding_container_profile_contains_profile (
Packit 971217
          (GstEncodingContainerProfile *) prof, sprof2));
Packit 971217
  gst_encoding_profile_unref (sprof2);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
  gst_caps_unref (tmpcaps2);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_loading_profile)
Packit 971217
{
Packit 971217
  GstEncodingTarget *target;
Packit 971217
  gchar *profile_file_name;
Packit 971217
  GstEncodingProfile *profile;
Packit 971217
  GstCaps *tmpcaps;
Packit 971217
  GValue strvalue = { 0, };
Packit 971217
  GValue objectvalue = { 0, };
Packit 971217
Packit 971217
  gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
Packit 971217
Packit 971217
  /* Test loading using short method and all arguments */
Packit 971217
  target = gst_encoding_target_load ("myponytarget", "herding", NULL);
Packit 971217
  fail_unless (target != NULL);
Packit 971217
  test_individual_target (target);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
Packit 971217
  /* Test loading using short method and no category */
Packit 971217
  target = gst_encoding_target_load ("myponytarget", NULL, NULL);
Packit 971217
  fail_unless (target != NULL);
Packit 971217
  test_individual_target (target);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
Packit 971217
  /* Test loading using fully specified path */
Packit 971217
  profile_file_name =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", "myponytarget.gep", NULL);
Packit 971217
Packit 971217
  GST_DEBUG ("Loading target from '%s'", profile_file_name);
Packit 971217
  target = gst_encoding_target_load_from_file (profile_file_name, NULL);
Packit 971217
  g_free (profile_file_name);
Packit 971217
  fail_unless (target != NULL);
Packit 971217
  test_individual_target (target);
Packit 971217
  gst_encoding_target_unref (target);
Packit 971217
Packit 971217
  /* Test getting the profiles directly
Packit 971217
   * First without category */
Packit 971217
  profile = gst_encoding_profile_find ("myponytarget", "pony", NULL);
Packit 971217
  fail_unless (profile != NULL);
Packit 971217
  tmpcaps = gst_caps_from_string ("animal/x-pony");
Packit 971217
  CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
Packit 971217
      0, 0);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
  gst_encoding_profile_unref (profile);
Packit 971217
Packit 971217
  /* Then with a specific category */
Packit 971217
  profile = gst_encoding_profile_find ("myponytarget", "pony", "herding");
Packit 971217
  fail_unless (profile != NULL);
Packit 971217
  tmpcaps = gst_caps_from_string ("animal/x-pony");
Packit 971217
  CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
Packit 971217
      0, 0);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
  gst_encoding_profile_unref (profile);
Packit 971217
Packit 971217
  /* For my next trick, I will need the assistance of a GValue */
Packit 971217
  g_value_init (&strvalue, G_TYPE_STRING);
Packit 971217
  g_value_init (&objectvalue, GST_TYPE_ENCODING_PROFILE);
Packit 971217
  g_value_set_static_string (&strvalue, "myponytarget/pony");
Packit 971217
  fail_unless (g_value_transform (&strvalue, &objectvalue));
Packit 971217
  profile = (GstEncodingProfile *) g_value_dup_object (&objectvalue);
Packit 971217
  fail_if (profile == NULL);
Packit 971217
  g_value_unset (&strvalue);
Packit 971217
  g_value_unset (&objectvalue);
Packit 971217
  tmpcaps = gst_caps_from_string ("animal/x-pony");
Packit 971217
  CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
Packit 971217
      0, 0);
Packit 971217
  gst_caps_unref (tmpcaps);
Packit 971217
  gst_encoding_profile_unref (profile);
Packit 971217
Packit 971217
  /* Let's go crazy for error detection */
Packit 971217
  fail_if (gst_encoding_profile_find ("myponytarget", "whales", NULL));
Packit 971217
  fail_if (gst_encoding_profile_find ("myponytarget", "whales", "herding"));
Packit 971217
  fail_if (gst_encoding_profile_find ("myponytarget", "", NULL));
Packit 971217
  fail_if (gst_encoding_profile_find ("", "pony", NULL));
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
GST_START_TEST (test_target_list)
Packit 971217
{
Packit 971217
  GList *categories;
Packit 971217
  GList *targets;
Packit 971217
  GList *tmp;
Packit 971217
Packit 971217
  /* Make sure we get our test category in the available categories */
Packit 971217
  categories = gst_encoding_list_available_categories ();
Packit 971217
  fail_if (categories == NULL);
Packit 971217
  fail_if (g_list_find_custom (categories, "herding",
Packit 971217
          (GCompareFunc) g_strcmp0) == NULL);
Packit 971217
  g_list_foreach (categories, (GFunc) g_free, NULL);
Packit 971217
  g_list_free (categories);
Packit 971217
Packit 971217
  /* Try getting all available targets with a specified category */
Packit 971217
  targets = gst_encoding_list_all_targets ("herding");
Packit 971217
  fail_if (targets == NULL);
Packit 971217
  for (tmp = targets; tmp; tmp = tmp->next) {
Packit 971217
    GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
Packit 971217
    if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
Packit 971217
      break;
Packit 971217
  }
Packit 971217
  /* If tmp is NULL, it means we iterated the whole list without finding
Packit 971217
   * our target */
Packit 971217
  fail_if (tmp == NULL);
Packit 971217
  g_list_foreach (targets, (GFunc) g_object_unref, NULL);
Packit 971217
  g_list_free (targets);
Packit 971217
Packit 971217
  /* Try getting all available targets without a specified category */
Packit 971217
  targets = gst_encoding_list_all_targets (NULL);
Packit 971217
  fail_if (targets == NULL);
Packit 971217
  for (tmp = targets; tmp; tmp = tmp->next) {
Packit 971217
    GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
Packit 971217
    if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
Packit 971217
      break;
Packit 971217
  }
Packit 971217
  /* If tmp is NULL, it means we iterated the whole list without finding
Packit 971217
   * our target */
Packit 971217
  fail_if (tmp == NULL);
Packit 971217
  g_list_foreach (targets, (GFunc) g_object_unref, NULL);
Packit 971217
  g_list_free (targets);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
static const gchar *profile_string = "\
Packit 971217
[GStreamer Encoding Target]\n\
Packit 971217
name=myponytarget\n\
Packit 971217
category=herding\n\
Packit 971217
description=Plenty of pony glitter profiles\n\
Packit 971217
\n\
Packit 971217
[profile-pony1]\n\
Packit 971217
name=pony\n\
Packit 971217
type=container\n\
Packit 971217
description=I don't want a description !\n\
Packit 971217
format=animal/x-pony\n\
Packit 971217
\n\
Packit 971217
[streamprofile-pony11]\n\
Packit 971217
parent=pony\n\
Packit 971217
type=audio\n\
Packit 971217
format=audio/x-pony-song,pretty=True\n\
Packit 971217
restriction=audio/x-raw,channels=1,rate=44100\n\
Packit 971217
presence=1\n\
Packit 971217
\n\
Packit 971217
[streamprofile-pony12]\n\
Packit 971217
parent=pony\n\
Packit 971217
type=video\n\
Packit 971217
preset=seriously glittery\n\
Packit 971217
format=video/x-glitter,sparkling=True\n\
Packit 971217
restriction=video/x-raw,width=640,height=480,framerate=15/1\n\
Packit 971217
presence=0\n\
Packit 971217
variableframerate=true\n\
Packit 971217
";
Packit 971217
Packit 971217
static void
Packit 971217
remove_profile_file (void)
Packit 971217
{
Packit 971217
  gchar *profile_file_name;
Packit 971217
Packit 971217
  profile_file_name =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", "myponytarget.gep", NULL);
Packit 971217
  g_unlink (profile_file_name);
Packit 971217
  g_free (profile_file_name);
Packit 971217
  profile_file_name =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", "myponytarget2.gep", NULL);
Packit 971217
  g_unlink (profile_file_name);
Packit 971217
  g_free (profile_file_name);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
create_profile_file (void)
Packit 971217
{
Packit 971217
  gchar *profile_file_name;
Packit 971217
  gchar *profile_dir;
Packit 971217
  GError *error = NULL;
Packit 971217
Packit 971217
  profile_dir =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", NULL);
Packit 971217
  profile_file_name =
Packit 971217
      g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
Packit 971217
      "encoding-profiles", "herding", "myponytarget.gep", NULL);
Packit 971217
Packit 971217
  /* on Windows it will ignore the mode anyway */
Packit 971217
#ifdef G_OS_WIN32
Packit 971217
  g_mkdir_with_parents (profile_dir, 0700);
Packit 971217
#else
Packit 971217
  g_mkdir_with_parents (profile_dir, S_IRUSR | S_IWUSR | S_IXUSR);
Packit 971217
#endif
Packit 971217
Packit 971217
  if (!g_file_set_contents (profile_file_name, profile_string,
Packit 971217
          strlen (profile_string), &error))
Packit 971217
    GST_WARNING ("Couldn't write contents to file : %s", error->message);
Packit 971217
  g_free (profile_dir);
Packit 971217
  g_free (profile_file_name);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
test_setup (void)
Packit 971217
{
Packit 971217
  create_profile_file ();
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
test_teardown (void)
Packit 971217
{
Packit 971217
  remove_profile_file ();
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_file_extension)
Packit 971217
{
Packit 971217
  GstEncodingContainerProfile *cprof;
Packit 971217
  GstCaps *ogg, *speex, *vorbis, *theora, *id3, *mp3;
Packit 971217
Packit 971217
  /* 1 - ogg variants */
Packit 971217
  ogg = gst_caps_new_empty_simple ("application/ogg");
Packit 971217
  cprof = gst_encoding_container_profile_new ("myprofile", NULL, ogg, NULL);
Packit 971217
  gst_caps_unref (ogg);
Packit 971217
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_file_extension
Packit 971217
      (GST_ENCODING_PROFILE (cprof)), "ogg");
Packit 971217
Packit 971217
  speex = gst_caps_new_empty_simple ("audio/x-speex");
Packit 971217
  gst_encoding_container_profile_add_profile (cprof,
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (speex, NULL,
Packit 971217
          NULL, 1));
Packit 971217
  gst_caps_unref (speex);
Packit 971217
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_file_extension
Packit 971217
      (GST_ENCODING_PROFILE (cprof)), "spx");
Packit 971217
Packit 971217
  vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
Packit 971217
  gst_encoding_container_profile_add_profile (cprof,
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, NULL,
Packit 971217
          NULL, 1));
Packit 971217
  gst_caps_unref (vorbis);
Packit 971217
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_file_extension
Packit 971217
      (GST_ENCODING_PROFILE (cprof)), "ogg");
Packit 971217
Packit 971217
  theora = gst_caps_new_empty_simple ("video/x-theora");
Packit 971217
  gst_encoding_container_profile_add_profile (cprof,
Packit 971217
      (GstEncodingProfile *) gst_encoding_video_profile_new (theora, NULL,
Packit 971217
          NULL, 1));
Packit 971217
  gst_caps_unref (theora);
Packit 971217
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_file_extension
Packit 971217
      (GST_ENCODING_PROFILE (cprof)), "ogv");
Packit 971217
Packit 971217
  gst_encoding_profile_unref (cprof);
Packit 971217
Packit 971217
  /* 2 - tag container */
Packit 971217
  id3 = gst_caps_new_empty_simple ("application/x-id3");
Packit 971217
  cprof = gst_encoding_container_profile_new ("myprofile", NULL, id3, NULL);
Packit 971217
  gst_caps_unref (id3);
Packit 971217
Packit 971217
  fail_unless (gst_encoding_profile_get_file_extension (GST_ENCODING_PROFILE
Packit 971217
          (cprof)) == NULL);
Packit 971217
Packit 971217
  mp3 = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
Packit 971217
      "layer", G_TYPE_INT, 3, NULL);
Packit 971217
  gst_encoding_container_profile_add_profile (cprof,
Packit 971217
      (GstEncodingProfile *) gst_encoding_audio_profile_new (mp3, NULL,
Packit 971217
          NULL, 1));
Packit 971217
  gst_caps_unref (mp3);
Packit 971217
Packit 971217
  fail_unless_equals_string (gst_encoding_profile_get_file_extension
Packit 971217
      (GST_ENCODING_PROFILE (cprof)), "mp3");
Packit 971217
Packit 971217
  gst_encoding_profile_unref (cprof);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static Suite *
Packit 971217
profile_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("profile support library");
Packit 971217
  TCase *tc_chain = tcase_create ("general");
Packit 971217
  gboolean can_write;
Packit 971217
  gchar *gst_dir;
Packit 971217
Packit 971217
  /* cehck if we can create profiles */
Packit 971217
#ifdef G_OS_UNIX
Packit 971217
  gst_dir = g_build_filename (g_get_user_data_dir (), "gstreamer-1.0", NULL);
Packit 971217
  can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
Packit 971217
  g_free (gst_dir);
Packit 971217
#else
Packit 971217
  can_write = FALSE;            /* FIXME: fix can_write test on Windows */
Packit 971217
#endif
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
Packit 971217
  tcase_add_test (tc_chain, test_profile_creation);
Packit 971217
  tcase_add_test (tc_chain, test_profile_input_caps);
Packit 971217
  tcase_add_test (tc_chain, test_target_naming);
Packit 971217
  tcase_add_test (tc_chain, test_target_profile);
Packit 971217
  tcase_add_test (tc_chain, test_file_extension);
Packit 971217
  if (can_write) {
Packit 971217
    tcase_add_test (tc_chain, test_loading_profile);
Packit 971217
    tcase_add_test (tc_chain, test_saving_profile);
Packit 971217
    tcase_add_test (tc_chain, test_target_list);
Packit 971217
  }
Packit 971217
Packit 971217
  tcase_add_unchecked_fixture (tc_chain, test_setup, test_teardown);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (profile);