[Cogl] [PATCH] tests: port test-texture-get-set-data to be standalone

Robert Bragg robert at sixbynine.org
Mon Nov 26 15:47:10 PST 2012


From: Robert Bragg <robert at linux.intel.com>

This ports the test-texture-get-set-data clutter test to be a standalone
Cogl test.
---
 tests/conform/Makefile.am                 |    2 +-
 tests/conform/test-conform-main.c         |    2 +-
 tests/conform/test-texture-get-set-data.c |   69 +++++++++-------------------
 3 files changed, 24 insertions(+), 49 deletions(-)

diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index c002f6a..2463d7d 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -17,7 +17,6 @@ unported_test_sources = \
 	test-npot-texture.c \
 	test-object.c \
 	test-readpixels.c \
-	test-texture-get-set-data.c \
 	test-texture-mipmaps.c \
 	test-texture-pixmap-x11.c \
 	test-texture-rectangle.c \
@@ -59,6 +58,7 @@ test_sources = \
 	test-map-buffer-range.c \
 	test-npot-texture.c \
 	test-alpha-textures.c \
+	test-texture-get-set-data.c \
 	$(NULL)
 
 test_conformance_SOURCES = $(common_sources) $(test_sources)
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 4b7b698..1137683 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -72,7 +72,7 @@ main (int argc, char **argv)
   ADD_TEST (test_texture_3d, TEST_REQUIREMENT_TEXTURE_3D, 0);
   ADD_TEST (test_wrap_modes, 0, 0);
   UNPORTED_TEST (test_texture_pixmap_x11);
-  UNPORTED_TEST (test_texture_get_set_data);
+  ADD_TEST (test_texture_get_set_data, 0, 0);
   ADD_TEST (test_atlas_migration, 0, 0);
   ADD_TEST (test_read_texture_formats, 0, 0);
   ADD_TEST (test_write_texture_formats, 0, 0);
diff --git a/tests/conform/test-texture-get-set-data.c b/tests/conform/test-texture-get-set-data.c
index 6cb4f99..cf24e4d 100644
--- a/tests/conform/test-texture-get-set-data.c
+++ b/tests/conform/test-texture-get-set-data.c
@@ -1,15 +1,16 @@
-#include <clutter/clutter.h>
-#include <glib.h>
+#include <cogl/cogl.h>
+
 #include <string.h>
 
-#include "test-conform-common.h"
+#include "test-utils.h"
 
 static void
 check_texture (int width, int height, CoglTextureFlags flags)
 {
-  CoglHandle tex;
+  CoglTexture *tex;
   uint8_t *data, *p;
   int y, x;
+  int rowstride;
 
   p = data = g_malloc (width * height * 4);
   for (y = 0; y < height; y++)
@@ -21,16 +22,19 @@ check_texture (int width, int height, CoglTextureFlags flags)
         *(p++) = (x ^ y);
       }
 
-  tex = cogl_texture_new_from_data (width, height,
+  tex = cogl_texture_new_from_data (test_ctx,
+                                    width, height,
                                     flags,
                                     COGL_PIXEL_FORMAT_RGBA_8888,
                                     COGL_PIXEL_FORMAT_RGBA_8888,
                                     width * 4,
-                                    data);
+                                    data,
+                                    NULL); /* abort on error */
 
   /* Replace the bottom right quarter of the data with negated data to
      test set_region */
-  p = data + (height + 1) * width * 2;
+  rowstride = width * 4;
+  p = data + (height / 2) * rowstride + rowstride / 2;
   for (y = 0; y < height / 2; y++)
     {
       for (x = 0; x < width / 2; x++)
@@ -44,17 +48,15 @@ check_texture (int width, int height, CoglTextureFlags flags)
       p += width * 2;
     }
   cogl_texture_set_region (tex,
-                           width / 2, /* src_x */
-                           height / 2, /* src_y */
-                           width / 2, /* dst_x */
-                           height / 2, /* dst_y */
-                           width / 2, /* dst_width */
-                           height / 2, /* dst_height */
-                           width,
-                           height,
+                           width / 2, /* region width */
+                           height / 2, /* region height */
                            COGL_PIXEL_FORMAT_RGBA_8888,
-                           width * 4, /* rowstride */
-                           data);
+                           rowstride,
+                           data + (height / 2) * rowstride + rowstride / 2,
+                           width / 2, /* dest x */
+                           height / 2, /* dest y */
+                           0, /* mipmap level 0 */
+                           NULL); /* abort on error */
 
   /* Check passing a NULL pointer and a zero rowstride. The texture
      should calculate the needed data size and return it */
@@ -119,12 +121,12 @@ check_texture (int width, int height, CoglTextureFlags flags)
         p += 4;
       }
 
-  cogl_handle_unref (tex);
+  cogl_object_unref (tex);
   g_free (data);
 }
 
-static void
-paint_cb (void)
+void
+test_texture_get_set_data (void)
 {
   /* First try without atlasing */
   check_texture (256, 256, COGL_TEXTURE_NO_ATLAS);
@@ -136,31 +138,4 @@ paint_cb (void)
   check_texture (4, 5128, COGL_TEXTURE_NO_ATLAS);
   /* And in the other direction. */
   check_texture (5128, 4, COGL_TEXTURE_NO_ATLAS);
-
-  clutter_main_quit ();
-}
-
-void
-test_texture_get_set_data (TestUtilsGTestFixture *fixture,
-                                void *data)
-{
-  ClutterActor *stage;
-  unsigned int paint_handler;
-
-  /* We create a stage even though we don't usually need it so that if
-     the draw-and-read texture fallback is needed then it will have
-     something to draw to */
-  stage = clutter_stage_get_default ();
-
-  paint_handler = g_signal_connect_after (stage, "paint",
-                                          G_CALLBACK (paint_cb), NULL);
-
-  clutter_actor_show (stage);
-
-  clutter_main ();
-
-  g_signal_handler_disconnect (stage, paint_handler);
-
-  if (cogl_test_verbose ())
-    g_print ("OK\n");
 }
-- 
1.7.7.6



More information about the Cogl mailing list