static gboolean
_default_mem_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
{
+ g_return_val_if_fail ((guint8 *) data >= mem->data
+ && (guint8 *) data < mem->data + mem->maxsize, FALSE);
+
if (size != -1) {
+ /* check if resize happened or unmap was called with different data */
+ if (mem->data + mem->offset != data) {
+ /* adjust the size */
+ size = (guint8 *) data - mem->data + size - mem->offset;
+ }
+
g_return_val_if_fail (mem->offset + size <= mem->maxsize, FALSE);
mem->size = size;
}
+
return TRUE;
}
fail_unless (data != NULL);
fail_unless (size == 100);
fail_unless (maxsize == maxalloc);
+ ASSERT_CRITICAL (gst_memory_unmap (mem, (guint8 *) data - 1, maxsize + 1));
gst_memory_unmap (mem, data, size);
/* make smaller by unmapping less */
GST_END_TEST;
+GST_START_TEST (test_map_resize)
+{
+ GstMemory *mem;
+ gsize size, maxsize;
+ gpointer data;
+
+ mem = gst_allocator_alloc (NULL, 100, 0);
+
+ /* do mapping */
+ data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
+ fail_unless (data != NULL);
+ fail_unless (size == 100);
+
+ /* resize the buffer */
+ gst_memory_resize (mem, 1, maxsize - 1);
+
+ /* unmap the buffer with original pointer and size */
+ gst_memory_unmap (mem, data, maxsize);
+
+ gst_memory_unref (mem);
+}
+
+GST_END_TEST;
+
static Suite *
gst_memory_suite (void)
tcase_add_test (tc_chain, test_resize);
tcase_add_test (tc_chain, test_map);
tcase_add_test (tc_chain, test_map_nested);
+ tcase_add_test (tc_chain, test_map_resize);
return s;
}