tests: allocator: Fix FDMemory portability issue
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 28 Oct 2020 19:51:27 +0000 (15:51 -0400)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 29 Oct 2020 09:45:25 +0000 (09:45 +0000)
This fixes few issues in the test but mainly some portability issue reported
on Ubutun. The test now uses a randomly name tempory file located into system
default tempory location and uses glib wrappers when available.

Fixes !895

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/901>

tests/check/libs/allocators.c

index 36c4a38..6b974b2 100644 (file)
@@ -70,28 +70,32 @@ GST_START_TEST (test_fdmem)
   GstAllocator *alloc;
   GstMemory *mem;
   GstMapInfo info;
+  GError *error = NULL;
   int fd;
   const char *data = "0123456789";
 
-  fd = open ("test.txt", O_RDWR | O_CREAT);
-  g_assert (write (fd, data, 10) == 10);
+  fd = g_file_open_tmp (NULL, NULL, &error);
+  fail_if (error);
+  fail_unless (write (fd, data, 10) == 10);
 
   alloc = gst_fd_allocator_new ();
-  g_assert (alloc);
+  fail_unless (alloc);
   mem = gst_fd_allocator_alloc (alloc, fd, 10, GST_FD_MEMORY_FLAG_KEEP_MAPPED);
 
-  g_assert (gst_memory_map (mem, &info, GST_MAP_READ));
-  g_assert (info.data[5] == '5');
+  fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
+  fail_unless (info.data[5] == '5');
   gst_memory_unmap (mem, &info);
-  g_assert (gst_memory_map (mem, &info, GST_MAP_WRITE));
+
+  fail_unless (gst_memory_map (mem, &info, GST_MAP_WRITE));
   info.data[5] = 'X';
   gst_memory_unmap (mem, &info);
-  g_assert (gst_memory_map (mem, &info, GST_MAP_READ));
-  g_assert (info.data[5] == 'X');
+
+  fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
+  fail_unless (info.data[5] == 'X');
   gst_memory_unmap (mem, &info);
 
   gst_memory_unref (mem);
-  g_assert (remove ("test.txt") == 0);
+  fail_unless (g_close (fd, NULL) == 0);
   gst_object_unref (alloc);
 }