Blame tests/check/libs/gstglquery.c

Packit Service 4387a0
/* GStreamer
Packit Service 4387a0
 * Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
Packit Service 4387a0
 *
Packit Service 4387a0
 * This library is free software; you can redistribute it and/or
Packit Service 4387a0
 * modify it under the terms of the GNU Library General Public
Packit Service 4387a0
 * License as published by the Free Software Foundation; either
Packit Service 4387a0
 * version 2 of the License, or (at your option) any later version.
Packit Service 4387a0
 *
Packit Service 4387a0
 * This library is distributed in the hope that it will be useful,
Packit Service 4387a0
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 4387a0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 4387a0
 * Library General Public License for more details.
Packit Service 4387a0
 *
Packit Service 4387a0
 * You should have received a copy of the GNU Library General Public
Packit Service 4387a0
 * License along with this library; if not, write to the
Packit Service 4387a0
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit Service 4387a0
 * Boston, MA 02110-1301, USA.
Packit Service 4387a0
 */
Packit Service 4387a0
Packit Service 4387a0
#ifdef HAVE_CONFIG_H
Packit Service 4387a0
#  include "config.h"
Packit Service 4387a0
#endif
Packit Service 4387a0
Packit Service 4387a0
#include <gst/check/gstcheck.h>
Packit Service 4387a0
Packit Service 4387a0
#include <gst/gl/gl.h>
Packit Service 4387a0
Packit Service 4387a0
#include <stdio.h>
Packit Service 4387a0
Packit Service 4387a0
static GstGLDisplay *display;
Packit Service 4387a0
static GstGLContext *context;
Packit Service 4387a0
Packit Service 4387a0
GST_DEBUG_CATEGORY_STATIC (gst_test_debug_cat);
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
setup (void)
Packit Service 4387a0
{
Packit Service 4387a0
  GError *error = NULL;
Packit Service 4387a0
Packit Service 4387a0
  display = gst_gl_display_new ();
Packit Service 4387a0
  context = gst_gl_context_new (display);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_context_create (context, NULL, &error);
Packit Service 4387a0
Packit Service 4387a0
  fail_if (error != NULL, "Error creating context: %s\n",
Packit Service 4387a0
      error ? error->message : "Unknown Error");
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
teardown (void)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_object_unref (display);
Packit Service 4387a0
  gst_object_unref (context);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_init_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery q1;
Packit Service 4387a0
Packit Service 4387a0
  /* no usage */
Packit Service 4387a0
  gst_gl_query_init (&q1, context, GST_GL_QUERY_TIMESTAMP);
Packit Service 4387a0
  gst_gl_query_unset (&q1;;
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_init)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_init_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_init_invalid_query_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery q1;
Packit Service 4387a0
Packit Service 4387a0
  /* no usage */
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_init (&q1, context, GST_GL_QUERY_NONE));
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_init_invalid_query)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_init_invalid_query_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_new_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* no usage */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIMESTAMP);
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_new)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_new_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_time_elapsed_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start (q1);
Packit Service 4387a0
  gst_gl_query_end (q1);
Packit Service 4387a0
  /* GST_GL_QUERY_TIME_ELAPSED doesn't supported counter() */
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_counter (q1));
Packit Service 4387a0
  gst_gl_query_result (q1);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_time_elapsed)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_time_elapsed_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_start_log_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start_log (q1, NULL, GST_LEVEL_ERROR, NULL, "%s",
Packit Service 4387a0
      "testing query proxy-logging for gst_gl_query_start_log()");
Packit Service 4387a0
  gst_gl_query_end (q1);
Packit Service 4387a0
  gst_gl_query_result (q1);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_start_log)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_start_log_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_timestamp_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery q2;
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
Packit Service 4387a0
Packit Service 4387a0
  /* GST_GL_QUERY_TIMESTAMP doesn't supported start()/end() */
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_start (&q2));
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_end (&q2));
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_counter (&q2;;
Packit Service 4387a0
  gst_gl_query_result (&q2;;
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_unset (&q2;;
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_timestamp)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_timestamp_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_counter_log_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery q2;
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_counter_log (&q2, gst_test_debug_cat, GST_LEVEL_ERROR, NULL,
Packit Service 4387a0
      "%s",
Packit Service 4387a0
      "testing query proxy-logging works from gst_gl_query_counter_log()");
Packit Service 4387a0
  gst_gl_query_result (&q2;;
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_unset (&q2;;
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_counter_log)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_counter_log_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_start_free_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* test mismatched start()/free() */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start (q1);
Packit Service 4387a0
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_free (q1));
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_start_free)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_start_free_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_start_result_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* test mismatched start()/result() */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start (q1);
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_result (q1));
Packit Service 4387a0
  gst_gl_query_end (q1);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_start_result)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_start_result_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_start_start_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* test double end() */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start (q1);
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_start (q1));
Packit Service 4387a0
  gst_gl_query_end (q1);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_start_start)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_start_start_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_end_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* test mismatched end() */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_end (q1));
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_end)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_end_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static void
Packit Service 4387a0
_test_query_end_end_gl (GstGLContext * context, gpointer data)
Packit Service 4387a0
{
Packit Service 4387a0
  GstGLQuery *q1;
Packit Service 4387a0
Packit Service 4387a0
  /* test double end() */
Packit Service 4387a0
  q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
Packit Service 4387a0
  fail_if (q1 == NULL);
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_start (q1);
Packit Service 4387a0
  gst_gl_query_end (q1);
Packit Service 4387a0
  ASSERT_CRITICAL (gst_gl_query_end (q1));
Packit Service 4387a0
Packit Service 4387a0
  gst_gl_query_free (q1);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_START_TEST (test_query_end_end)
Packit Service 4387a0
{
Packit Service 4387a0
  gst_gl_context_thread_add (context,
Packit Service 4387a0
      (GstGLContextThreadFunc) _test_query_end_end_gl, NULL);
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_END_TEST;
Packit Service 4387a0
Packit Service 4387a0
static Suite *
Packit Service 4387a0
gst_gl_upload_suite (void)
Packit Service 4387a0
{
Packit Service 4387a0
  Suite *s = suite_create ("GstGLQuery");
Packit Service 4387a0
  TCase *tc_chain = tcase_create ("glquery");
Packit Service 4387a0
Packit Service 4387a0
  GST_DEBUG_CATEGORY_INIT (gst_test_debug_cat, "test-debug", 0,
Packit Service 4387a0
      "proxy-logging test debug");
Packit Service 4387a0
Packit Service 4387a0
  suite_add_tcase (s, tc_chain);
Packit Service 4387a0
  tcase_add_checked_fixture (tc_chain, setup, teardown);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_init);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_init_invalid_query);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_new);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_time_elapsed);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_timestamp);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_counter_log);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_start_log);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_start_free);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_start_result);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_start_start);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_end);
Packit Service 4387a0
  tcase_add_test (tc_chain, test_query_end_end);
Packit Service 4387a0
Packit Service 4387a0
  return s;
Packit Service 4387a0
}
Packit Service 4387a0
Packit Service 4387a0
GST_CHECK_MAIN (gst_gl_upload);