]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/misc/mbsencode
tests: mbsencode - test for HAVE_WIDECHAR
[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
25STRINGS=(
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
43if grep -q '^#define HAVE_WIDECHAR' ${top_builddir}/config.h ;then
44 HAVE_WIDECHAR=true
45else
46 HAVE_WIDECHAR=false
47fi
48
cad13ba3
VD
49ts_init_subtest "safe-ascii"
50$TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
51ts_finalize_subtest
52
53ts_init_subtest "invalid-ascii"
8326119a
VD
54if [ "$HAVE_WIDECHAR" = true ]; then
55 $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
56 ts_finalize_subtest
57else
58 ts_skip_subtest 'No widechar support'
59fi
cad13ba3
VD
60
61ts_init_subtest "safe-utf8"
8326119a
VD
62if [ "$HAVE_WIDECHAR" = true ]; then
63 LC_ALL=C.UTF-8 \
64 $TS_HELPER_MBSENCODE --safe "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
65 ts_finalize_subtest
66else
67 ts_skip_subtest 'No widechar support'
68fi
cad13ba3
VD
69
70ts_init_subtest "invalid-utf8"
8326119a
VD
71if [ "$HAVE_WIDECHAR" = true ]; then
72 LC_ALL=C.UTF-8 \
73 $TS_HELPER_MBSENCODE --invalid "${STRINGS[@]}" >> $TS_OUTPUT 2>&1
74 ts_finalize_subtest
75else
76 ts_skip_subtest 'No widechar support'
77fi
cad13ba3
VD
78
79ts_finalize
80