[gtk/wip/baedert/nodeeditor: 9/23] testsuite: Add serialize-deserialize tests



commit 934c2b2590aaad6abdd551bd60e521dbef66aeb8
Author: Timm Bäder <mail baedert org>
Date:   Tue Apr 23 18:08:06 2019 +0200

    testsuite: Add serialize-deserialize tests
    
    Check that we can successfully deserialize a node, then serialize it
    again and serialize that result once more.

 testsuite/gsk/meson.build                          |  35 ++-
 testsuite/gsk/nodeparser/border.valid.node         |   5 +
 testsuite/gsk/nodeparser/color.valid.node          |   4 +
 .../{crash1.node => crash1.invalid.node}           |   0
 .../{crash2.node => crash2.invalid.node}           |   0
 .../{crash3.node => crash3.invalid.node}           |   0
 testsuite/gsk/nodeparser/testswitch.valid.node     | 256 +++++++++++++++++++++
 testsuite/gsk/serialize-deserialize.c              |  42 ++++
 8 files changed, 339 insertions(+), 3 deletions(-)
---
diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build
index df863a8fad..918302c149 100644
--- a/testsuite/gsk/meson.build
+++ b/testsuite/gsk/meson.build
@@ -26,6 +26,14 @@ node_parser = executable(
   install_dir: testexecdir
 )
 
