tests: Adds our first white-box unit test

This adds a white-box unit test that verifies that GL_BLEND is disabled
when drawing an opaque rectangle, enabled when drawing a transparent
rectangle and then disabled again when drawing a transparent rectangle
but with a blend string that effectively disables blending.

This shares the test utilities and launcher infrastructure we are using
for conformance tests so we get consistent reporting and so unit tests
will be run against a range of different drivers.

This adds a --enable-unit-tests configure option which is enabled by
default but if disabled will make all UNIT_TESTS() into static inline
functions that we should expect the compiler to discard since they won't
be referenced by anything.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 9047cce06bbf9051ec77e622be2fdbb96ed767a8)
This commit is contained in:
Robert Bragg
2013-05-30 13:22:22 +01:00
parent f4fd724caf
commit eb7fafe700
16 changed files with 322 additions and 56 deletions

View File

@ -25,9 +25,7 @@
* Robert Bragg <robert@linux.intel.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl-debug.h"
#include "cogl-util-gl-private.h"
@ -41,6 +39,8 @@
#include "cogl-pipeline-progend-glsl-private.h"
#include <test-fixtures/test-unit.h>
#include <glib.h>
#include <string.h>
@ -444,6 +444,38 @@ flush_depth_state (CoglContext *ctx,
}
}
UNIT_TEST (check_gl_blend_enable,
0 /* no requirements */,
0 /* no failure cases */)
{
CoglPipeline *pipeline = cogl_pipeline_new (test_ctx);
/* By default blending should be disabled */
g_assert_cmpint (test_ctx->gl_blend_enable_cache, ==, 0);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 1, 1);
_cogl_framebuffer_flush_journal (test_fb);
/* After drawing an opaque rectangle blending should still be
* disabled */
g_assert_cmpint (test_ctx->gl_blend_enable_cache, ==, 0);
cogl_pipeline_set_color4f (pipeline, 0, 0, 0, 0);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 1, 1);
_cogl_framebuffer_flush_journal (test_fb);
/* After drawing a transparent rectangle blending should be enabled */
g_assert_cmpint (test_ctx->gl_blend_enable_cache, ==, 1);
cogl_pipeline_set_blend (pipeline, "RGBA=ADD(SRC_COLOR, 0)", NULL);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 1, 1);
_cogl_framebuffer_flush_journal (test_fb);
/* After setting a blend string that effectively disables blending
* then blending should be disabled */
g_assert_cmpint (test_ctx->gl_blend_enable_cache, ==, 0);
}
static void
_cogl_pipeline_flush_color_blend_alpha_depth_state (
CoglPipeline *pipeline,