1 /* GStreamer unit tests for the RTSP support library
2  * Copyright (C) 2010 Andy Wingo <wingo@oblong.com>
3  * Copyright (C) 2015 Tim-Philipp Müller <tim@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <glib/gstdio.h>
26 #include <gst/check/gstcheck.h>
27 
28 #include <gst/allocators/gstdmabuf.h>
29 #include <string.h>
30 
31 #define FILE_SIZE 4096
32 
33 
GST_START_TEST(test_dmabuf)34 GST_START_TEST (test_dmabuf)
35 {
36   char tmpfilename[] = "/tmp/dmabuf-test.XXXXXX";
37   int fd;
38   GstMemory *mem;
39   GstAllocator *alloc;
40   GstMapInfo info;
41 
42   fd = mkstemp (tmpfilename);
43   fail_unless (fd > 0);
44   fail_unless (g_unlink (tmpfilename) == 0);
45 
46   alloc = gst_dmabuf_allocator_new ();
47 
48   mem = gst_dmabuf_allocator_alloc (alloc, fd, FILE_SIZE);
49 
50   fail_unless (gst_memory_map (mem, &info, GST_MAP_READWRITE));
51   fail_unless (info.flags == GST_MAP_READWRITE);
52   fail_unless (info.data != NULL);
53   fail_unless (info.size == FILE_SIZE);
54   fail_unless (info.maxsize == FILE_SIZE);
55   gst_memory_unmap (mem, &info);
56 
57   gst_memory_unref (mem);
58   g_object_unref (alloc);
59 }
60 
61 GST_END_TEST;
62 
63 static Suite *
allocators_suite(void)64 allocators_suite (void)
65 {
66   Suite *s = suite_create ("allocators");
67   TCase *tc_chain = tcase_create ("general");
68 
69   suite_add_tcase (s, tc_chain);
70   tcase_add_test (tc_chain, test_dmabuf);
71 
72   return s;
73 }
74 
75 GST_CHECK_MAIN (allocators);
76