diff --git a/testsuite/gsk/diff.c b/testsuite/gsk/diff.c index 2bc34ebec6..28ee4ff1f8 100644 --- a/testsuite/gsk/diff.c +++ b/testsuite/gsk/diff.c @@ -25,6 +25,7 @@ test_can_diff_basic (void) { GskRenderNode *container1, *container2; GskRenderNode *color1, *color2; + GskRenderNode *debug1, *debug2; color1 = gsk_color_node_new (&(GdkRGBA){0, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10)); color2 = gsk_color_node_new (&(GdkRGBA){1, 1, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, 10, 10)); @@ -32,10 +33,15 @@ test_can_diff_basic (void) container1 = gsk_container_node_new (&color1, 1); container2 = gsk_container_node_new (&color2, 1); + debug1 = gsk_debug_node_new (color1, g_strdup ("Debug node!")); + debug2 = gsk_debug_node_new (color2, g_strdup ("Debug node!")); + /* We can diff two color nodes */ g_assert_true (gsk_render_node_can_diff (color1, color2)); /* We can diff two container nodes */ g_assert_true (gsk_render_node_can_diff (container1, container2)); + /* We can diff two debug nodes */ + g_assert_true (gsk_render_node_can_diff (debug1, debug2)); /* We can diff container nodes against anything else */ g_assert_true (gsk_render_node_can_diff (container1, color2)); g_assert_true (gsk_render_node_can_diff (color1, container2)); @@ -45,6 +51,9 @@ test_can_diff_basic (void) gsk_render_node_unref (container1); gsk_render_node_unref (container2); + + gsk_render_node_unref (debug1); + gsk_render_node_unref (debug2); } static void diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build index 317f6a6670..82fe0d5dfc 100644 --- a/testsuite/gsk/meson.build +++ b/testsuite/gsk/meson.build @@ -129,6 +129,8 @@ node_parser_tests = [ 'blend.node', 'border.node', 'color.node', + 'conic-gradient.node', + 'conic-gradient.ref.node', 'crash1.errors', 'crash1.node', 'crash1.ref.node', @@ -141,6 +143,9 @@ node_parser_tests = [ 'crash4.node', 'crash4.ref.node', 'debug.node', + 'debug-fail.node', + 'debug-fail.ref.node', + 'debug-fail.errors', 'empty-blend.node', 'empty-blend.ref.node', 'empty-blur.node', @@ -181,9 +186,33 @@ node_parser_tests = [ 'empty-texture.ref.node', 'empty-transform.node', 'empty-transform.ref.node', + 'glshader.node', + 'glshader.ref.node', + 'glshader.errors', + 'gradient-fail.node', + 'gradient-fail.ref.node', + 'gradient-fail.errors', + 'radial-gradient.node', + 'radial-gradient.ref.node', + 'repeating-linear-gradient.node', + 'repeating-linear-gradient.ref.node', + 'repeating-radial-gradient.node', + 'repeating-radial-gradient.ref.node', 'rounded-rect.node', 'shadow.node', + 'shadow-fail.node', + 'shadow-fail.ref.node', + 'shadow-fail.errors', 'testswitch.node', + 'text-fail.node', + 'text-fail.ref.node', + 'text-fail.errors', + 'texture-fail.node', + 'texture-fail.ref.node', + 'texture-fail.ref.errors', + 'transform-fail.node', + 'transform-fail.ref.node', + 'transform-fail.errors', 'widgetfactory.node', ] @@ -205,7 +234,6 @@ foreach test : node_parser_tests endforeach tests = [ - ['rounded-rect'], ['transform'], ['shader'], ] @@ -242,6 +270,8 @@ endforeach internal_tests = [ [ 'diff' ], [ 'half-float' ], + ['rounded-rect'], + ['misc'], ] foreach t : internal_tests diff --git a/testsuite/gsk/misc.c b/testsuite/gsk/misc.c new file mode 100644 index 0000000000..7b4af1cf28 --- /dev/null +++ b/testsuite/gsk/misc.c @@ -0,0 +1,96 @@ +#include +#include "gsk/gskrendernodeprivate.h" + +static void +test_rendernode_gvalue (void) +{ + GValue value = G_VALUE_INIT; + GskRenderNode *node, *node2; + + g_assert_false (GSK_VALUE_HOLDS_RENDER_NODE (&value)); + g_value_init (&value, GSK_TYPE_RENDER_NODE); + g_assert_true (GSK_VALUE_HOLDS_RENDER_NODE (&value)); + + node = gsk_value_get_render_node (&value); + g_assert_null (node); + + node = gsk_color_node_new (&(GdkRGBA){0,1,1,1}, &GRAPHENE_RECT_INIT (0, 0, 50, 50)); + gsk_value_set_render_node (&value, node); + + node2 = gsk_value_dup_render_node (&value); + g_assert_true (node == node2); + + g_value_reset (&value); + gsk_value_take_render_node (&value, node); + + g_value_unset (&value); +} + +static void +test_bordernode_uniform (void) +{ + GskRenderNode *node; + GskRoundedRect rect; + GdkRGBA colors[4] = { + { 0, 0, 0, 1 }, + { 0, 0, 0, 1 }, + { 0, 0, 0, 1 }, + { 0, 0, 0, 1 }, + }; + + gsk_rounded_rect_init (&rect, + &GRAPHENE_RECT_INIT (0, 0, 50, 50), + &GRAPHENE_SIZE_INIT (10, 10), + &GRAPHENE_SIZE_INIT (10, 10), + &GRAPHENE_SIZE_INIT (10, 10), + &GRAPHENE_SIZE_INIT (10, 10)); + + node = gsk_border_node_new (&rect, (const float[]){ 1, 1, 1, 1}, colors); + + g_assert_true (gsk_border_node_get_uniform (node)); + g_assert_true (gsk_border_node_get_uniform_color (node)); + + gsk_render_node_unref (node); + + node = gsk_border_node_new (&rect, (const float[]){ 1, 2, 3, 4}, colors); + + g_assert_false (gsk_border_node_get_uniform (node)); + g_assert_true (gsk_border_node_get_uniform_color (node)); + + gsk_render_node_unref (node); +} + +#define DEG_TO_RAD(x) ((x) * (G_PI / 180.f)) + +static void +test_conic_gradient_angle (void) +{ + GskRenderNode *node; + GskColorStop stops[] = { + { 0.f, (GdkRGBA) { 0, 0, 0, 1} }, + { 1.f, (GdkRGBA) { 1, 0, 1, 1} }, + }; + + node = gsk_conic_gradient_node_new (&GRAPHENE_RECT_INIT (0, 0, 50, 50), + &GRAPHENE_POINT_INIT (10, 20), + 33.f, + stops, + G_N_ELEMENTS (stops)); + + g_assert_cmpfloat_with_epsilon (gsk_conic_gradient_node_get_angle (node), DEG_TO_RAD (90.f - 33.f), 0.001); + + gsk_render_node_unref (node); +} + +int +main (int argc, char *argv[]) +{ + (g_test_init) (&argc, &argv, NULL); + gtk_init (); + + g_test_add_func ("/rendernode/gvalue", test_rendernode_gvalue); + g_test_add_func ("/rendernode/border/uniform", test_bordernode_uniform); + g_test_add_func ("/rendernode/conic-gradient/angle", test_conic_gradient_angle); + + return g_test_run (); +} diff --git a/testsuite/gsk/nodeparser/conic-gradient.node b/testsuite/gsk/nodeparser/conic-gradient.node new file mode 100644 index 0000000000..d42bfbbf47 --- /dev/null +++ b/testsuite/gsk/nodeparser/conic-gradient.node @@ -0,0 +1,6 @@ +conic-gradient { + bounds: 0 0 50 50; + center: 20 30; + rotation: 25; + stops: 0 #444, 0.2 #0F0, 1 #F0A; +} \ No newline at end of file diff --git a/testsuite/gsk/nodeparser/conic-gradient.ref.node b/testsuite/gsk/nodeparser/conic-gradient.ref.node new file mode 100644 index 0000000000..dce5e637b5 --- /dev/null +++ b/testsuite/gsk/nodeparser/conic-gradient.ref.node @@ -0,0 +1,6 @@ +conic-gradient { + bounds: 0 0 50 50; + center: 20 30; + rotation: 25; + stops: 0 rgb(68,68,68), 0.2 rgb(0,255,0), 1 rgb(255,0,170); +} diff --git a/testsuite/gsk/nodeparser/debug-fail.errors b/testsuite/gsk/nodeparser/debug-fail.errors new file mode 100644 index 0000000000..e8b664c7d9 --- /dev/null +++ b/testsuite/gsk/nodeparser/debug-fail.errors @@ -0,0 +1,2 @@ +:5:10-11: error: GTK_CSS_PARSER_WARNING_SYNTAX +:6:8-9: error: GTK_CSS_PARSER_WARNING_SYNTAX diff --git a/testsuite/gsk/nodeparser/debug-fail.node b/testsuite/gsk/nodeparser/debug-fail.node new file mode 100644 index 0000000000..3ad439296e --- /dev/null +++ b/testsuite/gsk/nodeparser/debug-fail.node @@ -0,0 +1,8 @@ +debug { + message: "I'm a debug node."; + child: container { + } + message: "With repeating message and child."; + child: container { + } +} diff --git a/testsuite/gsk/nodeparser/debug-fail.ref.node b/testsuite/gsk/nodeparser/debug-fail.ref.node new file mode 100644 index 0000000000..c59d7b7743 --- /dev/null +++ b/testsuite/gsk/nodeparser/debug-fail.ref.node @@ -0,0 +1,5 @@ +debug { + message: "With repeating message and child."; + child: container { + } +} diff --git a/testsuite/gsk/nodeparser/glshader.errors b/testsuite/gsk/nodeparser/glshader.errors new file mode 100644 index 0000000000..f345ed1ef5 --- /dev/null +++ b/testsuite/gsk/nodeparser/glshader.errors @@ -0,0 +1 @@ +:10:43-47: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/gsk/nodeparser/glshader.node b/testsuite/gsk/nodeparser/glshader.node new file mode 100644 index 0000000000..0e6be6e0a1 --- /dev/null +++ b/testsuite/gsk/nodeparser/glshader.node @@ -0,0 +1,11 @@ +glshader { + bounds: 0 0 50 50; + sourcecode: "uniform vec3 iResolution;\A\ +uniform vec4 another;\A\ +uniform vec2 point;\A\ +uniform int iii;\A\ +uniform uint uuu;\A\ +uniform bool bbb;\A\ +uniform float num;"; + args: 10 20 30, 1 2 3 4, -1 -2, 0, 100, true, 3.1415; +} diff --git a/testsuite/gsk/nodeparser/glshader.ref.node b/testsuite/gsk/nodeparser/glshader.ref.node new file mode 100644 index 0000000000..3fbec15acb --- /dev/null +++ b/testsuite/gsk/nodeparser/glshader.ref.node @@ -0,0 +1,11 @@ +glshader { + bounds: 0 0 50 50; + sourcecode: "uniform vec3 iResolution;\A\ +uniform vec4 another;\A\ +uniform vec2 point;\A\ +uniform int iii;\A\ +uniform uint uuu;\A\ +uniform bool bbb;\A\ +uniform float num;"; + args: 10 20 30, 1 2 3 4, -1 -2, 0, 100, 0, 0; +} diff --git a/testsuite/gsk/nodeparser/gradient-fail.errors b/testsuite/gsk/nodeparser/gradient-fail.errors new file mode 100644 index 0000000000..052224ba76 --- /dev/null +++ b/testsuite/gsk/nodeparser/gradient-fail.errors @@ -0,0 +1 @@ +:3:8-9: error: GTK_CSS_PARSER_WARNING_SYNTAX diff --git a/testsuite/gsk/nodeparser/gradient-fail.node b/testsuite/gsk/nodeparser/gradient-fail.node new file mode 100644 index 0000000000..c9b57fc3be --- /dev/null +++ b/testsuite/gsk/nodeparser/gradient-fail.node @@ -0,0 +1,4 @@ +repeating-linear-gradient { + stops: 0 #FF0, 0.25 #F0A, 1 #0FF; + stops: 0 #FF0, 0.25 #F0A, 1 #0FF; +} diff --git a/testsuite/gsk/nodeparser/gradient-fail.ref.node b/testsuite/gsk/nodeparser/gradient-fail.ref.node new file mode 100644 index 0000000000..9352158ba4 --- /dev/null +++ b/testsuite/gsk/nodeparser/gradient-fail.ref.node @@ -0,0 +1,6 @@ +repeating-linear-gradient { + bounds: 0 0 50 50; + start: 0 0; + end: 0 50; + stops: 0 rgb(255,255,0), 0.25 rgb(255,0,170), 1 rgb(0,255,255); +} diff --git a/testsuite/gsk/nodeparser/radial-gradient.node b/testsuite/gsk/nodeparser/radial-gradient.node new file mode 100644 index 0000000000..cd34ee2be0 --- /dev/null +++ b/testsuite/gsk/nodeparser/radial-gradient.node @@ -0,0 +1,9 @@ +radial-gradient { + bounds: 0 0 50 50; + center: 20 20; + hradius: 10; + vradius: 20; + start: 0.25; + end: 0.75; + stops: 0 #FF0, 0.5 #ABC, 1 #F0F; +} \ No newline at end of file diff --git a/testsuite/gsk/nodeparser/radial-gradient.ref.node b/testsuite/gsk/nodeparser/radial-gradient.ref.node new file mode 100644 index 0000000000..538ac522a5 --- /dev/null +++ b/testsuite/gsk/nodeparser/radial-gradient.ref.node @@ -0,0 +1,9 @@ +radial-gradient { + bounds: 0 0 50 50; + center: 20 20; + hradius: 10; + vradius: 20; + start: 0.25; + end: 0.75; + stops: 0 rgb(255,255,0), 0.5 rgb(170,187,204), 1 rgb(255,0,255); +} diff --git a/testsuite/gsk/nodeparser/repeating-linear-gradient.node b/testsuite/gsk/nodeparser/repeating-linear-gradient.node new file mode 100644 index 0000000000..f8ed50e58a --- /dev/null +++ b/testsuite/gsk/nodeparser/repeating-linear-gradient.node @@ -0,0 +1,6 @@ +repeating-linear-gradient { + bounds: 0 0 50 50; + start: 50 0; + end: 25 25; + stops: 0 #FF0, 0.25 #F0A, 1 #0FF; +} \ No newline at end of file diff --git a/testsuite/gsk/nodeparser/repeating-linear-gradient.ref.node b/testsuite/gsk/nodeparser/repeating-linear-gradient.ref.node new file mode 100644 index 0000000000..4985680ef0 --- /dev/null +++ b/testsuite/gsk/nodeparser/repeating-linear-gradient.ref.node @@ -0,0 +1,6 @@ +repeating-linear-gradient { + bounds: 0 0 50 50; + start: 50 0; + end: 25 25; + stops: 0 rgb(255,255,0), 0.25 rgb(255,0,170), 1 rgb(0,255,255); +} diff --git a/testsuite/gsk/nodeparser/repeating-radial-gradient.node b/testsuite/gsk/nodeparser/repeating-radial-gradient.node new file mode 100644 index 0000000000..5415d1e839 --- /dev/null +++ b/testsuite/gsk/nodeparser/repeating-radial-gradient.node @@ -0,0 +1,9 @@ +repeating-radial-gradient { + bounds: 0 0 50 50; + center: 20 30; + hradius: 30; + vradius: 20; + start: 0.25; + end: 0.75; + stops: 0 #F0F, 1 #0F0; +} \ No newline at end of file diff --git a/testsuite/gsk/nodeparser/repeating-radial-gradient.ref.node b/testsuite/gsk/nodeparser/repeating-radial-gradient.ref.node new file mode 100644 index 0000000000..4aa3eeed8d --- /dev/null +++ b/testsuite/gsk/nodeparser/repeating-radial-gradient.ref.node @@ -0,0 +1,9 @@ +repeating-radial-gradient { + bounds: 0 0 50 50; + center: 20 30; + hradius: 30; + vradius: 20; + start: 0.25; + end: 0.75; + stops: 0 rgb(255,0,255), 1 rgb(0,255,0); +} diff --git a/testsuite/gsk/nodeparser/shadow-fail.errors b/testsuite/gsk/nodeparser/shadow-fail.errors new file mode 100644 index 0000000000..bb77a372fc --- /dev/null +++ b/testsuite/gsk/nodeparser/shadow-fail.errors @@ -0,0 +1,9 @@ +:2:11-13: error: GTK_CSS_PARSER_ERROR_SYNTAX +:2:11-13: error: GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE +:2:13-14: error: GTK_CSS_PARSER_ERROR_SYNTAX +:2:13-14: error: GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE +:3:9-10: error: GTK_CSS_PARSER_WARNING_SYNTAX +:3:11-13: error: GTK_CSS_PARSER_ERROR_SYNTAX +:3:11-13: error: GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE +:3:13-14: error: GTK_CSS_PARSER_ERROR_SYNTAX +:3:13-14: error: GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE diff --git a/testsuite/gsk/nodeparser/shadow-fail.node b/testsuite/gsk/nodeparser/shadow-fail.node new file mode 100644 index 0000000000..5b851e7eb1 --- /dev/null +++ b/testsuite/gsk/nodeparser/shadow-fail.node @@ -0,0 +1,4 @@ +shadow { + shadows: 22; + shadows: 22; +} diff --git a/testsuite/gsk/nodeparser/shadow-fail.ref.node b/testsuite/gsk/nodeparser/shadow-fail.ref.node new file mode 100644 index 0000000000..77e42196fb --- /dev/null +++ b/testsuite/gsk/nodeparser/shadow-fail.ref.node @@ -0,0 +1,7 @@ +shadow { + shadows: rgb(0,0,0) 22 0, rgb(0,0,0) 22 0; + child: color { + bounds: 0 0 50 50; + color: rgb(255,0,204); + } +} diff --git a/testsuite/gsk/nodeparser/text-fail.errors b/testsuite/gsk/nodeparser/text-fail.errors new file mode 100644 index 0000000000..1df16b5cff --- /dev/null +++ b/testsuite/gsk/nodeparser/text-fail.errors @@ -0,0 +1,3 @@ +:4:7-8: error: GTK_CSS_PARSER_WARNING_SYNTAX +:6:9-10: error: GTK_CSS_PARSER_WARNING_SYNTAX +:8:1-2: error: GTK_CSS_PARSER_ERROR_UNKNOWN_VALUE diff --git a/testsuite/gsk/nodeparser/text-fail.node b/testsuite/gsk/nodeparser/text-fail.node new file mode 100644 index 0000000000..cbbf594fd4 --- /dev/null +++ b/testsuite/gsk/nodeparser/text-fail.node @@ -0,0 +1,8 @@ +text { + color: rgb(50,50,50); + font: ""; + font: ""; + glyphs: "N"; + glyphs: "N"; + offset: 0 32.0186; +} diff --git a/testsuite/gsk/nodeparser/text-fail.ref.node b/testsuite/gsk/nodeparser/text-fail.ref.node new file mode 100644 index 0000000000..404fb1b892 --- /dev/null +++ b/testsuite/gsk/nodeparser/text-fail.ref.node @@ -0,0 +1,4 @@ +color { + bounds: 0 0 50 50; + color: rgb(255,0,204); +} diff --git a/testsuite/gsk/nodeparser/texture-fail.errors b/testsuite/gsk/nodeparser/texture-fail.errors new file mode 100644 index 0000000000..cc436f0e71 --- /dev/null +++ b/testsuite/gsk/nodeparser/texture-fail.errors @@ -0,0 +1 @@ +:2:12-14: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/gsk/nodeparser/texture-fail.node b/testsuite/gsk/nodeparser/texture-fail.node new file mode 100644 index 0000000000..996ada6181 --- /dev/null +++ b/testsuite/gsk/nodeparser/texture-fail.node @@ -0,0 +1,3 @@ +texture { + texture: 22; +} diff --git a/testsuite/gsk/nodeparser/texture-fail.ref.node b/testsuite/gsk/nodeparser/texture-fail.ref.node new file mode 100644 index 0000000000..b8027cb332 --- /dev/null +++ b/testsuite/gsk/nodeparser/texture-fail.ref.node @@ -0,0 +1,6 @@ +texture { + bounds: 0 0 50 50; + texture: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAKUlEQVQYlWP8z3DmPwMaYGQwYUQX\ +Y0IXwAUGUCGGoxkYGBiweXAoeAYAz44F3e3U1xUAAAAASUVORK5CYII=\ +"); +} diff --git a/testsuite/gsk/nodeparser/transform-fail.errors b/testsuite/gsk/nodeparser/transform-fail.errors new file mode 100644 index 0000000000..a951d27419 --- /dev/null +++ b/testsuite/gsk/nodeparser/transform-fail.errors @@ -0,0 +1 @@ +:2:14-16: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/gsk/nodeparser/transform-fail.node b/testsuite/gsk/nodeparser/transform-fail.node new file mode 100644 index 0000000000..676dde3755 --- /dev/null +++ b/testsuite/gsk/nodeparser/transform-fail.node @@ -0,0 +1,3 @@ +transform { + transform: 22; +} \ No newline at end of file diff --git a/testsuite/gsk/nodeparser/transform-fail.ref.node b/testsuite/gsk/nodeparser/transform-fail.ref.node new file mode 100644 index 0000000000..8a63720daa --- /dev/null +++ b/testsuite/gsk/nodeparser/transform-fail.ref.node @@ -0,0 +1,6 @@ +transform { + child: color { + bounds: 0 0 50 50; + color: rgb(255,0,204); + } +} diff --git a/testsuite/gsk/rounded-rect.c b/testsuite/gsk/rounded-rect.c index 78bae68ab2..0127d1cb54 100644 --- a/testsuite/gsk/rounded-rect.c +++ b/testsuite/gsk/rounded-rect.c @@ -20,6 +20,7 @@ #include "config.h" #include +#include static void test_contains_rect (void) @@ -114,6 +115,51 @@ test_contains_point (void) g_assert_true (gsk_rounded_rect_contains_point (&rect, &GRAPHENE_POINT_INIT (10, 95))); } +static void +test_is_circular (void) +{ + GskRoundedRect rect; + + gsk_rounded_rect_init (&rect, + &GRAPHENE_RECT_INIT (0, 0, 100, 100), + &GRAPHENE_SIZE_INIT (0, 0), + &GRAPHENE_SIZE_INIT (10, 10), + &GRAPHENE_SIZE_INIT (10, 20), + &GRAPHENE_SIZE_INIT (20, 10)); + + g_assert_false (gsk_rounded_rect_is_circular (&rect)); + + gsk_rounded_rect_init (&rect, + &GRAPHENE_RECT_INIT (0, 0, 100, 100), + &GRAPHENE_SIZE_INIT (0, 0), + &GRAPHENE_SIZE_INIT (10, 10), + &GRAPHENE_SIZE_INIT (20, 20), + &GRAPHENE_SIZE_INIT (30, 30)); + + g_assert_true (gsk_rounded_rect_is_circular (&rect)); +} + +static void +test_to_float (void) +{ + GskRoundedRect rect; + float flt[12]; + + gsk_rounded_rect_init (&rect, + &GRAPHENE_RECT_INIT (0, 11, 22, 33), + &GRAPHENE_SIZE_INIT (4, 5), + &GRAPHENE_SIZE_INIT (6, 7), + &GRAPHENE_SIZE_INIT (8, 9), + &GRAPHENE_SIZE_INIT (10, 11)); + + gsk_rounded_rect_to_float (&rect, flt); + g_assert_true (flt[0] == 0. && flt[1] == 11. && flt[2] == 22. && flt[3] == 33.); + g_assert_true (flt[4] == 4. && flt[5] == 6.); + g_assert_true (flt[6] == 8. && flt[7] == 10.); + g_assert_true (flt[8] == 5. && flt[9] == 7.); + g_assert_true (flt[10] == 9. && flt[11] == 11.); +} + int main (int argc, char *argv[]) @@ -123,6 +169,8 @@ main (int argc, g_test_add_func ("/rounded-rect/contains-rect", test_contains_rect); g_test_add_func ("/rounded-rect/intersects-rect", test_intersects_rect); g_test_add_func ("/rounded-rect/contains-point", test_contains_point); + g_test_add_func ("/rounded-rect/is-circular", test_is_circular); + g_test_add_func ("/rounded-rect/to-float", test_to_float); return g_test_run (); } diff --git a/testsuite/gsk/shader.c b/testsuite/gsk/shader.c index 555acb0869..4bc4f0245b 100644 --- a/testsuite/gsk/shader.c +++ b/testsuite/gsk/shader.c @@ -76,6 +76,7 @@ test_create_simple (void) { GBytes *bytes; GskGLShader *shader; + GBytes *source; bytes = g_bytes_new_static (shader1, sizeof (shader1)); shader = gsk_gl_shader_new_from_bytes (bytes); @@ -100,19 +101,48 @@ test_create_simple (void) g_assert_cmpstr (gsk_gl_shader_get_uniform_name (shader, 7), ==, "test5"); g_assert_cmpint (gsk_gl_shader_get_uniform_type (shader, 7), ==, GSK_GL_UNIFORM_TYPE_VEC4); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "progress"), ==, 0); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "dots"), ==, 1); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "center"), ==, 2); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "test1"), ==, 3); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "test2"), ==, 4); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "test3"), ==, 5); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "test4"), ==, 6); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "test5"), ==, 7); + g_assert_cmpint (gsk_gl_shader_find_uniform_by_name (shader, "nosucharg"), ==, -1); + + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 0), ==, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 1), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 2), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 3), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 4), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 5), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 6), >, 0); + g_assert_cmpint (gsk_gl_shader_get_uniform_offset (shader, 7), >, 0); + + g_assert_null (gsk_gl_shader_get_resource (shader)); + + g_object_get (shader, "source", &source, NULL); + g_assert_true (g_bytes_equal (source, bytes)); + g_object_unref (shader); g_bytes_unref (bytes); + g_bytes_unref (source); } static void test_create_data (void) { GBytes *bytes; + GBytes *bytes2; GskGLShader *shader; GskShaderArgsBuilder *builder; + GskShaderArgsBuilder *builder2; graphene_vec2_t v2, vv2; graphene_vec3_t v3, vv3; graphene_vec4_t v4, vv4; + GskRenderNode *node; + GskRenderNode *children[2]; bytes = g_bytes_new_static (shader1, sizeof (shader1)); shader = gsk_gl_shader_new_from_bytes (bytes); @@ -150,6 +180,31 @@ test_create_data (void) gsk_gl_shader_get_arg_vec4 (shader, bytes, 7, &vv4); g_assert_true (graphene_vec4_equal (&v4, &vv4)); + children[0] = gsk_color_node_new (&(GdkRGBA){0,0,0,1}, &GRAPHENE_RECT_INIT (0, 0, 50, 50)); + children[1] = gsk_color_node_new (&(GdkRGBA){1,0,0,1}, &GRAPHENE_RECT_INIT (0, 0, 50, 50)); + node = gsk_gl_shader_node_new (shader, + &GRAPHENE_RECT_INIT (0, 0, 50, 50), + bytes, + children, + 2); + + g_assert_true (gsk_gl_shader_node_get_shader (node) == shader); + g_assert_cmpuint (gsk_gl_shader_node_get_n_children (node), ==, 2); + g_assert_true (gsk_gl_shader_node_get_child (node, 0) == children[0]); + g_assert_true (gsk_gl_shader_node_get_child (node, 1) == children[1]); + + gsk_render_node_unref (children[0]); + gsk_render_node_unref (children[1]); + gsk_render_node_unref (node); + + builder2 = gsk_shader_args_builder_new (shader, bytes); + gsk_shader_args_builder_ref (builder2); + bytes2 = gsk_shader_args_builder_free_to_args (builder2); + gsk_shader_args_builder_unref (builder2); + + g_assert_true (g_bytes_equal (bytes, bytes2)); + + g_bytes_unref (bytes2); g_bytes_unref (bytes); gsk_shader_args_builder_unref (builder); diff --git a/testsuite/gsk/transform.c b/testsuite/gsk/transform.c index ec2b138761..1300dedf6a 100644 --- a/testsuite/gsk/transform.c +++ b/testsuite/gsk/transform.c @@ -655,6 +655,19 @@ test_to_2d (void) g_assert_cmpfloat (yy, ==, 1); g_assert_cmpfloat (dx, ==, 0.0); g_assert_cmpfloat (dy, ==, 0.0); + + transform = gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (10.0, 5.0)); + transform = gsk_transform_rotate (transform, 33.0); + + gsk_transform_to_2d (transform, &xx, &yx, &xy, &yy, &dx, &dy); + gsk_transform_unref (transform); + + g_assert_cmpfloat (xx, ==, 0.838670552f); + g_assert_cmpfloat (yx, ==, 0.544639051f); + g_assert_cmpfloat (xy, ==, -0.544639051f); + g_assert_cmpfloat (yy, ==, 0.838670552f); + g_assert_cmpfloat (dx, ==, 10.f); + g_assert_cmpfloat (dy, ==, 5.f); } static void @@ -735,6 +748,101 @@ test_transform_point (void) gsk_transform_unref (t2); } +static void +test_skew_transform (void) +{ + GskTransform *t1, *t2, *t3; + char *string; + gboolean res; + GskTransform *x; + + t1 = gsk_transform_skew (NULL, 30, 60); + t2 = gsk_transform_skew (NULL, 0, 30); + t3 = gsk_transform_skew (NULL, 0, -30); + + g_assert_true (gsk_transform_get_category (t1) == GSK_TRANSFORM_CATEGORY_2D); + g_assert_true (gsk_transform_get_category (t2) == GSK_TRANSFORM_CATEGORY_2D); + g_assert_false (gsk_transform_equal (t1, t2)); + + t2 = gsk_transform_invert (t2); + graphene_assert_fuzzy_transform_equal (t2, t3, EPSILON); + + string = gsk_transform_to_string (t1); + res = gsk_transform_parse (string, &x); + g_assert_true (res); + g_assert_true (gsk_transform_equal (t1, x)); + + gsk_transform_unref (t1); + gsk_transform_unref (t2); + gsk_transform_unref (t3); + g_free (string); + gsk_transform_unref (x); +} + +static void +test_perspective_transform (void) +{ + GskTransform *t1, *t2; + + t1 = gsk_transform_perspective (NULL, 1000); + t2 = gsk_transform_perspective (NULL, 300); + + g_assert_true (gsk_transform_get_category (t1) == GSK_TRANSFORM_CATEGORY_ANY); + g_assert_true (gsk_transform_get_category (t2) == GSK_TRANSFORM_CATEGORY_ANY); + g_assert_false (gsk_transform_equal (t1, t2)); + + t2 = gsk_transform_perspective (t2, 700); + + g_assert_true (gsk_transform_equal (t1, t2)); + + gsk_transform_unref (t1); + gsk_transform_unref (t2); +} + +static void +test_rotate_transform (void) +{ + GskTransform *t1, *t2, *t3; + + t1 = gsk_transform_rotate (NULL, 60); + t2 = gsk_transform_rotate (NULL, 20); + + g_assert_true (gsk_transform_get_category (t1) == GSK_TRANSFORM_CATEGORY_2D); + g_assert_true (gsk_transform_get_category (t2) == GSK_TRANSFORM_CATEGORY_2D); + g_assert_false (gsk_transform_equal (t1, t2)); + + t2 = gsk_transform_rotate (t2, 40); + g_assert_true (gsk_transform_equal (t1, t2)); + + t1 = gsk_transform_invert (t1); + t3 = gsk_transform_rotate (NULL, -60); + g_assert_true (gsk_transform_equal (t1, t3)); + + gsk_transform_unref (t1); + gsk_transform_unref (t2); + gsk_transform_unref (t3); +} + +static void +test_rotate3d_transform (void) +{ + GskTransform *t1, *t2; + graphene_vec3_t vec; + + t1 = gsk_transform_rotate_3d (NULL, 60, graphene_vec3_init (&vec, 1, 2, 3)); + t2 = gsk_transform_rotate_3d (NULL, -60, graphene_vec3_init (&vec, 1, 2, 3)); + + g_assert_true (gsk_transform_get_category (t1) == GSK_TRANSFORM_CATEGORY_3D); + g_assert_true (gsk_transform_get_category (t2) == GSK_TRANSFORM_CATEGORY_3D); + g_assert_false (gsk_transform_equal (t1, t2)); + + t2 = gsk_transform_invert (t2); + g_assert_true (gsk_transform_equal (t1, t2)); + + gsk_transform_unref (t1); + gsk_transform_unref (t2); +} + int main (int argc, char *argv[]) @@ -753,6 +861,10 @@ main (int argc, g_test_add_func ("/transform/point", test_transform_point); g_test_add_func ("/transform/to-2d", test_to_2d); g_test_add_func ("/transform/to-2d-components", test_to_2d_components); + g_test_add_func ("/transform/skew", test_skew_transform); + g_test_add_func ("/transform/perspective", test_perspective_transform); + g_test_add_func ("/transform/rotate", test_rotate_transform); + g_test_add_func ("/transform/rotate3d", test_rotate3d_transform); return g_test_run (); }