X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Flibpspp%2Fi18n-test.c;h=b0d027090e967a51977e6fe98c8669fe1a621e8b;hb=62b5101a28fc2c4a9b8b26a998fb6c4ec12d84c7;hp=f2bead96f78e6bd1412e2bc925c4bbbf43407b9d;hpb=c555358da9c0b1747b9b236ba28ec55efdc89852;p=pspp diff --git a/tests/libpspp/i18n-test.c b/tests/libpspp/i18n-test.c index f2bead96f7..b0d027090e 100644 --- a/tests/libpspp/i18n-test.c +++ b/tests/libpspp/i18n-test.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,29 +18,89 @@ #include #include +#include #include "libpspp/i18n.h" +#undef NDEBUG +#include + int main (int argc, char *argv[]) { - char *s; + i18n_init (); + + if (argc > 1 && !strcmp (argv[1], "supports_encodings")) + { + int status = 0; + int i; + + for (i = 2; i < argc; i++) + if (!is_encoding_supported (argv[i])) + { + printf ("encoding \"%s\" is NOT supported\n", argv[i]); + status = 77; + } + i18n_done (); + exit (status); + } + 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; + + result = utf8_encoding_concat (head, tail, encoding, max_len); + puts (result); + + assert (strlen (result) + == utf8_encoding_concat_len (head, tail, encoding, max_len)); - if (argc != 4) + 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 supports_encodings ENCODING...\n\ +where ENCODING is the name of an encoding.\n\ +Exits with status 0 if all the encodings are supported, 77 otherwise.\n\ +\n\ +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], argv[0]); return EXIT_FAILURE; } - i18n_init (); - s = recode_string (argv[2], argv[1], argv[3], -1); - puts (s); - free (s); + i18n_done (); return 0; }