]>
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 | ||
25 | STRINGS=( | |
26 | # ASCII | |
27 | $'foo\tbar baz' | |
28 | '\\foo.local\bar' | |
29 | '\\foo.local\xbar' | |
30 | ||
31 | # UNICODE | |
32 | 'über' | |
33 | $'c\xcc\x8ca\xcc\x81rka' # 'c\u030Ca\u0301rka' | |
34 | 'Москва́' | |
35 | '北京' | |
910a879f | 36 | $'\xc2\x83' # U+0083 |
cad13ba3 VD |
37 | |
38 | # INVALID UNICODE | |
39 | $'\xff' | |
40 | $'\xe8\xe1\xf9\xa7' | |
41 | ) | |
42 | ||
8326119a VD |
43 | if grep -q '^#define HAVE_WIDECHAR' ${top_builddir}/config.h ;then |
44 | HAVE_WIDECHAR=true | |
45 | else | |
46 | HAVE_WIDECHAR=false | |
47 | fi | |
48 | ||
cad13ba3 VD |
49 | ts_init_subtest "safe-ascii" |
50 | $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
51 | ts_finalize_subtest | |
52 | ||
53 | ts_init_subtest "invalid-ascii" | |
8326119a VD |
54 | if [ "$HAVE_WIDECHAR" = true ]; then |
55 | $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
56 | ts_finalize_subtest | |
57 | else | |
58 | ts_skip_subtest 'No widechar support' | |
59 | fi | |
cad13ba3 VD |
60 | |
61 | ts_init_subtest "safe-utf8" | |
8326119a VD |
62 | if [ "$HAVE_WIDECHAR" = true ]; then |
63 | LC_ALL=C.UTF-8 \ | |
64 | $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
65 | ts_finalize_subtest | |
66 | else | |
67 | ts_skip_subtest 'No widechar support' | |
68 | fi | |
cad13ba3 VD |
69 | |
70 | ts_init_subtest "invalid-utf8" | |
8326119a VD |
71 | if [ "$HAVE_WIDECHAR" = true ]; then |
72 | LC_ALL=C.UTF-8 \ | |
73 | $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1 | |
74 | ts_finalize_subtest | |
75 | else | |
76 | ts_skip_subtest 'No widechar support' | |
77 | fi | |
cad13ba3 VD |
78 | |
79 | ts_finalize | |
80 |