1 /* GStreamer
2  * Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23 
24 #include <gst/check/gstcheck.h>
25 
26 #include <gst/gl/gl.h>
27 
28 #include <stdio.h>
29 
30 static GstGLDisplay *display;
31 static GstGLContext *context;
32 
33 GST_DEBUG_CATEGORY_STATIC (gst_test_debug_cat);
34 
35 static void
setup(void)36 setup (void)
37 {
38   GError *error = NULL;
39 
40   display = gst_gl_display_new ();
41   context = gst_gl_context_new (display);
42 
43   gst_gl_context_create (context, NULL, &error);
44 
45   fail_if (error != NULL, "Error creating context: %s\n",
46       error ? error->message : "Unknown Error");
47 }
48 
49 static void
teardown(void)50 teardown (void)
51 {
52   gst_object_unref (display);
53   gst_object_unref (context);
54 }
55 
56 static void
_test_query_init_gl(GstGLContext * context,gpointer data)57 _test_query_init_gl (GstGLContext * context, gpointer data)
58 {
59   GstGLQuery q1;
60 
61   /* no usage */
62   gst_gl_query_init (&q1, context, GST_GL_QUERY_TIMESTAMP);
63   gst_gl_query_unset (&q1);
64 }
65 
GST_START_TEST(test_query_init)66 GST_START_TEST (test_query_init)
67 {
68   gst_gl_context_thread_add (context,
69       (GstGLContextThreadFunc) _test_query_init_gl, NULL);
70 }
71 
72 GST_END_TEST;
73 
74 static void
_test_query_init_invalid_query_gl(GstGLContext * context,gpointer data)75 _test_query_init_invalid_query_gl (GstGLContext * context, gpointer data)
76 {
77   GstGLQuery q1;
78 
79   /* no usage */
80   ASSERT_CRITICAL (gst_gl_query_init (&q1, context, GST_GL_QUERY_NONE));
81 }
82 
GST_START_TEST(test_query_init_invalid_query)83 GST_START_TEST (test_query_init_invalid_query)
84 {
85   gst_gl_context_thread_add (context,
86       (GstGLContextThreadFunc) _test_query_init_invalid_query_gl, NULL);
87 }
88 
89 GST_END_TEST;
90 
91 static void
_test_query_new_gl(GstGLContext * context,gpointer data)92 _test_query_new_gl (GstGLContext * context, gpointer data)
93 {
94   GstGLQuery *q1;
95 
96   /* no usage */
97   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIMESTAMP);
98   gst_gl_query_free (q1);
99 }
100 
GST_START_TEST(test_query_new)101 GST_START_TEST (test_query_new)
102 {
103   gst_gl_context_thread_add (context,
104       (GstGLContextThreadFunc) _test_query_new_gl, NULL);
105 }
106 
107 GST_END_TEST;
108 
109 static void
_test_query_time_elapsed_gl(GstGLContext * context,gpointer data)110 _test_query_time_elapsed_gl (GstGLContext * context, gpointer data)
111 {
112   GstGLQuery *q1;
113 
114   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
115   fail_if (q1 == NULL);
116 
117   gst_gl_query_start (q1);
118   gst_gl_query_end (q1);
119   /* GST_GL_QUERY_TIME_ELAPSED doesn't supported counter() */
120   ASSERT_CRITICAL (gst_gl_query_counter (q1));
121   gst_gl_query_result (q1);
122 
123   gst_gl_query_free (q1);
124 }
125 
GST_START_TEST(test_query_time_elapsed)126 GST_START_TEST (test_query_time_elapsed)
127 {
128   gst_gl_context_thread_add (context,
129       (GstGLContextThreadFunc) _test_query_time_elapsed_gl, NULL);
130 }
131 
132 GST_END_TEST;
133 
134 static void
_test_query_start_log_gl(GstGLContext * context,gpointer data)135 _test_query_start_log_gl (GstGLContext * context, gpointer data)
136 {
137   GstGLQuery *q1;
138 
139   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
140   fail_if (q1 == NULL);
141 
142   gst_gl_query_start_log (q1, NULL, GST_LEVEL_ERROR, NULL, "%s",
143       "testing query proxy-logging for gst_gl_query_start_log()");
144   gst_gl_query_end (q1);
145   gst_gl_query_result (q1);
146 
147   gst_gl_query_free (q1);
148 }
149 
GST_START_TEST(test_query_start_log)150 GST_START_TEST (test_query_start_log)
151 {
152   gst_gl_context_thread_add (context,
153       (GstGLContextThreadFunc) _test_query_start_log_gl, NULL);
154 }
155 
156 GST_END_TEST;
157 
158 static void
_test_query_timestamp_gl(GstGLContext * context,gpointer data)159 _test_query_timestamp_gl (GstGLContext * context, gpointer data)
160 {
161   GstGLQuery q2;
162 
163   gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
164 
165   /* GST_GL_QUERY_TIMESTAMP doesn't supported start()/end() */
166   ASSERT_CRITICAL (gst_gl_query_start (&q2));
167   ASSERT_CRITICAL (gst_gl_query_end (&q2));
168 
169   gst_gl_query_counter (&q2);
170   gst_gl_query_result (&q2);
171 
172   gst_gl_query_unset (&q2);
173 }
174 
GST_START_TEST(test_query_timestamp)175 GST_START_TEST (test_query_timestamp)
176 {
177   gst_gl_context_thread_add (context,
178       (GstGLContextThreadFunc) _test_query_timestamp_gl, NULL);
179 }
180 
181 GST_END_TEST;
182 
183 static void
_test_query_counter_log_gl(GstGLContext * context,gpointer data)184 _test_query_counter_log_gl (GstGLContext * context, gpointer data)
185 {
186   GstGLQuery q2;
187 
188   gst_gl_query_init (&q2, context, GST_GL_QUERY_TIMESTAMP);
189 
190   gst_gl_query_counter_log (&q2, gst_test_debug_cat, GST_LEVEL_ERROR, NULL,
191       "%s",
192       "testing query proxy-logging works from gst_gl_query_counter_log()");
193   gst_gl_query_result (&q2);
194 
195   gst_gl_query_unset (&q2);
196 }
197 
GST_START_TEST(test_query_counter_log)198 GST_START_TEST (test_query_counter_log)
199 {
200   gst_gl_context_thread_add (context,
201       (GstGLContextThreadFunc) _test_query_counter_log_gl, NULL);
202 }
203 
204 GST_END_TEST;
205 
206 static void
_test_query_start_free_gl(GstGLContext * context,gpointer data)207 _test_query_start_free_gl (GstGLContext * context, gpointer data)
208 {
209   GstGLQuery *q1;
210 
211   /* test mismatched start()/free() */
212   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
213   fail_if (q1 == NULL);
214 
215   gst_gl_query_start (q1);
216 
217   ASSERT_CRITICAL (gst_gl_query_free (q1));
218 }
219 
GST_START_TEST(test_query_start_free)220 GST_START_TEST (test_query_start_free)
221 {
222   gst_gl_context_thread_add (context,
223       (GstGLContextThreadFunc) _test_query_start_free_gl, NULL);
224 }
225 
226 GST_END_TEST;
227 
228 static void
_test_query_start_result_gl(GstGLContext * context,gpointer data)229 _test_query_start_result_gl (GstGLContext * context, gpointer data)
230 {
231   GstGLQuery *q1;
232 
233   /* test mismatched start()/result() */
234   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
235   fail_if (q1 == NULL);
236 
237   gst_gl_query_start (q1);
238   ASSERT_CRITICAL (gst_gl_query_result (q1));
239   gst_gl_query_end (q1);
240 
241   gst_gl_query_free (q1);
242 }
243 
GST_START_TEST(test_query_start_result)244 GST_START_TEST (test_query_start_result)
245 {
246   gst_gl_context_thread_add (context,
247       (GstGLContextThreadFunc) _test_query_start_result_gl, NULL);
248 }
249 
250 GST_END_TEST;
251 
252 static void
_test_query_start_start_gl(GstGLContext * context,gpointer data)253 _test_query_start_start_gl (GstGLContext * context, gpointer data)
254 {
255   GstGLQuery *q1;
256 
257   /* test double end() */
258   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
259   fail_if (q1 == NULL);
260 
261   gst_gl_query_start (q1);
262   ASSERT_CRITICAL (gst_gl_query_start (q1));
263   gst_gl_query_end (q1);
264 
265   gst_gl_query_free (q1);
266 }
267 
GST_START_TEST(test_query_start_start)268 GST_START_TEST (test_query_start_start)
269 {
270   gst_gl_context_thread_add (context,
271       (GstGLContextThreadFunc) _test_query_start_start_gl, NULL);
272 }
273 
274 GST_END_TEST;
275 
276 static void
_test_query_end_gl(GstGLContext * context,gpointer data)277 _test_query_end_gl (GstGLContext * context, gpointer data)
278 {
279   GstGLQuery *q1;
280 
281   /* test mismatched end() */
282   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
283   fail_if (q1 == NULL);
284   ASSERT_CRITICAL (gst_gl_query_end (q1));
285   gst_gl_query_free (q1);
286 }
287 
GST_START_TEST(test_query_end)288 GST_START_TEST (test_query_end)
289 {
290   gst_gl_context_thread_add (context,
291       (GstGLContextThreadFunc) _test_query_end_gl, NULL);
292 }
293 
294 GST_END_TEST;
295 
296 static void
_test_query_end_end_gl(GstGLContext * context,gpointer data)297 _test_query_end_end_gl (GstGLContext * context, gpointer data)
298 {
299   GstGLQuery *q1;
300 
301   /* test double end() */
302   q1 = gst_gl_query_new (context, GST_GL_QUERY_TIME_ELAPSED);
303   fail_if (q1 == NULL);
304 
305   gst_gl_query_start (q1);
306   gst_gl_query_end (q1);
307   ASSERT_CRITICAL (gst_gl_query_end (q1));
308 
309   gst_gl_query_free (q1);
310 }
311 
GST_START_TEST(test_query_end_end)312 GST_START_TEST (test_query_end_end)
313 {
314   gst_gl_context_thread_add (context,
315       (GstGLContextThreadFunc) _test_query_end_end_gl, NULL);
316 }
317 
318 GST_END_TEST;
319 
320 static Suite *
gst_gl_upload_suite(void)321 gst_gl_upload_suite (void)
322 {
323   Suite *s = suite_create ("GstGLQuery");
324   TCase *tc_chain = tcase_create ("glquery");
325 
326   GST_DEBUG_CATEGORY_INIT (gst_test_debug_cat, "test-debug", 0,
327       "proxy-logging test debug");
328 
329   suite_add_tcase (s, tc_chain);
330   tcase_add_checked_fixture (tc_chain, setup, teardown);
331   tcase_add_test (tc_chain, test_query_init);
332   tcase_add_test (tc_chain, test_query_init_invalid_query);
333   tcase_add_test (tc_chain, test_query_new);
334   tcase_add_test (tc_chain, test_query_time_elapsed);
335   tcase_add_test (tc_chain, test_query_timestamp);
336   tcase_add_test (tc_chain, test_query_counter_log);
337   tcase_add_test (tc_chain, test_query_start_log);
338   tcase_add_test (tc_chain, test_query_start_free);
339   tcase_add_test (tc_chain, test_query_start_result);
340   tcase_add_test (tc_chain, test_query_start_start);
341   tcase_add_test (tc_chain, test_query_end);
342   tcase_add_test (tc_chain, test_query_end_end);
343 
344   return s;
345 }
346 
347 GST_CHECK_MAIN (gst_gl_upload);
348