[gtk/text-placeholder-visibility: 12/13] gsk: More test coverage




commit d3ef9ca7cab545d02a7fd0643e817eddfbebcd41
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jul 15 15:45:15 2022 -0400

    gsk: More test coverage

 testsuite/gsk/shader.c    |  55 +++++++++++++++++++++++
 testsuite/gsk/transform.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)
---
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 ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]