[gtk/im-context-work: 4/5] Add tests for string values




commit 814a4a781a62afbc90c31a122ca3795a1ac529bf
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 2 11:53:24 2021 -0500

    Add tests for string values
    
    Add a test that checks we parse values with
    multiple characters correctly.

 testsuite/gtk/compose/strings          |  4 +++
 testsuite/gtk/compose/strings.expected |  6 +++++
 testsuite/gtk/composetable.c           | 48 +++++++++++++++++++++++++++++++---
 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]