2 * Copyright (C) 2013 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>
22 #include <rtsp-token.h>
24 GST_START_TEST (test_token)
31 token = gst_rtsp_token_new_empty ();
32 fail_if (gst_rtsp_token_is_allowed (token, "missing"));
33 gst_rtsp_token_unref (token);
35 token = gst_rtsp_token_new ("role", G_TYPE_STRING, "user",
36 "permission1", G_TYPE_BOOLEAN, TRUE,
37 "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
38 fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user");
39 fail_unless (gst_rtsp_token_is_allowed (token, "permission1"));
40 fail_if (gst_rtsp_token_is_allowed (token, "permission2"));
41 fail_if (gst_rtsp_token_is_allowed (token, "missing"));
42 copy = GST_RTSP_TOKEN (gst_mini_object_copy (GST_MINI_OBJECT (token)));
43 gst_rtsp_token_unref (token);
44 fail_unless_equals_string (gst_rtsp_token_get_string (copy, "role"), "user");
45 fail_unless (gst_rtsp_token_is_allowed (copy, "permission1"));
46 fail_if (gst_rtsp_token_is_allowed (copy, "permission2"));
47 fail_if (gst_rtsp_token_is_allowed (copy, "missing"));
48 gst_rtsp_token_unref (copy);
50 token = gst_rtsp_token_new ("role", G_TYPE_STRING, "user",
51 "permission1", G_TYPE_BOOLEAN, TRUE,
52 "permission2", G_TYPE_BOOLEAN, FALSE, NULL);
53 fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user");
54 fail_unless (gst_rtsp_token_is_allowed (token, "permission1"));
55 fail_if (gst_rtsp_token_is_allowed (token, "permission2"));
56 fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user");
58 fail_unless (gst_mini_object_is_writable (GST_MINI_OBJECT (token)));
59 fail_unless (gst_rtsp_token_writable_structure (token) != NULL);
60 fail_unless (gst_rtsp_token_get_structure (token) != NULL);
62 token2 = gst_rtsp_token_ref (token);
64 fail_if (gst_mini_object_is_writable (GST_MINI_OBJECT (token)));
65 ASSERT_CRITICAL (fail_unless (gst_rtsp_token_writable_structure (token) ==
67 fail_unless (gst_rtsp_token_get_structure (token) != NULL);
69 gst_rtsp_token_unref (token2);
71 fail_unless (gst_mini_object_is_writable (GST_MINI_OBJECT (token)));
72 fail_unless (gst_rtsp_token_writable_structure (token) != NULL);
73 fail_unless (gst_rtsp_token_get_structure (token) != NULL);
75 str = gst_rtsp_token_writable_structure (token);
76 gst_structure_set (str, "permission2", G_TYPE_BOOLEAN, TRUE, NULL);
77 fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user");
78 fail_unless (gst_rtsp_token_is_allowed (token, "permission1"));
79 fail_unless (gst_rtsp_token_is_allowed (token, "permission2"));
80 fail_unless_equals_string (gst_rtsp_token_get_string (token, "role"), "user");
81 gst_rtsp_token_unref (token);
87 rtsptoken_suite (void)
89 Suite *s = suite_create ("rtsptoken");
90 TCase *tc = tcase_create ("general");
92 suite_add_tcase (s, tc);
93 tcase_set_timeout (tc, 20);
94 tcase_add_test (tc, test_token);
99 GST_CHECK_MAIN (rtsptoken);