tocsetter: fix memory leaks in unit test
authorAlexander Saprykin <xelfium@gmail.com>
Tue, 10 Apr 2012 10:18:48 +0000 (14:18 +0400)
committerStefan Sauer <ensonic@users.sf.net>
Wed, 11 Apr 2012 07:58:06 +0000 (09:58 +0200)
tests/check/gst/gsttocsetter.c

index 34e589a..3fefcdc 100644 (file)
@@ -34,7 +34,7 @@
 
 #define ENTRY_TAG       "EntryTag"
 #define TOC_TAG         "TocTag"
-#define INFO_NAME       "info"
+#define INFO_NAME       "gst-toc-setter-check"
 #define INFO_FIELD      "info-test"
 #define INFO_TEXT_EN    "info-text-entry"
 #define INFO_TEXT_TOC   "info-text-toc"
@@ -43,6 +43,7 @@
 {                                                                        \
   gchar *tag_c;                                                          \
   const GValue *val;                                                     \
+  GstStructure *struct_c;                                                \
                                                                          \
   fail_unless_equals_string (entry_c->uid, uid_c);                       \
   fail_unless (entry_c->type == type_c);                                 \
   fail_unless (entry_c->pads == NULL);                                   \
                                                                          \
   fail_unless (entry_c->info != NULL);                                   \
-  val = gst_structure_get_value (entry_c->info, INFO_FIELD);             \
+  gst_structure_get (entry_c->info, INFO_NAME, GST_TYPE_STRUCTURE,       \
+      &struct_c, NULL);                                                  \
+  fail_unless (struct_c != NULL);                                        \
+  val = gst_structure_get_value (struct_c, INFO_FIELD);             \
   fail_unless (val != NULL);                                             \
   fail_unless_equals_string (g_value_get_string (val), INFO_TEXT_EN);    \
                                                                          \
   fail_unless (gst_tag_list_get_string (entry_c->tags,                   \
                GST_TAG_TITLE, &tag_c));                                  \
   fail_unless_equals_string (tag_c, ENTRY_TAG);                          \
+  g_free (tag_c);                                                        \
+  gst_structure_free (struct_c);                                         \
 }
 
 #define CHECK_TOC(toc_t)                                                 \
   GstTocEntry *entry_t, *subentry_t;                                     \
   gchar *tag_t;                                                          \
   const GValue *val;                                                     \
+  GstStructure *struct_toc;                                              \
+                                                                         \
   /* check TOC */                                                        \
   fail_unless (g_list_length (toc_t->entries) == 2);                     \
   fail_unless (toc_t->tags != NULL);                                     \
   fail_unless (gst_tag_list_get_string (toc_t->tags,                     \
                GST_TAG_TITLE, &tag_t));                                  \
   fail_unless_equals_string (tag_t, TOC_TAG);                            \
+  g_free (tag_t);                                                        \
                                                                          \
   fail_unless (toc_t->info != NULL);                                     \
-  val = gst_structure_get_value (toc_t->info, INFO_FIELD);               \
+  gst_structure_get (toc_t->info, INFO_NAME, GST_TYPE_STRUCTURE,         \
+      &struct_toc, NULL);                                                \
+  fail_unless (struct_toc != NULL);                                      \
+  val = gst_structure_get_value (struct_toc, INFO_FIELD);                \
   fail_unless (val != NULL);                                             \
   fail_unless_equals_string (g_value_get_string (val), INFO_TEXT_TOC);   \
+  gst_structure_free (struct_toc);                                       \
                                                                          \
   /* check edition1 */                                                   \
   entry_t = g_list_nth_data (toc_t->entries, 0);                         \
@@ -131,31 +144,38 @@ gst_dummy_enc_init (GstDummyEnc * enc)
 static GstToc *
 create_toc (void)
 {
+  GstStructure *structure;
   GstToc *toc;
   GstTocEntry *ed, *ch, *subch;
 
   toc = gst_toc_new ();
   gst_tag_list_add (toc->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       TOC_TAG, NULL);
-  toc->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_TOC,
       NULL);
+  gst_structure_set (toc->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   /* create edition1 */
   ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED1);
   gst_tag_list_add (ed->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  ed->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (ed->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   /* append chapter1 to edition1 */
   ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH1);
   gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  ch->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   ed->subentries = g_list_append (ed->subentries, ch);
 
@@ -163,9 +183,11 @@ create_toc (void)
   ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH2);
   gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  ch->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   ed->subentries = g_list_append (ed->subentries, ch);
 
@@ -176,25 +198,32 @@ create_toc (void)
   ed = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, ENTRY_ED2);
   gst_tag_list_add (ed->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  ed->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (ed->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   /* create chapter3 */
   ch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_CH3);
   gst_tag_list_add (ch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  ch->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (ch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure, NULL);
+  gst_structure_free (structure);
 
   /* create subchapter1 */
   subch = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, ENTRY_SUB1);
   gst_tag_list_add (subch->tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE,
       ENTRY_TAG, NULL);
-  subch->info =
+  structure =
       gst_structure_new (INFO_NAME, INFO_FIELD, G_TYPE_STRING, INFO_TEXT_EN,
       NULL);
+  gst_structure_set (subch->info, INFO_NAME, GST_TYPE_STRUCTURE, structure,
+      NULL);
+  gst_structure_free (structure);
 
   /* append subchapter1 to chapter3 */
   ch->subentries = g_list_append (ch->subentries, subch);
@@ -238,6 +267,7 @@ GST_START_TEST (test_set)
   gst_toc_setter_add_toc_entry (setter, "0", entry);
 
   gst_toc_free (toc);
+  gst_toc_entry_free (entry);
   toc = gst_toc_setter_get_toc_copy (setter);
 
   CHECK_TOC (toc);