[gtk/texture-fixes] Add tests for gdk_memory_texture_new_subtexture




commit 9686979f2239f916b4d9997f6747885ae02c5116
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 13 09:31:40 2022 -0400

    Add tests for gdk_memory_texture_new_subtexture
    
    This checks the fixes in the previous commit.

 testsuite/gdk/meson.build |  4 ++--
 testsuite/gdk/texture.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build
index 3de704fc64..03528a3905 100644
--- a/testsuite/gdk/meson.build
+++ b/testsuite/gdk/meson.build
@@ -26,7 +26,6 @@ tests = [
   { 'name': 'rectangle' },
   { 'name': 'rgba' },
   { 'name': 'seat' },
-  { 'name': 'texture' },
   { 'name': 'texture-threads' },
 ]
 
@@ -54,7 +53,8 @@ foreach t : tests
 endforeach
 
 internal_tests = [
-  'image'
+  'image',
+  'texture',
 ]
 
 foreach t : internal_tests
diff --git a/testsuite/gdk/texture.c b/testsuite/gdk/texture.c
index 1a218ddd4a..91627bda2d 100644
--- a/testsuite/gdk/texture.c
+++ b/testsuite/gdk/texture.c
@@ -1,5 +1,7 @@
 #include <gtk.h>
 
+#include "gdk/gdkmemorytextureprivate.h"
+
 static void
 compare_pixels (int     width,
                 int     height,
@@ -108,6 +110,45 @@ test_texture_save_to_png (void)
   g_object_unref (texture2);
 }
 
+static void
+test_texture_subtexture (void)
+{
+  GdkPixbuf *pixbuf, *subpixbuf;
+  GdkTexture *texture, *subtexture;
+  GError *error = NULL;
+  guchar *data;
+  gsize stride;
+
+  pixbuf = gdk_pixbuf_new_from_resource 
("/org/gtk/libgtk/icons/64x64/actions/gesture-swipe-left-symbolic.symbolic.png", &error);
+
+  texture = gdk_texture_new_for_pixbuf (pixbuf);
+
+  subpixbuf = gdk_pixbuf_new_subpixbuf (pixbuf, 0, 0, 32, 32);
+  subtexture = gdk_memory_texture_new_subtexture (GDK_MEMORY_TEXTURE (texture), 0, 0, 32, 32);
+
+  g_assert_cmpint (GDK_MEMORY_R8G8B8A8, ==, gdk_texture_get_format (texture));
+  g_assert_cmpint (GDK_MEMORY_R8G8B8A8, ==, gdk_texture_get_format (subtexture));
+
+  g_assert_cmpint (gdk_texture_get_width (subtexture), ==, 32);
+  g_assert_cmpint (gdk_texture_get_height (subtexture), ==, 32);
+
+  data = g_new0 (guchar, 32 * 32 * 4);
+  stride = 32 * 4;
+  gdk_texture_download (subtexture, data, stride);
+
+  compare_pixels (32, 32,
+                  data, stride,
+                  gdk_pixbuf_get_pixels (subpixbuf),
+                  gdk_pixbuf_get_rowstride (subpixbuf));
+
+  g_free (data);
+
+  g_object_unref (subtexture);
+  g_object_unref (subpixbuf);
+  g_object_unref (texture);
+  g_object_unref (pixbuf);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -117,6 +158,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/texture/from-pixbuf", test_texture_from_pixbuf);
   g_test_add_func ("/texture/from-resource", test_texture_from_resource);
   g_test_add_func ("/texture/save-to-png", test_texture_save_to_png);
+  g_test_add_func ("/texture/subtexture", test_texture_subtexture);
 
   return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]