[gtksourceview/wip/chergert/vim] add some tests to ensure parent ownership works



commit 0558a6aa3b107d167b7c739af33f357d75a57c5e
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 5 16:43:57 2021 -0700

    add some tests to ensure parent ownership works

 testsuite/meson.build      |  1 +
 testsuite/test-vim-state.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
---
diff --git a/testsuite/meson.build b/testsuite/meson.build
index 28713e83..bfc8358e 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -37,6 +37,7 @@ testsuite_sources = [
   ['test-syntax'],
   ['test-utils'],
   ['test-view'],
+  ['test-vim-state'],
   ['test-vim-text-object'],
 ]
 
diff --git a/testsuite/test-vim-state.c b/testsuite/test-vim-state.c
new file mode 100644
index 00000000..f02774d6
--- /dev/null
+++ b/testsuite/test-vim-state.c
@@ -0,0 +1,73 @@
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2021 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "config.h"
+
+#include <gtksourceview/gtksource.h>
+#include <gtksourceview/vim/gtk-source-vim.h>
+#include <gtksourceview/vim/gtk-source-vim-command.h>
+#include <gtksourceview/vim/gtk-source-vim-insert.h>
+#include <gtksourceview/vim/gtk-source-vim-normal.h>
+#include <gtksourceview/vim/gtk-source-vim-state.h>
+
+static void
+test_parents (void)
+{
+       GtkWidget *view = gtk_source_view_new ();
+       GtkSourceVim *vim = gtk_source_vim_new (GTK_SOURCE_VIEW (view));
+       GtkSourceVimState *normal = gtk_source_vim_state_get_current (GTK_SOURCE_VIM_STATE (vim));
+       GtkSourceVimState *insert = gtk_source_vim_insert_new ();
+       GtkSourceVimState *command = gtk_source_vim_command_new (":join");
+
+       gtk_source_vim_state_push (normal, g_object_ref (insert));
+       g_assert_true (normal == gtk_source_vim_state_get_parent (insert));
+
+       gtk_source_vim_state_pop (insert);
+       g_assert_true (normal == gtk_source_vim_state_get_parent (insert));
+
+       gtk_source_vim_state_push (normal, g_object_ref (command));
+       gtk_source_vim_state_pop (command);
+
+       /* Now insert should be released */
+       g_assert_finalize_object (insert);
+
+       g_assert_true (GTK_SOURCE_IS_VIM_NORMAL (normal));
+       g_object_ref (normal);
+
+       g_assert_finalize_object (vim);
+       g_assert_finalize_object (normal);
+       g_assert_finalize_object (command);
+}
+
+int
+main (int argc,
+      char *argv[])
+{
+       int ret;
+
+       gtk_init ();
+       gtk_source_init ();
+       g_test_init (&argc, &argv, NULL);
+       g_test_add_func ("/GtkSourceView/vim-state/set-parent", test_parents);
+       ret = g_test_run ();
+       gtk_source_finalize ();
+       return ret;
+}


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