Blame tests/check/libs/xmpwriter.c

Packit 971217
/* GStreamer
Packit 971217
 *
Packit 971217
 * unit tests for xmp config library
Packit 971217
 *
Packit 971217
 * Copyright (C) 2011 Thiago Santos <thiago.sousa.santos@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 <gst/check/gstcheck.h>
Packit 971217
Packit 971217
#include <gst/tag/tag.h>
Packit 971217
#include <gst/tag/xmpwriter.h>
Packit 971217
Packit 971217
#include <string.h>
Packit 971217
Packit 971217
#define TEST_ELEMENT_TYPE (test_element_get_type())
Packit 971217
Packit 971217
typedef struct TestElement TestElement;
Packit 971217
typedef struct TestElementClass TestElementClass;
Packit 971217
Packit 971217
struct TestElement
Packit 971217
{
Packit 971217
  GstElement parent;
Packit 971217
};
Packit 971217
Packit 971217
struct TestElementClass
Packit 971217
{
Packit 971217
  GstElementClass parent_class;
Packit 971217
};
Packit 971217
Packit 971217
GType test_element_get_type (void);
Packit 971217
Packit 971217
static void init_interface (GType type);
Packit 971217
Packit 971217
G_DEFINE_TYPE_WITH_CODE (TestElement, test_element, GST_TYPE_ELEMENT,
Packit 971217
    init_interface (g_define_type_id));
Packit 971217
Packit 971217
static void
Packit 971217
init_interface (GType type)
Packit 971217
{
Packit 971217
  static const GInterfaceInfo tagxmpwriter_info = {
Packit 971217
    NULL,
Packit 971217
    NULL,
Packit 971217
    NULL,
Packit 971217
  };
Packit 971217
Packit 971217
  g_type_add_interface_static (type, GST_TYPE_TAG_XMP_WRITER,
Packit 971217
      &tagxmpwriter_info);
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
test_element_class_init (TestElementClass * klass)
Packit 971217
{
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
test_element_init (TestElement * this)
Packit 971217
{
Packit 971217
}
Packit 971217
Packit 971217
static gboolean
Packit 971217
gst_buffer_equals (GstBuffer * buf_a, GstBuffer * buf_b)
Packit 971217
{
Packit 971217
  gboolean res;
Packit 971217
  GstMapInfo map1, map2;
Packit 971217
Packit 971217
  gst_buffer_map (buf_a, &map1, GST_MAP_READ);
Packit 971217
  gst_buffer_map (buf_b, &map2, GST_MAP_READ);
Packit 971217
Packit 971217
  if (map1.size == map2.size) {
Packit 971217
    res = memcmp (map1.data, map2.data, map1.size) == 0;
Packit 971217
  } else {
Packit 971217
    res = FALSE;
Packit 971217
  }
Packit 971217
  gst_buffer_unmap (buf_a, &map1;;
Packit 971217
  gst_buffer_unmap (buf_b, &map2;;
Packit 971217
Packit 971217
  return res;
Packit 971217
}
Packit 971217
Packit 971217
static GstTagList *
Packit 971217
create_taglist (void)
Packit 971217
{
Packit 971217
  return gst_tag_list_new (GST_TAG_ARTIST, "artist",
Packit 971217
      GST_TAG_TITLE, "title", GST_TAG_COPYRIGHT, "copyright", NULL);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_no_xmp)
Packit 971217
{
Packit 971217
  GstTagList *taglist = create_taglist ();
Packit 971217
  GstElement *test_element =
Packit 971217
      (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
Packit 971217
Packit 971217
  gst_tag_xmp_writer_remove_all_schemas (GST_TAG_XMP_WRITER (test_element));
Packit 971217
Packit 971217
  fail_unless (gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
Packit 971217
          (test_element), taglist, TRUE) == NULL);
Packit 971217
Packit 971217
  gst_object_unref (test_element);
Packit 971217
  gst_tag_list_unref (taglist);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_default)
Packit 971217
{
Packit 971217
  GstTagList *taglist = create_taglist ();
Packit 971217
  GstElement *test_element =
Packit 971217
      (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
Packit 971217
  GstBuffer *buf;
Packit 971217
  GstBuffer *buf2;
Packit 971217
Packit 971217
  buf =
Packit 971217
      gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
Packit 971217
      (test_element), taglist, TRUE);
Packit 971217
  buf2 = gst_tag_list_to_xmp_buffer (taglist, TRUE, NULL);
Packit 971217
  fail_unless (gst_buffer_equals (buf, buf2));
Packit 971217
Packit 971217
  gst_object_unref (test_element);
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
  gst_buffer_unref (buf2);
Packit 971217
  gst_tag_list_unref (taglist);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
GST_START_TEST (test_disable)
Packit 971217
{
Packit 971217
  GstTagList *taglist;
Packit 971217
  GstTagList *taglist2;
Packit 971217
  GstElement *test_element =
Packit 971217
      (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL);
Packit 971217
  GstBuffer *buf;
Packit 971217
  const gchar *str;
Packit 971217
Packit 971217
  taglist = gst_tag_list_new (GST_TAG_ARTIST, "artist", NULL);
Packit 971217
Packit 971217
  /* add a tag that is mapped on xmp schema (as of Mar, 21th 2011) */
Packit 971217
  gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, GST_TAG_USER_RATING, 5,
Packit 971217
      NULL);
Packit 971217
Packit 971217
  buf =
Packit 971217
      gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
Packit 971217
      (test_element), taglist, TRUE);
Packit 971217
  taglist2 = gst_tag_list_from_xmp_buffer (buf);
Packit 971217
  fail_unless (gst_tag_list_is_equal (taglist, taglist2));
Packit 971217
  gst_tag_list_unref (taglist2);
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
Packit 971217
  gst_tag_xmp_writer_remove_schema (GST_TAG_XMP_WRITER (test_element), "xap");
Packit 971217
  buf =
Packit 971217
      gst_tag_xmp_writer_tag_list_to_xmp_buffer (GST_TAG_XMP_WRITER
Packit 971217
      (test_element), taglist, TRUE);
Packit 971217
  taglist2 = gst_tag_list_from_xmp_buffer (buf);
Packit 971217
Packit 971217
  /* artist should be there, but rating shouldn't */
Packit 971217
  fail_unless (gst_tag_list_peek_string_index (taglist2, GST_TAG_ARTIST, 0,
Packit 971217
          &str);;
Packit 971217
  fail_unless (gst_tag_list_get_value_index (taglist2, GST_TAG_USER_RATING,
Packit 971217
          0) == NULL);
Packit 971217
Packit 971217
  gst_tag_list_unref (taglist2);
Packit 971217
  gst_buffer_unref (buf);
Packit 971217
Packit 971217
  gst_object_unref (test_element);
Packit 971217
  gst_tag_list_unref (taglist);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
Packit 971217
static Suite *
Packit 971217
xmp_config_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("xmpconfig interface");
Packit 971217
  TCase *tc_chain = tcase_create ("configuration");
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
  tcase_add_test (tc_chain, test_no_xmp);
Packit 971217
  tcase_add_test (tc_chain, test_default);
Packit 971217
  tcase_add_test (tc_chain, test_disable);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (xmp_config);