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>
+
* gst/gstutils.h: (GST_BOILERPLATE_FULL):
Try to fix 'dereferencing type-punned pointer will break strict
aliasing rules' warnings with C++ compilers and GLib >= 2.14.0: GLib
GstSegment *result = NULL;
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;
}
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 *
gst_segment_suite (void)
{
tcase_add_test (tc_chain, segment_newsegment_runningtime);
tcase_add_test (tc_chain, segment_newsegment_accum);
tcase_add_test (tc_chain, segment_newsegment_accum2);
+ tcase_add_test (tc_chain, segment_copy);
return s;
}