xref: /illumos-gate/usr/src/test/util-tests/tests/iconv/iconv_test.sh (revision 55a13001fbd9772352bc050632ef966a249dc73b)
1#!/bin/sh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
16#
17
18ICONV=${ICONV:-/usr/bin/iconv}
19#ICONV=${ROOT}/usr/bin/iconv
20
21# test name, file a, file b
22check() {
23  if ! cmp -s "$2" "$3" ; then
24    echo "TEST FAIL: $1"
25    exit 1
26  fi
27  echo "TEST PASS: $1"
28}
29
30
31# fromcs, tocs, in, out
32test_conv() {
33  echo "$3" > in
34  echo "$4" > o1
35  $ICONV -f "$1" -t "$2" < in > o2
36  check "${1}:${2}" o1 o2
37  rm in o1 o2
38}
39
40mkmap_one() {
41  echo '<code_set_name> one'
42  echo 'CHARMAP'
43  echo '<NULL>\t\x00'
44  for i in 8 9 a b c d e f
45  do
46    for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
47    do
48      echo "<c1-$i$j>\t\x$i$j"
49    done
50  done
51  echo 'END CHARMAP'
52}
53
54mkmap_two() {
55  echo '<code_set_name> two'
56  echo 'CHARMAP'
57  echo '<NULL>\t\x00'
58  for i in 8 9 a b c d e f
59  do
60    for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
61    do
62      echo "<c1-$i$j>\t\x20\x$i$j"
63    done
64  done
65  echo 'END CHARMAP'
66}
67
68# write 1023 bytes of space
69wr1023() {
70  n=1023
71  while [[ $n -gt 0 ]]; do
72    echo ' \c'
73   ((n-=1))
74  done
75}
76
77# two-byte utf-8 crossing 1024 byte boundary
78mkbuf_utf8() {
79  wr1023
80  echo '\0303\0240'
81}
82
83# one-byte 8859-1 at 1024 byte boundary
84mkbuf_8859() {
85  wr1023
86  echo '\0340'
87}
88
89# Test some simple, built-in conversions
90
91test_conv ascii utf-8 abcdef abcdef
92test_conv utf-8 ascii abcdef abcdef
93test_conv ascii ucs-2le abc 'a\0b\0c\0\n\0\c'
94test_conv ucs-2le ascii 'a\0b\0c\0\n\0\c' abc
95
96# Test user-provided charmap
97
98mkmap_one > one.cm
99mkmap_two > two.cm
100test_conv ./one.cm ./two.cm '\0200\0201\0202\c' ' \0200 \0201 \0202\c'
101rm one.cm two.cm
102
103# test crossing 1024 byte buffer boundary
104
105mkbuf_utf8 > in
106mkbuf_8859 > o1
107$ICONV -f UTF-8 -t 8859-1 < in > o2
108check "boundary" o1 o2
109rm in o1 o2
110
111exit 0
112