[gtksourceview/wip/undo-manager-fix] UndoManager: unit tests for empty user actions



commit 97d61298b70b7918a3397ee332b3d333d5e88f1c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Oct 7 14:19:01 2014 +0200

    UndoManager: unit tests for empty user actions
    
    The unit test fails.

 tests/test-undo-manager.c |   51 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-undo-manager.c b/tests/test-undo-manager.c
index d79d514..46a7db2 100644
--- a/tests/test-undo-manager.c
+++ b/tests/test-undo-manager.c
@@ -616,6 +616,54 @@ test_modified (void)
        g_object_unref (source_buffer);
 }
 
+static void
+empty_user_actions (GtkTextBuffer *text_buffer,
+                   gint           count)
+{
+       gint i;
+
+       for (i = 0; i < count; i++)
+       {
+               gtk_text_buffer_begin_user_action (text_buffer);
+               gtk_text_buffer_end_user_action (text_buffer);
+       }
+}
+
+static void
+test_empty_user_actions (void)
+{
+       GtkSourceBuffer *source_buffer;
+       GtkTextBuffer *text_buffer;
+       GList *contents_history = NULL;
+
+       source_buffer = gtk_source_buffer_new (NULL);
+       text_buffer = GTK_TEXT_BUFFER (source_buffer);
+       gtk_source_buffer_set_max_undo_levels (source_buffer, -1);
+
+       contents_history = g_list_append (contents_history, get_contents (source_buffer));
+
+       empty_user_actions (text_buffer, 3);
+       check_contents_history (source_buffer, contents_history);
+
+       insert_text (source_buffer, "foo\n");
+       contents_history = g_list_append (contents_history, get_contents (source_buffer));
+       check_contents_history (source_buffer, contents_history);
+
+       empty_user_actions (text_buffer, 1);
+       check_contents_history (source_buffer, contents_history);
+
+       insert_text (source_buffer, "bar\n");
+       contents_history = g_list_append (contents_history, get_contents (source_buffer));
+       check_contents_history (source_buffer, contents_history);
+
+       gtk_source_buffer_undo (source_buffer);
+       empty_user_actions (text_buffer, 1);
+       check_contents_history (source_buffer, contents_history);
+
+       g_object_unref (source_buffer);
+       g_list_free_full (contents_history, g_free);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -648,5 +696,8 @@ main (int argc, char **argv)
        g_test_add_func ("/UndoManager/test-modified",
                         test_modified);
 
+       g_test_add_func ("/UndoManager/test-empty-user-actions",
+                        test_empty_user_actions);
+
        return g_test_run ();
 }


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