gl/query: split tests and fix some corresponding issues in usage
authorMatthew Waters <matthew@centricular.com>
Sat, 28 Oct 2017 07:33:44 +0000 (18:33 +1100)
committerMatthew Waters <matthew@centricular.com>
Sat, 28 Oct 2017 07:34:57 +0000 (18:34 +1100)
gst-libs/gst/gl/gstglquery.c
tests/check/libs/gstglquery.c

index faceebf..3023959 100644 (file)
@@ -90,7 +90,6 @@ _gst_gl_query_type_to_gl (GstGLQueryType query_type)
   if (query_type == GST_GL_QUERY_TIMESTAMP)
     return GL_TIMESTAMP;
 
-  g_assert_not_reached ();
   return 0;
 }
 
@@ -136,17 +135,20 @@ gst_gl_query_init (GstGLQuery * query, GstGLContext * context,
     GstGLQueryType query_type)
 {
   const GstGLFuncs *gl;
+  GLenum gl_query_type;
 
   g_return_if_fail (query != NULL);
   g_return_if_fail (GST_IS_GL_CONTEXT (context));
   gl = context->gl_vtable;
+  gl_query_type = _gst_gl_query_type_to_gl (query_type);
+  g_return_if_fail (gl_query_type != GL_NONE);
 
   memset (query, 0, sizeof (*query));
 
   _init_debug ();
 
+  query->query_type = gl_query_type;
   query->context = gst_object_ref (context);
-  query->query_type = _gst_gl_query_type_to_gl (query_type);
   query->supported = _context_supports_query_type (context, query->query_type);
 
   if (query->supported)
@@ -241,11 +243,13 @@ gst_gl_query_start (GstGLQuery * query)
 
   g_return_if_fail (query != NULL);
   g_return_if_fail (_query_type_supports_begin_end (query->query_type));
+  g_return_if_fail (query->start_called == FALSE);
+
+  query->start_called = TRUE;
 
   if (!query->supported)
     return;
 
-  query->start_called = TRUE;
   gst_gl_async_debug_output_log_msg (&query->debug);
 
   GST_TRACE ("%p start query type \'%s\' id %u", query,
@@ -270,10 +274,12 @@ gst_gl_query_end (GstGLQuery * query)
 
   g_return_if_fail (query != NULL);
   g_return_if_fail (_query_type_supports_begin_end (query->query_type));
+  g_return_if_fail (query->start_called);
+
+  query->start_called = FALSE;
 
   if (!query->supported)
     return;
-  g_return_if_fail (query->start_called);
 
   GST_TRACE ("%p end query type \'%s\' id %u", query,
       _query_type_to_string (query->query_type), query->query_id);
@@ -281,7 +287,6 @@ gst_gl_query_end (GstGLQuery * query)
   gl = query->context->gl_vtable;
 
   gl->EndQuery (query->query_type);
-  query->start_called = FALSE;
 }
 
 /**
index 2dfa240..8563abb 100644 (file)
@@ -54,21 +54,111 @@ teardown (void)
 }
 
 static void
-_test_query_gl (GstGLContext * context, gpointer data)
+_test_query_init_gl (GstGLContext * context, gpointer data)
 {
-  GstGLQuery *q1, q2;
+  GstGLQuery q1;
+
+  /* no usage */
+  gst_gl_query_init (&q1, context, GST_GL_QUERY_TIMESTAMP);
+  gst_gl_query_unset (&q1);
+}
+
+GST_START_TEST (test_query_init)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_init_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_init_invalid_query_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery q1;
+
+  /* no usage */
+  ASSERT_CRITICAL (gst_gl_query_init (&q1, context, GST_GL_QUERY_NONE));
+}
+
+GST_START_TEST (test_query_init_invalid_query)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_init_invalid_query_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_new_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
+
+  /* no usage */
+  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIMESTAMP);
+  gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_new)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_new_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_time_elapsed_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
 
   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
   fail_if (q1 == NULL);
 
-  gst_gl_query_start_log (q1, NULL, GST_LEVEL_ERROR, NULL, "%s",
-      "1. testing query proxy-logging");
+  gst_gl_query_start (q1);
   gst_gl_query_end (q1);
   /* GST_GL_QUERY_TIME_ELAPSED doesn't supported counter() */
   ASSERT_CRITICAL (gst_gl_query_counter (q1));
   gst_gl_query_result (q1);
 
   gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_time_elapsed)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_time_elapsed_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_start_log_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
