#/bin/sh
#
# LI18NUX2K.L1/utils/sort/sort.sh
#
# Copyright (c) 1991, 1992, 1997, 1998, 1999, 2001 X/Open Company Ltd.
# (X/Open)
# trading as The Open Group
# Copyright (c) 2001, 2003 International Business Machines Corp.
# All rights reserved except as granted by this License.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the "Artistic License" which comes with this
# Kit, with the following modification:
# a) "executable(s)" should be interpreted to include
# "test case(s)"
# b) if you wish to make changes as defined in clause 2 and 3, and
# distribute a modified version of this package, then
# clauses 3c and 4c are required
# c) Clause 7 is rephrased as follows: "Subroutines supplied by you
# and linked into this Package shall not be considered part of this
# Package".
#
#
# X/OPEN, TRADING AS THE OPEN GROUP, AND IBM CORP. DISCLAIM ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL X/OPEN OR IBM CORP. BE
# LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# You should have received a copy of the Artistic License with this
# Kit, in the file named "Artistic".  If not, we'll be glad to provide one.


tet_startup="startup"			# startup function
tet_cleanup="cleanup"			# cleanup function
iclist="ic1"
ic1="tp1 tp2 tp3 tp4 tp5 tp6 tp7 tp8 tp9 tp10 tp11 tp12 tp13 tp14 tp15 tp16 tp17 tp18 tp19 tp20 tp21 tp22 tp23 tp24 tp25 tp26 tp27 tp28 tp29 tp30 tp31 tp32 tp33 tp34 tp35 tp36 tp37 tp38 tp39 tp40 tp41 tp42 tp43 tp44 tp45 tp46 tp47 tp48"

targetlocale="LTP_1.UTF-8"

tp1()
{
	tet_infoline "* Verify this utility sorts lines according to the collating sequence of the current locale."
	tet_infoline " "

	export LANG=$targetlocale

	sort sort.test01.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout1 >/dev/null 2>&1

	result_output_code $? "Can't sort input lines according to the collating sequence."
}

tp2()
{
	tet_infoline "* When -u option is specified, verify duplicate lines are turned into one line even if the lines have multibyte characters."
	tet_infoline " "

	export LANG=$targetlocale

	sort -u sort.test02.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout2 >/dev/null 2>&1

	result_output_code $? "Can't unify duplicate lines including multibyte characters."
}

tp3()
{
	tet_infoline "* When -d option is specified, verify this utility interprets which character is a blank character or an alphanumeric character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -d sort.test03.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout3 >/dev/null 2>&1

	result_output_code $? "Can't interpret blank and alphanumeric character according to the current locale."
}

tp4()
{
	tet_infoline "* When -f option is specified, verify this utility treats a lower-case character as same as its upper-case character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -f sort.test04.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout4 >/dev/null 2>&1

	result_output_code $? "Can't interpret a lower-case character as upper-case character."
}

tp5()
{
	tet_infoline "* When -i option is specified, verify this utility interprets a printable character correctly."
	tet_infoline " "

	export LANG=$targetlocale

	sort -i sort.test05.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout5 >/dev/null 2>&1

	result_output_code $? "Can't interpret printable characters correctly."
}

tp6()
{
	tet_infoline "* When -n option is specified, verify this utility sorts numeric order. (Especially check the radix character, thousands separator and minus sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -n sort.test06.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout6 >/dev/null 2>&1

	result_output_code $? "Can't sort in numeric order."
}

tp7()
{
	tet_infoline "* When -b option is specified, verify this utility interprets which character is a blank character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -b sort.test07.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout7 >/dev/null 2>&1

	result_output_code $? "Can't interpret blank character."
}

tp8()
{
	tet_infoline "* When -t option is specified, verify this utility use a character as a field separator even if the character is a multibyte character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -t ＠ +1 -n sort.test08.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout8 >/dev/null 2>&1

	result_output_code $? "Can't handle field separator written in a multibyte chaaracter."
}

