1 #undef G_DISABLE_ASSERT
9 gboolean success
= TRUE
;
12 decode (const gchar
*input
)
16 GString
*result
= g_string_new (NULL
);
20 if (sscanf (input
+ offset
, "%x", &ch
) != 1)
22 fprintf (stderr
, "Error parsing character string %s\n", input
);
26 g_string_append_unichar (result
, ch
);
28 while (input
[offset
] && input
[offset
] != ' ')
30 while (input
[offset
] && input
[offset
] == ' ')
33 while (input
[offset
]);
35 return g_string_free (result
, FALSE
);
38 const char *names
[4] = {
55 gboolean mode_is_compat
= (mode
== G_NORMALIZE_NFKC
||
56 mode
== G_NORMALIZE_NFKD
);
58 if (mode_is_compat
|| !do_compat
)
60 for (i
= 0; i
< 3; i
++)
62 char *result
= g_utf8_normalize (c
[i
], -1, mode
);
63 if (strcmp (result
, c
[expected
]) != 0)
65 fprintf (stderr
, "\nFailure: %d/%d: %s\n", line
, i
+ 1, raw
[5]);
66 fprintf (stderr
, " g_utf8_normalize (%s, %s) != %s\n",
67 raw
[i
], names
[mode
], raw
[expected
]);
74 if (mode_is_compat
|| do_compat
)
76 for (i
= 3; i
< 5; i
++)
78 char *result
= g_utf8_normalize (c
[i
], -1, mode
);
79 if (strcmp (result
, c
[expected
]) != 0)
81 fprintf (stderr
, "\nFailure: %d/%d: %s\n", line
, i
, raw
[5]);
82 fprintf (stderr
, " g_utf8_normalize (%s, %s) != %s\n",
83 raw
[i
], names
[mode
], raw
[expected
]);
93 process_one (int line
, gchar
**columns
)
97 gboolean skip
= FALSE
;
101 c
[i
] = decode(columns
[i
]);
108 test_form (line
, G_NORMALIZE_NFD
, FALSE
, 2, c
, columns
);
109 test_form (line
, G_NORMALIZE_NFD
, TRUE
, 4, c
, columns
);
110 test_form (line
, G_NORMALIZE_NFC
, FALSE
, 1, c
, columns
);
111 test_form (line
, G_NORMALIZE_NFC
, TRUE
, 3, c
, columns
);
112 test_form (line
, G_NORMALIZE_NFKD
, TRUE
, 4, c
, columns
);
113 test_form (line
, G_NORMALIZE_NFKC
, TRUE
, 3, c
, columns
);
116 for (i
=0; i
< 5; i
++)
122 int main (int argc
, char **argv
)
125 GError
*error
= NULL
;
126 GString
*buffer
= g_string_new (NULL
);
130 if (argc
!= 2 && argc
!= 3)
132 fprintf (stderr
, "Usage: unicode-normalize NormalizationTest.txt LINE\n");
137 line_to_do
= atoi(argv
[2]);
139 in
= g_io_channel_new_file (argv
[1], "r", &error
);
142 fprintf (stderr
, "Cannot open %s: %s\n", argv
[1], error
->message
);
151 if (g_io_channel_read_line_string (in
, buffer
, &term_pos
, &error
) != G_IO_STATUS_NORMAL
)
154 if (line_to_do
&& line
!= line_to_do
)
157 buffer
->str
[term_pos
] = '\0';
159 if (buffer
->str
[0] == '#') /* Comment */
161 if (buffer
->str
[0] == '@') /* Part */
163 fprintf (stderr
, "\nProcessing %s\n", buffer
->str
+ 1);
167 columns
= g_strsplit (buffer
->str
, ";", -1);
171 if (!process_one (line
, columns
))
173 g_strfreev (columns
);
176 g_string_truncate (buffer
, 0);
182 fprintf (stderr
, "Error reading test file, %s\n", error
->message
);
186 g_io_channel_unref (in
);
187 g_string_free (buffer
, TRUE
);