1 /* GStreamer RTP header extension unit tests
2 * Copyright (C) 2020 Matthew Waters <matthew@centricular.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General
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.
20 #include "gst/gstcaps.h"
21 #include "gst/gstvalue.h"
22 #include "gst/rtp/gstrtphdrext.h"
28 #include <gst/check/check.h>
29 #include <gst/rtp/rtp.h>
31 #include "rtpdummyhdrextimpl.c"
33 GST_START_TEST (rtp_header_ext_write)
35 GstRTPHeaderExtension *dummy;
41 dummy = rtp_dummy_hdr_ext_new ();
42 gst_rtp_header_extension_set_id (dummy, 1);
44 buffer = gst_buffer_new ();
45 size = gst_rtp_header_extension_get_max_size (dummy, buffer);
46 fail_unless (size > 0);
48 data = g_malloc0 (size);
49 fail_unless (data != NULL);
52 gst_rtp_header_extension_write (dummy, buffer, 0, buffer, data, size);
53 fail_unless (written > 0 && written <= size);
54 fail_unless_equals_int (GST_RTP_DUMMY_HDR_EXT (dummy)->write_count, 1);
56 fail_unless (gst_rtp_header_extension_read (dummy, 0, data, size, buffer));
57 fail_unless_equals_int (GST_RTP_DUMMY_HDR_EXT (dummy)->read_count, 1);
60 gst_buffer_unref (buffer);
61 g_object_unref (dummy);
66 GST_START_TEST (rtp_header_ext_create_from_uri)
68 GstElementFactory *factory;
69 GstRTPHeaderExtension *dummy;
71 fail_unless (gst_element_register (NULL, "test-dummyrtphdrext",
72 GST_RANK_MARGINAL, GST_TYPE_RTP_DUMMY_HDR_EXT));
74 dummy = gst_rtp_header_extension_create_from_uri (DUMMY_HDR_EXT_URI);
75 fail_unless (GST_IS_RTP_DUMMY_HDR_EXT (dummy));
77 factory = gst_element_get_factory (GST_ELEMENT (dummy));
78 gst_registry_remove_feature (gst_registry_get (),
79 GST_PLUGIN_FEATURE (factory));
80 gst_object_unref (dummy);
85 GST_START_TEST (rtp_header_ext_caps_with_attributes)
87 GstRTPHeaderExtension *dummy;
88 GstCaps *caps = gst_caps_new_empty_simple ("application/x-rtp");
89 GstStructure *s = gst_caps_get_structure (caps, 0);
90 const GValue *arr, *val;
91 const gchar *attributes = "attr0 attr1";
92 const gchar *direction = "recvonly";
94 dummy = rtp_dummy_hdr_ext_new ();
96 gst_rtp_header_extension_set_id (dummy, 1);
98 GST_RTP_DUMMY_HDR_EXT (dummy)->direction = g_strdup (direction);
99 GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = g_strdup (attributes);
101 fail_unless (gst_rtp_header_extension_set_caps_from_attributes (dummy, caps));
102 fail_unless (gst_structure_has_field_typed (s, "extmap-1", GST_TYPE_ARRAY));
103 arr = gst_structure_get_value (s, "extmap-1");
104 fail_unless (GST_VALUE_HOLDS_ARRAY (arr));
105 fail_unless_equals_int (gst_value_array_get_size (arr), 3);
106 val = gst_value_array_get_value (arr, 0);
107 fail_unless_equals_int (g_strcmp0 (g_value_get_string (val), direction), 0);
108 val = gst_value_array_get_value (arr, 1);
109 fail_unless_equals_int (g_strcmp0 (g_value_get_string (val),
110 gst_rtp_header_extension_get_uri (dummy)), 0);
111 val = gst_value_array_get_value (arr, 2);
112 fail_unless_equals_int (g_strcmp0 (g_value_get_string (val), attributes), 0);
114 g_free (GST_RTP_DUMMY_HDR_EXT (dummy)->direction);
115 GST_RTP_DUMMY_HDR_EXT (dummy)->direction = NULL;
116 g_free (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes);
117 GST_RTP_DUMMY_HDR_EXT (dummy)->attributes = NULL;
119 fail_unless (gst_rtp_header_extension_set_attributes_from_caps (dummy, caps));
121 fail_unless_equals_int (g_strcmp0 (GST_RTP_DUMMY_HDR_EXT (dummy)->attributes,
123 fail_unless_equals_int (g_strcmp0 (GST_RTP_DUMMY_HDR_EXT (dummy)->direction,
126 gst_caps_unref (caps);
127 gst_object_unref (dummy);
133 rtp_header_extension_suite (void)
135 Suite *s = suite_create ("rtp_header_extension_test");
136 TCase *tc_chain = tcase_create ("header extension test");
138 suite_add_tcase (s, tc_chain);
139 tcase_add_test (tc_chain, rtp_header_ext_write);
140 tcase_add_test (tc_chain, rtp_header_ext_create_from_uri);
141 tcase_add_test (tc_chain, rtp_header_ext_caps_with_attributes);
146 GST_CHECK_MAIN (rtp_header_extension)