<?xml version="1.0"?>

<!--
   Derby - Script org/apache/derbyTesting/functionTests/tests/junitTests/compatibility/testScript.xml

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to you under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->


<project default="allTests" basedir="../../../../../../../../..">
  <description>
	Driver for running compatibility tests, mixing and matching
	clients and servers at different Derby rev levels on different
	VMs. Invoke as follows:

	ant -buildfile testScript.xml -DoutDir=OUTPUT_DIRECTORY [ -Ddrb.tests.debug=true ]

	where    OUTPUT_DIRECTORY is the directory which will hold output files.
	         drb.tests.debug=true coaxes extra diagnostics out of the tests.

	This script assumes that you have set the following variables
	in the ant.properties file in your user home directory:

	j14lib          The library directory of your 1.4 JRE
	jdk15           The JAVA_HOME of your 1.5 vm.
    jdk16           The JAVA_HOME of your 1.6 vm.

       10.0.2.1_lib    Directory containing the released 10.0.2.1 jars.
       10.1.1.0_lib    Directory containing the released 10.1.1.0 jars.
       10.1.2.1_lib    Directory containing the released 10.1.2.1 jars.
       10.1.3.1_lib    Directory containing the released 10.1.3.1 jars.
       10.2.1.6_lib    Directory containing the released 10.2.1.6 jars.
       10.2.2.0_lib    Directory containing the released 10.2.2.0 jars.
       10.3.1.4_lib    Directory containing the released 10.3.1.4 jars.
       10.3.2.1_lib    Directory containing the released 10.3.2.1 jars.
       10.3.3.0_lib    Directory containing the released 10.3.3.0 jars.
       10.4.1.3_lib    Directory containing the released 10.4.1.3 jars.
       10.4.2.0_lib    Directory containing the released 10.4.2.0 jars.
       10.5.1.1_lib    Directory containing the released 10.5.1.1 jars.
       10.5.2.0_lib    Directory containing the released 10.5.2.0 jars.
       10.5.3.0_lib    Directory containing the released 10.5.3.0 jars.
       10.6.1.0_lib    Directory containing the released 10.6.1.0 jars.
       trunk_lib       Directory containing jars built from the development mainline (trunk).

	The basic loop runs as follows:

		run compatibility tests against current embedded server in all VMs.

		for each server VM
		{
			for each server version
			{
				bring up server
				recreate database

				for each client VM
				{
					for each client version
					{
						run compatibility tests
					}
				}

				bring down server
			}
		}

    If a combination fails, the test continues with the next combination.
    Consult the summary file to see if all combinations succeeded or not.
    The summary file is named 'SUMMARY_COMPAT.txt' and can be found in the
    specified output directory.

	To run just one combination, copy the oneCombo.properties template
	file from this suite and customize it. Then invoke the oneCombination
	target:

	ant -buildfile testScript.xml -DoutDir=OUTPUT_DIRECTORY -DoneComboProps=FILE_YOU_JUST_CUSTOMIZED -Ddrb.tests.debug=true oneCombination

  </description>

  <property file="${user.home}/ant.properties"/>
  <property name="properties.dir" value="tools/ant/properties"/>
  <property file="${properties.dir}/dirs.properties"/>
  <property file="${properties.dir}/extrapath.properties"/>
  <property file="${properties.dir}/compilepath.properties"/>
  <property name="summaryFile" value="${outDir}/SUMMARY_COMPAT.txt"/>
  <property name="databaseName" value="compatDB"/>

  <property name="TEST_JARS" value="${trunk_lib}/derbyTesting.jar;${junit}"/>

  <!-- legal values of serverVM and clientVM -->
  <property name="VM_1.4" value="${j14lib}/../bin/java"/>
  <property name="VM_1.5" value="${jdk15}/bin/java"/>
  <property name="VM_1.6" value="${jdk16}/bin/java"/>

  <!-- legal values of serverClasspath -->
  <property name="SERVER_10.0.2.1" value="${10.0.2.1_lib}/derby.jar;${10.0.2.1_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.1.1.0" value="${10.1.1.0_lib}/derby.jar;${10.1.1.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.1.2.1" value="${10.1.2.1_lib}/derby.jar;${10.1.2.1_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.1.3.1" value="${10.1.3.1_lib}/derby.jar;${10.1.3.1_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.2.1.6" value="${10.2.1.6_lib}/derby.jar;${10.2.1.6_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.2.2.0" value="${10.2.2.0_lib}/derby.jar;${10.2.2.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.3.1.4" value="${10.2.2.0_lib}/derby.jar;${10.2.2.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.3.2.1" value="${10.3.2.1_lib}/derby.jar;${10.3.2.1_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.3.3.0" value="${10.3.3.0_lib}/derby.jar;${10.3.3.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.4.1.3" value="${10.4.1.3_lib}/derby.jar;${10.4.1.3_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.4.2.0" value="${10.4.2.0_lib}/derby.jar;${10.4.2.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.5.1.1" value="${10.5.1.1_lib}/derby.jar;${10.5.1.1_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.5.2.0" value="${10.5.2.0_lib}/derby.jar;${10.5.2.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.5.3.0" value="${10.5.3.0_lib}/derby.jar;${10.5.3.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_10.6.1.0" value="${10.6.1.0_lib}/derby.jar;${10.6.1.0_lib}/derbynet.jar;${TEST_JARS}"/>
  <property name="SERVER_TRUNK" value="${trunk_lib}/derby.jar;${trunk_lib}/derbynet.jar;${TEST_JARS}"/>

  <!-- legal values of clientClasspath -->
  <property name="CLIENT_10.1.1.0" value="${10.1.1.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.1.2.1" value="${10.1.2.1_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.1.3.1" value="${10.1.3.1_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.2.1.6" value="${10.2.1.6_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.2.2.0" value="${10.2.2.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.3.1.4" value="${10.3.1.4_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.3.2.1" value="${10.3.2.1_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.3.3.0" value="${10.3.3.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.4.1.3" value="${10.4.1.3_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.4.2.0" value="${10.4.2.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.5.1.1" value="${10.5.1.1_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.5.2.0" value="${10.5.2.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.5.3.0" value="${10.5.3.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_10.6.1.0" value="${10.6.1.0_lib}/derbyclient.jar"/>
  <property name="CLIENT_TRUNK" value="${trunk_lib}/derbyclient.jar"/>

  <property name="FULL_TRUNK" value="${SERVER_TRUNK};${CLIENT_TRUNK}"/>

  <property name="CLASSPATH_TRUNK" value="${basedir}/classes;${compile.classpath}"/>

  <property name="VM_DEFAULT" value="${VM_1.4}"/>

  <property name="JDBC_SUITE" value="org.apache.derbyTesting.functionTests.tests.junitTests.compatibility.CompatibilitySuite"/>
  <property name="EMBEDDED_CLIENT" value="org.apache.derby.jdbc.EmbeddedDriver"/>

  <!-- May be overridden on the command line -->
  <property name="drb.tests.debug" value="false"/>

  <!--
    If this file exists, it sets up properties for oneCombination.
    The property file is passed in on the command line.
  -->
  <property file="${oneComboProps}"/>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! PUBLIC ENTRY POINTS
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

  <target
    name="cleanup"
    depends="_vetSetup"
    description="Brings down the server in case it is still running."
  >

	<antcall target="_stopServer"/>

  </target>

  <target
    name="allTests"
    description="Run all compatibility tests."
  >

    <antcall target="compatibility"/>

  </target>

  <target
    name="compatibility"
    depends="cleanup"
    description="Run compatibility tests against all combinations."
  >
    <antcall target="embeddedTrunk"/>

	<!-- Now loop through server VMs -->

	<antcall target="_forServerVM">
	  <param name="fsvVM" value="${VM_1.4}"/>
	  <param name="fsvName" value="serverVM-1.4"/>
    </antcall>

	<antcall target="_forServerVM">
	  <param name="fsvVM" value="${VM_1.5}"/>
	  <param name="fsvName" value="serverVM-1.5"/>
    </antcall>

    <antcall target="_forServerVM">
      <param name="fsvVM" value="${VM_1.6}"/>
      <param name="fsvName" value="serverVM-1.6"/>
    </antcall>

	<!-- Done looping through server VMs -->

	<antcall target="_checkSuccess"/>

  </target>

  <!--
       Run tests against one combination. The combination is
       determined by the following variables, which are set
	   in the properties file identified on the command line by
	   the -DoneComboProps flag:

       serverVM          VM to run server in
       serverClasspath   Classpath containing server jars
       clientVM          VM to run client in
       clientClasspath   Classpath containing client jars
  -->
  <target
    name="oneCombination"
    description="Run compatibility tests one combination."
  >
	<antcall target="_stopServer"/>

	<antcall target="_startServer">
	  <param name="svrVM" value="${serverVM}"/>
	  <param name="srvClasspath" value="${serverClasspath}"/>
	  <param name="srvSecurity" value="-noSecurityManager"/>
    </antcall>

	<antcall target="_recreateDatabase"/>

    <antcall target="_oneTest">
	  <param name="otTestName" value="${JDBC_SUITE}"/>

	  <param name="otClasspath" value="${clientClasspath}"/>
	  <param name="otOutfile" value="oneCombination"/>
	  <param name="otVM" value="${clientVM}"/>
	  <param name="otClientName" value=""/>
    </antcall>

	<antcall target="_stopServer"/>

	<antcall target="_checkSuccess"/>

  </target>

  <target
    name="embeddedTrunk"
    depends="cleanup"
    description="Run compatibility tests against the latest embedded server. This combination tracks the compatibility of the embedded and network clients."
  >
	<antcall target="_recreateDatabaseGuts">
	  <param name="codeline" value="${SERVER_TRUNK}"/>
    </antcall>

    <antcall target="_forEmbeddedVM">
	  <param name="eVM" value="${VM_1.4}"/>
	  <param name="eName" value="VM-1.4"/>
    </antcall>

    <antcall target="_forEmbeddedVM">
	  <param name="eVM" value="${VM_1.5}"/>
	  <param name="eName" value="VM-1.5"/>
    </antcall>

    <antcall target="_forEmbeddedVM">
      <param name="eVM" value="${VM_1.6}"/>
      <param name="eName" value="VM-1.6"/>
    </antcall>

  </target>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! LOOP MANAGEMENT
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

  <!--
       Run embedded tests for a given server VM.

       eVM             VM to run server in
       eName           Human-readable name for VM.
  -->
  <target name="_forEmbeddedVM">

    <antcall target="_oneTest">
	  <param name="otTestName" value="${JDBC_SUITE}"/>

	  <param name="otClasspath" value="${SERVER_TRUNK}"/>
	  <param name="otOutfile" value="embedded_${eName}"/>
	  <param name="otVM" value="${eVM}"/>
	  <param name="otClientName" value="${EMBEDDED_CLIENT}"/>
    </antcall>

  </target>

  <!--
       Run tests for a given server VM.

       fsvVM             VM to run server in
       fsvName           Human-readable name for VM.
  -->
  <target name="_forServerVM">

	<!-- Now loop through servers -->

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_TRUNK}"/>
	  <param name="fsvnName" value="${fsvName}_serverTrunk"/>
	  <param name="fsvnSecurity" value="-noSecurityManager"/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.6.1.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.6.1.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.5.3.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.5.3.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.5.2.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.5.2.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.5.1.1}"/>
	  <param name="fsvnName" value="${fsvName}_server10.5.1.1"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.4.2.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.4.2.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.4.1.3}"/>
	  <param name="fsvnName" value="${fsvName}_server10.4.1.3"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.3.3.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.3.3.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.3.2.1}"/>
	  <param name="fsvnName" value="${fsvName}_server10.3.2.1"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.3.1.4}"/>
	  <param name="fsvnName" value="${fsvName}_server10.3.1.4"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.2.2.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.2.2.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.1.3.1}"/>
	  <param name="fsvnName" value="${fsvName}_server10.1.3.1"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.1.2.1}"/>
	  <param name="fsvnName" value="${fsvName}_server10.1.2.1"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.1.1.0}"/>
	  <param name="fsvnName" value="${fsvName}_server10.1.1.0"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<antcall target="_forServerVersion">
	  <param name="fsvnVM" value="${fsvVM}"/>
	  <param name="fsvnCP" value="${SERVER_10.0.2.1}"/>
	  <param name="fsvnName" value="${fsvName}_server10.0.2.1"/>
	  <param name="fsvnSecurity" value=""/>
    </antcall>

	<!-- Done looping through servers -->


  </target>

  <!--
       Run tests for a given server version.

       fsvnVM            VM to run server in
       fsvnCP            Classpath of server
       fsvnName          Human-readable name of VM/server combination
  -->
  <target name="_forServerVersion">

	<antcall target="_startServer">
	  <param name="svrVM" value="${fsvnVM}"/>
	  <param name="srvClasspath" value="${fsvnCP}"/>
	  <param name="srvSecurity" value="${fsvnSecurity}"/>
    </antcall>

	<antcall target="_recreateDatabase"/>

	<!-- Now loop through client VMs -->

	<antcall target="_forClientVM">
	  <param name="fcvVM" value="${VM_1.4}"/>
	  <param name="fcvName" value="${fsvnName}_clientVM-1.4"/>
    </antcall>

	<antcall target="_forClientVM">
	  <param name="fcvVM" value="${VM_1.5}"/>
	  <param name="fcvName" value="${fsvnName}_clientVM-1.5"/>
    </antcall>

    <antcall target="_forClientVM">
      <param name="fcvVM" value="${VM_1.6}"/>
      <param name="fcvName" value="${fsvnName}_clientVM-1.6"/>
    </antcall>

	<!-- Done looping through client VMs -->

	<antcall target="_stopServer"/>

  </target>

  <!--
       Run tests for a given client VM

       fcvVM             VM to run client in
       fcvName           Human-readable name of VM/server/VM combination
  -->
  <target name="_forClientVM">

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_TRUNK}"/>
	  <param name="fcvnName" value="${fcvName}_clientTrunk"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.6.1.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.6.1.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.5.3.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.5.3.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.5.2.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.5.2.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.5.1.1}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.5.1.1"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.4.2.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.4.2.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.4.1.3}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.4.1.3"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.3.3.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.3.3.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.3.2.1}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.3.2.1"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.3.1.4}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.3.1.4"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.2.2.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.2.2.0"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.1.3.1}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.1.3.1"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.1.2.1}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.1.2.1"/>
    </antcall>

    <antcall target="_forClientVersion">
	  <param name="fcvnVM" value="${fcvVM}"/>
	  <param name="fcvnCP" value="${CLIENT_10.1.1.0}"/>
	  <param name="fcvnName" value="${fcvName}_clientDerby10.1.1.0"/>
    </antcall>

  </target>

  <!--
       Run tests for a given client version

       fcvnVM            VM to run client in
       fcvnCP            Classpath of client
       fcvnName          Human-readable name of VM/server/VM/client
                         combination. Used to construct output filename.

  -->
  <target name="_forClientVersion">

    <antcall target="_oneTest">
	  <param name="otTestName" value="${JDBC_SUITE}"/>

	  <param name="otClasspath" value="${fcvnCP}"/>
	  <param name="otOutfile" value="${fcvnName}"/>
	  <param name="otVM" value="${fcvnVM}"/>
	  <param name="otClientName" value=""/>
    </antcall>

  </target>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! CLIENT WORKHORSE
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

  <!--
       Run a single junit test.

       otVM             VM to run test in
       otClasspath      Classpath to use.
       otTestname       Name of test class.
       otOutFile        File to hold test's stdout and stderr.

       Assumes that the test takes the following arguments:

       arg[ 0 ]         Database name.
  -->
  <target name="_oneTest">

    <exec
	  executable="${otVM}"
	  dir="${outDir}"
	  output="${outDir}/${otOutfile}"
	  resultproperty="testStatus"
	>
	  <arg value="-cp"/>
	  <arg path="${otClasspath}:${TEST_JARS}"/>

	  <arg value="-Ddrb.tests.debug=${drb.tests.debug}"/>

	  <arg value="${otTestName}"/>

	  <arg value="${databaseName}"/>

	  <arg value="${otClientName}"/>

	</exec>

    <condition property="compatFailure">
	  <not>
	    <equals arg1="${testStatus}" arg2="0" />
	  </not>
	</condition>

	<antcall target="_checkFailure">
	  <param name="testrun" value="${otOutfile}"/>
    </antcall>

  </target>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! SERVER MANAGEMENT
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

  <!--
       Start up a server.

       srvVM             VM to run server in.
       srvClasspath      Classpath to use.
  -->
  <target name="_startServer">
