]>
Commit | Line | Data |
---|---|---|
cad13ba3 VD |
1 | #!/bin/bash |
2 | ||
3 | # | |
4 | # Copyright (C) 2018 Vaclav Dolezal <vdolezal@redhat.com> | |
5 | # | |
6 | # This file is part of util-linux. | |
7 | # | |
8 | # This file is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This file is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | ||
19 | TS_TOPDIR="${0%/*}/../.." | |
20 | TS_DESC="mbsencode" | |
21 | ||
22 | . $TS_TOPDIR/functions.sh | |
23 | ts_init "$*" | |
24 | ||
09fc9470 KZ |
25 | ts_check_test_command $TS_HELPER_MBSENCODE |
26 | ||
fb178a04 VD |
27 | # These test may fail on some machines (locales, other libc...) |
28 | TS_KNOWN_FAIL="yes" | |
29 | ||
cad13ba3 VD |
30 | STRINGS=( |
31 | # ASCII | |
32 | $'foo\tbar baz' | |
33 | '\\foo.local\bar' | |
34 | '\\foo.local\xbar' | |
35 | ||
36 | # UNICODE | |
37 | 'über' | |
38 | $'c\xcc\x8ca\xcc\x81rka' # 'c\u030Ca\u0301rka' | |
39 | 'Москва́' | |
40 | '北京' | |
910a879f | 41 | $'\xc2\x83' # U+0083 |
cad13ba3 VD |
42 | |
43 | # INVALID UNICODE | |
44 | $'\xff' | |
45 | $'\xe8\xe1\xf9\xa7' | |
46 | ) | |
47 | ||
8326119a VD |
48 | if grep -q '^#define HAVE_WIDECHAR' ${top_builddir}/config.h ;then |
49 | HAVE_WIDECHAR=true | |
50 | else | |
51 | HAVE_WIDECHAR=false | |
52 | fi | |
53 | ||
cad13ba3 VD |
54 | ts_init_subtest "safe-ascii" |
55 | $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
56 | ts_finalize_subtest | |
57 | ||
58 | ts_init_subtest "invalid-ascii" | |
8326119a VD |
59 | if [ "$HAVE_WIDECHAR" = true ]; then |
60 | $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
61 | ts_finalize_subtest | |
62 | else | |
63 | ts_skip_subtest 'No widechar support' | |
64 | fi | |
cad13ba3 VD |
65 | |
66 | ts_init_subtest "safe-utf8" | |
8326119a VD |
67 | if [ "$HAVE_WIDECHAR" = true ]; then |
68 | LC_ALL=C.UTF-8 \ | |
69 | $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
70 | ts_finalize_subtest | |
71 | else | |
72 | ts_skip_subtest 'No widechar support' | |
73 | fi | |
cad13ba3 VD |
74 | |
75 | ts_init_subtest "invalid-utf8" | |
8326119a VD |
76 | if [ "$HAVE_WIDECHAR" = true ]; then |
77 | LC_ALL=C.UTF-8 \ | |
78 | $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
79 | ts_finalize_subtest | |
80 | else | |
81 | ts_skip_subtest 'No widechar support' | |
82 | fi | |
cad13ba3 VD |
83 | |
84 | ts_finalize | |
85 |