1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# This test checks whether arithmetric operator '<character>
28# is working
29#
30# This was reported as CR #6805794 ('[ku1] printf returns "invalid character constant" for $ printf "%d\n" "'<euro>"'):
31# ------------ snip ------------
32# There seems be a bug in how ast-ksh.2008-11-04's "printf" builtin
33# handles multibyte characters. For example if I try this in the
34# en_US.UTF-8 locale ("<euro>" needs to be replace with the EURO symbol):
35# -- snip --
36# $ printf "%d\n" "'<euro>"
37# -ksh93: printf: warning: ': invalid character constant
38# 226
39# -- snip --
40# AFAIK the correct behaviour was to return the numeric value of the
41# <euro> symbol in this case (hexadecimal "20ac", decimal 8364), e.g.
42# -- snip --
43# $ printf "%d\n"
44# "'<euro>"
45# 8364
46# -- snip --
47# Frequency
48#    Always
49# Regression
50#    No
51# Steps to Reproduce
52#    Enter this in an interractive shell:
53# $ printf "%d\n" "'<euro>"
54# Expected Result
55#    -- snip --
56# $ printf "%d\n"
57# "'<euro>"
58# 8364
59# -- snip --
60# Actual Result
61#    -- snip --
62# $ printf "%d\n" "'<euro>"
63# -ksh93: printf: warning: ': invalid character constant
64# 226
65# -- snip --
66# Error Message(s)
67#    printf: warning: ': invalid character constant
68# Test Case
69#    printf "%d\n" "'<euro>"
70# Workaround
71#    None.
72# ------------ snip ------------
73#
74
75# test setup
76function err_exit
77{
78	print -u2 -n "\t"
79	print -u2 -r ${Command}[$1]: "${@:2}"
80	(( Errors < 127 && Errors++ ))
81}
82alias err_exit='err_exit $LINENO'
83
84set -o nounset
85Command=${0##*/}
86integer Errors=0
87
88
89# declare variables
90typeset str
91
92# test whether the locale uses an UTF-8 (-like) encoding and override it on demand
93[[ "$(printf "\u[20ac]")" == $'\342\202\254' ]] || LC_ALL=en_US.UTF-8
94if [[ "$(printf "\u[20ac]")" != $'\342\202\254' ]] ; then
95	err_exit "Local overrride failed."
96	exit $((Errors))
97fi
98
99# run test
100str=$(print $'printf "%d\\\\n" "\'\342\202\254"' | source /dev/stdin)
101[[ "${str}" == "8364" ]] || err_exit "expected 8364, got ${str}"
102
103
104# tests done
105exit $((Errors))
106