No, let's not use g_slice_{dup|copy} here, since they only exist since GLib 2.14 and we still depend only on >= 2.12....

Original commit message from CVS:
* gst/gstsegment.c:
* tests/check/gst/gstsegment.c:
No, let's not use g_slice_{dup|copy} here, since they only exist
since GLib 2.14 and we still depend only on >= 2.12. Also add
unit test for gst_segment_copy().
This commit is contained in:
Tim-Philipp Müller 2008-05-09 20:48:24 +00:00
parent 7c0437a9da
commit 077450a434
3 changed files with 36 additions and 1 deletions

View file

@ -1,3 +1,11 @@
2008-05-09 Tim-Philipp Müller <tim.muller at collabora co uk>
* gst/gstsegment.c:
* tests/check/gst/gstsegment.c:
No, let's not use g_slice_{dup|copy} here, since they only exist
since GLib 2.14 and we still depend only on >= 2.12. Also add
unit test for gst_segment_copy().
2008-05-09 Tim-Philipp Müller <tim.muller at collabora co uk> 2008-05-09 Tim-Philipp Müller <tim.muller at collabora co uk>
* gst/gstutils.h: (GST_BOILERPLATE_FULL): * gst/gstutils.h: (GST_BOILERPLATE_FULL):

View file

@ -99,7 +99,10 @@ gst_segment_copy (GstSegment * segment)
GstSegment *result = NULL; GstSegment *result = NULL;
if (segment) { if (segment) {
result = (GstSegment *) g_slice_copy (sizeof (GstSegment), segment); /* we do not use g_slice_dup or g_slice_copy here because those were
* added in GLib 2.14 and we require only >= 2.12 */
result = g_slice_new (GstSegment);
*result = *segment;
} }
return result; return result;
} }

View file

@ -1624,6 +1624,29 @@ GST_START_TEST (segment_newsegment_accum2)
GST_END_TEST; GST_END_TEST;
GST_START_TEST (segment_copy)
{
GstSegment *copy;
GstSegment segment = { 0.0, };
/* this is a boxed type copy function, we support copying NULL */
fail_unless (gst_segment_copy (NULL) == NULL);
gst_segment_init (&segment, GST_FORMAT_TIME);
gst_segment_set_newsegment_full (&segment, FALSE, -1.0, 1.0,
GST_FORMAT_TIME, 0, 200, 0);
copy = gst_segment_copy (&segment);
fail_unless (copy != NULL);
/* we inited the struct on the stack to zeroes, so direct comparison should
* be ok here despite the padding field and regardless of implementation */
fail_unless (memcmp (copy, &segment, sizeof (GstSegment)) == 0);
gst_segment_free (copy);
}
GST_END_TEST;
static Suite * static Suite *
gst_segment_suite (void) gst_segment_suite (void)
{ {
@ -1646,6 +1669,7 @@ gst_segment_suite (void)
tcase_add_test (tc_chain, segment_newsegment_runningtime); tcase_add_test (tc_chain, segment_newsegment_runningtime);
tcase_add_test (tc_chain, segment_newsegment_accum); tcase_add_test (tc_chain, segment_newsegment_accum);
tcase_add_test (tc_chain, segment_newsegment_accum2); tcase_add_test (tc_chain, segment_newsegment_accum2);
tcase_add_test (tc_chain, segment_copy);
return s; return s;
} }