+
+  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
+  fail_if (q1 == NULL);
+
+  gst_gl_query_start_log (q1, NULL, GST_LEVEL_ERROR, NULL, "%s",
+      "testing query proxy-logging for gst_gl_query_start_log()");
+  gst_gl_query_end (q1);
+  gst_gl_query_result (q1);
+
+  gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_start_log)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_start_log_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_timestamp_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery q2;
 
   gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
 
@@ -76,15 +166,47 @@ _test_query_gl (GstGLContext * context, gpointer data)
   ASSERT_CRITICAL (gst_gl_query_start (&q2));
   ASSERT_CRITICAL (gst_gl_query_end (&q2));
 
-  gst_gl_query_counter_log (&q2, gst_test_debug_cat, GST_LEVEL_ERROR, NULL,
-      "%s", "2. testing query proxy-logging works from _unset()");
+  gst_gl_query_counter (&q2);
   gst_gl_query_result (&q2);
 
   gst_gl_query_unset (&q2);
+}
+
+GST_START_TEST (test_query_timestamp)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_timestamp_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_counter_log_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery q2;
 
-  /* no usage */
   gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
+
+  gst_gl_query_counter_log (&q2, gst_test_debug_cat, GST_LEVEL_ERROR, NULL,
+      "%s",
+      "testing query proxy-logging works from gst_gl_query_counter_log()");
+  gst_gl_query_result (&q2);
+
   gst_gl_query_unset (&q2);
+}
+
+GST_START_TEST (test_query_counter_log)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_counter_log_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_start_free_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
 
   /* test mismatched start()/free() */
   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
@@ -93,6 +215,20 @@ _test_query_gl (GstGLContext * context, gpointer data)
   gst_gl_query_start (q1);
 
   ASSERT_CRITICAL (gst_gl_query_free (q1));
+}
+
+GST_START_TEST (test_query_start_free)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_start_free_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_start_result_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
 
   /* test mismatched start()/result() */
   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
@@ -103,12 +239,64 @@ _test_query_gl (GstGLContext * context, gpointer data)
   gst_gl_query_end (q1);
 
   gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_start_result)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_start_result_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_start_start_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
+
+  /* test double end() */
+  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
+  fail_if (q1 == NULL);
+
+  gst_gl_query_start (q1);
+  ASSERT_CRITICAL (gst_gl_query_start (q1));
+  gst_gl_query_end (q1);
+
+  gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_start_start)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_start_start_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_end_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
 
   /* test mismatched end() */
   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
   fail_if (q1 == NULL);
   ASSERT_CRITICAL (gst_gl_query_end (q1));
   gst_gl_query_free (q1);
+}
+
+GST_START_TEST (test_query_end)
+{
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_end_gl, NULL);
+}
+
+GST_END_TEST;
+
+static void
+_test_query_end_end_gl (GstGLContext * context, gpointer data)
+{
+  GstGLQuery *q1;
 
   /* test double end() */
   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
@@ -119,14 +307,12 @@ _test_query_gl (GstGLContext * context, gpointer data)
   ASSERT_CRITICAL (gst_gl_query_end (q1));
 
   gst_gl_query_free (q1);
-
-  /* double start is allowed */
 }
 
-GST_START_TEST (test_query)
+GST_START_TEST (test_query_end_end)
 {
-  gst_gl_context_thread_add (context, (GstGLContextThreadFunc) _test_query_gl,
-      NULL);
+  gst_gl_context_thread_add (context,
+      (GstGLContextThreadFunc) _test_query_end_end_gl, NULL);
 }
 
 GST_END_TEST;
@@ -142,7 +328,18 @@ gst_gl_upload_suite (void)
 
   suite_add_tcase (s, tc_chain);
   tcase_add_checked_fixture (tc_chain, setup, teardown);
-  tcase_add_test (tc_chain, test_query);
+  tcase_add_test (tc_chain, test_query_init);
+  tcase_add_test (tc_chain, test_query_init_invalid_query);
+  tcase_add_test (tc_chain, test_query_new);
+  tcase_add_test (tc_chain, test_query_time_elapsed);
+  tcase_add_test (tc_chain, test_query_timestamp);
+  tcase_add_test (tc_chain, test_query_counter_log);
+  tcase_add_test (tc_chain, test_query_start_log);
+  tcase_add_test (tc_chain, test_query_start_free);
+  tcase_add_test (tc_chain, test_query_start_result);
+  tcase_add_test (tc_chain, test_query_start_start);
+  tcase_add_test (tc_chain, test_query_end);
+  tcase_add_test (tc_chain, test_query_end_end);
 
   return s;
 }