From b8b87694a177de1ca7a64056a13ddfb22b299d0b Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Sat, 5 May 2018 21:29:40 +1000 Subject: [PATCH] glformat: add test for formats --- tests/check/Makefile.am | 9 ++ tests/check/libs/.gitignore | 1 + tests/check/libs/gstglformat.c | 246 +++++++++++++++++++++++++++++++++++++++++ tests/check/meson.build | 1 + 4 files changed, 257 insertions(+) create mode 100644 tests/check/libs/gstglformat.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 9ba823e..d3e14c7 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -42,6 +42,7 @@ check_gl=\ libs/gstglslstage \ libs/gstglshader \ libs/gstglheaders \ + libs/gstglformat \ elements/glimagesink \ elements/glbin \ pipelines/gl-launch-lines @@ -504,6 +505,14 @@ libs_gstglheaders_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS) +libs_gstglformat_CFLAGS = \ + $(GST_PLUGINS_BASE_CFLAGS) \ + $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS) + +libs_gstglformat_LDADD = \ + $(top_builddir)/gst-libs/gst/gl/libgstgl-@GST_API_VERSION@.la \ + $(GST_BASE_LIBS) $(GST_LIBS) $(LDADD) + elements_glimagesink_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GL_CFLAGS) $(AM_CFLAGS) diff --git a/tests/check/libs/.gitignore b/tests/check/libs/.gitignore index a9134ce..f883967 100644 --- a/tests/check/libs/.gitignore +++ b/tests/check/libs/.gitignore @@ -10,6 +10,7 @@ fft gstglcolorconvert gstglcontext gstglheaders +gstglformat gstglmatrix gstglmemory gstglquery diff --git a/tests/check/libs/gstglformat.c b/tests/check/libs/gstglformat.c new file mode 100644 index 0000000..3b0870d --- /dev/null +++ b/tests/check/libs/gstglformat.c @@ -0,0 +1,246 @@ +/* GStreamer + * + * unit test for state changes on all elements + * + * Copyright (C) <2017> Julien Isorce + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include +#include + +static GstGLDisplay *display; +static GstGLContext *context; + +static void +setup (void) +{ + display = gst_gl_display_new (); + context = gst_gl_context_new (display); + gst_gl_context_create (context, 0, NULL); +} + +static void +teardown (void) +{ + gst_object_unref (context); + gst_object_unref (display); +} + +/* keep in sync with the list in gstglformat.h */ +static const struct +{ + GstGLFormat format; + guint gl_type; + guint n_bytes; +} formats[] = { + /* *INDENT-OFF* */ + {GST_GL_LUMINANCE, GL_UNSIGNED_BYTE, 1}, + {GST_GL_ALPHA, GL_UNSIGNED_BYTE, 1}, + {GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2}, + {GST_GL_RED, GL_UNSIGNED_BYTE, 1}, + {GST_GL_R8, GL_UNSIGNED_BYTE, 1}, + {GST_GL_RG, GL_UNSIGNED_BYTE, 2}, + {GST_GL_RG8, GL_UNSIGNED_BYTE, 2}, + {GST_GL_RGB, GL_UNSIGNED_BYTE, 3}, + {GST_GL_RGB8, GL_UNSIGNED_BYTE, 3}, + {GST_GL_RGB565, GL_UNSIGNED_SHORT_5_6_5, 2}, + {GST_GL_RGB16, GL_UNSIGNED_SHORT, 6}, + {GST_GL_RGBA, GL_UNSIGNED_BYTE, 4}, + {GST_GL_RGBA8, GL_UNSIGNED_BYTE, 4}, + {GST_GL_RGBA16, GL_UNSIGNED_SHORT, 8}, +/* {GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE, 2}, + {GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE, 4},*/ + /* *INDENT-ON* */ +}; + +GST_START_TEST (test_format_n_bytes) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (formats); i++) { + GST_DEBUG ("idx %i: expected %u, args format 0x%x, gl type 0x%x", i, + formats[i].n_bytes, formats[i].format, formats[i].gl_type); + fail_unless_equals_int (formats[i].n_bytes, + gst_gl_format_type_n_bytes (formats[i].format, formats[i].gl_type)); + } +} + +GST_END_TEST; + +/* keep in sync with the list in gstglformat.h */ +static const struct +{ + GstGLFormat format; + GstGLFormat unsized_format; + guint gl_type; +} sized_formats[] = { + /* *INDENT-OFF* */ + {GST_GL_LUMINANCE, GST_GL_LUMINANCE, GL_UNSIGNED_BYTE}, + {GST_GL_ALPHA, GST_GL_ALPHA, GL_UNSIGNED_BYTE}, + {GST_GL_LUMINANCE_ALPHA, GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE}, +/* {GST_GL_R8, GST_GL_RED, GL_UNSIGNED_BYTE}, can be either R8 or RED depending on extensions and GL version */ +/* {GST_GL_R8, GST_GL_R8, GL_UNSIGNED_BYTE}, can be either R8 or RED depending on extensions and GL version */ +/* {GST_GL_RG8, GST_GL_RG, GL_UNSIGNED_BYTE}, can be either RG8 or RG depending on extensions and GL version */ +/* {GST_GL_RG8, GST_GL_RG8, GL_UNSIGNED_BYTE}, can be either RG8 or RG depending on extensions and GL version */ + {GST_GL_RGB8, GST_GL_RGB, GL_UNSIGNED_BYTE}, + {GST_GL_RGB8, GST_GL_RGB8, GL_UNSIGNED_BYTE}, + {GST_GL_RGB565, GST_GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, + {GST_GL_RGB565, GST_GL_RGB565, GL_UNSIGNED_SHORT_5_6_5}, + {GST_GL_RGB16, GST_GL_RGB, GL_UNSIGNED_SHORT}, + {GST_GL_RGB16, GST_GL_RGB16, GL_UNSIGNED_SHORT}, + {GST_GL_RGBA8, GST_GL_RGBA, GL_UNSIGNED_BYTE}, + {GST_GL_RGBA8, GST_GL_RGBA8, GL_UNSIGNED_BYTE}, + {GST_GL_RGBA16, GST_GL_RGBA, GL_UNSIGNED_SHORT}, + {GST_GL_RGBA16, GST_GL_RGBA16, GL_UNSIGNED_SHORT}, +/* {GST_GL_DEPTH_COMPONENT16, GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE}, + {GST_GL_DEPTH24_STENCIL8, GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE},*/ + /* *INDENT-ON* */ +}; + +GST_START_TEST (test_sized_from_unsized) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (sized_formats); i++) { + GST_DEBUG ("idx %i: expected 0x%x, args format 0x%x, gl type 0x%x", i, + sized_formats[i].format, sized_formats[i].unsized_format, + sized_formats[i].gl_type); + fail_unless_equals_int (sized_formats[i].format, + gst_gl_sized_gl_format_from_gl_format_type (context, + sized_formats[i].unsized_format, sized_formats[i].gl_type)); + } +} + +GST_END_TEST; + +/* keep in sync with the list in gstglformat.h */ +static const struct +{ + GstGLFormat unsized_format; + guint gl_type; + GstGLFormat format; +} unsized_formats[] = { + /* *INDENT-OFF* */ + {GST_GL_LUMINANCE, GL_UNSIGNED_BYTE, GST_GL_LUMINANCE}, + {GST_GL_ALPHA, GL_UNSIGNED_BYTE, GST_GL_ALPHA}, + {GST_GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GST_GL_LUMINANCE_ALPHA}, + {GST_GL_RED, GL_UNSIGNED_BYTE, GST_GL_RED}, + {GST_GL_RED, GL_UNSIGNED_BYTE, GST_GL_R8}, + {GST_GL_RG, GL_UNSIGNED_BYTE, GST_GL_RG}, + {GST_GL_RG, GL_UNSIGNED_BYTE, GST_GL_RG8}, + {GST_GL_RGB, GL_UNSIGNED_BYTE, GST_GL_RGB}, + {GST_GL_RGB, GL_UNSIGNED_BYTE, GST_GL_RGB8}, + {GST_GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GST_GL_RGB565}, + {GST_GL_RGB, GL_UNSIGNED_SHORT, GST_GL_RGB16}, + {GST_GL_RGBA, GL_UNSIGNED_BYTE, GST_GL_RGBA}, + {GST_GL_RGBA, GL_UNSIGNED_BYTE, GST_GL_RGBA8}, + {GST_GL_RGBA, GL_UNSIGNED_SHORT, GST_GL_RGBA16}, +/* {GST_GL_DEPTH_COMPONENT16, GL_UNSIGNED_BYTE, GST_GL_DEPTH_COMPONENT16}, + {GST_GL_DEPTH24_STENCIL8, GL_UNSIGNED_BYTE, GST_GL_DEPTH24_STENCIL8},*/ + /* *INDENT-ON* */ +}; + +GST_START_TEST (test_unsized_from_sized) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (unsized_formats); i++) { + GstGLFormat unsized_format; + guint gl_type; + + GST_DEBUG ("idx %i: expected 0x%x 0x%x, args format 0x%x", i, + unsized_formats[i].unsized_format, unsized_formats[i].gl_type, + unsized_formats[i].format); + gst_gl_format_type_from_sized_gl_format (unsized_formats[i].format, + &unsized_format, &gl_type); + + fail_unless_equals_int (unsized_formats[i].unsized_format, unsized_format); + fail_unless_equals_int (unsized_formats[i].gl_type, gl_type); + } +} + +GST_END_TEST; + +static GstGLTextureTarget texture_targets[] = { + GST_GL_TEXTURE_TARGET_2D, + GST_GL_TEXTURE_TARGET_RECTANGLE, + GST_GL_TEXTURE_TARGET_EXTERNAL_OES, +}; + +GST_START_TEST (test_texture_target_strings) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (texture_targets); i++) { + GstGLTextureTarget res; + const gchar *str; + + str = gst_gl_texture_target_to_string (texture_targets[i]); + res = gst_gl_texture_target_from_string (str); + + GST_DEBUG ("from %u to \'%s\' to %u", texture_targets[i], str, res); + + fail_unless_equals_int (texture_targets[i], res); + } +} + +GST_END_TEST; + +GST_START_TEST (test_texture_target_gl) +{ + int i; + + for (i = 0; i < G_N_ELEMENTS (texture_targets); i++) { + GstGLTextureTarget res; + guint gl; + + gl = gst_gl_texture_target_to_gl (texture_targets[i]); + res = gst_gl_texture_target_from_gl (gl); + + GST_DEBUG ("from %u to 0x%x to %u", texture_targets[i], gl, res); + + fail_unless_equals_int (texture_targets[i], res); + } +} + +GST_END_TEST; + +static Suite * +gst_gl_format_suite (void) +{ + Suite *s = suite_create ("Gst GL Formats"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_checked_fixture (tc_chain, setup, teardown); + tcase_add_test (tc_chain, test_format_n_bytes); + tcase_add_test (tc_chain, test_sized_from_unsized); + tcase_add_test (tc_chain, test_unsized_from_sized); + tcase_add_test (tc_chain, test_texture_target_strings); + tcase_add_test (tc_chain, test_texture_target_gl); + + return s; +} + +GST_CHECK_MAIN (gst_gl_format); diff --git a/tests/check/meson.build b/tests/check/meson.build index fb9c153..d89c6f6 100644 --- a/tests/check/meson.build +++ b/tests/check/meson.build @@ -75,6 +75,7 @@ if build_gstgl base_tests += [ [ 'libs/gstglcolorconvert.c', not build_gstgl, [gstgl_dep]], [ 'libs/gstglcontext.c', not build_gstgl, [gstgl_dep]], + [ 'libs/gstglformat.c', not build_gstgl, [gstgl_dep]], [ 'libs/gstglheaders.c', not build_gstgl, [gstgl_dep]], [ 'libs/gstglmatrix.c', not build_gstgl, [gstgl_dep]], [ 'libs/gstglmemory.c', not build_gstgl, [gstgl_dep]], -- 2.7.4