#!/bin/sh
# -[Sun Feb  7 04:47:01 1999 by cxh]-
# Simple script that builds a test directory
# Usage: mktestdir directoryname

prog=`basename $0`
if [ $# -ne 1 ]; then
	echo "$0: Usage: $prog directoryname"
	exit 2
fi

directoryname=$1

if [ "`basename $directoryname`" != "test" ]; then
	echo "$0: '$directoryname' does not end in test"
	exit 3
fi

if [ -d $directoryname ]; then
	echo "$0: '$directoryname' already exists. exiting."
	exit 4
fi



# 1) Create the test directory
mkdir $directoryname
cd $directoryname

# Figure out the relative path
absolute_ptii=`cd $PTII; pwd`
absolute_dirpath=`pwd`
RELPATH=`echo "$absolute_ptii $absolute_dirpath" |
	awk  '{ptIIdepth = split($1,f,"/")
		dirpathdepth = split($2,f,"/")
		for(i=ptIIdepth; i< (dirpathdepth-1); i++) {
			printf "../"
	        }
		printf("..");
	      }'`
echo "Relative path is '$RELPATH'"

# 2) Get the Java files above and generate a list of tcl files
JSIMPLE_TESTS=`cd ..; ls -1 *.java |  sed 's/.java$/.tcl/' |
	 awk '{printf("\t%s %c\n", $0, 92) }' `

echo "Generating makefile"

cat > makefile <<EoF
# FIXME: Makefile for Ptolemy II xxxx tests
#
# @Authors: Christopher Hylands, based on a file by Thomas M. Parks
#
# @Version: $Id: mktestdir 13471 2000-10-31 19:29:02Z eal $
#
# @Copyright (c) 1999 The Regents of the University of California.
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY

ME =		$directoryname

# Root of the Ptolemy II directory
ROOT =		$RELPATH

CLASSPATH =	$(ROOT)

# Get configuration info
CONFIG =	$(ROOT)/mk/ptII.mk
include $(CONFIG)

TCL_SRCS = \\
	testDefs.tcl

JSRCS = \\

# Non-graphical Java tests written in Tcl
JSIMPLE_TESTS = \\
$JSIMPLE_TESTS

# Graphical Java tests that use Tcl.
# Since there are no tests, we use a dummy file so that the script that builds
# alljtests.tcl works.  If you add a test, be sure to add
# $(JGRAPHICAL_TESTS) to EXTRA_SRCS
JGRAPHICAL_TESTS = \
	dummy.tcl

EXTRA_SRCS =	$(TCL_SRCS) $(JSRCS) $(JSIMPLE_TESTS) #$(JGRAPHICAL_TESTS)

# Sources that may or may not be present, but if they are present, we don't
# want make checkjunk to barf on them.
MISC_FILES =	alljtests.tcl

# make checkjunk will not report OPTIONAL_FILES as trash
# make distclean removes OPTIONAL_FILES
OPTIONAL_FILES =	#codeDoc

JCLASS = $(JSRCS:%.java=%.class)

# Don't include all or install rules here, we want the user
# to run 'make tests' to run the tests.

tests:: $(EXTRA_SRCS) jclass test_java test_jsimple

test_java: jclass

# Tycho-wide test definitions.
KERNEL_TESTDEFS = $(ROOT)/util/testsuite/testDefs.tcl

# These tests do not require a graphics terminal, but do use TclBlend and Java
test_jsimple: $(EXTRA_SRCS) jclass $(KERNEL_TESTDEFS) alljtests.tcl
	CLASSPATH=$(CLASSPATH)$(AUXCLASSPATH) $(JTCLSH) alljtests.tcl


docs: javadocs

depend:
	@echo "no dependencies in this directory"

# Get the rest of the rules
include $(ROOT)/mk/ptcommon.mk

EoF


# 2) Create testDefs.tcl
cp $PTII/ptolemy/kernel/util/test/testDefs.tcl testDefs.tcl

# 3) Create stub files
JAVAFILES=`cd ..; ls -1 *.java | sed 's/.java$//'`
for file in $JAVAFILES
do
	classname=$file

	echo "Generating $file.tcl"
	cat > $file.tcl << EoF2
# Tests for the $classname class
#
# @Author: Christopher Hylands
#
# @Version: $Id: mktestdir 13471 2000-10-31 19:29:02Z eal $
#
# @Copyright (c) 1999 The Regents of the University of California.
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY
#######################################################################

# Ptolemy II bed, see $PTII/doc/coding/testing.html for more information.

# Load up the test definitions.
if {[string compare test [info procs test]] == 1} then {
    source testDefs.tcl
} {}

if {[info procs enumToObjects] == "" } then {
     source enums.tcl
}

# Uncomment this to get a full report, or set in your Tcl shell window.
# set VERBOSE 1

######################################################################
####
#
test $classname-2.1 {} {
} {}
EoF2

done
