Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Unittest for curlhttpsink |
| 3 | */ |
| 4 | |
| 5 | #include <gst/check/gstcheck.h> |
| 6 | #include <glib/gstdio.h> |
| 7 | #include <curl/curl.h> |
| 8 | |
| 9 | static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
| 10 | GST_PAD_SRC, |
| 11 | GST_PAD_ALWAYS, |
| 12 | GST_STATIC_CAPS_ANY); |
| 13 | |
| 14 | static GstPad *srcpad; |
| 15 | |
| 16 | static GstElement *sink; |
| 17 | |
| 18 | static GstElement * |
| 19 | setup_curlhttpsink (void) |
| 20 | { |
| 21 | GST_DEBUG ("setup_curlhttpsink"); |
| 22 | sink = gst_check_setup_element ("curlhttpsink"); |
| 23 | srcpad = gst_check_setup_src_pad (sink, &srctemplate); |
Sebastian Rasmussen | 54d160b | 2014-04-22 22:26:56 +0200 | [diff] [blame] | 24 | fail_unless (gst_pad_set_active (srcpad, TRUE)); |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 25 | |
| 26 | return sink; |
| 27 | } |
| 28 | |
| 29 | static void |
| 30 | cleanup_curlhttpsink (GstElement * sink) |
| 31 | { |
| 32 | GST_DEBUG ("cleanup_curlhttpsink"); |
| 33 | |
| 34 | gst_check_teardown_src_pad (sink); |
| 35 | gst_check_teardown_element (sink); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | GST_START_TEST (test_properties) |
| 40 | { |
| 41 | GstElement *sink; |
| 42 | gchar *res_location = NULL; |
| 43 | gchar *res_file_name = NULL; |
| 44 | gchar *res_user; |
| 45 | gchar *res_passwd; |
| 46 | gchar *res_proxy; |
| 47 | guint res_proxy_port; |
| 48 | gchar *res_proxy_user; |
| 49 | gchar *res_proxy_passwd; |
| 50 | gchar *res_content_type; |
| 51 | gboolean res_use_content_length; |
| 52 | |
| 53 | sink = setup_curlhttpsink (); |
| 54 | |
| 55 | g_object_set (G_OBJECT (sink), |
| 56 | "location", "mylocation", |
Tim-Philipp Müller | 2adecc1 | 2015-12-23 23:13:21 +0000 | [diff] [blame] | 57 | "file-name", "myfile", |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 58 | "user", "user", |
| 59 | "passwd", "passwd", |
| 60 | "proxy", "myproxy", |
| 61 | "proxy-port", 7777, |
| 62 | "proxy-user", "proxy_user", |
| 63 | "proxy-passwd", "proxy_passwd", |
Tim-Philipp Müller | 2adecc1 | 2015-12-23 23:13:21 +0000 | [diff] [blame] | 64 | "content-type", "image/jpeg", "use-content-length", TRUE, NULL); |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 65 | |
| 66 | g_object_get (sink, |
| 67 | "location", &res_location, |
| 68 | "file-name", &res_file_name, |
| 69 | "user", &res_user, |
| 70 | "passwd", &res_passwd, |
| 71 | "proxy", &res_proxy, |
| 72 | "proxy-port", &res_proxy_port, |
| 73 | "proxy-user", &res_proxy_user, |
| 74 | "proxy-passwd", &res_proxy_passwd, |
| 75 | "content-type", &res_content_type, |
Tim-Philipp Müller | 2adecc1 | 2015-12-23 23:13:21 +0000 | [diff] [blame] | 76 | "use-content-length", &res_use_content_length, NULL); |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 77 | |
| 78 | fail_unless (strncmp (res_location, "mylocation", strlen ("mylocation")) |
| 79 | == 0); |
| 80 | fail_unless (strncmp (res_file_name, "myfile", strlen ("myfile")) |
| 81 | == 0); |
| 82 | fail_unless (strncmp (res_user, "user", strlen ("user")) == 0); |
| 83 | fail_unless (strncmp (res_passwd, "passwd", strlen ("passwd")) == 0); |
| 84 | fail_unless (strncmp (res_proxy, "myproxy", strlen ("myproxy")) == 0); |
| 85 | fail_unless (res_proxy_port == 7777); |
| 86 | fail_unless (strncmp (res_proxy_user, "proxy_user", strlen ("proxy_user")) |
| 87 | == 0); |
| 88 | fail_unless (strncmp (res_proxy_passwd, "proxy_passwd", |
Tim-Philipp Müller | 2adecc1 | 2015-12-23 23:13:21 +0000 | [diff] [blame] | 89 | strlen ("proxy_passwd")) == 0); |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 90 | fail_unless (strncmp (res_content_type, "image/jpeg", strlen ("image/jpeg")) |
| 91 | == 0); |
| 92 | fail_unless (res_use_content_length == TRUE); |
| 93 | |
| 94 | g_free (res_location); |
| 95 | g_free (res_file_name); |
| 96 | g_free (res_user); |
| 97 | g_free (res_passwd); |
| 98 | g_free (res_proxy); |
| 99 | g_free (res_proxy_user); |
| 100 | g_free (res_proxy_passwd); |
| 101 | g_free (res_content_type); |
| 102 | |
| 103 | /* new properties */ |
| 104 | g_object_set (G_OBJECT (sink), "location", "newlocation", NULL); |
| 105 | g_object_get (sink, "location", &res_location, NULL); |
| 106 | fail_unless (strncmp (res_location, "newlocation", strlen ("newlocation")) |
| 107 | == 0); |
| 108 | g_free (res_location); |
| 109 | |
| 110 | g_object_set (G_OBJECT (sink), "file-name", "newfile", NULL); |
| 111 | g_object_get (sink, "file-name", &res_file_name, NULL); |
| 112 | fail_unless (strncmp (res_file_name, "newfile", strlen ("newfile")) |
| 113 | == 0); |
| 114 | g_free (res_file_name); |
| 115 | |
| 116 | cleanup_curlhttpsink (sink); |
| 117 | } |
Tim-Philipp Müller | 2adecc1 | 2015-12-23 23:13:21 +0000 | [diff] [blame] | 118 | |
Patricia Muscalu | ae39cbf | 2012-01-23 09:00:47 +0100 | [diff] [blame] | 119 | GST_END_TEST; |
| 120 | |
| 121 | static Suite * |
| 122 | curlsink_suite (void) |
| 123 | { |
| 124 | Suite *s = suite_create ("curlhttpsink"); |
| 125 | TCase *tc_chain = tcase_create ("general"); |
| 126 | |
| 127 | suite_add_tcase (s, tc_chain); |
| 128 | tcase_set_timeout (tc_chain, 20); |
| 129 | tcase_add_test (tc_chain, test_properties); |
| 130 | |
| 131 | return s; |
| 132 | } |
| 133 | |
| 134 | GST_CHECK_MAIN (curlsink); |