fa26eead7aed04d528de2805d110287e804ba0d2
[platform/upstream/gstreamer.git] / tests / check / libs / rtsp.c
1 /* GStreamer unit tests for the RTSP support library
2  *
3  * Copyright (C) 2010 Andy Wingo <wingo@oblong.com>
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
27 #include <gst/rtsp/gstrtspurl.h>
28 #include <string.h>
29
30 GST_START_TEST (test_rtsp_url_basic)
31 {
32   GstRTSPUrl *url = NULL;
33   GstRTSPResult res;
34
35   res = gst_rtsp_url_parse ("rtsp://localhost/foo/bar", &url);
36   fail_unless (res == GST_RTSP_OK);
37   fail_unless (url != NULL);
38   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_TCP);
39   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP);
40   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP_MCAST);
41   fail_unless (url->family == GST_RTSP_FAM_INET);
42   fail_unless (!url->user);
43   fail_unless (!url->passwd);
44   fail_unless (!strcmp (url->host, "localhost"));
45   /* fail_unless (url->port == GST_RTSP_DEFAULT_PORT); */
46   fail_unless (!strcmp (url->abspath, "/foo/bar"));
47   fail_unless (!url->query);
48
49   gst_rtsp_url_free (url);
50 }
51
52 GST_END_TEST;
53
54 GST_START_TEST (test_rtsp_url_components_1)
55 {
56   GstRTSPUrl *url = NULL;
57   GstRTSPResult res;
58   gchar **comps = NULL;
59
60   res = gst_rtsp_url_parse ("rtsp://localhost/foo/bar", &url);
61   fail_unless (res == GST_RTSP_OK);
62   fail_unless (url != NULL);
63
64   comps = gst_rtsp_url_decode_path_components (url);
65   fail_unless (comps != NULL);
66   fail_unless (g_strv_length (comps) == 3);
67   fail_unless (!strcmp (comps[0], ""));
68   fail_unless (!strcmp (comps[1], "foo"));
69   fail_unless (!strcmp (comps[2], "bar"));
70
71   gst_rtsp_url_free (url);
72 }
73
74 GST_END_TEST;
75
76 GST_START_TEST (test_rtsp_url_components_2)
77 {
78   GstRTSPUrl *url = NULL;
79   GstRTSPResult res;
80   gchar **comps = NULL;
81
82   res = gst_rtsp_url_parse ("rtsp://localhost/foo%2Fbar/qux%20baz", &url);
83   fail_unless (res == GST_RTSP_OK);
84   fail_unless (url != NULL);
85
86   comps = gst_rtsp_url_decode_path_components (url);
87   fail_unless (comps != NULL);
88   fail_unless (g_strv_length (comps) == 3);
89   fail_unless (!strcmp (comps[0], ""));
90   fail_unless (!strcmp (comps[1], "foo/bar"));
91   fail_unless (!strcmp (comps[2], "qux baz"));
92
93   gst_rtsp_url_free (url);
94 }
95
96 GST_END_TEST;
97
98 GST_START_TEST (test_rtsp_url_components_3)
99 {
100   GstRTSPUrl *url = NULL;
101   GstRTSPResult res;
102   gchar **comps = NULL;
103
104   res = gst_rtsp_url_parse ("rtsp://localhost/foo%00bar/qux%20baz", &url);
105   fail_unless (res == GST_RTSP_OK);
106   fail_unless (url != NULL);
107
108   comps = gst_rtsp_url_decode_path_components (url);
109   fail_unless (comps != NULL);
110   fail_unless (g_strv_length (comps) == 3);
111   fail_unless (!strcmp (comps[0], ""));
112   fail_unless (!strcmp (comps[1], "foo%00bar"));
113   fail_unless (!strcmp (comps[2], "qux baz"));
114
115   gst_rtsp_url_free (url);
116 }
117
118 GST_END_TEST;
119
120 static Suite *
121 rtsp_suite (void)
122 {
123   Suite *s = suite_create ("rtsp support library");
124   TCase *tc_chain = tcase_create ("general");
125
126   suite_add_tcase (s, tc_chain);
127   tcase_add_test (tc_chain, test_rtsp_url_basic);
128   tcase_add_test (tc_chain, test_rtsp_url_components_1);
129   tcase_add_test (tc_chain, test_rtsp_url_components_2);
130   tcase_add_test (tc_chain, test_rtsp_url_components_3);
131
132   return s;
133 }
134
135 int
136 main (int argc, char **argv)
137 {
138   int nf;
139
140   Suite *s = rtsp_suite ();
141   SRunner *sr = srunner_create (s);
142
143   gst_check_init (&argc, &argv);
144
145   srunner_run_all (sr, CK_NORMAL);
146   nf = srunner_ntests_failed (sr);
147   srunner_free (sr);
148
149   return nf;
150 }