tests: add more tests
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 27 Nov 2012 11:51:55 +0000 (12:51 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 27 Nov 2012 11:51:55 +0000 (12:51 +0100)
tests/check/gst/client.c

index b12e0ad..59d5972 100644 (file)
 static gint cseq;
 
 static gboolean
-test_option_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
+test_response_400 (GstRTSPClient * client, GstRTSPMessage * response,
     gboolean close, gpointer user_data)
 {
   GstRTSPStatusCode code;
   const gchar *reason;
   GstRTSPVersion version;
-  gchar *str;
-  GstRTSPMethod methods;
 
   fail_unless (gst_rtsp_message_get_type (response) ==
       GST_RTSP_MESSAGE_RESPONSE);
 
-  gst_rtsp_message_dump (response);
   fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
           &version)
       == GST_RTSP_OK);
-  fail_unless (code == GST_RTSP_STS_OK);
-  fail_unless (g_str_equal (reason, "OK"));
+  fail_unless (code == GST_RTSP_STS_BAD_REQUEST);
+  fail_unless (g_str_equal (reason, "Bad Request"));
   fail_unless (version == GST_RTSP_VERSION_1_0);
 
-  fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
-          0) == GST_RTSP_OK);
-  fail_unless (atoi (str) == cseq++);
+  return TRUE;
+}
 
-  fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
-          0) == GST_RTSP_OK);
+static gboolean
+test_response_404 (GstRTSPClient * client, GstRTSPMessage * response,
+    gboolean close, gpointer user_data)
+{
+  GstRTSPStatusCode code;
+  const gchar *reason;
+  GstRTSPVersion version;
 
-  methods = gst_rtsp_options_from_text (str);
-  fail_if (methods == 0);
-  fail_unless (methods == (GST_RTSP_DESCRIBE |
-          GST_RTSP_OPTIONS |
-          GST_RTSP_PAUSE |
-          GST_RTSP_PLAY |
-          GST_RTSP_SETUP |
-          GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
+  fail_unless (gst_rtsp_message_get_type (response) ==
+      GST_RTSP_MESSAGE_RESPONSE);
+
+  fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
+          &version)
+      == GST_RTSP_OK);
+  fail_unless (code == GST_RTSP_STS_NOT_FOUND);
+  fail_unless (g_str_equal (reason, "Not Found"));
+  fail_unless (version == GST_RTSP_VERSION_1_0);
 
   return TRUE;
 }
 
 static gboolean
-test_option_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
+test_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
     gboolean close, gpointer user_data)
 {
   GstRTSPStatusCode code;
@@ -73,7 +75,6 @@ test_option_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
 
   fail_unless (gst_rtsp_message_get_type (response) ==
       GST_RTSP_MESSAGE_RESPONSE);
-  gst_rtsp_message_dump (response);
 
   fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
           &version)
@@ -85,7 +86,7 @@ test_option_response_454 (GstRTSPClient * client, GstRTSPMessage * response,
   return TRUE;
 }
 
-GST_START_TEST (test_options)
+GST_START_TEST (test_request)
 {
   GstRTSPClient *client;
   GstRTSPMessage request = { 0, };
@@ -93,17 +94,17 @@ GST_START_TEST (test_options)
 
   client = gst_rtsp_client_new ();
 
-  /* simple OPTIONS */
+  /* OPTIONS with invalid url */
   fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
-          "rtsp://localhost/test") == GST_RTSP_OK);
+          "foopy://padoop/") == GST_RTSP_OK);
   str = g_strdup_printf ("%d", cseq);
   gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
   g_free (str);
 
-  gst_rtsp_client_set_send_func (client, test_option_response_200, NULL, NULL);
-  gst_rtsp_message_dump (&request);
+  gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL);
   fail_unless (gst_rtsp_client_handle_message (client,
           &request) == GST_RTSP_OK);
+
   gst_rtsp_message_unset (&request);
 
   /* OPTIONS with unknown session id */
