i18n: Add simple tests.
[pspp] / tests / libpspp / i18n.at
1 AT_BANNER([i18n routines])
2
3 # CHECK_I18N([TITLE], [FROM-CODING], [TO-CODING], [FROM-TEXT], [TO-TEXT])
4 #
5 # Converts FROM-TEXT from FROM-CODING to TO-CODING and checks that the result
6 # is TO-TEXT.  The "printf" program is applied to both FROM-TEXT and TO-TEXT
7 # to allow for backslash-escapes.  (Be aware that hex escapes are not portable;
8 # use octal escapes instead.)
9 m4_define([CHECK_I18N],
10   [AT_SETUP([convert $1])
11    AT_KEYWORDS([i18n])
12
13    dnl Skip the test if this host doesn't know the source and target encodings.
14    AT_CHECK(
15      [case "$host" in
16         *-*-linux* | *-*-*-gnu*)
17           dnl GNU/Linux always has the encodings we want.  We can't ask
18           dnl config.charset about them because it has a special case here
19           dnl too and won't tell us.
20           ;;
21         *)
22           $SHELL $top_srcdir/gl/config.charset "$host" | grep '$2' || exit 77
23           $SHELL $top_srcdir/gl/config.charset "$host" | grep '$3' || exit 77
24           ;;
25       esac
26      ], [0], [ignore])
27    AT_CHECK_UNQUOTED([i18n-test '$2' '$3' `printf '$4'`], [0], [`printf '$5'`
28 ])
29    AT_CLEANUP])
30      
31 CHECK_I18N([reflexively], [ASCII], [ASCII], [abc], [abc])
32 CHECK_I18N([without any change], [ASCII], [UTF-8], [abc], [abc])
33
34 CHECK_I18N([from ISO-8859-1 to UTF-8], [ISO-8859-1], [UTF-8],
35            [\242], [\302\242])
36 CHECK_I18N([from UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
37            [\302\242], [\242])
38
39 # 0xc0 == 0300 is invalid in UTF-8
40 CHECK_I18N([invalid UTF-8 to ISO-8859-1], [UTF-8], [ISO-8859-1],
41            [xy\300z], [xy?z])
42 # 0xc2 == 0302 is the first byte of a 2-byte UTF-8 sequence
43 CHECK_I18N([truncated UTF-8 to ISO-8559-1], [UTF-8], [ISO-8859-1],
44            [xy\302], [xy?])