<!-- Trace -->
<echo level="info"> svrVM:${svrVM}, outDir:${outDir}, srvClasspath:${srvClasspath}, srvSecurity:${srvSecurity}. </echo>
<!-- -->
    <exec
	  executable="${svrVM}"
	  dir="${outDir}"
	  spawn="true"
	>
	  <arg value="-cp"/>
	  <arg path="${srvClasspath}"/>

	  <arg value="org.apache.derby.drda.NetworkServerControl"/>
	  <arg value="start"/>

	  <!-- arg value="${srvSecurity}"/ Fails for srvSecurity blank with jvm1.4... -->
	  <arg line="${srvSecurity}"/> 
	  <!-- 'value' is the preferred arg according to http://ant.apache.org/manual/using.html#arg -->

	</exec>

	<!-- Pause until server comes up. -->
	<antcall target="_pingServer"/>

  </target>

  <!--
       Bring down server.
  -->
  <target name="_stopServer">

    <exec
	  executable="${VM_DEFAULT}"
	  dir="${outDir}"
	>
	  <arg value="-cp"/>
	  <arg path="${SERVER_TRUNK}"/>

	  <arg value="org.apache.derby.drda.NetworkServerControl"/>
      <arg value="shutdown"/>

	</exec>

  </target>

  <!--
       Check if server is alive.
  -->
  <target name="_pingServer">

    <exec
	  executable="${VM_DEFAULT}"
	  dir="${outDir}"
	>
	  <arg value="-cp"/>
	  <arg path="${FULL_TRUNK}"/>

	  <arg value="org.apache.derbyTesting.functionTests.tests.junitTests.compatibility.Pinger"/>

	</exec>

  </target>

  <!--
       Recreate database.
  -->
  <target name="_recreateDatabase">

	<antcall target="_recreateDatabaseGuts">
	  <param name="codeline" value="${CLIENT_10.1.1.0}"/>
    </antcall>

  </target>

  <target name="_recreateDatabaseGuts">

    <delete dir="${outDir}/${databaseName}"/>

    <exec
	  executable="${VM_DEFAULT}"
	  dir="${outDir}"
	>
	  <arg value="-cp"/>
	  <arg path="${codeline};${TEST_JARS}"/>

	  <arg value="${JDBC_SUITE}$Creator"/>
	  <arg value="${databaseName}"/>

	</exec>

  </target>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! SUMMARY MINIONS
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->


  <!-- Check if all tests succeeded -->
  <target name="_checkSuccess" unless="compatFailure">

    <antcall target="_writeSummary">
	  <param name="summaryMessage" value="SUCCESS!"/>
    </antcall>

  </target>

  <!-- Check if a test failed -->
  <target name="_checkFailure" if="compatFailure">

    <antcall target="_writeSummary">
	  <param name="summaryMessage" value="FAILURE: Check ${testrun} for details."/>
    </antcall>

	<antcall target="_stopServer"/>

    <!-- try to continue on error! fail message="Testrun ${testrun} failed."/ -->

  </target>

  <!-- Write the summary file -->
  <target name="_writeSummary">

    <echo level="info" file="${summaryFile}" append="true"> 