@@ -114,8 +115,7 @@ GST_START_TEST (test_options)
   g_free (str);
   gst_rtsp_message_add_header (&request, GST_RTSP_HDR_SESSION, "foobar");
 
-  gst_rtsp_client_set_send_func (client, test_option_response_454, NULL, NULL);
-  gst_rtsp_message_dump (&request);
+  gst_rtsp_client_set_send_func (client, test_response_454, NULL, NULL);
   fail_unless (gst_rtsp_client_handle_message (client,
           &request) == GST_RTSP_OK);
 
@@ -126,6 +126,95 @@ GST_START_TEST (test_options)
 
 GST_END_TEST;
 
+static gboolean
+test_option_response_200 (GstRTSPClient * client, GstRTSPMessage * response,
+    gboolean close, gpointer user_data)
+{
+  GstRTSPStatusCode code;
+  const gchar *reason;
+  GstRTSPVersion version;
+  gchar *str;
+  GstRTSPMethod methods;
+
+  fail_unless (gst_rtsp_message_get_type (response) ==
+      GST_RTSP_MESSAGE_RESPONSE);
+
+  fail_unless (gst_rtsp_message_parse_response (response, &code, &reason,
+          &version)
+      == GST_RTSP_OK);
+  fail_unless (code == GST_RTSP_STS_OK);
+  fail_unless (g_str_equal (reason, "OK"));
+  fail_unless (version == GST_RTSP_VERSION_1_0);
+
+  fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_CSEQ, &str,
+          0) == GST_RTSP_OK);
+  fail_unless (atoi (str) == cseq++);
+
+  fail_unless (gst_rtsp_message_get_header (response, GST_RTSP_HDR_PUBLIC, &str,
+          0) == GST_RTSP_OK);
+
+  methods = gst_rtsp_options_from_text (str);
+  fail_if (methods == 0);
+  fail_unless (methods == (GST_RTSP_DESCRIBE |
+          GST_RTSP_OPTIONS |
+          GST_RTSP_PAUSE |
+          GST_RTSP_PLAY |
+          GST_RTSP_SETUP |
+          GST_RTSP_GET_PARAMETER | GST_RTSP_SET_PARAMETER | GST_RTSP_TEARDOWN));
+
+  return TRUE;
+}
+
+GST_START_TEST (test_options)
+{
+  GstRTSPClient *client;
+  GstRTSPMessage request = { 0, };
+  gchar *str;
+
+  client = gst_rtsp_client_new ();
+
+  /* simple OPTIONS */
+  fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS,
+          "rtsp://localhost/test") == GST_RTSP_OK);
+  str = g_strdup_printf ("%d", cseq);
+  gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
+  g_free (str);
+
+  gst_rtsp_client_set_send_func (client, test_option_response_200, NULL, NULL);
+  fail_unless (gst_rtsp_client_handle_message (client,
+          &request) == GST_RTSP_OK);
+  gst_rtsp_message_unset (&request);
+
+  g_object_unref (client);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_describe)
+{
+  GstRTSPClient *client;
+  GstRTSPMessage request = { 0, };
+  gchar *str;
+
+  client = gst_rtsp_client_new ();
+
+  /* simple DESCRIBE for non-existing url */
+  fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_DESCRIBE,
+          "rtsp://localhost/test") == GST_RTSP_OK);
+  str = g_strdup_printf ("%d", cseq);
+  gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str);
+  g_free (str);
+
+  gst_rtsp_client_set_send_func (client, test_response_404, NULL, NULL);
+  fail_unless (gst_rtsp_client_handle_message (client,
+          &request) == GST_RTSP_OK);
+  gst_rtsp_message_unset (&request);
+
+  g_object_unref (client);
+}
+
+GST_END_TEST;
+
 static Suite *
 rtspclient_suite (void)
 {
@@ -134,7 +223,9 @@ rtspclient_suite (void)
 
   suite_add_tcase (s, tc);
   tcase_set_timeout (tc, 20);
+  tcase_add_test (tc, test_request);
   tcase_add_test (tc, test_options);
+  tcase_add_test (tc, test_describe);
 
   return s;
 }