<project name="build.tests">
    <import  file="properties.xml" />
    <import  file="compile.xml" />
    <import  file="jars.xml" />

	<!-- =================================================
	 Tests
	 ================================================= -->
	
	<!-- Compiles, then runs HTML test -->
	<target name="test" depends="compile" description="Test">
		<java
				classname="org.xhtmlrenderer.swing.HTMLTest"
				classpath="${dest.java.dir};${dest.dir}"
				fork="${java-exec.fork.tests}">
			<arg value="${file}"/>
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<classpath refid="libraries.all"/>
		</java>
	</target>
	
	<!-- Runs a speed test after a compile -->
	<target name="test.speed" depends="test.css-speed"></target>
	
	<!-- Runs a speed test after a compile -->
	<target name="test.css-speed" depends="compile" description="Test timing on loading Hamlet.xhtml multiple times.">
		<java classname="org.xhtmlrenderer.test.HamletSpeedTest"
				fork="${java-exec.fork.tests}">
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<classpath>
				<pathelement path="${basedir}"/>
				<pathelement path="${dest.dir}"/>
				<pathelement path="${dest.java.dir}"/>
				<fileset dir="${libraries.dir}">
					<include name="*.jar"/>
				</fileset>
			</classpath>
		</java>
	</target>

	<!-- Runs a custom block test after a compile -->
	<target name="test.customblock" depends="compile">
		<java classname="org.xhtmlrenderer.test.CustomBlockTest"
				classpath="${dest.java.dir}"
				fork="${java-exec.fork.tests}">
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<classpath refid="libraries.all"/>
		</java>
	</target>
	
	<!-- target just shows how a single test can be run -->
	<target name="test.junit.simple" depends="compile.junit">
		<junit printsummary="withOutAndErr"
				timeout="60000"
				filtertrace="on"
				haltonerror="on"
				showoutput="on"
				haltonfailure="on">
			
			<classpath>
				<pathelement path="${basedir}" />
				<pathelement path="${dest.dir}" />
				<pathelement path="${dest.java.dir}" />
				<fileset dir="${libraries.dir}">
					<include name="*.jar"/>
				</fileset>
			</classpath>
			
			<formatter type="plain" usefile="false" />
	
	<!-- run a single test -->
			<test name="tests.public_apis.SimpleJUnitTest" />
		</junit>
	</target>
        
	<!-- target just shows how a single test can be run -->
	<target name="test.junit.ident" depends="compile.junit" description="test idents">
		<junit printsummary="withOutAndErr"
				timeout="60000"
				filtertrace="on"
				haltonerror="on"
				showoutput="on"
				haltonfailure="on">
			
			<classpath>
				<pathelement path="${basedir}" />
				<pathelement path="${dest.dir}" />
				<pathelement path="${dest.java.dir}" />
				<fileset dir="${libraries.dir}">
					<include name="*.jar"/>
				</fileset>
			</classpath>
			
			<formatter type="plain" usefile="false" />
	
                        <!-- run a single test -->
			<test name="tests.public_apis.css.properties.resolve.IdentResolutionTest" />
		</junit>
	</target>        
	
	<target name="test.junit.public-apis" depends="compile.junit" description="Runs all JUnit unit tests.">
		<junit printsummary="withOutAndErr"
				timeout="60000"
				filtertrace="on"
				haltonerror="on"
				showoutput="on"
				haltonfailure="on">
		 
	<!-- <sysproperty key="show-config" value="${show-config}" /> -->
	<!-- <sysproperty key="show-config" value="ALL" /> -->
			
			<classpath>
				<pathelement path="${basedir}" />
				<pathelement path="${dest.dir}" />
				<pathelement path="${dest.java.dir}" />
				<fileset dir="${libraries.dir}">
					<include name="*.jar"/>
				</fileset>
			</classpath>
			
			<formatter type="plain" usefile="false" />
	
	<!-- run all class files with Test in the name in the java dest directory -->
			<batchtest fork="no">
				<fileset dir="${dest.java.dir}">
					<include name="tests/**/factory/*Test*" />
					<exclude name="tests/**/Abstract*Test*" />
					<exclude name="tests/**/SimpleJUnitTest*" />
				</fileset>
			</batchtest>
		</junit>
	</target>

    <!-- Compiles, then runs HTML test -->
	<target name="test.headless" depends="compile" description="Test">
		<java
				classname="org.xhtmlrenderer.test.Graphics2DRendererTest"
				classpath="${dest.java.dir};${dest.dir}"
				fork="${java-exec.fork.tests}">
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<classpath refid="libraries.all"/>
		</java>
	</target>

    <!-- Builds the core jar and runs unit tests -->
	<target name="unit-tests" depends="diff-tests"></target>

    <!-- Builds the core jar and runs diff tests -->
	<target name="diff-tests" depends="jar.core">
		<java classname="org.xhtmlrenderer.test.DocumentDiffTest"
				fork="${java-exec.fork.tests}">
			<classpath refid="libraries-and-dest.all"/>
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
		</java>
	</target>

    <!-- Builds the core jar and runs diff tests -->
	<target name="diff-test-file" depends="jar.core">
		<java classname="org.xhtmlrenderer.test.DocumentDiffTest"
				fork="${java-exec.fork.tests}">
			<classpath refid="libraries-and-dest.all"/>
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<arg value="${file}"/>
		</java>
	</target>

	    <!-- Builds the core jar and runs diff tests -->
	<target name="gen-diff-file" depends="jar.core">
		<java classname="org.xhtmlrenderer.test.DocumentDiffGenerate"
				fork="${java-exec.fork.tests}">
			<classpath refid="libraries-and-dest.all"/>
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<arg value="${file}"/>
			<arg value="${diff}"/>
		</java>
	</target>

    <target name="regress.snapshot" depends="check.app.version, jar.core">
        <!-- copy current test files -->
        <delete dir="${regress.temp.dir}" failonerror="true" includeemptydirs="true" quiet="true" />
        <delete file="${regress.target.zip}" />
        <mkdir  dir="${regress.temp.dir}" />
        <copy   todir="${regress.temp.dir}">
            <fileset dir="${regress.source.dir}" />
        </copy>
        <java classname="org.xhtmlrenderer.test.Regress"
                fork="${java-exec.fork.tests}">
            <classpath>
              <path refid="libraries.all"/>
              <fileset dir="${dest.dir}">
                <include name="*.jar"/>
              </fileset>
              <pathelement path="${dest.java.dir}" />
            </classpath>
            <sysproperty key="show-config" value="${show-config}"/>
            <syspropertyset>
                <propertyref prefix="xr."/>
            </syspropertyset>
            <arg value="${regress.temp.dir}"/>
        </java>
        <zip basedir="${regress.temp.dir}" zipfile="${regress.target.zip}" encoding="utf-8" level="9" />
        <delete file="${regress.temp.dir}" />
    </target>

    <target name="regress.verify" depends="check.app.version, jar.core">
        <fail message="Missing file ${regress.target.zip}; call regress.snapshot to generate it.">
            <condition>
                <not>
                    <available file="${regress.target.zip}" />
                </not>
            </condition>
        </fail>
        <!--cleanup from last verify run-->
        <delete dir="${regress.verify.dir}"/>
        <delete dir="${regress.verify.failed.dir}"/>
        <!--unpack snapshots from regress.snapshot, this is our basis of comparison-->
        <unzip src="${regress.target.zip}" dest="${regress.verify.dir}" />
        <echo message="${dest.java.dir}" />
        <java classname="org.xhtmlrenderer.test.ReferenceComparison"
                fork="${java-exec.fork.tests}"
                
                maxmemory="256m">
            <classpath>
              <path refid="libraries.all"/>
              <fileset dir="${dest.dir}">
                <include name="*.jar"/>
              </fileset>
              <pathelement path="${dest.java.dir}" />
            </classpath>
            <sysproperty key="java.awt.headless" value="false"/>
            <sysproperty key="show-config" value="${show-config}"/>
            <syspropertyset>
                <propertyref prefix="xr."/>
            </syspropertyset>
            <!--<jvmarg line="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" />-->
            <arg value="${regress.source.dir}"/>
            <arg value="${regress.verify.dir}"/>
            <arg value="${regress.verify.failed.dir}"/>
        </java>
    </target>

			<!-- Builds and jars the browser demo, and runs it -->
	<target name="test.simple-page" depends="compile, jar">
		<java
				classname="org.xhtmlrenderer.test.SimplePageTest"
				fork="${java-exec.fork.tests}">
			<classpath refid="libraries-and-dest.all"/>
			<sysproperty key="show-config" value="${show-config}"/>
			<syspropertyset>
				<propertyref prefix="xr."/>
			</syspropertyset>
			<sysproperty key="sun.java2D.opengl" value="true"/>
		</java>
      <!-- <nbprofile classname="org.xhtmlrenderer.test.SimplePageTest">
        <classpath refid="libraries-and-dest.all"/>
      </nbprofile> -->
	</target>
</project>
