2 * Copyright (C) 2014 Sebastian Rasmussen <sebras@hotmail.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 Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <gst/check/gstcheck.h>
21 #include <rtsp-session-pool.h>
25 GstRTSPSession *sessions[3];
26 GstRTSPFilterResult response[3];
29 static GstRTSPFilterResult
30 filter_func (GstRTSPSessionPool * pool, GstRTSPSession * session,
33 Responses *responses = (Responses *) user_data;
36 for (i = 0; i < 3; i++)
37 if (session == responses->sessions[i])
38 return responses->response[i];
40 return GST_RTSP_FILTER_KEEP;
43 GST_START_TEST (test_pool)
45 GstRTSPSessionPool *pool;
46 GstRTSPSession *session1, *session2, *session3;
47 GstRTSPSession *compare;
48 gchar *session1id, *session2id, *session3id;
54 pool = gst_rtsp_session_pool_new ();
55 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 0);
56 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 0);
58 gst_rtsp_session_pool_set_max_sessions (pool, 3);
59 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3);
61 session1 = gst_rtsp_session_pool_create (pool);
62 fail_unless (GST_IS_RTSP_SESSION (session1));
63 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 1);
64 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3);
65 session1id = g_strdup (gst_rtsp_session_get_sessionid (session1));
67 session2 = gst_rtsp_session_pool_create (pool);
68 fail_unless (GST_IS_RTSP_SESSION (session2));
69 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2);
70 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3);
71 session2id = g_strdup (gst_rtsp_session_get_sessionid (session2));
73 session3 = gst_rtsp_session_pool_create (pool);
74 fail_unless (GST_IS_RTSP_SESSION (session3));
75 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 3);
76 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3);
77 session3id = g_strdup (gst_rtsp_session_get_sessionid (session3));
79 fail_if (GST_IS_RTSP_SESSION (gst_rtsp_session_pool_create (pool)));
81 compare = gst_rtsp_session_pool_find (pool, session1id);
82 fail_unless (compare == session1);
83 g_object_unref (compare);
84 compare = gst_rtsp_session_pool_find (pool, session2id);
85 fail_unless (compare == session2);
86 g_object_unref (compare);
87 compare = gst_rtsp_session_pool_find (pool, session3id);
88 fail_unless (compare == session3);
89 g_object_unref (compare);
90 fail_unless (gst_rtsp_session_pool_find (pool, "") == NULL);
92 fail_unless (gst_rtsp_session_pool_remove (pool, session2));
93 g_object_unref (session2);
94 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2);
95 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 3);
97 gst_rtsp_session_pool_set_max_sessions (pool, 2);
98 fail_unless_equals_int (gst_rtsp_session_pool_get_n_sessions (pool), 2);
99 fail_unless_equals_int (gst_rtsp_session_pool_get_max_sessions (pool), 2);
101 session2 = gst_rtsp_session_pool_create (pool);
102 fail_if (GST_IS_RTSP_SESSION (session2));
105 list = gst_rtsp_session_pool_filter (pool, NULL, NULL);
106 fail_unless_equals_int (g_list_length (list), 2);
107 fail_unless (g_list_find (list, session1) != NULL);
108 fail_unless (g_list_find (list, session3) != NULL);
109 g_list_free_full (list, (GDestroyNotify) g_object_unref);
113 Responses responses = {
114 {session1, session2, session3},
115 {GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP},
118 list = gst_rtsp_session_pool_filter (pool, filter_func, &responses);
119 fail_unless (list == NULL);
123 Responses responses = {
124 {session1, session2, session3},
125 {GST_RTSP_FILTER_REF, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP},
128 list = gst_rtsp_session_pool_filter (pool, filter_func, &responses);
129 fail_unless_equals_int (g_list_length (list), 1);
130 fail_unless (g_list_nth_data (list, 0) == session1);
131 g_list_free_full (list, (GDestroyNotify) g_object_unref);
135 Responses responses = {
136 {session1, session2, session3},
137 {GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_KEEP, GST_RTSP_FILTER_REMOVE},
140 list = gst_rtsp_session_pool_filter (pool, filter_func, &responses);
141 fail_unless_equals_int (g_list_length (list), 0);
145 compare = gst_rtsp_session_pool_find (pool, session1id);
146 fail_unless (compare == session1);
147 g_object_unref (compare);
148 fail_unless (gst_rtsp_session_pool_find (pool, session2id) == NULL);
149 fail_unless (gst_rtsp_session_pool_find (pool, session3id) == NULL);
151 g_object_get (pool, "max-sessions", &maxsessions, NULL);
152 fail_unless_equals_int (maxsessions, 2);
154 g_object_set (pool, "max-sessions", 3, NULL);
155 g_object_get (pool, "max-sessions", &maxsessions, NULL);
156 fail_unless_equals_int (maxsessions, 3);
158 fail_unless_equals_int (gst_rtsp_session_pool_cleanup (pool), 0);
160 gst_rtsp_session_set_timeout (session1, 1);
162 source = gst_rtsp_session_pool_create_watch (pool);
163 fail_unless (source != NULL);
165 sourceid = g_source_attach (source, NULL);
166 fail_unless (sourceid != 0);
168 while (!g_main_context_iteration (NULL, TRUE));
170 g_source_unref (source);
172 g_object_unref (session1);
173 g_object_unref (session3);
179 g_object_unref (pool);
185 rtspsessionpool_suite (void)
187 Suite *s = suite_create ("rtspsessionpool");
188 TCase *tc = tcase_create ("general");
190 suite_add_tcase (s, tc);
191 tcase_set_timeout (tc, 15);
192 tcase_add_test (tc, test_pool);
197 GST_CHECK_MAIN (rtspsessionpool);