summaryrefslogtreecommitdiff
path: root/tests/testtextbuffer.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2001-10-22 23:35:03 +0000
committerHavoc Pennington <hp@src.gnome.org>2001-10-22 23:35:03 +0000
commit0d5635b36613c0e5eca772e223001d1858433c28 (patch)
tree7e1ecb35c78379de14107396ff045dab6ceeddf2 /tests/testtextbuffer.c
parent60ef9dd421b3050581f6e540541d1cc5a5e0bef3 (diff)
downloadgtk+-0d5635b36613c0e5eca772e223001d1858433c28.tar.gz
don't back up a char from the end iterator, fixes #61859 ("can't put
2001-10-22 Havoc Pennington <hp@redhat.com> * gtk/gtktextbuffer.c (gtk_text_buffer_place_cursor): don't back up a char from the end iterator, fixes #61859 ("can't put cursor at the end of the buffer") * gtk/gtktextiter.c (gtk_text_iter_forward_to_line_end): fix this to work with delimiters other than newline. * tests/testtextbuffer.c: add some tests for get_chars_in_line, get_bytes_in_line * gtk/gtktextiter.c (gtk_text_iter_get_chars_in_line): fix for the last line, since the newline is no longer counted. (gtk_text_iter_get_bytes_in_line): ditto
Diffstat (limited to 'tests/testtextbuffer.c')
-rw-r--r--tests/testtextbuffer.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/testtextbuffer.c b/tests/testtextbuffer.c
index 0e29a0768f..f0dcd36f2d 100644
--- a/tests/testtextbuffer.c
+++ b/tests/testtextbuffer.c
@@ -67,6 +67,15 @@ main (int argc, char** argv)
if (n != 0)
g_error ("%d chars, expected 0", n);
+ /* empty first line contains 0 chars */
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ n = gtk_text_iter_get_chars_in_line (&start);
+ if (n != 0)
+ g_error ("%d chars in first line, expected 0", n);
+ n = gtk_text_iter_get_bytes_in_line (&start);
+ if (n != 0)
+ g_error ("%d bytes in first line, expected 0", n);
+
/* Run gruesome alien test suite on buffer */
run_tests (buffer);
@@ -77,6 +86,8 @@ main (int argc, char** argv)
check_get_set_text (buffer, "Hello\r");
check_get_set_text (buffer, "Hello\nBar\nFoo");
check_get_set_text (buffer, "Hello\nBar\nFoo\n");
+
+ g_print ("get/set tests passed.\n");
/* Put stuff in the buffer */
@@ -112,7 +123,7 @@ static void
check_get_set_text (GtkTextBuffer *buffer,
const char *str)
{
- GtkTextIter start, end;
+ GtkTextIter start, end, iter;
char *text;
int n;
@@ -127,6 +138,32 @@ check_get_set_text (GtkTextBuffer *buffer,
g_error ("Got '%s' as buffer contents", text);
g_free (text);
+ /* line char counts */
+ iter = start;
+ n = 0;
+ do
+ {
+ n += gtk_text_iter_get_chars_in_line (&iter);
+ }
+ while (gtk_text_iter_forward_line (&iter));
+
+ if (n != gtk_text_buffer_get_char_count (buffer))
+ g_error ("Sum of chars in lines is %d but buffer char count is %d",
+ n, gtk_text_buffer_get_char_count (buffer));
+
+ /* line byte counts */
+ iter = start;
+ n = 0;
+ do
+ {
+ n += gtk_text_iter_get_bytes_in_line (&iter);
+ }
+ while (gtk_text_iter_forward_line (&iter));
+
+ if (n != strlen (str))
+ g_error ("Sum of chars in lines is %d but buffer byte count is %d",
+ n, strlen (str));
+
gtk_text_buffer_set_text (buffer, "", -1);
n = gtk_text_buffer_get_line_count (buffer);