tp9()
{
	tet_infoline "* When -k keydef option is specified, verify this utility is able to define start/end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 3.4,3.4 sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout9 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp10()
{
	tet_infoline "* When -k keydef option is specified and keydef has a character b, verify this utility interprets which character is a blank character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 2.6b,2 sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout10 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp11()
{
	tet_infoline "* When -k keydef option is specified and keydef has a character d, verify this utility interprets which character is a blank character or an alphanumeric character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 1.5d,1 sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout11 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp12()
{
	tet_infoline "* When -k keydef option is specified and keydef has a character f, verify this utility treats a lower-case character as same as its upper-case character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 3.5f sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout12 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp13()
{
	tet_infoline "* When -k keydef option is specified and keydef has a character i, verify this utility interprets a printable character correctly in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 1.5i,1 sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout13 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp14()
{
	tet_infoline "* When -k keydef option is specified and keydef has a character n, verify this utility sorts numeric order in the range which defined by keydef. (Especially check the radix character, thousands separator and sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -k 2.6,2.8nr sort.test14.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout14 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp15()
{
	tet_infoline "* When +pos option is specified, verify this utility is able to define start position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort +1.5b sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout15 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp16()
{
	tet_infoline "* When -pos option is specified, verify this utility is able to define end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort +2.3 -2.4 sort.test09.txt >out.stdout 2>out.stderr
	diff out.stdout sort.expout16 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp17()
{
	tet_infoline "* When -c option is specified, verify this utility checks the file whose lines are sorted according to the collating sequence of the current locale."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c sort.expout1 >out.stdout 2>out.stderr

	result_output_code $? "Can't sort input lines according to the collating sequence."
}

tp18()
{
	tet_infoline "* When -c and -u option are specified, verify this utility checks the file which has duplicate lines even if the lines have multibyte characters."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -u sort.expout2 >out.stdout 2>out.stderr

	result_output_code $? "Can't unify duplicate lines including multibyte characters."
}

tp19()
{
	tet_infoline "* When -c and -d option are specified, verify this utility interprets which character is a blank character or an alphanumeric character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -d sort.expout3 >out.stdout 2>out.stderr

	result_output_code $? "Can't interpret blank and alphanumeric character according to the current locale."
}

tp20()
{
	tet_infoline "* When -c and -f option are specified, verify this utility treats a lower-case character as same as its upper-case character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -f sort.expout4 >out.stdout 2>out.stderr

	result_output_code $? "Can't interpret a lower-case character as upper-case character."
}

tp21()
{
	tet_infoline "* When -c and -i option are specified, verify this utility interprets a printable character correctly."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -i sort.expout5 >out.stdout 2>out.stderr

	result_output_code $? "Can't interpret printable characters correctly."
}

tp22()
{
	tet_infoline "* When -c and -n option are specified, verify this utility check the file whose lines are sorted numeric order. (Especially check the radix character, thousands separator and sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -n sort.expout6 >out.stdout 2>out.stderr

	result_output_code $? "Can't sort in numeric order."
}

tp23()
{
	tet_infoline "* When -c and -b option are specified, verify this utility interprets which character is a blank character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -b sort.expout7 >out.stdout 2>out.stderr

	result_output_code $? "Can't interpret blank character."
}

tp24()
{
	tet_infoline "* When -c and -t option are specified, verify this utility use a character as a field separator even if the character is a multibyte character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -t ＠ +1 -n sort.expout8 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle field separator written in a multibyte chaaracter."
}

tp25()
{
	tet_infoline "* When -c and -k keydef option are specified, verify this utility is able to define start/end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 3.4,3.4 sort.expout9 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp26()
{
	tet_infoline "* When -c and -k keydef option are specified and the keydef has a character b, verify this utility interprets which character is a blank character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 2.6b,2 sort.expout10 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp27()
{
	tet_infoline "* When -c and -k keydef option are specified and keydef has a character d, verify this utility interprets which character is a blank character or an alphanumeric character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 1.5d,1 sort.expout11 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp28()
{
	tet_infoline "* When -c and -k keydef option is specified and keydef has a character f, verify this utility treats a lower-case character as same as its upper-case character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 3.5f sort.expout12 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp29()
{
	tet_infoline "* When -c and -k keydef option are specified and keydef has a character i, verify this utility interprets a printable character correctly in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 1.5i,1 sort.expout13 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp30()
{
	tet_infoline "* When -c and -k keydef option are specified and keydef has a character n, verify this utility check the file whose lines are sorted numeric order in the range which defined by keydef. (Especially check the radix character, thousands separator and sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -c -k 2.6,2.8nr sort.expout14 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp31()
{
	tet_infoline "* When -c and +pos option are specified, verify this utility is able to define start position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c +1.5b sort.expout15 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp32()
{
	tet_infoline "* When -c and-pos option are specified, verify this utility is able to define end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -c +2.3 -2.4 sort.expout16 >out.stdout 2>out.stderr

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp33()
{
	tet_infoline "* When -m option is specified, verify the outputs this utility makes is sorted according to the collating sequence of the current locale."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m sort.expout1 sort.expout1 >out.stdout 2>out.stderr
	diff out.stdout sort.expout33 >/dev/null 2>&1

	result_output_code $? "Can't sort input lines according to the collating sequence."
}

tp34()
{
	tet_infoline "* When -m and -u option are specified, verify duplicate lines are turned into one line even if the line have multibyte characters."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -u sort.expout2 sort.expout2 >out.stdout 2>out.stderr
	diff out.stdout sort.expout2 >/dev/null 2>&1

	result_output_code $? "Can't unify duplicate lines including multibyte characters."
}

tp35()
{
	tet_infoline "* When -m and -d option are specified verify this utility interprets which character is a blank character or an alphanumeric character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -d sort.expout3 sort.expout3 >out.stdout 2>out.stderr
	diff out.stdout sort.expout35 >/dev/null 2>&1

	result_output_code $? "Can't interpret blank and alphanumeric character according to the current locale."
}

tp36()
{
	tet_infoline "* When -m and -f option are specified, verify this utility treats a lower-case character as same as its upper-case character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -f sort.expout4 sort.expout4 >out.stdout 2>out.stderr
	diff out.stdout sort.expout36 >/dev/null 2>&1

	result_output_code $? "Can't interpret a lower-case character as upper-case character."
}

tp37()
{
	tet_infoline "* When -m and -i option are specified, verify this utility interprets a printable character correctly."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -i sort.expout5 sort.expout5 >out.stdout 2>out.stderr
	diff out.stdout sort.expout37 >/dev/null 2>&1

	result_output_code $? "Can't interpret printable characters correctly."
}

tp38()
{
	tet_infoline "* When -m and -n option are specified, verify the outputs this utility makes is sorted numeric order. (Especially check the radix character, thousands separator and sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -n sort.expout6 sort.expout6 >out.stdout 2>out.stderr
	diff out.stdout sort.expout38 >/dev/null 2>&1

	result_output_code $? "Can't sort in numeric order."
}

tp39()
{
	tet_infoline "* When -m and -b option are specified, verify this utility interprets which character is a blank character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -b sort.expout7 sort.expout7 >out.stdout 2>out.stderr
	diff out.stdout sort.expout39 >/dev/null 2>&1

	result_output_code $? "Can't interpret blank character."
}

tp40()
{
	tet_infoline "* When -m and -t option are specified, verify this utility use a character as a field separator even if the character is a multibyte character."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -t ＠ +1 -n sort.expout8 sort.expout8 >out.stdout 2>out.stderr
	diff out.stdout sort.expout40 >/dev/null 2>&1

	result_output_code $? "Can't handle field separator written in a multibyte chaaracter."
}

tp41()
{
	tet_infoline "* When -m and -k keydef option are specified, verify this utility is able to define start/end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 3.4,3.4 sort.expout9 sort.expout9 >out.stdout 2>out.stderr
	diff out.stdout sort.expout41 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp42()
{
	tet_infoline "* When -m and -k keydef option are specified and keydef has a character b, verify this utility interprets which character is a blank character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 2.6b,2 sort.expout10 sort.expout10 >out.stdout 2>out.stderr
	diff out.stdout sort.expout42 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp43()
{
	tet_infoline "* When -m and -k keydef option are specified and keydef has a character d, verify this utility interprets which character is a blank character or an alphanumeric character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 1.5d,1 sort.expout11 sort.expout11 >out.stdout 2>out.stderr
	diff out.stdout sort.expout43 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp44()
{
	tet_infoline "* When -m and -k keydef option are specified and keydef has a character f, verify this utility treats a lower-case character as same as its upper-case character in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 3.5f sort.expout12 sort.expout12 >out.stdout 2>out.stderr
	diff out.stdout sort.expout44 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp45()
{
	tet_infoline "* When -m and -k keydef option are specified and keydef has a character i, verify this utility interprets a printable character correctly in the range which defined by keydef."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 1.5i,1 sort.expout13 sort.expout13 >out.stdout 2>out.stderr
	diff out.stdout sort.expout45 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp46()
{
	tet_infoline "* When -m and -k keydef option are specified and keydef has a character n, verify the outputs this utility makes is sorted numeric order in the range which defined by keydef. (Especially check the radix character, thousands separator and sign are interpreted correctly.)"
	tet_infoline " "

	export LANG=$targetlocale

	sort -m -k 2.6,2.8nr sort.expout14 sort.expout14 >out.stdout 2>out.stderr
	diff out.stdout sort.expout46 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp47()
{
	tet_infoline "* When -m and +pos option are specified, verify this utility is able to define start position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m +1.5b sort.expout15 sort.expout15 >out.stdout 2>out.stderr
	diff out.stdout sort.expout47 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

tp48()
{
	tet_infoline "* When -m and -pos option are specified, verify this utility is able to define end position even if the lines have multibyte characters (Especially check about the character position. i.e. 'field.character')."
	tet_infoline " "

	export LANG=$targetlocale

	sort -m +2.3 -2.4 sort.expout16 sort.expout16 >out.stdout 2>out.stderr
	diff out.stdout sort.expout48 >/dev/null 2>&1

	result_output_code $? "Can't handle key definition when field contains mutibyte characters."
}

startup() # startup function
{
	rm -f out.stdout out.stderr >/dev/null 2>&1
}


cleanup() # clean-up function
{
#	rm -f out.stdout out.stderr >/dev/null 2>&1
	rm -f tet1.* tet2.*
}

# source common shell functions

. $TET_EXECUTE/LIB/i18nfuncs.sh
. $TET_EXECUTE/LIB/shfuncs.sh
. $TET_EXECUTE/LIB/lsbfuncs.sh

# execute shell test case manager - must be last line
. $TET_ROOT/lib/xpg3sh/tcm.sh
