tests: port test-texture-get-set-data to be standalone

This ports the test-texture-get-set-data clutter test to be a standalone
Cogl test.

(cherry picked from commit 40defa3dbd355754d0f7611d3c50de35db514e4a)
This commit is contained in:
Robert Bragg 2012-11-21 22:12:54 +00:00
parent 7011eb5db4
commit 4b41743b92
3 changed files with 21 additions and 46 deletions

View File

@ -18,7 +18,6 @@ unported_test_sources = \
test-npot-texture.c \ test-npot-texture.c \
test-object.c \ test-object.c \
test-readpixels.c \ test-readpixels.c \
test-texture-get-set-data.c \
test-texture-mipmaps.c \ test-texture-mipmaps.c \
test-texture-pixmap-x11.c \ test-texture-pixmap-x11.c \
test-texture-rectangle.c \ test-texture-rectangle.c \
@ -61,6 +60,7 @@ test_sources = \
test-map-buffer-range.c \ test-map-buffer-range.c \
test-npot-texture.c \ test-npot-texture.c \
test-alpha-textures.c \ test-alpha-textures.c \
test-texture-get-set-data.c \
$(NULL) $(NULL)
test_conformance_SOURCES = $(common_sources) $(test_sources) test_conformance_SOURCES = $(common_sources) $(test_sources)

View File

@ -73,7 +73,7 @@ main (int argc, char **argv)
ADD_TEST (test_texture_3d, TEST_REQUIREMENT_TEXTURE_3D, 0); ADD_TEST (test_texture_3d, TEST_REQUIREMENT_TEXTURE_3D, 0);
ADD_TEST (test_wrap_modes, 0, 0); ADD_TEST (test_wrap_modes, 0, 0);
UNPORTED_TEST (test_texture_pixmap_x11); UNPORTED_TEST (test_texture_pixmap_x11);
UNPORTED_TEST (test_texture_get_set_data); ADD_TEST (test_texture_get_set_data, 0, TEST_REQUIREMENT_NPOT);
ADD_TEST (test_atlas_migration, 0, 0); ADD_TEST (test_atlas_migration, 0, 0);
ADD_TEST (test_read_texture_formats, 0, 0); ADD_TEST (test_read_texture_formats, 0, 0);
ADD_TEST (test_write_texture_formats, 0, 0); ADD_TEST (test_write_texture_formats, 0, 0);

View File

@ -1,15 +1,16 @@
#include <clutter/clutter.h> #include <cogl/cogl.h>
#include <glib.h>
#include <string.h> #include <string.h>
#include "test-conform-common.h" #include "test-utils.h"
static void static void
check_texture (int width, int height, CoglTextureFlags flags) check_texture (int width, int height, CoglTextureFlags flags)
{ {
CoglHandle tex; CoglTexture *tex;
uint8_t *data, *p; uint8_t *data, *p;
int y, x; int y, x;
int rowstride;
p = data = g_malloc (width * height * 4); p = data = g_malloc (width * height * 4);
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
@ -30,7 +31,8 @@ check_texture (int width, int height, CoglTextureFlags flags)
/* Replace the bottom right quarter of the data with negated data to /* Replace the bottom right quarter of the data with negated data to
test set_region */ 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 (y = 0; y < height / 2; y++)
{ {
for (x = 0; x < width / 2; x++) for (x = 0; x < width / 2; x++)
@ -44,16 +46,16 @@ check_texture (int width, int height, CoglTextureFlags flags)
p += width * 2; p += width * 2;
} }
cogl_texture_set_region (tex, cogl_texture_set_region (tex,
width / 2, /* src_x */ width / 2,
height / 2, /* src_y */ height / 2,
width / 2, /* dst_x */ width / 2, /* dest x */
height / 2, /* dst_y */ height / 2, /* dest y */
width / 2, /* dst_width */ width / 2, /* region width */
height / 2, /* dst_height */ height / 2, /* region height */
width, width, /* src width */
height, height, /* src height */
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
width * 4, /* rowstride */ rowstride,
data); data);
/* Check passing a NULL pointer and a zero rowstride. The texture /* Check passing a NULL pointer and a zero rowstride. The texture
@ -119,12 +121,12 @@ check_texture (int width, int height, CoglTextureFlags flags)
p += 4; p += 4;
} }
cogl_handle_unref (tex); cogl_object_unref (tex);
g_free (data); g_free (data);
} }
static void void
paint_cb (void) test_texture_get_set_data (void)
{ {
/* First try without atlasing */ /* First try without atlasing */
check_texture (256, 256, COGL_TEXTURE_NO_ATLAS); check_texture (256, 256, COGL_TEXTURE_NO_ATLAS);
@ -136,31 +138,4 @@ paint_cb (void)
check_texture (4, 5128, COGL_TEXTURE_NO_ATLAS); check_texture (4, 5128, COGL_TEXTURE_NO_ATLAS);
/* And in the other direction. */ /* And in the other direction. */
check_texture (5128, 4, COGL_TEXTURE_NO_ATLAS); 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");
} }