Merge branch 'surround-test' into 'master'

Remove an unimplemented function

Closes #4151

See merge request GNOME/gtk!3820
This commit is contained in:
Matthias Clasen 2021-08-03 01:00:13 +00:00
commit 8713843022
5 changed files with 164 additions and 2 deletions

View File

@ -102,7 +102,6 @@ void _gtk_entry_completion_connect (GtkEntryCompletion *completion,
GtkEntry *entry);
void _gtk_entry_completion_disconnect (GtkEntryCompletion *completion);
GtkIMContext * _gtk_entry_get_im_context (GtkEntry *entry);
GtkEventController * gtk_entry_get_key_controller (GtkEntry *entry);
GtkText *gtk_entry_get_text_widget (GtkEntry *entry);

View File

@ -8436,7 +8436,7 @@ gtk_text_view_retrieve_surrounding_handler (GtkIMContext *context,
start1 = start;
end1 = end;
gtk_text_iter_set_line_offset (&start, 0);
gtk_text_iter_set_line_offset (&start1, 0);
gtk_text_iter_forward_to_line_end (&end1);
pre = gtk_text_iter_get_slice (&start1, &start);
@ -10016,3 +10016,9 @@ gtk_text_view_get_rtl_context (GtkTextView *text_view)
return text_view->priv->layout->rtl_context;
}
GtkEventController *
gtk_text_view_get_key_controller (GtkTextView *text_view)
{
return text_view->priv->key_controller;
}

View File

@ -30,6 +30,8 @@ GtkCssNode * gtk_text_view_get_selection_node (GtkTextView *text_view)
GtkTextAttributes * gtk_text_view_get_default_attributes (GtkTextView *text_view);
GtkEventController *gtk_text_view_get_key_controller (GtkTextView *text_view);
G_END_DECLS

154
testsuite/gtk/imcontext.c Normal file
View File

@ -0,0 +1,154 @@
#include <gtk/gtk.h>
#include <locale.h>
#include "../gtk/gtktextprivate.h"
#include "../gtk/gtktextviewprivate.h"
static void
test_text_surrounding (void)
{
GtkWidget *widget;
GtkEventController *controller;
GtkIMContext *context;
gboolean ret;
char *text;
int cursor_pos, selection_bound;
widget = gtk_text_new ();
controller = gtk_text_get_key_controller (GTK_TEXT (widget));
context = gtk_event_controller_key_get_im_context (GTK_EVENT_CONTROLLER_KEY (controller));
gtk_editable_set_text (GTK_EDITABLE (widget), "abcd");
gtk_editable_set_position (GTK_EDITABLE (widget), 2);
ret = gtk_im_context_get_surrounding_with_selection (context,
&text,
&cursor_pos,
&selection_bound);
g_assert_true (ret);
g_assert_cmpstr (text, ==, "abcd");
g_assert_cmpint (cursor_pos, ==, 2);
g_assert_cmpint (selection_bound, ==, 2);
g_free (text);
ret = gtk_im_context_delete_surrounding (context, -1, 1);
g_assert_true (ret);
g_assert_cmpstr (gtk_editable_get_text (GTK_EDITABLE (widget)), ==, "acd");
g_assert_cmpint (gtk_editable_get_position (GTK_EDITABLE (widget)), ==, 1);
ret = gtk_im_context_delete_surrounding (context, 1, 1);
g_assert_true (ret);
g_assert_cmpstr (gtk_editable_get_text (GTK_EDITABLE (widget)), ==, "ac");
g_assert_cmpint (gtk_editable_get_position (GTK_EDITABLE (widget)), ==, 1);
gtk_editable_set_text (GTK_EDITABLE (widget), "abcd");
gtk_editable_select_region (GTK_EDITABLE (widget), 4, 2);
ret = gtk_im_context_get_surrounding_with_selection (context,
&text,
&cursor_pos,
&selection_bound);
g_assert_true (ret);
g_assert_cmpstr (text, ==, "abcd");
g_assert_cmpint (cursor_pos, ==, 2);
g_assert_cmpint (selection_bound, ==, 4);
g_free (text);
g_object_ref_sink (widget);
g_object_unref (widget);
}
static void
test_textview_surrounding (void)
{
GtkWidget *widget;
GtkEventController *controller;
GtkIMContext *context;
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextIter start, end;
gboolean ret;
char *text;
int cursor_pos, selection_bound;
widget = gtk_text_view_new ();
controller = gtk_text_view_get_key_controller (GTK_TEXT_VIEW (widget));
context = gtk_event_controller_key_get_im_context (GTK_EVENT_CONTROLLER_KEY (controller));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
gtk_text_buffer_set_text (buffer, "abcd\nefgh\nijkl", -1);
gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 1, 2);
gtk_text_buffer_place_cursor (buffer, &iter);
ret = gtk_im_context_get_surrounding_with_selection (context,
&text,
&cursor_pos,
&selection_bound);
g_assert_true (ret);
g_assert_cmpstr (text, ==, "efgh");
g_assert_cmpint (cursor_pos, ==, 2);
g_assert_cmpint (selection_bound, ==, 2);
g_free (text);
ret = gtk_im_context_delete_surrounding (context, -1, 1);
g_assert_true (ret);
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
g_assert_cmpstr (text, ==, "abcd\negh\nijkl");
g_free (text);
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
g_assert_cmpint (gtk_text_iter_get_line (&start), ==, 1);
g_assert_cmpint (gtk_text_iter_get_line_offset (&start), ==, 1);
ret = gtk_im_context_delete_surrounding (context, 1, 1);
g_assert_true (ret);
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
g_assert_cmpstr (text, ==, "abcd\neg\nijkl");
g_free (text);
gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
g_assert_cmpint (gtk_text_iter_get_line (&start), ==, 1);
g_assert_cmpint (gtk_text_iter_get_line_offset (&start), ==, 1);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
gtk_text_buffer_set_text (buffer, "abcd\nefgh\nijkl", -1);
gtk_text_buffer_get_iter_at_line_offset (buffer, &start, 1, 2);
gtk_text_buffer_get_iter_at_line_offset (buffer, &end, 2, 2);
gtk_text_buffer_select_range (buffer, &start, &end);
ret = gtk_im_context_get_surrounding_with_selection (context,
&text,
&cursor_pos,
&selection_bound);
g_assert_true (ret);
g_assert_cmpstr (text, ==, "efgh\nijkl");
g_assert_cmpint (cursor_pos, ==, 7);
g_assert_cmpint (selection_bound, ==, 2);
g_free (text);
g_object_ref_sink (widget);
g_object_unref (widget);
}
int
main (int argc, char *argv[])
{
gtk_test_init (&argc, &argv, NULL);
g_test_add_func ("/im-context/text-surrounding", test_text_surrounding);
g_test_add_func ("/im-context/textview-surrounding", test_textview_surrounding);
return g_test_run ();
}

View File

@ -113,6 +113,7 @@ internal_tests = [
'../testutils.c'
],
},
{ 'name': 'imcontext' },
{ 'name': 'constraint-solver' },
{ 'name': 'rbtree-crash' },
{ 'name': 'propertylookuplistmodel' },