tests_libpspp_hmapx_test_CPPFLAGS = $(AM_CPPFLAGS) -DASSERT_LEVEL=10
tests_libpspp_i18n_test_SOURCES = tests/libpspp/i18n-test.c
-tests_libpspp_i18n_test_LDADD = src/libpspp-core.la
+tests_libpspp_i18n_test_LDADD = src/libpspp-core.la gl/libgl.la
tests_libpspp_abt_test_SOURCES = \
src/libpspp/abt.c \
#include "libpspp/i18n.h"
+#include "gl/xalloc.h"
+
#undef NDEBUG
#include <assert.h>
+/* Returns a malloc()'d copy of INPUT with \ooo octal escapes replaced by their
+ values. */
+static char *
+backslash_decode (const char *input)
+{
+ char *output = xmalloc (strlen (input) + 1);
+ char *p = output;
+ for (; *input; input++)
+ {
+ if (*input == '\\' && input[1] >= '0' && input[1] <= '7')
+ {
+ uint8_t c = 0;
+ while (input[1] >= '0' && input[1] <= '7')
+ c = c * 8 + (*++input - '0');
+ *p++ = c;
+ }
+ else
+ *p++ = *input;
+ }
+ *p = '\0';
+
+ return output;
+}
+
int
main (int argc, char *argv[])
{
{
const char *from = argv[2];
const char *to = argv[3];
- const char *string = argv[4];
+ char *string = backslash_decode (argv[4]);
char *result = recode_string (to, from, string, -1);
puts (result);
assert (strlen (result) == recode_string_len (to, from, string, -1));
+ free (string);
free (result);
}
else if (argc == 6 && !strcmp (argv[1], "concat"))
{
- const char *head = argv[2];
- const char *tail = argv[3];
+ char *head = backslash_decode (argv[2]);
+ char *tail = backslash_decode (argv[3]);
const char *encoding = argv[4];
int max_len = atoi (argv[5]);
char *result;
}
free (result);
+ free (head);
+ free (tail);
}
else
{
# [FROM-TEXT], [TO-TEXT])
#
# Converts FROM-TEXT from FROM-CODING to TO-CODING and checks that the result
-# is TO-TEXT. The "printf" program is applied to both FROM-TEXT and TO-TEXT to
-# allow for backslash-escapes. (Hex escapes are not portable; use octal
-# escapes instead.)
+# is TO-TEXT. Octal backslash-escapes are supported in FROM-TEXT and TO-TEXT.
m4_define([CHECK_I18N_RECODE],
[AT_SETUP([convert $1])
AT_KEYWORDS([i18n])
dnl Skip the test if this host doesn't know the source and target encodings.
AT_CHECK([i18n-test supports_encodings '$2' '$3'])
- AT_CHECK_UNQUOTED([i18n-test recode '$2' '$3' `printf '$4'`], [0], [`printf '$5'`
+ AT_CHECK_UNQUOTED([i18n-test recode '$2' '$3' '$4'], [0], [`printf '$5'`
])
AT_CLEANUP])
dnl Skip the test if this host doesn't know the encoding.
AT_CHECK([i18n-test supports_encodings '$3'])
AT_CHECK_UNQUOTED(
- [i18n-test concat "`printf '$1'`" "`printf '$2'`" '$3' '$4'], [0],
- [`printf '$5'`
+ [i18n-test concat '$1' '$2' '$3' '$4'], [0], [`printf '$5'`
])
AT_CLEANUP])