[gtk/wip/baedert/nodeeditor: 7/21] testsuite: Add serialize-deserialize tests



commit f56c22772682f82ed5fd991cb1999e7f1d4a76f5
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     | 389 +++++++++++++++++++++
 testsuite/gsk/serialize-deserialize.c              |  43 +++
 8 files changed, 473 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..940d821e00
--- /dev/null
+++ b/testsuite/gsk/nodeparser/testswitch.valid.node
@@ -0,0 +1,389 @@
+transform {
+  transform: translate(0, 0);
+  child: container {
+    color {
+      bounds: 0 0 404 204;
+      color: rgb(246,245,244);
+    }
+    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: rgb(225,222,219);
+              }
+            }
+            border {
+              outline: -1 -1 50 26 / 13;
+              widths: 1 1 1 1;
+              colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+            }
+            container {
+              container {
+                outset-shadow {
+                  outline: -1 -1 26 26 / 13;
+                  color: rgba(0,0,0,0.1);
+                  dx: 0;
+                  dy: 1;
+                  spread: 0;
+                  blur: 0;
+                }
+                outset-shadow {
+                  outline: -1 -1 26 26 / 13;
+                  color: rgba(0,0,0,0.07);
+                  dx: 0;
+                  dy: 1;
+                  spread: 0;
+                  blur: 2;
+                }
+                rounded-clip {
+                  clip: -1 -1 26 26 / 13;
+                  child: linear-gradient {
+                    bounds: 0 0 24 24;
+                    start: 12 0;
+                    end: 12 24;
+                    stops: 0.2 rgb(255,255,255),0.9 rgb(246,245,244);
+                  }
+                }
+                inset-shadow {
+                  outline: 0 0 24 24 / 12;
+                  color: rgb(255,255,255);
+                  dx: 0;
+                  dy: 1;
+                  spread: 0;
+                  blur: 0;
+                }
+              }
+              border {
+                outline: -1 -1 26 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgb(191,184,177) rgb(191,184,177) rgb(191,184,177) rgb(191,184,177);
+              }
+            }
+          }
+        }
+        transform {
+          transform: translate(56, 0);
+          child: text {
+            font: "Cantarell 11";
+            x: 145;
+            y: 18;
+            color: rgb(46,52,54);
+            glyphs: 37 11264 0 0 1, 324 4096 0 0 1, 417 7168 0 0 1, 244 8192 0 0 1, 272 8192 0 0 1, 349 4096 
0 0 1, 287 8192 0 0 1, 280 8192 0 0 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: rgb(53,132,228);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgb(24,95,180) rgb(24,95,180) rgb(24,95,180) rgb(24,95,180);
+              }
+              transform {
+                transform: translate(24, 0);
+                child: container {
+                  container {
+                    outset-shadow {
+                      outline: -1 -1 26 26 / 13;
+                      color: rgba(0,0,0,0.1);
+                      dx: 0;
+                      dy: 1;
+                      spread: 0;
+                      blur: 0;
+                    }
+                    outset-shadow {
+                      outline: -1 -1 26 26 / 13;
+                      color: rgba(0,0,0,0.07);
+                      dx: 0;
+                      dy: 1;
+                      spread: 0;
+                      blur: 2;
+                    }
+                    rounded-clip {
+                      clip: -1 -1 26 26 / 13;
+                      child: cross-fade {
+                        progress: 0.756154;
+                        start: cross-fade {
+                          progress: 0.788575;
+                          start: color {
+                            bounds: 0 0 24 24;
+                            color: rgb(246,245,244);
+                          }
+                          end: linear-gradient {
+                            bounds: 0 0 24 24;
+                            start: 12 0;
+                            end: 12 24;
+                            stops: 0.2 rgb(255,255,255),0.9 rgb(246,245,244);
+                          }
+                        }
+                        end: linear-gradient {
+                          bounds: 0 0 24 24;
+                          start: 12 0;
+                          end: 12 24;
+                          stops: 0.1 rgb(255,255,255),0.9 rgb(255,255,255);
+                        }
+                      }
+                    }
+                    inset-shadow {
+                      outline: 0 0 24 24 / 12;
+                      color: rgb(255,255,255);
+                      dx: 0;
+                      dy: 1;
+                      spread: 0;
+                      blur: 0;
+                    }
+                  }
+                  border {
+                    outline: -1 -1 26 26 / 13;
+                    widths: 1 1 1 1;
+                    colors: rgb(24,95,180) rgb(24,95,180) rgb(24,95,180) rgb(24,95,180);
+                  }
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child: text {
+              font: "Cantarell 11";
+              x: 147;
+              y: 18;
+              color: rgb(46,52,54);
+              glyphs: 45 9216 0 0 1, 360 8192 0 0 1, 244 8192 0 0 1, 272 8192 0 0 1, 349 4096 0 0 1, 287 
8192 0 0 1, 280 8192 0 0 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: rgb(250,249,248);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+              }
+              container {
+                rounded-clip {
+                  clip: -1 -1 26 26 / 13;
+                  child: color {
+                    bounds: 0 0 24 24;
+                    color: rgb(250,249,248);
+                  }
+                }
+                border {
+                  outline: -1 -1 26 26 / 13;
+                  widths: 1 1 1 1;
+                  colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child: text {
+              font: "Cantarell 11";
+              x: 145;
+              y: 18;
+              color: rgb(46,52,54);
+              glyphs: 37 11264 0 0 1, 324 4096 0 0 1, 417 7168 0 0 1, 244 8192 0 0 1, 272 8192 0 0 1, 349 
4096 0 0 1, 287 8192 0 0 1, 280 8192 0 0 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: rgb(250,249,248);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+              }
+              transform {
+                transform: translate(24, 0);
+                child: container {
+                  rounded-clip {
+                    clip: -1 -1 26 26 / 13;
+                    child: color {
+                      bounds: 0 0 24 24;
+                      color: rgb(250,249,248);
+                    }
+                  }
+                  border {
+                    outline: -1 -1 26 26 / 13;
+                    widths: 1 1 1 1;
+                    colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+                  }
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(56, 0);
+            child: text {
+              font: "Cantarell 11";
+              x: 147;
+              y: 18;
+              color: rgb(46,52,54);
+              glyphs: 45 9216 0 0 1, 360 8192 0 0 1, 244 8192 0 0 1, 272 8192 0 0 1, 349 4096 0 0 1, 287 
8192 0 0 1, 280 8192 0 0 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: rgb(225,222,219);
+                }
+              }
+              border {
+                outline: -1 -1 50 26 / 13;
+                widths: 1 1 1 1;
+                colors: rgb(205,199,194) rgb(205,199,194) rgb(205,199,194) rgb(205,199,194);
+              }
+              container {
+                container {
+                  outset-shadow {
+                    outline: -1 -1 26 26 / 13;
+                    color: rgba(0,0,0,0.1);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 0;
+                  }
+                  outset-shadow {
+                    outline: -1 -1 26 26 / 13;
+                    color: rgba(0,0,0,0.07);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 2;
+                  }
+                  rounded-clip {
+                    clip: -1 -1 26 26 / 13;
+                    child: linear-gradient {
+                      bounds: 0 0 24 24;
+                      start: 12 0;
+                      end: 12 24;
+                      stops: 0.2 rgb(255,255,255),0.9 rgb(246,245,244);
+                    }
+                  }
+                  inset-shadow {
+                    outline: 0 0 24 24 / 12;
+                    color: rgb(255,255,255);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 0;
+                  }
+                }
+                border {
+                  outline: -1 -1 26 26 / 13;
+                  widths: 1 1 1 1;
+                  colors: rgb(191,184,177) rgb(191,184,177) rgb(191,184,177) rgb(191,184,177);
+                }
+              }
+            }
+          }
+          transform {
+            transform: translate(78, 0);
+            child: text {
+              font: "Cantarell 11";
+              x: 123;
+              y: 18;
+              color: rgb(46,52,54);
+              glyphs: 37 11264 0 0 1, 324 4096 0 0 1, 417 7168 0 0 1, 244 8192 0 0 1, 272 8192 0 0 1, 349 
4096 0 0 1, 287 8192 0 0 1, 280 8192 0 0 1;
+            }
+          }
+          transform {
+            transform: translate(388, 0);
+            child: transform {
+              transform: translate(1, 6);
+              child: container {
+                container {
+                  outset-shadow {
+                    outline: -1 -1 16 16 / 3;
+                    color: rgba(0,0,0,0.1);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 0;
+                  }
+                  outset-shadow {
+                    outline: -1 -1 16 16 / 3;
+                    color: rgba(0,0,0,0.07);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 2;
+                  }
+                  linear-gradient {
+                    bounds: 0 0 14 14;
+                    start: 7 0;
+                    end: 7 14;
+                    stops: 0.2 rgb(255,255,255),0.9 rgb(246,245,244);
+                  }
+                  inset-shadow {
+                    outline: 0 0 14 14 / 2;
+                    color: rgb(255,255,255);
+                    dx: 0;
+                    dy: 1;
+                    spread: 0;
+                    blur: 0;
+                  }
+                }
+                border {
+                  outline: -1 -1 16 16 / 3;
+                  widths: 1 1 1 1;
+                  colors: rgb(191,184,177) rgb(191,184,177) rgb(191,184,177) rgb(191,184,177);
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
diff --git a/testsuite/gsk/serialize-deserialize.c b/testsuite/gsk/serialize-deserialize.c
new file mode 100644
index 0000000000..45d4472a70
--- /dev/null
+++ b/testsuite/gsk/serialize-deserialize.c
@@ -0,0 +1,43 @@
+#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_clear_pointer (&deserialized, 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]