summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-02-02 11:53:24 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-02-02 11:53:24 -0500
commitdf5edc18c00dc21c90f25691ca3f8a89793da845 (patch)
treefb392c69e9e7f95b34ec87ae496d5c70ea214809
parent2c3c65f8b6447442823dbbf37ba6a8355ba588aa (diff)
downloadgtk+-im-context-work.tar.gz
Add tests for string valuesim-context-work
Add a test that checks we parse values with multiple characters correctly.
-rw-r--r--testsuite/gtk/compose/strings4
-rw-r--r--testsuite/gtk/compose/strings.expected6
-rw-r--r--testsuite/gtk/composetable.c48
3 files changed, 54 insertions, 4 deletions
diff --git a/testsuite/gtk/compose/strings b/testsuite/gtk/compose/strings
new file mode 100644
index 0000000000..36d76785ac
--- /dev/null
+++ b/testsuite/gtk/compose/strings
@@ -0,0 +1,4 @@
+<Multi_key> <s> <e> <q> : "!a"
+<Multi_key> <s> <e> <q> <u> : "?"
+<Multi_key> <u> <b> <2> <3> : "\121\122"
+<Multi_key> <s> <a> <s> : "\"\\"
diff --git a/testsuite/gtk/compose/strings.expected b/testsuite/gtk/compose/strings.expected
new file mode 100644
index 0000000000..e1dfdc6dc1
--- /dev/null
+++ b/testsuite/gtk/compose/strings.expected
@@ -0,0 +1,6 @@
+# n_seqs: 4
+# max_seq_len: 5
+<Uff20> <U73> <U61> <U73> <U0> : "\"\\"
+<Uff20> <U73> <U65> <U71> <U0> : "!a"
+<Uff20> <U73> <U65> <U71> <U75> : "?" # U3f
+<Uff20> <U75> <U62> <U32> <U33> : "QR"
diff --git a/testsuite/gtk/composetable.c b/testsuite/gtk/composetable.c
index 0d0644932f..2d88ad570d 100644
--- a/testsuite/gtk/composetable.c
+++ b/testsuite/gtk/composetable.c
@@ -5,6 +5,34 @@
#include "../gtk/gtkimcontextsimpleseqs.h"
#include "testsuite/testutils.h"
+static void
+append_escaped (GString *str,
+ const char *s)
+{
+ for (const char *p = s; *p; p = g_utf8_next_char (p))
+ {
+ gunichar ch = g_utf8_get_char (p);
+ if (ch == '"')
+ g_string_append (str, "\\\"");
+ else if (ch == '\\')
+ g_string_append (str, "\\\\");
+ else if (g_unichar_isprint (ch))
+ g_string_append_unichar (str, ch);
+ else
+ {
+ guint n[8] = { 0, };
+ int i = 0;
+ while (ch != 0)
+ {
+ n[i++] = ch & 7;
+ ch = ch >> 3;
+ }
+ for (; i >= 0; i--)
+ g_string_append_printf (str, "\\%o", n[i]);
+ }
+ }
+}
+
static char *
gtk_compose_table_print (GtkComposeTable *table)
{
@@ -21,15 +49,26 @@ gtk_compose_table_print (GtkComposeTable *table)
for (i = 0, seq = table->data; i < table->n_seqs; i++, seq += table->max_seq_len + 2)
{
gunichar value;
- char buf[7] = { 0 };
+ char buf[8] = { 0 };
for (j = 0; j < table->max_seq_len; j++)
g_string_append_printf (str, "<U%x> ", seq[j]);
- value = 0x10000 * seq[table->max_seq_len] + seq[table->max_seq_len + 1];
- g_unichar_to_utf8 (value, buf);
+ value = (seq[table->max_seq_len] << 16) | seq[table->max_seq_len + 1];
+ if ((value & (1 << 31)) != 0)
+ {
+ const char *out = &table->char_data[value & ~(1 << 31)];
+
+ g_string_append (str, ": \"");
+ append_escaped (str, out);
+ g_string_append (str, "\"\n");
+ }
+ else
+ {
+ g_unichar_to_utf8 (value, buf);
+ g_string_append_printf (str, ": \"%s\" # U%x\n", buf, value);
+ }
- g_string_append_printf (str, ": \"%s\" # U%x\n", buf, value);
}
return g_string_free (str, FALSE);
@@ -271,6 +310,7 @@ main (int argc, char *argv[])
g_test_add_data_func ("/compose-table/octal", "octal", compose_table_compare);
g_test_add_data_func ("/compose-table/codepoint", "codepoint", compose_table_compare);
g_test_add_data_func ("/compose-table/multi", "multi", compose_table_compare);
+ g_test_add_data_func ("/compose-table/strings", "strings", compose_table_compare);
g_test_add_func ("/compose-table/match", compose_table_match);
g_test_add_func ("/compose-table/match-compact", compose_table_match_compact);
g_test_add_func ("/compose-table/match-algorithmic", match_algorithmic);