${summaryMessage}

</echo>

  </target>

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!
!! CLASSPATH/VM VETTING
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

  <!-- Check that classpaths and vms look good -->
  <target name="_vetSetup">

    <antcall target="_vetClasspath"/>
    <antcall target="_vetVMs"/>

  </target>

  <!-- Check that classpaths look good -->
  <target name="_vetClasspath">

    <antcall target="_vetServer"> <param name="vsLib" value="${10.0.2.1_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.1.1.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.1.2.1_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.1.3.1_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.2.2.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.3.1.4_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.3.2.1_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.3.3.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.4.1.3_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.4.2.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.5.1.1_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.5.2.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.5.3.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${10.6.1.0_lib}"/> </antcall>
    <antcall target="_vetServer"> <param name="vsLib" value="${trunk_lib}"/> </antcall>

    <antcall target="_vetClient"> <param name="vcLib" value="${10.1.1.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.1.2.1_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.1.3.1_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.2.2.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.3.1.4_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.3.2.1_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.3.3.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.4.1.3_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.4.2.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.5.1.1_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.5.2.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.5.3.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${10.6.1.0_lib}"/> </antcall>
    <antcall target="_vetClient"> <param name="vcLib" value="${trunk_lib}"/> </antcall>

  </target>

  <!-- Check that required client jar files are visible -->
  <target name="_vetClient">

    <antcall target="_vetJar">
	  <param name="vjLib" value="${vcLib}"/>
	  <param name="vjJar" value="derbyclient.jar"/>
    </antcall>

  </target>

  <!-- Check that required server jar files are visible -->
  <target name="_vetServer">

    <antcall target="_vetJar">
	  <param name="vjLib" value="${vsLib}"/>
	  <param name="vjJar" value="derby.jar"/>
    </antcall>

    <antcall target="_vetJar">
	  <param name="vjLib" value="${vsLib}"/>
	  <param name="vjJar" value="derbynet.jar"/>
    </antcall>

  </target>

  <!-- Check that required jarfile is visible -->
  <target name="_vetJar">

	<fail>
	  <condition>
	    <not>
	      <available file="${vjLib}/${vjJar}"/>
	    </not>
	  </condition>
	  Cannot find jar file ${vjJar} in directory ${vjLib}.
	  Make sure that your ant.properties contains the correct
	  values for all properties described in the header comment
	  (-projecthelp) of this script.
	</fail>

  </target>

  <!-- Check that required vms are visible -->
  <target name="_vetVMs">

    <antcall target="_vetVM"> <param name="vv" value="${j13lib}"/> </antcall>
    <antcall target="_vetVM"> <param name="vv" value="${j14lib}"/> </antcall>
    <antcall target="_vetVM"> <param name="vv" value="${jdk15}"/> </antcall>

  </target>

  <!-- Check that required vm is visible -->
  <target name="_vetVM">

	<fail>
	  <condition>
	    <not>
	      <available file="${vv}" type="dir"/>
	    </not>
	  </condition>
	  Cannot find VM ${vv}.
	  Make sure that your ant.properties contains the correct
	  values for all properties described in the header comment
	  (-projecthelp) of this script.
	</fail>

  </target>


</project>
