#!/bin/sh
if test "$1" = ""
then
	echo "usage: test_sh <display_type> > <display_type>/test_sh.out_new 2>&1"
	echo "where <display_type> = machine-type_kbd-type_kbd-layout_kbd-mode"
	echo e.g. XP_VT_X-ESC_ND
	exit
fi
xmodmap -g
xmodmap -z
# load up Multi_key keysym if necessary
if test ! -d $1
then
	mkdir $1
fi
if test -f $1/Xkm.compose
then
	xmodmap $1/Xkm.compose
fi
xmodmap -nocompose
xmodmap -verbose ctest
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctest.out_new
if cmp $1/ctest.out $1/ctest.out_new
then
	:
else
	echo regression test ctest failed
fi
xmodmap -noc
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/noctest.out_new
if test -s $1/noctest.out_new
then
	echo regression test noctest failed
fi
xmodmap -resetc
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/resetctest.out_new
if cmp $1/resetctest.out $1/resetctest.out_new
then
	:
else
	echo regression test resetctest failed
fi
xmodmap -resetcompose -noc
# -noc should have no effect
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/resetcompt.out_new
if cmp $1/resetctest.out $1/resetcompt.out_new
then
	:
else
	echo regression test resetcompt failed
fi
# clear composes, then add one
xmodmap -e "clear compose sequences"
xmodmap -fast -e "compose Mod1 keysyms Multi_key Z z = Mod5 keysym A"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctest1.out_new
if cmp $1/ctest1.out $1/ctest1.out_new
then
	:
else
	echo regression test ctest1 failed
fi
xmodmap -e "remove compose Mod1 keysyms Multi_key"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctest2.out_new
if cmp $1/ctest2.out $1/ctest2.out_new
then
	:
else
	echo regression test ctest2 failed
fi
xmodmap -e "clear compose cancel"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctcancel.out_new
if cmp $1/ctcancel.out $1/ctcancel.out_new
then
	:
else
	echo regression test ctcancel failed
fi
xmodmap -e "compose cancel 25"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctcancel1.out_new
if cmp $1/ctcancel1.out $1/ctcancel1.out_new
then
	:
else
	echo regression test ctcancel1 failed
fi
xmodmap -e "remove compose cancel 25"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctcancel2.out_new
if cmp $1/ctcancel2.out $1/ctcancel2.out_new
then
	:
else
	echo regression test ctcancel2 failed
fi
xmodmap -e "compose numeric A = keysym KP_Enter"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum5.out_new
if cmp $1/ctnum5.out $1/ctnum5.out_new
then
	:
else
	echo regression test ctnum5 failed
fi
xmodmap -e "clear compose numeric"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum6.out_new
if cmp $1/ctnum6.out $1/ctnum6.out_new
then
	:
else
	echo regression test ctnum6 failed
fi
xmodmap -e "compose numeric A = 100"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum7.out_new
if cmp $1/ctnum7.out $1/ctnum7.out_new
then
	:
else
	echo regression test ctnum7 failed
fi
xmodmap -e "remove compose numeric A = 100"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum8.out_new
if cmp $1/ctnum8.out $1/ctnum8.out_new
then
	:
else
	echo regression test ctnum8 failed
fi

xmodmap -e "compose Mod1 keysym Multi_key hex" -e "compose 100 binary" \
	-e "compose 101 decimal" -e "compose 102 octal"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum9.out_new
if cmp $1/ctnum9.out $1/ctnum9.out_new
then
	:
else
	echo regression test ctnum9 failed
fi
xmodmap -e "remove compose Mod1 keysym Multi_key hex"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctnum10.out_new
if cmp $1/ctnum10.out $1/ctnum10.out_new
then
	:
else
	echo regression test ctnum10 failed
fi
xmodmap -e "compose keysyms A a = keysym A"
xprop -root |fgrep KB_COMPOSE_ | fgrep -v CUT_BUFFER > $1/ctestshift.out_new
if cmp $1/ctestshift.out $1/ctestshift.out_new
then
	:
else
	echo regression test ctestshift failed
fi