+serialize_deserialize = executable(
+  'serialize-deserialize',
+  ['serialize-deserialize.c'],
+  dependencies: libgtk_dep,
+  install: get_option('install-tests'),
+  install_dir: testexecdir,
+)
+
 test('nodes (cairo)', test_render_nodes,
      args: [ '--tap', '-k' ],
      env: [ 'GIO_USE_VOLUME_MONITOR=unix',
@@ -102,9 +110,9 @@ foreach renderer : renderers
 endforeach
 
 node_parser_tests = [
-  'crash1',
-  'crash2',
-  'crash3',
+  'crash1.invalid',
+  'crash2.invalid',
+  'crash3.invalid',
 ]
 
 foreach test : node_parser_tests
@@ -121,6 +129,27 @@ foreach test : node_parser_tests
        suite: 'gsk')
 endforeach
 
+serialize_deserialize_tests = [
+  'color.valid',
+  'border.valid',
+  'testswitch.valid',
+]
+
+foreach test : serialize_deserialize_tests
+  test('serialize-deserialize ' + test, serialize_deserialize,
+       args: [join_paths(meson.current_source_dir(), 'nodeparser', test + '.node')],
+       env: [ 'GIO_USE_VOLUME_MONITOR=unix',
+              'GSETTINGS_BACKEND=memory',
+              'GTK_CSD=1',
+              'G_ENABLE_DIAGNOSTIC=0',
+              'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
+              'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
+              'GSK_RENDERER=opengl'
+            ],
+       suite: 'gsk')
+endforeach
+
+
 if have_vulkan
   test('nodes (vulkan)', test_render_nodes,
        args: [ '--tap', '-k' ],
diff --git a/testsuite/gsk/nodeparser/border.valid.node b/testsuite/gsk/nodeparser/border.valid.node
new file mode 100644
index 0000000000..89b490329f
--- /dev/null
+++ b/testsuite/gsk/nodeparser/border.valid.node
@@ -0,0 +1,5 @@
+border {
+  outline: -1 -1 50 26 / 13;
+  widths: 1 1 1 1;
+  colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1);
+}
diff --git a/testsuite/gsk/nodeparser/color.valid.node b/testsuite/gsk/nodeparser/color.valid.node
new file mode 100644
index 0000000000..acbc79288d
--- /dev/null
+++ b/testsuite/gsk/nodeparser/color.valid.node
@@ -0,0 +1,4 @@
+color {
+  bounds: 100 100 200 300;
+  color: red;
+}
diff --git a/testsuite/gsk/nodeparser/crash1.node b/testsuite/gsk/nodeparser/crash1.invalid.node
similarity index 100%
rename from testsuite/gsk/nodeparser/crash1.node
rename to testsuite/gsk/nodeparser/crash1.invalid.node
diff --git a/testsuite/gsk/nodeparser/crash2.node b/testsuite/gsk/nodeparser/crash2.invalid.node
similarity index 100%
rename from testsuite/gsk/nodeparser/crash2.node
rename to testsuite/gsk/nodeparser/crash2.invalid.node
diff --git a/testsuite/gsk/nodeparser/crash3.node b/testsuite/gsk/nodeparser/crash3.invalid.node
similarity index 100%
rename from testsuite/gsk/nodeparser/crash3.node
rename to testsuite/gsk/nodeparser/crash3.invalid.node
diff --git a/testsuite/gsk/nodeparser/testswitch.valid.node b/testsuite/gsk/nodeparser/testswitch.valid.node
new file mode 100644
index 0000000000..141c351603
--- /dev/null
+++ b/testsuite/gsk/nodeparser/testswitch.valid.node
@@ -0,0 +1,256 @@
+transform {
+  transform: translate(0, 0);
+  child:   container {
+    color {
+      bounds: 0 0 636 1057;
+      color: rgba(246, 245, 244, 1);
+    }
+    container {
+      container {
+        transform {
+          transform: translate(1, 1);
+          child:           container {
+            rounded-clip {
+              clip: -1 -1 50 26 / 13;
+              child:               color {
+                bounds: -1 -1 50 26;
+                color: rgba(234, 232, 230, 1);
+              }
+            }
+            border {
+              outline: -1 -1 50 26 / 13;
+              widths: 1 1 1 1;
+              colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 
204, 1);
+            }
+            container {
+              rounded-clip {
+                clip: -1 -1 26 26 / 13;
+                child:                 color {
+                  bounds: 0 0 24 24;
+                  color: rgba(246, 245, 244, 1);
+                }
+              }
+              border {
+                outline: -1 -1 26 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 
204, 1);
+              }
+            }
+          }
+        }
+        transform {
+          transform: translate(56, 0);
+          child:           text {
+            font: "Cantarell 11";
+            x: 261;
+            y: 18;
+            color: rgba(146, 149, 149, 1);
+          }
+        }
+      }
+      transform {
+        transform: translate(0, 38);
+        child:         container {
+          transform {
+            transform: translate(1, 1);
+            child:             container {
+              rounded-clip {
+                clip: -1 -1 50 26 / 13;
+                child:                 color {
+                  bounds: -1 -1 50 26;
+                  color: rgba(53, 132, 228, 1);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgba(53, 132, 228, 1) rgba(53, 132, 228, 1) rgba(53, 132, 228, 1) rgba(53, 132, 228, 
1);
+              }
+              transform {
+                transform: translate(24, 0);
+                child:                 container {
+                  rounded-clip {
+                    clip: -1 -1 26 26 / 13;
+                    child:                     color {
+                      bounds: 0 0 24 24;
+                      color: rgba(246, 245, 244, 1);
+                    }
+                  }
+                  border {
+                    outline: -1 -1 26 26 / 13;
+                    widths: 1 1 1 1;
+                    colors: rgba(53, 132, 228, 1) rgba(53, 132, 228, 1) rgba(53, 132, 228, 1) rgba(53, 132, 
228, 1);
+                  }
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child:             text {
+              font: "Cantarell 11";
+              x: 263;
+              y: 18;
+              color: rgba(146, 149, 149, 1);
+            }
+          }
+        }
+      }
+      transform {
+        transform: translate(0, 76);
+        child:         container {
+          transform {
+            transform: translate(1, 1);
+            child:             container {
+              rounded-clip {
+                clip: -1 -1 50 26 / 13;
+                child:                 color {
+                  bounds: -1 -1 50 26;
+                  color: rgba(250, 249, 248, 1);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 
204, 1);
+              }
+              container {
+                rounded-clip {
+                  clip: -1 -1 26 26 / 13;
+                  child:                   color {
+                    bounds: 0 0 24 24;
+                    color: rgba(250, 249, 248, 1);
+                  }
+                }
+                border {
+                  outline: -1 -1 26 26 / 13;
+                  widths: 1 1 1 1;
+                  colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 
208, 204, 1);
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child:             text {
+              font: "Cantarell 11";
+              x: 261;
+              y: 18;
+              color: rgba(146, 149, 149, 1);
+            }
+          }
+        }
+      }
+      transform {
+        transform: translate(0, 114);
+        child:         container {
+          transform {
+            transform: translate(1, 1);
+            child:             container {
+              rounded-clip {
+                clip: -1 -1 50 26 / 13;
+                child:                 color {
+                  bounds: -1 -1 50 26;
+                  color: rgba(250, 249, 248, 1);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 
204, 1);
+              }
+              transform {
+                transform: translate(24, 0);
+                child:                 container {
+                  rounded-clip {
+                    clip: -1 -1 26 26 / 13;
+                    child:                     color {
+                      bounds: 0 0 24 24;
+                      color: rgba(250, 249, 248, 1);
+                    }
+                  }
+                  border {
+                    outline: -1 -1 26 26 / 13;
+                    widths: 1 1 1 1;
+                    colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 
208, 204, 1);
+                  }
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child:             text {
+              font: "Cantarell 11";
+              x: 263;
+              y: 18;
+              color: rgba(146, 149, 149, 1);
+            }
+          }
+        }
+      }
+      transform {
+        transform: translate(0, 152);
+        child:         container {
+          transform {
+            transform: translate(1, 1);
+            child:             container {
+              rounded-clip {
+                clip: -1 -1 50 26 / 13;
+                child:                 color {
+                  bounds: -1 -1 50 26;
+                  color: rgba(234, 232, 230, 1);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 
204, 1);
+              }
+              container {
+                rounded-clip {
+                  clip: -1 -1 26 26 / 13;
+                  child:                   color {
+                    bounds: 0 0 24 24;
+                    color: rgba(246, 245, 244, 1);
+                  }
+                }
+                border {
+                  outline: -1 -1 26 26 / 13;
+                  widths: 1 1 1 1;
+                  colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 
208, 204, 1);
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(78, 0);
+            child:             text {
+              font: "Cantarell 11";
+              x: 239;
+              y: 18;
+              color: rgba(146, 149, 149, 1);
+            }
+          }
+          transform {
+            transform: translate(620, 0);
+            child:             transform {
+              transform: translate(1, 6);
+              child:               container {
+                color {
+                  bounds: 0 0 14 14;
+                  color: rgba(246, 245, 244, 1);
+                }
+                border {
+                  outline: -1 -1 16 16 / 3;
+                  widths: 1 1 1 1;
+                  colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 
208, 204, 1);
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/testsuite/gsk/serialize-deserialize.c b/testsuite/gsk/serialize-deserialize.c
new file mode 100644
index 0000000000..cb79eb43e6
--- /dev/null
+++ b/testsuite/gsk/serialize-deserialize.c
@@ -0,0 +1,42 @@
+#include <gtk/gtk.h>
+
+int
+main (int argc, char **argv)
+{
+  GError *error = NULL;
+  GskRenderNode *node;
+  GskRenderNode *deserialized;
+  GBytes *bytes;
+  GFile *file;
+
+  g_assert (argc == 2);
+
+  gtk_init ();
+
+  file = g_file_new_for_commandline_arg (argv[1]);
+  bytes = g_file_load_bytes (file, NULL, NULL, &error);
+  g_assert_no_error (error);
+  g_assert (bytes != NULL);
+
+  node = gsk_render_node_deserialize (bytes, &error);
+  g_assert_no_error (error);
+
+  /* Now serialize */
+  g_bytes_unref (bytes);
+  bytes = gsk_render_node_serialize (node);
+  /* and deserialize again... */
+  deserialized = gsk_render_node_deserialize (bytes, &error);
+  g_assert_no_error (error);
+
+  /* And check if that all worked. */
+  g_assert_cmpint (gsk_render_node_get_node_type (deserialized), ==,
+                   gsk_render_node_get_node_type (node));
+
+
+  g_clear_error (&error);
+  g_clear_pointer (&node, gsk_render_node_unref);
+  g_bytes_unref (bytes);
+  g_object_unref (file);
+
+  return 0;
+}


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