tests: add unit test for the client object
[platform/upstream/gstreamer.git] / tests / check / gst / client.c
1 /* GStreamer
2  * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.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-client.h>
23
24 static gint cseq;
25
26 static gboolean
27 test_option_response (GstRTSPClient * client, GstRTSPMessage * response,
28     gboolean close, gpointer user_data)
29 {
30   GstRTSPStatusCode code;
31   const gchar *reason;
32   GstRTSPVersion version;
33   gchar *str;
34   GstRTSPMethod methods;
35
36   fail_unless (gst_rtsp_message_get_type (response) ==
37       GST_RTSP_MESSAGE_RESPONSE);
38
39   gst_rtsp_message_dump (response);
40   fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
41           &version)
42       == GST_RTSP_OK);
43   fail_unless (code == GST_RTSP_STS_OK);
44   fail_unless (g_str_equal (reason, "OK"));
45   fail_unless (version == GST_RTSP_VERSION_1_0);
46
47   fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
48           0) == GST_RTSP_OK);
49   fail_unless (atoi (str) == cseq++);
50
51   fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
52           0) == GST_RTSP_OK);
53
54   methods = gst_rtsp_options_from_text (str);
55   fail_if (methods == 0);
56   fail_unless (methods == (GST_RTSP_DESCRIBE |
57           GST_RTSP_OPTIONS |
58           GST_RTSP_PAUSE |
59           GST_RTSP_PLAY |
60           GST_RTSP_SETUP |
61           GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
62
63   return TRUE;
64 }
65
66 GST_START_TEST (test_options)
67 {
68   GstRTSPClient *client;
69   GstRTSPMessage request = { 0, };
70   gchar *str;
71
72   client = gst_rtsp_client_new ();
73
74   fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
75           "rtsp://localhost/test") == GST_RTSP_OK);
76   str = g_strdup_printf ("%d", cseq);
77   gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
78   g_free (str);
79
80   gst_rtsp_client_set_send_func (client, test_option_response, NULL, NULL);
81   gst_rtsp_message_dump (&request);
82   fail_unless (gst_rtsp_client_handle_message (client,
83           &request) == GST_RTSP_OK);
84
85   gst_rtsp_message_unset (&request);
86
87   g_object_unref (client);
88 }
89
90 GST_END_TEST;
91
92 static Suite *
93 rtspclient_suite (void)
94 {
95   Suite *s = suite_create ("rtspclient");
96   TCase *tc = tcase_create ("general");
97
98   suite_add_tcase (s, tc);
99   tcase_set_timeout (tc, 20);
100   tcase_add_test (tc, test_options);
101
102   return s;
103 }
104
105 GST_CHECK_MAIN (rtspclient);