[libshumate] tests: Add tests for view add/remove/insert



commit ba97e474216db4c95e5e8fe7ddbac5f9514a853e
Author: James Westman <james jwestman net>
Date:   Mon Mar 8 13:23:51 2021 -0600

    tests: Add tests for view add/remove/insert

 tests/meson.build |  1 +
 tests/view.c      | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 79a5ab4..e3fd945 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,6 +9,7 @@ test_env = [
 tests = [
   'coordinate',
   'marker',
+  'view',
   'viewport',
 ]
 
diff --git a/tests/view.c b/tests/view.c
new file mode 100644
index 0000000..044d45a
--- /dev/null
+++ b/tests/view.c
@@ -0,0 +1,61 @@
+#include <gtk/gtk.h>
+#include <shumate/shumate.h>
+
+static void
+test_view_add_layers (void)
+{
+  ShumateView *view = shumate_view_new ();
+  ShumateViewport *viewport = shumate_view_get_viewport (view);
+  ShumateLayer *layer1 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  ShumateLayer *layer2 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  ShumateLayer *layer3;
+
+  // Add layer1
+  shumate_view_add_layer (view, layer1);
+  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (view)) == GTK_WIDGET (layer1));
+
+  // Add layer2, should end up on top
+  shumate_view_add_layer (view, layer2);
+  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (view)) == GTK_WIDGET (layer2));
+
+  // Add layer3 above layer2
+  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  shumate_view_insert_layer_above (view, layer3, layer2);
+  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (view)) == GTK_WIDGET (layer3));
+
+  // Remove layer3
+  shumate_view_remove_layer (view, layer3);
+  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (view)) == GTK_WIDGET (layer2));
+
+  // Add layer3 behind layer1
+  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  shumate_view_insert_layer_behind (view, layer3, layer1);
+  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (view)) == GTK_WIDGET (layer3));
+
+  // Remove layer3
+  shumate_view_remove_layer (view, layer3);
+  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (view)) == GTK_WIDGET (layer1));
+
+  // Add layer3 behind NULL
+  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  shumate_view_insert_layer_behind (view, layer3, NULL);
+  g_assert_true (gtk_widget_get_last_child (GTK_WIDGET (view)) == GTK_WIDGET (layer3));
+  shumate_view_remove_layer (view, layer3);
+
+  // Add layer3 above NULL
+  layer3 = SHUMATE_LAYER (shumate_path_layer_new (viewport));
+  shumate_view_insert_layer_above (view, layer3, NULL);
+  g_assert_true (gtk_widget_get_first_child (GTK_WIDGET (view)) == GTK_WIDGET (layer3));
+  shumate_view_remove_layer (view, layer3);
+}
+
+int
+main (int argc, char *argv[])
+{
+  g_test_init (&argc, &argv, NULL);
+  gtk_init ();
+
+  g_test_add_func ("/view/add-layers", test_view_add_layers);
+
+  return g_test_run ();
+}


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