2011-05-05 22:34:38 +00:00
|
|
|
#ifndef _TEST_UTILS_H_
|
|
|
|
#define _TEST_UTILS_H_
|
|
|
|
|
2013-10-09 12:31:12 +00:00
|
|
|
/* NB: This header is for private and public api testing and so
|
|
|
|
* we need consider that if we are testing the public api we should
|
|
|
|
* just include <cogl/cogl.h> but since that will only provide
|
|
|
|
* opaque typedefs we need to include the specific internal headers
|
|
|
|
* for testing private apis...
|
|
|
|
*/
|
|
|
|
#ifdef COGL_COMPILATION
|
2013-07-03 09:50:37 +00:00
|
|
|
#include <cogl/cogl-context.h>
|
|
|
|
#include <cogl/cogl-onscreen.h>
|
|
|
|
#include <cogl/cogl-offscreen.h>
|
|
|
|
#include <cogl/cogl-texture-2d.h>
|
2013-06-09 00:09:04 +00:00
|
|
|
#include <cogl/cogl-primitive-texture.h>
|
|
|
|
#include <cogl/cogl-texture-2d-sliced.h>
|
|
|
|
#include <cogl/cogl-meta-texture.h>
|
|
|
|
#include <cogl/cogl-atlas-texture.h>
|
2013-10-09 12:31:12 +00:00
|
|
|
#else
|
|
|
|
#include <cogl/cogl.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 18:01:10 +00:00
|
|
|
#include <glib.h>
|
|
|
|
|
2012-03-06 18:21:28 +00:00
|
|
|
/* We don't really care about functions that are defined without a
|
|
|
|
header for the unit tests so we can just disable it here */
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma GCC diagnostic ignored "-Wmissing-declarations"
|
|
|
|
#endif
|
|
|
|
|
2012-03-06 23:41:49 +00:00
|
|
|
typedef enum _TestFlags
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2012-12-10 18:11:28 +00:00
|
|
|
TEST_KNOWN_FAILURE = 1<<0,
|
|
|
|
TEST_REQUIREMENT_GL = 1<<1,
|
|
|
|
TEST_REQUIREMENT_NPOT = 1<<2,
|
|
|
|
TEST_REQUIREMENT_TEXTURE_3D = 1<<3,
|
|
|
|
TEST_REQUIREMENT_TEXTURE_RECTANGLE = 1<<4,
|
|
|
|
TEST_REQUIREMENT_POINT_SPRITE = 1<<5,
|
|
|
|
TEST_REQUIREMENT_GLES2_CONTEXT = 1<<6,
|
|
|
|
TEST_REQUIREMENT_MAP_WRITE = 1<<7,
|
2012-12-13 15:27:52 +00:00
|
|
|
TEST_REQUIREMENT_GLSL = 1<<8,
|
2013-01-11 01:13:34 +00:00
|
|
|
TEST_REQUIREMENT_OFFSCREEN = 1<<9,
|
2012-11-08 16:56:02 +00:00
|
|
|
TEST_REQUIREMENT_FENCE = 1<<10,
|
|
|
|
TEST_REQUIREMENT_PER_VERTEX_POINT_SIZE = 1<<11
|
2012-03-06 23:41:49 +00:00
|
|
|
} TestFlags;
|
2012-02-23 12:30:51 +00:00
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
/**
|
|
|
|
* TestUtilsTextureFlags:
|
|
|
|
* @TEST_UTILS_TEXTURE_NONE: No flags specified
|
|
|
|
* @TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP: Disables the automatic generation of
|
|
|
|
* the mipmap pyramid from the base level image whenever it is
|
|
|
|
* updated. The mipmaps are only generated when the texture is
|
|
|
|
* rendered with a mipmap filter so it should be free to leave out
|
|
|
|
* this flag when using other filtering modes
|
|
|
|
* @TEST_UTILS_TEXTURE_NO_SLICING: Disables the slicing of the texture
|
|
|
|
* @TEST_UTILS_TEXTURE_NO_ATLAS: Disables the insertion of the texture inside
|
|
|
|
* the texture atlas used by Cogl
|
|
|
|
*
|
|
|
|
* Flags to pass to the test_utils_texture_new_* family of functions.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
TEST_UTILS_TEXTURE_NONE = 0,
|
|
|
|
TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP = 1 << 0,
|
|
|
|
TEST_UTILS_TEXTURE_NO_SLICING = 1 << 1,
|
|
|
|
TEST_UTILS_TEXTURE_NO_ATLAS = 1 << 2
|
|
|
|
} TestUtilsTextureFlags;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
extern CoglContext *test_ctx;
|
|
|
|
extern CoglFramebuffer *test_fb;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
void
|
2012-11-09 16:47:01 +00:00
|
|
|
test_utils_init (TestFlags requirement_flags,
|
|
|
|
TestFlags known_failure_flags);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_fini (void);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
/*
|
|
|
|
* test_utils_texture_new_with_size:
|
|
|
|
* @context: A #CoglContext
|
|
|
|
* @width: width of texture in pixels.
|
|
|
|
* @height: height of texture in pixels.
|
|
|
|
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
|
2013-07-02 00:48:54 +00:00
|
|
|
* @components: What texture components are required
|
2013-06-09 00:09:04 +00:00
|
|
|
*
|
|
|
|
* Creates a new #CoglTexture with the specified dimensions and pixel format.
|
|
|
|
*
|
|
|
|
* The storage for the texture is not necesarily created before this
|
|
|
|
* function returns. The storage can be explicitly allocated using
|
|
|
|
* cogl_texture_allocate() or preferably you can let Cogl
|
|
|
|
* automatically allocate the storage lazily when uploading data when
|
|
|
|
* Cogl may know more about how the texture will be used and can
|
|
|
|
* optimize how it is allocated.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #CoglTexture
|
|
|
|
*/
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_with_size (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
TestUtilsTextureFlags flags,
|
2013-07-02 00:48:54 +00:00
|
|
|
CoglTextureComponents components);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* test_utils_texture_new_from_data:
|
|
|
|
* @context: A #CoglContext
|
|
|
|
* @width: width of texture in pixels
|
|
|
|
* @height: height of texture in pixels
|
|
|
|
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
|
|
|
|
* @format: the #CoglPixelFormat the buffer is stored in in RAM
|
|
|
|
* @rowstride: the memory offset in bytes between the starts of
|
|
|
|
* scanlines in @data
|
|
|
|
* @data: pointer the memory region where the source buffer resides
|
|
|
|
* @error: A #CoglError to catch exceptional errors or %NULL
|
|
|
|
*
|
|
|
|
* Creates a new #CoglTexture based on data residing in memory.
|
|
|
|
*
|
2013-07-02 00:48:54 +00:00
|
|
|
* Note: If the given @format has an alpha channel then the data
|
|
|
|
* will be loaded into a premultiplied internal format. If you want
|
|
|
|
* to avoid having the source data be premultiplied then you can
|
|
|
|
* either specify that the data is already premultiplied or use
|
|
|
|
* test_utils_texture_new_from_bitmap which lets you explicitly
|
|
|
|
* request whether the data should internally be premultipled or not.
|
|
|
|
*
|
2013-06-09 00:09:04 +00:00
|
|
|
* Return value: A newly created #CoglTexture or %NULL on failure
|
|
|
|
*/
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_from_data (CoglContext *ctx,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
TestUtilsTextureFlags flags,
|
|
|
|
CoglPixelFormat format,
|
|
|
|
int rowstride,
|
|
|
|
const uint8_t *data);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* test_utils_texture_new_from_bitmap:
|
|
|
|
* @bitmap: A #CoglBitmap pointer
|
|
|
|
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
|
2013-07-02 00:48:54 +00:00
|
|
|
* @premultiplied: Whether the texture should hold premultipled data.
|
|
|
|
* (if the bitmap already holds premultiplied data
|
|
|
|
* and %TRUE is given then no premultiplication will
|
|
|
|
* be done. The data will be premultipled while
|
|
|
|
* uploading if the bitmap has an alpha channel but
|
|
|
|
* does not already have a premultiplied format.)
|
2013-06-09 00:09:04 +00:00
|
|
|
*
|
|
|
|
* Creates a #CoglTexture from a #CoglBitmap.
|
|
|
|
*
|
|
|
|
* Return value: A newly created #CoglTexture or %NULL on failure
|
|
|
|
*/
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
|
|
|
|
TestUtilsTextureFlags flags,
|
2013-07-02 00:48:54 +00:00
|
|
|
CoglBool premultiplied);
|
2013-06-09 00:09:04 +00:00
|
|
|
|
2011-10-26 13:15:14 +00:00
|
|
|
/*
|
|
|
|
* test_utils_check_pixel:
|
2012-03-16 19:54:13 +00:00
|
|
|
* @framebuffer: The #CoglFramebuffer to read from
|
2011-10-26 13:15:14 +00:00
|
|
|
* @x: x co-ordinate of the pixel to test
|
|
|
|
* @y: y co-ordinate of the pixel to test
|
|
|
|
* @pixel: An integer of the form 0xRRGGBBAA representing the expected
|
|
|
|
* pixel value
|
|
|
|
*
|
2012-03-16 19:54:13 +00:00
|
|
|
* This performs reads a pixel on the given cogl @framebuffer and
|
2011-10-26 13:15:14 +00:00
|
|
|
* asserts that it matches the given color. The alpha channel of the
|
|
|
|
* color is ignored. The pixels are converted to a string and compared
|
|
|
|
* with g_assert_cmpstr so that if the comparison fails then the
|
|
|
|
* assert will display a meaningful message
|
|
|
|
*/
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_pixel (CoglFramebuffer *framebuffer,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
int x, int y, uint32_t expected_pixel);
|
2011-10-26 13:15:14 +00:00
|
|
|
|
2013-05-22 18:49:05 +00:00
|
|
|
/**
|
|
|
|
* @framebuffer: The #CoglFramebuffer to read from
|
|
|
|
* @x: x co-ordinate of the pixel to test
|
|
|
|
* @y: y co-ordinate of the pixel to test
|
|
|
|
* @pixel: An integer of the form 0xRRGGBBAA representing the expected
|
|
|
|
* pixel value
|
|
|
|
*
|
|
|
|
* This performs reads a pixel on the given cogl @framebuffer and
|
|
|
|
* asserts that it matches the given color. The alpha channel is also
|
|
|
|
* checked unlike with test_utils_check_pixel(). The pixels are
|
|
|
|
* converted to a string and compared with g_assert_cmpstr so that if
|
|
|
|
* the comparison fails then the assert will display a meaningful
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
test_utils_check_pixel_and_alpha (CoglFramebuffer *fb,
|
|
|
|
int x, int y, uint32_t expected_pixel);
|
|
|
|
|
2011-10-26 13:15:14 +00:00
|
|
|
/*
|
|
|
|
* test_utils_check_pixel:
|
2012-03-16 19:54:13 +00:00
|
|
|
* @framebuffer: The #CoglFramebuffer to read from
|
2011-10-26 13:15:14 +00:00
|
|
|
* @x: x co-ordinate of the pixel to test
|
|
|
|
* @y: y co-ordinate of the pixel to test
|
|
|
|
* @pixel: An integer of the form 0xrrggbb representing the expected pixel value
|
|
|
|
*
|
2012-03-16 19:54:13 +00:00
|
|
|
* This performs reads a pixel on the given cogl @framebuffer and
|
2011-10-26 13:15:14 +00:00
|
|
|
* asserts that it matches the given color. The alpha channel of the
|
|
|
|
* color is ignored. The pixels are converted to a string and compared
|
|
|
|
* with g_assert_cmpstr so that if the comparison fails then the
|
|
|
|
* assert will display a meaningful message
|
|
|
|
*/
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_pixel_rgb (CoglFramebuffer *framebuffer,
|
|
|
|
int x, int y, int r, int g, int b);
|
2011-10-26 13:15:14 +00:00
|
|
|
|
2011-10-31 14:55:20 +00:00
|
|
|
/*
|
|
|
|
* test_utils_check_region:
|
2012-03-16 19:54:13 +00:00
|
|
|
* @framebuffer: The #CoglFramebuffer to read from
|
2011-10-31 14:55:20 +00:00
|
|
|
* @x: x co-ordinate of the region to test
|
|
|
|
* @y: y co-ordinate of the region to test
|
|
|
|
* @width: width of the region to test
|
|
|
|
* @height: height of the region to test
|
|
|
|
* @pixel: An integer of the form 0xrrggbb representing the expected region color
|
|
|
|
*
|
2012-03-16 19:54:13 +00:00
|
|
|
* Performs a read pixel on the specified region of the given cogl
|
|
|
|
* @framebuffer and asserts that it matches the given color. The alpha
|
2011-10-31 14:55:20 +00:00
|
|
|
* channel of the color is ignored. The pixels are converted to a
|
|
|
|
* string and compared with g_assert_cmpstr so that if the comparison
|
|
|
|
* fails then the assert will display a meaningful message
|
|
|
|
*/
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_utils_check_region (CoglFramebuffer *framebuffer,
|
|
|
|
int x, int y,
|
2011-10-31 14:55:20 +00:00
|
|
|
int width, int height,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint32_t expected_rgba);
|
2011-10-31 14:55:20 +00:00
|
|
|
|
2012-01-28 13:40:22 +00:00
|
|
|
/*
|
|
|
|
* test_utils_compare_pixel:
|
|
|
|
* @screen_pixel: A pixel stored in memory
|
|
|
|
* @expected_pixel: The expected RGBA value
|
|
|
|
*
|
|
|
|
* Compares a pixel from a buffer to an expected value. The pixels are
|
|
|
|
* converted to a string and compared with g_assert_cmpstr so that if
|
|
|
|
* the comparison fails then the assert will display a meaningful
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
test_utils_compare_pixel (const uint8_t *screen_pixel, uint32_t expected_pixel);
|
2012-01-28 13:40:22 +00:00
|
|
|
|
2013-01-21 18:43:24 +00:00
|
|
|
/*
|
|
|
|
* test_utils_compare_pixel_and_alpha:
|
|
|
|
* @screen_pixel: A pixel stored in memory
|
|
|
|
* @expected_pixel: The expected RGBA value
|
|
|
|
*
|
|
|
|
* Compares a pixel from a buffer to an expected value. This is
|
|
|
|
* similar to test_utils_compare_pixel() except that it doesn't ignore
|
|
|
|
* the alpha component.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
test_utils_compare_pixel_and_alpha (const uint8_t *screen_pixel,
|
|
|
|
uint32_t expected_pixel);
|
|
|
|
|
2012-02-10 16:57:24 +00:00
|
|
|
/*
|
|
|
|
* test_utils_create_color_texture:
|
|
|
|
* @context: A #CoglContext
|
|
|
|
* @color: A color to put in the texture
|
|
|
|
*
|
|
|
|
* Creates a 1x1-pixel RGBA texture filled with the given color.
|
|
|
|
*/
|
|
|
|
CoglTexture *
|
|
|
|
test_utils_create_color_texture (CoglContext *context,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint32_t color);
|
2012-02-10 16:57:24 +00:00
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
/* cogl_test_verbose:
|
|
|
|
*
|
|
|
|
* Queries if the user asked for verbose output or not.
|
|
|
|
*/
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
CoglBool
|
2012-02-23 12:30:51 +00:00
|
|
|
cogl_test_verbose (void);
|
|
|
|
|
2013-06-09 00:09:04 +00:00
|
|
|
/* test_util_is_pot:
|
|
|
|
* @number: A number to test
|
|
|
|
*
|
|
|
|
* Returns whether the given integer is a power of two
|
|
|
|
*/
|
|
|
|
static inline CoglBool
|
|
|
|
test_utils_is_pot (unsigned int number)
|
|
|
|
{
|
|
|
|
/* Make sure there is only one bit set */
|
|
|
|
return (number & (number - 1)) == 0;
|
|
|
|
}
|
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
#endif /* _TEST_UTILS_H_ */
|