From e0ffbb61fcac2405498220ea0326052b6178a673 Mon Sep 17 00:00:00 2001
From: Krzesimir Nowak <qdlacz@gmail.com>
Date: Fri, 12 Nov 2010 20:42:39 +0100
Subject: [PATCH 2/2] Added unit test case for getting buffer.

---
 tests/Makefile.am      |    7 +++++++
 tests/test-getbuffer.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
 create mode 100644 tests/test-getbuffer.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4e4e1c2..8713e4e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,6 +41,13 @@ test_printcompositor_LDADD = 		\
 	$(DEP_LIBS)			\
 	$(TESTS_LIBS)
 
+UNIT_TEST_PROGS += test-getbuffer
+test_getbuffer_SOURCES = test-getbuffer.c
+test_getbuffer_LDADD = 		\
+	$(top_builddir)/gtksourceview/libgtksourceview-3.0.la \
+	$(DEP_LIBS)			\
+	$(TESTS_LIBS)
+
 python_tests =			\
 	test-completion.py	\
 	test-widget.py
diff --git a/tests/test-getbuffer.c b/tests/test-getbuffer.c
new file mode 100644
index 0000000..bb1cfa5
--- /dev/null
+++ b/tests/test-getbuffer.c
@@ -0,0 +1,47 @@
+#include "config.h"
+#include <string.h>
+#include <stdlib.h>
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourcebuffer.h>
+#include <gtksourceview/gtksourceview.h>
+
+static void
+test_get_buffer (void)
+{
+	GtkWidget* view;
+	GtkSourceBuffer* buffer;
+
+	view = gtk_source_view_new ();
+
+	buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+
+	g_assert (buffer != NULL);
+	g_assert (GTK_IS_SOURCE_BUFFER (buffer));
+
+	if (g_object_is_floating (view))
+	{
+		g_object_ref_sink (view);
+	}
+
+	/* Here we check if notify_buffer doesn't recreate the buffer while view
+	 * is being destroyed, which causes assertion failure in GtkTextView's
+	 * finalize () function.
+	 * Please see: https://bugzilla.gnome.org/show_bug.cgi?id=634510 */
+	if (g_test_trap_fork (0, 0))
+	{
+		g_object_unref (view);
+		exit (EXIT_SUCCESS);
+	}
+	g_test_trap_assert_passed ();
+}
+
+int
+main (int argc, char** argv)
+{
+	gtk_test_init (&argc, &argv);
+
+	g_test_add_func ("/Buffer/get-buffer", test_get_buffer);
+
+	return g_test_run();
+}
-- 
1.7.2.3

