forked from AuroraMiddleware/gtk
Add tests for GtkComposeTable
Add some tests for the code that parses Compose files. This tests the fix in the previous commit.
This commit is contained in:
parent
be35c46ce9
commit
569294070b
1
testsuite/gtk/compose/basic
Normal file
1
testsuite/gtk/compose/basic
Normal file
@ -0,0 +1 @@
|
||||
<Multi_key> <s> <e> <q> : "!"
|
3
testsuite/gtk/compose/basic.expected
Normal file
3
testsuite/gtk/compose/basic.expected
Normal file
@ -0,0 +1,3 @@
|
||||
# n_seqs: 1
|
||||
# max_seq_len: 4
|
||||
<Uff20> <U73> <U65> <U71> : "!" # U21
|
1
testsuite/gtk/compose/codepoint
Normal file
1
testsuite/gtk/compose/codepoint
Normal file
@ -0,0 +1 @@
|
||||
<Multi_key> <U73> <U6F> <U7a> : "!"
|
3
testsuite/gtk/compose/codepoint.expected
Normal file
3
testsuite/gtk/compose/codepoint.expected
Normal file
@ -0,0 +1,3 @@
|
||||
# n_seqs: 1
|
||||
# max_seq_len: 4
|
||||
<Uff20> <U73> <U6f> <U7a> : "!" # U21
|
1
testsuite/gtk/compose/long
Normal file
1
testsuite/gtk/compose/long
Normal file
@ -0,0 +1 @@
|
||||
<Multi_key> <e> <m> <m> <e> <n> <t> <a> <l> <e> <r> : "🧀"
|
3
testsuite/gtk/compose/long.expected
Normal file
3
testsuite/gtk/compose/long.expected
Normal file
@ -0,0 +1,3 @@
|
||||
# n_seqs: 1
|
||||
# max_seq_len: 11
|
||||
<Uff20> <U65> <U6d> <U6d> <U65> <U6e> <U74> <U61> <U6c> <U65> <U72> : "🧀" # U1f9c0
|
3
testsuite/gtk/compose/multi
Normal file
3
testsuite/gtk/compose/multi
Normal file
@ -0,0 +1,3 @@
|
||||
<Multi_key> <s> <e> <q> : "!"
|
||||
<Multi_key> <u> <b> <2> <3> : "/"
|
||||
<Multi_key> <s> <a> <s> : "_"
|
5
testsuite/gtk/compose/multi.expected
Normal file
5
testsuite/gtk/compose/multi.expected
Normal file
@ -0,0 +1,5 @@
|
||||
# n_seqs: 3
|
||||
# max_seq_len: 5
|
||||
<Uff20> <U73> <U61> <U73> <U0> : "_" # U5f
|
||||
<Uff20> <U73> <U65> <U71> <U0> : "!" # U21
|
||||
<Uff20> <U75> <U62> <U32> <U33> : "/" # U2f
|
1
testsuite/gtk/compose/octal
Normal file
1
testsuite/gtk/compose/octal
Normal file
@ -0,0 +1 @@
|
||||
<Multi_key> <s> <e> <q> : "\041"
|
3
testsuite/gtk/compose/octal.expected
Normal file
3
testsuite/gtk/compose/octal.expected
Normal file
@ -0,0 +1,3 @@
|
||||
# n_seqs: 1
|
||||
# max_seq_len: 4
|
||||
<Uff20> <U73> <U65> <U71> : "!" # U21
|
113
testsuite/gtk/composetable.c
Normal file
113
testsuite/gtk/composetable.c
Normal file
@ -0,0 +1,113 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include "../gtk/gtkcomposetable.h"
|
||||
#include "testsuite/testutils.h"
|
||||
|
||||
static char *
|
||||
gtk_compose_table_print (GtkComposeTable *table)
|
||||
{
|
||||
int i, j;
|
||||
guint16 *seq;
|
||||
GString *str;
|
||||
|
||||
str = g_string_new ("");
|
||||
|
||||
g_string_append_printf (str, "# n_seqs: %d\n# max_seq_len: %d\n",
|
||||
table->n_seqs,
|
||||
table->max_seq_len);
|
||||
|
||||
for (i = 0, seq = table->data; i < table->n_seqs; i++, seq += table->max_seq_len + 2)
|
||||
{
|
||||
gunichar value;
|
||||
char buf[7] = { 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);
|
||||
|
||||
g_string_append_printf (str, ": \"%s\" # U%x\n", buf, value);
|
||||
}
|
||||
|
||||
return g_string_free (str, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
generate_output (const char *file)
|
||||
{
|
||||
GSList *tables = NULL;
|
||||
GtkComposeTable *table;
|
||||
char *output;
|
||||
|
||||
tables = gtk_compose_table_list_add_file (tables, file);
|
||||
table = tables->data;
|
||||
output = gtk_compose_table_print (table);
|
||||
|
||||
g_print ("%s", output);
|
||||
}
|
||||
|
||||
static void
|
||||
compose_table_compare (gconstpointer data)
|
||||
{
|
||||
const char *basename = data;
|
||||
GSList *tables = NULL;
|
||||
GtkComposeTable *table;
|
||||
char *file;
|
||||
char *expected;
|
||||
char *output;
|
||||
char *diff;
|
||||
GError *error = NULL;
|
||||
|
||||
file = g_build_filename (g_test_get_dir (G_TEST_DIST), "compose", basename, NULL);
|
||||
expected = g_strconcat (file, ".expected", NULL);
|
||||
|
||||
tables = gtk_compose_table_list_add_file (tables, file);
|
||||
|
||||
g_assert_true (g_slist_length (tables) == 1);
|
||||
|
||||
table = tables->data;
|
||||
|
||||
output = gtk_compose_table_print (table);
|
||||
diff = diff_with_file (expected, output, -1, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (diff && diff[0])
|
||||
{
|
||||
g_print ("Resulting output doesn't match reference:\n%s", diff);
|
||||
g_test_fail ();
|
||||
}
|
||||
|
||||
g_free (output);
|
||||
g_free (file);
|
||||
g_free (expected);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
char *dir;
|
||||
|
||||
dir = g_dir_make_tmp ("composetableXXXXXX", NULL);
|
||||
g_setenv ("XDG_CACHE_HOME", dir, TRUE);
|
||||
g_free (dir);
|
||||
|
||||
if (argc == 3 && strcmp (argv[1], "--generate") == 0)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
generate_output (argv[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_data_func ("/compose-table/basic", "basic", compose_table_compare);
|
||||
g_test_add_data_func ("/compose-table/long", "long", compose_table_compare);
|
||||
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);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
@ -103,6 +103,13 @@ tests = [
|
||||
# Tests that test private apis and therefore are linked against libgtk-4.a
|
||||
internal_tests = [
|
||||
{ 'name': 'bitmask' },
|
||||
{
|
||||
'name': 'composetable',
|
||||
'sources': [
|
||||
'composetable.c',
|
||||
'../testutils.c'
|
||||
],
|
||||
},
|
||||
{ 'name': 'constraint-solver' },
|
||||
{ 'name': 'rbtree-crash' },
|
||||
{ 'name': 'propertylookuplistmodel' },
|
||||
|
Loading…
Reference in New Issue
Block a user