summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeungha Yang <seungha.yang@navercorp.com>2019-01-28 13:54:43 +0900
committerTim-Philipp Müller <tim@centricular.com>2019-05-01 17:40:11 +0100
commit094b59bd75b3e59f3d0805d8b7c0df72454d06b6 (patch)
tree40ef51d9c7d843b472a94760fbc7e47fe943333f
parentcb0980eae2db7a6a860d621b512995670cdaf2db (diff)
downloadgstreamer-plugins-base-094b59bd75b3e59f3d0805d8b7c0df72454d06b6.tar.gz
tests: discoverer: Add async API test cases
Add more test cases for async APIs such as gst_discoverer_{start,stop}, and gst_discoverer_discover_uri_async()
-rw-r--r--tests/check/libs/discoverer.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/check/libs/discoverer.c b/tests/check/libs/discoverer.c
index bbee562fd..cf0b4db12 100644
--- a/tests/check/libs/discoverer.c
+++ b/tests/check/libs/discoverer.c
@@ -243,6 +243,134 @@ GST_START_TEST (test_disco_missing_plugins)
GST_END_TEST;
+typedef struct _AsyncTestData
+{
+ gchar *uri;
+ GMainLoop *loop;
+ GstDiscovererResult result;
+} AsyncTestData;
+
+static void
+discovered_cb (GstDiscoverer * discoverer,
+ GstDiscovererInfo * info, GError * err, AsyncTestData * data)
+{
+ const gchar *uri = gst_discoverer_info_get_uri (info);
+
+ fail_unless_equals_string (data->uri, uri);
+
+ /* cannot ensure GST_DISCOVERER_OK since there might be missing plugins */
+ data->result = gst_discoverer_info_get_result (info);
+
+ g_main_loop_quit (data->loop);
+}
+
+static void
+test_disco_async_with_context (GMainContext * context)
+{
+ GstDiscoverer *dc;
+ GError *err = NULL;
+ AsyncTestData data = { 0, };
+ gchar *path =
+ g_build_filename (GST_TEST_FILES_PATH, "theora-vorbis.ogg", NULL);
+
+ if (context)
+ g_main_context_push_thread_default (context);
+
+ data.uri = gst_filename_to_uri (path, &err);
+ /* something wrong if we have error here */
+ fail_unless (err == NULL);
+ g_free (path);
+
+ data.loop = g_main_loop_new (context, FALSE);
+
+ /* high timeout, in case we're running under valgrind */
+ dc = gst_discoverer_new (5 * GST_SECOND, &err);
+ fail_unless (dc != NULL);
+ fail_unless (err == NULL);
+
+ g_signal_connect (dc, "discovered", G_CALLBACK (discovered_cb), &data);
+
+ gst_discoverer_start (dc);
+ fail_unless (gst_discoverer_discover_uri_async (dc, data.uri) == TRUE);
+
+ g_main_loop_run (data.loop);
+
+ if (have_theora && have_ogg) {
+ fail_unless_equals_int (data.result, GST_DISCOVERER_OK);
+ } else {
+ fail_unless_equals_int (data.result, GST_DISCOVERER_MISSING_PLUGINS);
+ }
+
+ gst_discoverer_stop (dc);
+ g_object_unref (dc);
+ g_free (data.uri);
+
+ g_main_loop_unref (data.loop);
+
+ if (context)
+ g_main_context_pop_thread_default (context);
+}
+
+GST_START_TEST (test_disco_async)
+{
+ /* use default GMainContext */
+ test_disco_async_with_context (NULL);
+}
+
+GST_END_TEST;
+
+typedef struct _CustomContextData
+{
+ GMutex lock;
+ GCond cond;
+ gboolean finish;
+} CustomContextData;
+
+
+static gpointer
+custom_context_thread_func (CustomContextData * data)
+{
+ GMainContext *context;
+
+ /* test async APIs with custom GMainContext */
+ context = g_main_context_new ();
+ test_disco_async_with_context (context);
+ g_main_context_unref (context);
+
+ data->finish = TRUE;
+ g_cond_signal (&data->cond);
+
+ return NULL;
+}
+
+GST_START_TEST (test_disco_async_custom_context)
+{
+ GThread *thread;
+ CustomContextData data;
+
+ g_mutex_init (&data.lock);
+ g_cond_init (&data.cond);
+ data.finish = FALSE;
+
+ /* ensure default context here, but we will use other thread default context
+ * instead of this */
+ g_main_context_default ();
+
+ thread = g_thread_new ("test-custom-context-thread",
+ (GThreadFunc) custom_context_thread_func, &data);
+
+ g_mutex_lock (&data.lock);
+ while (data.finish)
+ g_cond_wait (&data.cond, &data.lock);
+ g_mutex_unlock (&data.lock);
+
+ g_thread_join (thread);
+ g_mutex_clear (&data.lock);
+ g_cond_clear (&data.cond);
+}
+
+GST_END_TEST;
+
static Suite *
discoverer_suite (void)
{
@@ -262,6 +390,8 @@ discoverer_suite (void)
tcase_add_test (tc_chain, test_disco_sync_reuse_timeout);
tcase_add_test (tc_chain, test_disco_missing_plugins);
tcase_add_test (tc_chain, test_disco_serializing);
+ tcase_add_test (tc_chain, test_disco_async);
+ tcase_add_test (tc_chain, test_disco_async_custom_context);
return s;
}