From f54c51e75c7abe872127d559e029bf4383439bca Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 1 Sep 2010 02:10:51 +0200 Subject: [PATCH] test: Add subsurface-outside-target This test defines the behavior of subsurfaces when they are created to be bigger than their target. --- test/Makefile.sources | 1 + test/subsurface-outside-target.argb32.ref.png | Bin 0 -> 2063 bytes test/subsurface-outside-target.c | 178 ++++++++++++++++++ test/subsurface-outside-target.rgb24.ref.png | Bin 0 -> 1648 bytes 4 files changed, 179 insertions(+) create mode 100644 test/subsurface-outside-target.argb32.ref.png create mode 100644 test/subsurface-outside-target.c create mode 100644 test/subsurface-outside-target.rgb24.ref.png diff --git a/test/Makefile.sources b/test/Makefile.sources index bf8979d7a..e497cd745 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -251,6 +251,7 @@ test_sources = \ subsurface-pad.c \ subsurface-modify-child.c \ subsurface-modify-parent.c \ + subsurface-outside-target.c \ subsurface-similar-repeat.c \ surface-finish-twice.c \ surface-pattern.c \ diff --git a/test/subsurface-outside-target.argb32.ref.png b/test/subsurface-outside-target.argb32.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..337cdd80329e4b28daf286ee9c0b2642787e9748 GIT binary patch literal 2063 zcmZuyc{o&S7@w3D9->@i4Hef7Ehf1#Ci^bYttT0jvJ68vjm$9PQgcOfDMd*rWh+Zz zvNV>&G>?a2EJKzlDoJuJW0)D-Ge+kgo}Tl^InQ@~@Av+`-}`&t@A@%k8z~7T2^b6} zWoK)79C$Nfuyx4I8-Xu6QnLnlZ9MB>V+mUlK3UY3-9f{kksO&|( zdFt30Ctz&k)-0Lz2T$999s7v3Kr%?|n;w~EwY$J@J9llC*|uTx7O_PHZ;MLSOcri5 zIy^DhSVL=h_3DOo<}uN-E{A3`7si)Hi}v_mm)#<^yb9AeS{J9S94KAD?dkqSM%&ji z23U$t+KIH4DQTpW((*UrznoXH;zbQcwvg5b6U1n7!red+m>Ss5<4kWG)99UpWA@Hg z2+I2nTp4%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00001 diff --git a/test/subsurface-outside-target.c b/test/subsurface-outside-target.c new file mode 100644 index 000000000..fd5124340 --- /dev/null +++ b/test/subsurface-outside-target.c @@ -0,0 +1,178 @@ +/* + * Copyright 2010 Red Hat Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: Benjamin Otte + */ + +#include "cairo-test.h" + +#define ARRAY_LENGTH(array) (sizeof (array) / sizeof ((array)[0])) + +#define TARGET_SIZE 10 + +#define SUB_SIZE 15 +#define SUB_OFFSET -5 + +#define PAINT_OFFSET SUB_SIZE +#define PAINT_SIZE (3 * SUB_SIZE) + +static cairo_content_t contents[] = { CAIRO_CONTENT_ALPHA, + CAIRO_CONTENT_COLOR, + CAIRO_CONTENT_COLOR_ALPHA }; + +#define N_CONTENTS ARRAY_LENGTH (contents) +#define N_PADS (CAIRO_EXTEND_PAD + 1) + + +static cairo_surface_t * +create_target (cairo_surface_t *similar_to, + cairo_content_t content) +{ + cairo_surface_t *surface; + cairo_t *cr; + + surface = cairo_surface_create_similar (similar_to, + content, + TARGET_SIZE, TARGET_SIZE); + + cr = cairo_create (surface); + cairo_test_paint_checkered (cr); + cairo_destroy (cr); + + return surface; +} + +static cairo_test_status_t +check_surface_extents (const cairo_test_context_t *ctx, + cairo_surface_t * surface, + double x, + double y, + double width, + double height) +{ + double x1, y1, x2, y2; + cairo_t *cr; + + cr = cairo_create (surface); + cairo_clip_extents (cr, &x1, &y1, &x2, &y2); + + if (x != x1 || + y != y1 || + width != x2 - x1 || + height != y2 - y1) { + cairo_test_log (ctx, + "surface extents should be (%g, %g, %g, %g), but are (%g, %g, %g, %g)\n", + x, y, width, height, + x1, y1, x2 - x1, y2 - y1); + return CAIRO_TEST_FAILURE; + } + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +draw_for_size (cairo_t *cr, + double x, + double y) +{ + cairo_surface_t *target, *subsurface; + cairo_extend_t extend; + cairo_test_status_t check, result = CAIRO_TEST_SUCCESS; + unsigned int content; + + for (content = 0; content < N_CONTENTS; content++) { + cairo_save (cr); + + /* create a target surface for our subsurface */ + target = create_target (cairo_get_target (cr), + contents[content]); + + /* create a subsurface that extends the target surface */ + subsurface = cairo_surface_create_for_rectangle (target, + x, y, + SUB_SIZE, SUB_SIZE); + + /* ensure the extents are ok */ + check = check_surface_extents (cairo_test_get_context (cr), + subsurface, + 0, 0, + SUB_SIZE, SUB_SIZE); + if (result == CAIRO_TEST_SUCCESS) + result = check; + + /* paint this surface with all extend modes. */ + for (extend = 0; extend < N_PADS; extend++) { + cairo_save (cr); + + cairo_rectangle (cr, 0, 0, PAINT_SIZE, PAINT_SIZE); + cairo_clip (cr); + + cairo_set_source_surface (cr, subsurface, PAINT_OFFSET, PAINT_OFFSET); + cairo_pattern_set_extend (cairo_get_source (cr), extend); + cairo_paint (cr); + + cairo_restore (cr); + + cairo_translate (cr, PAINT_SIZE + TARGET_SIZE, 0); + } + + cairo_surface_destroy (subsurface); + cairo_surface_destroy (target); + + cairo_restore (cr); + + cairo_translate (cr, 0, PAINT_SIZE + TARGET_SIZE); + } + + return result; +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_test_status_t check, result = CAIRO_TEST_SUCCESS; + + /* paint background in nice gray */ + cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613); + cairo_paint (cr); + + /* Use CAIRO_OPERATOR_SOURCE in the tests so we get the actual + * contents of the subsurface */ + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + + result = draw_for_size (cr, SUB_OFFSET, SUB_OFFSET); + + check = draw_for_size (cr, 0, 0); + if (result == CAIRO_TEST_SUCCESS) + result = check; + + return result; +} + +CAIRO_TEST (subsurface_outside_target, + "Tests contents of subsurfaces outside target area", + "subsurface, pad", /* keywords */ + NULL, /* requirements */ + (PAINT_SIZE + TARGET_SIZE) * N_PADS - TARGET_SIZE, + (PAINT_SIZE + TARGET_SIZE) * N_CONTENTS * 2 - TARGET_SIZE, + NULL, draw) diff --git a/test/subsurface-outside-target.rgb24.ref.png b/test/subsurface-outside-target.rgb24.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..368936e5ca87c1198ce4d3b70ee2bdb6734ef240 GIT binary patch literal 1648 zcmeAS@N?(olHy`uVBq!ia0vp^mlzlr9XObPEH|aCFM$+WlDE4H!+#K5uy^@npn$5U zi(^Q|oVRxkgQPtf94=m+=I^qmq2WfmVwl5&3jWQ8jEo!4Z|OX}bkeD}GgB|jpLW07 zfa9Xr{wk9d)g?c&<@f#locrPG<($KLm_%|Dpq z?oh^(f=)aL;D6Bmv0HWd^UG)5j11(Se0=!h^W*8$r+2U4w|6h^zV9DDetcwn{riRw z^OjeroQ0aO?+Wt{`RC_%t()H%YhV5Q>i2)IjQ_u%_dWB}n|1T&&Hrztw{O?O-kV*` zI*d03C&&Vc8K0&k%|GYwer;Z?-u}Nm&(~gGb|&x7^S18zGi~N||Nrf)nZRRlLI|pM z=iRT_oXzUDr0?Ab`?hw*TUcNnX!p|$TdR5Nf}ObC-1#+YVnw$D&3OIREJieKo3es6 z(5qo)fOFH{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