]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/misc/mbsencode
tests: make sure TS_HELPER_MBSENCODE compiled
[thirdparty/util-linux.git] / tests / ts / misc / mbsencode
CommitLineData
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
19TS_TOPDIR="${0%/*}/../.."
20TS_DESC="mbsencode"
21
22. $TS_TOPDIR/functions.sh
23ts_init "$*"
24
09fc9470
KZ
25ts_check_test_command $TS_HELPER_MBSENCODE
26
fb178a04
VD
27# These test may fail on some machines (locales, other libc...)
28TS_KNOWN_FAIL="yes"
29
cad13ba3
VD
30STRINGS=(
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
48if grep -q '^#define HAVE_WIDECHAR' ${top_builddir}/config.h ;then
49 HAVE_WIDECHAR=true
50else
51 HAVE_WIDECHAR=false
52fi
53
cad13ba3
VD
54ts_init_subtest "safe-ascii"
55$TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
56ts_finalize_subtest
57
58ts_init_subtest "invalid-ascii"
8326119a
VD
59if [ "$HAVE_WIDECHAR" = true ]; then
60 $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
61 ts_finalize_subtest
62else
63 ts_skip_subtest 'No widechar support'
64fi
cad13ba3
VD
65
66ts_init_subtest "safe-utf8"
8326119a
VD
67if [ "$HAVE_WIDECHAR" = true ]; then
68 LC_ALL=C.UTF-8 \
69 $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
70 ts_finalize_subtest
71else
72 ts_skip_subtest 'No widechar support'
73fi
cad13ba3
VD
74
75ts_init_subtest "invalid-utf8"
8326119a
VD
76if [ "$HAVE_WIDECHAR" = true ]; then
77 LC_ALL=C.UTF-8 \
78 $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
79 ts_finalize_subtest
80else
81 ts_skip_subtest 'No widechar support'
82fi
cad13ba3
VD
83
84ts_finalize
85