Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / check / libs / netbuffer.c
1 /* GStreamer unit tests for libgstnetbuffer
2  *
3  * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <gst/check/gstcheck.h>
26 #include <gst/netbuffer/gstnetbuffer.h>
27
28 #define DATA_STRING "Yoho this is a string"
29
30 GST_START_TEST (test_netbuffer_copy)
31 {
32   GstNetBuffer *netbuf, *copy;
33   guint8 ipv6_addr[16] = { 0xff, 0x11, 0xee, 0x22, 0xdd, 0x33, 0xcc,
34     0x44, 0xbb, 0x55, 0xaa, 0x66, 0x00, 0x77, 0x99, 0x88
35   };
36   guint8 ipv6_copy[16];
37   guint32 ipv4_copy, ipv4_addr = 0xfe12dc34;
38   guint16 ipv6_port = 3490;
39   guint16 ipv4_port = 5678;
40   guint16 port;
41
42   netbuf = gst_netbuffer_new ();
43   fail_unless (netbuf != NULL, "failed to create net buffer");
44
45   gst_netaddress_set_ip4_address (&netbuf->from, ipv4_addr, ipv4_port);
46   gst_netaddress_set_ip6_address (&netbuf->to, ipv6_addr, ipv6_port);
47
48   GST_BUFFER_DATA (netbuf) = (guint8 *) DATA_STRING;
49   GST_BUFFER_SIZE (netbuf) = strlen (DATA_STRING);
50   GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_DISCONT);
51   GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_READONLY);
52
53   copy = (GstNetBuffer *) gst_buffer_copy (GST_BUFFER_CAST (netbuf));
54   fail_unless (copy != NULL, "failed to copy net buffer");
55   fail_unless (GST_IS_NETBUFFER (copy), "copied buffer is not a GstNetBuffer!");
56
57   fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (copy), 1);
58
59   fail_unless_equals_int (GST_BUFFER_SIZE (copy), GST_BUFFER_SIZE (netbuf));
60   fail_unless (memcmp (GST_BUFFER_DATA (copy), GST_BUFFER_DATA (netbuf),
61           GST_BUFFER_SIZE (copy)) == 0);
62
63   fail_if (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_READONLY));
64   fail_unless (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_DISCONT));
65
66   fail_unless (gst_netaddress_get_ip4_address (&copy->from, &ipv4_copy, &port));
67   fail_unless (ipv4_copy == ipv4_addr,
68       "Copied buffer has wrong IPV4 from address");
69   fail_unless (port == ipv4_port, "Copied buffer has wrong IPV4 from port");
70
71   fail_unless (gst_netaddress_get_ip6_address (&copy->to, ipv6_copy, &port));
72   fail_unless (memcmp (ipv6_copy, ipv6_addr, 16) == 0,
73       "Copied buffer has wrong IPv6 destination address");
74   fail_unless (port == ipv6_port,
75       "Copied buffer has wrong IPv6 destination port");
76
77   gst_buffer_unref (GST_BUFFER_CAST (netbuf));
78   gst_buffer_unref (GST_BUFFER_CAST (copy));
79 }
80
81 GST_END_TEST;
82
83 static Suite *
84 netbuffer_suite (void)
85 {
86   Suite *s = suite_create ("netbuffer");
87   TCase *tc_chain = tcase_create ("netbuffer");
88
89   suite_add_tcase (s, tc_chain);
90
91   tcase_add_test (tc_chain, test_netbuffer_copy);
92
93   return s;
94 }
95
96 GST_CHECK_MAIN (netbuffer);