[gedit] Added tests for document input stream
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] Added tests for document input stream
- Date: Sat, 23 Jan 2010 19:38:10 +0000 (UTC)
commit 230ab847cadc5e47f876f19460a726602c55fc56
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sat Jan 23 20:14:15 2010 +0100
Added tests for document input stream
tests/Makefile.am | 3 +
tests/document-input-stream.c | 135 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0b5248e..ed07cd4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,3 +8,6 @@ TEST_PROGS = smart-converter
smart_converter_SOURCES = smart-converter.c
smart_converter_LDADD = $(progs_ldadd)
+TEST_PROGS += document-input-stream
+document_input_stream_SOURCES = document-input-stream.c
+document_input_stream_LDADD = $(progs_ldadd)
diff --git a/tests/document-input-stream.c b/tests/document-input-stream.c
new file mode 100644
index 0000000..0aeb2b9
--- /dev/null
+++ b/tests/document-input-stream.c
@@ -0,0 +1,135 @@
+/*
+ * document-input-stream.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ *
+ * gedit is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gedit; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+
+#include "gedit-document-input-stream.h"
+#include <gio/gio.h>
+#include <gtk/gtk.h>
+#include <glib.h>
+#include <string.h>
+
+static void
+test_consecutive_read (const gchar *inbuf,
+ const gchar *outbuf,
+ GeditDocumentNewlineType type,
+ gsize mem)
+{
+ GtkTextBuffer *buf;
+ GInputStream *in;
+ gsize r, n;
+ GError *err = NULL;
+ gchar *b;
+
+ buf = gtk_text_buffer_new (NULL);
+
+ gtk_text_buffer_set_text (buf, inbuf, -1);
+
+ b = g_malloc (200);
+ in = gedit_document_input_stream_new (buf, type);
+
+ n = 0;
+
+ do
+ {
+ r = g_input_stream_read (in, b + n, mem, NULL, &err);
+ n += r;
+ g_assert_no_error (err);
+ } while (r != 0);
+
+ g_assert_cmpint (n, >, 0);
+
+ b[n] = '\0';
+
+ g_assert_cmpstr (b, ==, outbuf);
+}
+
+static void
+test_consecutive_cut_char ()
+{
+ /* first \n is read then fo and then is added \r but not \n */
+ test_consecutive_read ("\nfo\nbar\n\nblah\n", "\r\nfo\r\nbar\r\n\r\nblah\r\n\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 8);
+ test_consecutive_read ("\nfo\nbar\n\nblah", "\r\nfo\r\nbar\r\n\r\nblah\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 8);
+}
+
+static void
+test_consecutive_big_read ()
+{
+ test_consecutive_read ("\nfo\nbar\n\nblah\n", "\rfo\rbar\r\rblah\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 200);
+ test_consecutive_read ("\nfo\nbar\n\nblah", "\rfo\rbar\r\rblah\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 200);
+
+ test_consecutive_read ("\rfo\rbar\r\rblah\r", "\nfo\nbar\n\nblah\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 200);
+ test_consecutive_read ("\rfo\rbar\r\rblah", "\nfo\nbar\n\nblah\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 200);
+
+ test_consecutive_read ("\r\nfo\r\nbar\r\n\r\nblah\r\n", "\nfo\nbar\n\nblah\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 200);
+ test_consecutive_read ("\r\nfo\r\nbar\r\n\r\nblah", "\nfo\nbar\n\nblah\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 200);
+
+ test_consecutive_read ("\nfo\nbar\n\nblah\n", "\r\nfo\r\nbar\r\n\r\nblah\r\n\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 200);
+ test_consecutive_read ("\nfo\nbar\n\nblah", "\r\nfo\r\nbar\r\n\r\nblah\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 200);
+}
+
+static void
+test_consecutive_middle_read ()
+{
+ test_consecutive_read ("\nfo\nbar\n\nblah\n", "\rfo\rbar\r\rblah\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 6);
+ test_consecutive_read ("\nfo\nbar\n\nblah", "\rfo\rbar\r\rblah\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 6);
+
+ test_consecutive_read ("\rfo\rbar\r\rblah\r", "\nfo\nbar\n\nblah\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 6);
+ test_consecutive_read ("\rfo\rbar\r\rblah", "\nfo\nbar\n\nblah\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 6);
+
+ test_consecutive_read ("\r\nfo\r\nbar\r\n\r\nblah\r\n", "\nfo\nbar\n\nblah\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 6);
+ test_consecutive_read ("\r\nfo\r\nbar\r\n\r\nblah", "\nfo\nbar\n\nblah\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 6);
+
+ test_consecutive_read ("\nfo\nbar\n\nblah\n", "\r\nfo\r\nbar\r\n\r\nblah\r\n\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 6);
+ test_consecutive_read ("\nfo\nbar\n\nblah", "\r\nfo\r\nbar\r\n\r\nblah\r\n", GEDIT_DOCUMENT_NEWLINE_TYPE_CR_LF, 6);
+}
+
+static void
+test_consecutive_multibyte_cut ()
+{
+ test_consecutive_read ("hello\nhello\xe6\x96\x87\nworld\n", "hello\rhello\xe6\x96\x87\rworld\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 6);
+ test_consecutive_read ("hello\rhello\xe6\x96\x87\rworld\r", "hello\rhello\xe6\x96\x87\rworld\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 6);
+ test_consecutive_read ("hello\nhello\xe6\x96\x87\nworld\n", "hello\nhello\xe6\x96\x87\nworld\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 6);
+}
+
+static void
+test_consecutive_multibyte_big_read ()
+{
+ test_consecutive_read ("hello\nhello\xe6\x96\x87\nworld\n", "hello\rhello\xe6\x96\x87\rworld\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 200);
+ test_consecutive_read ("hello\rhello\xe6\x96\x87\rworld\r", "hello\rhello\xe6\x96\x87\rworld\r\r", GEDIT_DOCUMENT_NEWLINE_TYPE_CR, 200);
+ test_consecutive_read ("hello\nhello\xe6\x96\x87\nworld\n", "hello\nhello\xe6\x96\x87\nworld\n\n", GEDIT_DOCUMENT_NEWLINE_TYPE_LF, 200);
+}
+
+int main (int argc,
+ char *argv[])
+{
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/document-input-stream/consecutive_cut_char", test_consecutive_cut_char);
+ g_test_add_func ("/document-input-stream/consecutive_big_read", test_consecutive_big_read);
+ g_test_add_func ("/document-input-stream/consecutive_middle_read", test_consecutive_middle_read);
+
+ g_test_add_func ("/document-input-stream/consecutive_multibyte_cut", test_consecutive_multibyte_cut);
+ g_test_add_func ("/document-input-stream/consecutive_multibyte_big_read", test_consecutive_multibyte_big_read);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]