X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fi18n-test.c;h=b433756b0d21b2a1d9e455f1833de3b43eba006b;hb=9d1d71e732eeed85ca3002b264e1269cdd005a3f;hp=03b96f2e431ba9a4ad993cc7dc93856afdd743af;hpb=f5099c58d17e8f66a74a84918e688ef17936d392;p=pspp-builds.git diff --git a/tests/libpspp/i18n-test.c b/tests/libpspp/i18n-test.c index 03b96f2e..b433756b 100644 --- a/tests/libpspp/i18n-test.c +++ b/tests/libpspp/i18n-test.c @@ -28,24 +28,61 @@ int main (int argc, char *argv[]) { - char *s; + i18n_init (); + + if (argc == 5 && !strcmp (argv[1], "recode")) + { + const char *from = argv[2]; + const char *to = argv[3]; + const char *string = argv[4]; + char *result = recode_string (to, from, string, -1); + puts (result); + assert (strlen (result) == recode_string_len (to, from, string, -1)); + free (result); + } + else if (argc == 6 && !strcmp (argv[1], "concat")) + { + const char *head = argv[2]; + const char *tail = argv[3]; + const char *encoding = argv[4]; + int max_len = atoi (argv[5]); + char *result; - if (argc != 4) + result = utf8_encoding_concat (head, tail, encoding, max_len); + puts (result); + + assert (strlen (result) + == utf8_encoding_concat_len (head, tail, encoding, max_len)); + + if (tail[0] == '\0') + { + char *result2 = utf8_encoding_trunc (head, encoding, max_len); + assert (!strcmp (result, result2)); + assert (strlen (result2) + == utf8_encoding_trunc_len (head, encoding, max_len)); + free (result2); + } + + free (result); + } + else { - fprintf (stderr, - "usage: %s FROM TO STRING\n" - "where FROM is the source encoding,\n" - " TO is the target encoding,\n" - " and STRING is the text to recode.\n", - argv[0]); + fprintf (stderr, "\ +usage: %s recode FROM TO STRING\n\ +where FROM is the source encoding,\n\ + TO is the target encoding,\n\ + and STRING is the text to recode.\n\ +\n\ +usage: %s concat HEAD TAIL ENCODING MAX_LEN\n\ +where HEAD is the first string to concatenate\n\ + TAIL is the second string to concatenate\n\ + ENCODING is the encoding in which to measure the result's length\n\ + MAX_LEN is the maximum length of the result in ENCODING.\n", + argv[0], argv[0]); return EXIT_FAILURE; } - i18n_init (); - s = recode_string (argv[2], argv[1], argv[3], -1); - puts (s); - assert (strlen (s) == recode_string_len (argv[2], argv[1], argv[3], -1)); - free (s); + i18n_done (); return 0; }