tizen 2.4 release
[framework/multimedia/gst-rtsp-server.git] / tests / check / gst / token.c
1 /* GStreamer
2  * Copyright (C) 2013 Sebastian Rasmussen <sebras@hotmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <gst/check/gstcheck.h>
21
22 #include <rtsp-token.h>
23
24 GST_START_TEST (test_token)
25 {
26   GstRTSPToken *token;
27   GstRTSPToken *token2;
28   GstRTSPToken *copy;
29   GstStructure *str;
30
31   token = gst_rtsp_token_new_empty ();
32   fail_if (gst_rtsp_token_is_allowed (token, "missing"));
33   gst_rtsp_token_unref (token);
34
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);
49
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");
57
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);
61
62   token2 = gst_rtsp_token_ref (token);
63
64   fail_if (gst_mini_object_is_writable (GST_MINI_OBJECT (token)));
65   ASSERT_CRITICAL (fail_unless (gst_rtsp_token_writable_structure (token) ==
66           NULL));
67   fail_unless (gst_rtsp_token_get_structure (token) != NULL);
68
69   gst_rtsp_token_unref (token2);
70
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);
74
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);
82 }
83
84 GST_END_TEST;
85
86 static Suite *
87 rtsptoken_suite (void)
88 {
89   Suite *s = suite_create ("rtsptoken");
90   TCase *tc = tcase_create ("general");
91
92   suite_add_tcase (s, tc);
93   tcase_set_timeout (tc, 20);
94   tcase_add_test (tc, test_token);
95
96   return s;
97 }
98
99 GST_CHECK_MAIN (rtsptoken);