<?xml version="1.0" encoding="UTF-8"?>
<!-- 
============================================================================ 
Name        : test_emakeengine.ant.xml 
Part of     : Helium AntLib

Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
All rights reserved.
This component and the accompanying materials are made available
under the terms of the License "Eclipse Public License v1.0"
which accompanies this distribution, and is available
at the URL "http://www.eclipse.org/legal/epl-v10.html".

Initial Contributors:
Nokia Corporation - initial contribution.

Contributors:

Description:

============================================================================
-->
<project name="helium-antlib-imaker-emakeengine-unittest" xmlns:au="antlib:org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
    <description>Helium Antlib imaker unittests.</description>

    <taskdef resource="com/nokia/helium/imaker/ant/antlib.xml" uri="http://www.nokia.com/helium"/>
    <property name="epocroot" location="${basedir}/../epocroot_task" />
    <property name="epocroot.temp" location="${epocroot}/temp" />

    <!-- is called prior to the test -->
    <target name="setUp">
        <echo>-------------------------------------------------------------------------------</echo>
        <delete dir="${epocroot.temp}" failonerror="false" />
        <delete dir="${epocroot}/epoc32" failonerror="false" />
        <mkdir dir="${epocroot.temp}" />
    </target>

    <!-- is called after the test, even if that caused an error -->
    <target name="tearDown">
        <delete dir="${epocroot.temp}" failonerror="false" />
        <delete dir="${epocroot}/epoc32" failonerror="false" />
        <echo>-------------------------------------------------------------------------------</echo>
    </target>

    <target name="test-imaker-defaultconfig">
        <hlm:emakeEngine id="imaker.ec" />
        <hlm:imaker epocroot="${epocroot}" 
            output="${epocroot.temp}/output.log"
            engineRefId="imaker.ec">
            <hlm:imakerconfiguration>
                <makefileset>
                    <include name="**/product/*ui.mk" />
                </makefileset>
                <targetset>
                    <include name="core" />
                    <include name="langpack_\d+" />
                </targetset>
            </hlm:imakerconfiguration>
        </hlm:imaker>
        <au:assertFileExists file="${epocroot.temp}/output.log" />
    </target>

    <target name="test-imaker-defaultconfig-custom-args">
        <hlm:emakeEngine id="imaker.ec">
            <arg value="--autodepends=1" />
        </hlm:emakeEngine>
        <hlm:imaker epocroot="${epocroot}" 
            output="${epocroot.temp}/output.log"
            engineRefId="imaker.ec"
            verbose="true">
            <hlm:imakerconfiguration>
                <makefileset>
                    <include name="**/product/*ui.mk" />
                </makefileset>
                <targetset>
                    <include name="core" />
                    <include name="langpack_\d+" />
                </targetset>
            </hlm:imakerconfiguration>
        </hlm:imaker>
        <au:assertLogContains text="--autodepends=1" />
        <au:assertFileExists file="${epocroot.temp}/output.log" />
    </target>

    <target name="test-imaker-defaultconfig-with-cust-missing-template">
        <hlm:emakeEngine id="imaker.ec" template="missing.mk.ftl">
            <arg value="--autodepends=1" />
        </hlm:emakeEngine>
        <au:expectfailure message="Could not find template file:">
            <hlm:imaker epocroot="${epocroot}" 
            	output="${epocroot.temp}/output.log"
                engineRefId="imaker.ec"
                verbose="true">
                <hlm:imakerconfiguration>
                    <makefileset>
                        <include name="**/product/*ui.mk" />
                    </makefileset>
                    <targetset>
                        <include name="core" />
                        <include name="langpack_\d+" />
                    </targetset>
                </hlm:imakerconfiguration>
            </hlm:imaker>
        </au:expectfailure>
        <au:assertFileDoesntExist file="${epocroot.temp}/output.log" />
    </target>

    <target name="test-imaker-defaultconfig-with-cust-invalid-template">
        <hlm:emakeEngine id="imaker.ec" template="../emake_data/invalid.mk.ftl">
            <arg value="--autodepends=1" />
        </hlm:emakeEngine>
        <au:expectfailure message="Error while rendering the makefile template:">
            <hlm:imaker epocroot="${epocroot}" 
                output="${epocroot.temp}/output.log"
                engineRefId="imaker.ec"
                verbose="true">
                <hlm:imakerconfiguration>
                    <makefileset>
                        <include name="**/product/*ui.mk" />
                    </makefileset>
                    <targetset>
                        <include name="core" />
                        <include name="langpack_\d+" />
                    </targetset>
                </hlm:imakerconfiguration>
            </hlm:imaker>
        </au:expectfailure>
        <au:assertLogContains text="invalid.mk.ftl" />
        <au:assertFileDoesntExist file="${epocroot.temp}/output.log" />
    </target>

    <target name="test-imaker-defaultconfig-with-cust-template">
        <hlm:emakeEngine id="imaker.ec" template="../emake_data/cust.mk.ftl">
            <arg value="--autodepends=1" />
        </hlm:emakeEngine>
        <hlm:imaker epocroot="${epocroot}" 
            output="${epocroot.temp}/output.log"
            engineRefId="imaker.ec"
            verbose="true">
            <hlm:imakerconfiguration>
                <makefileset>
                    <include name="**/product/*ui.mk" />
                </makefileset>
                <targetset>
                    <include name="core" />
                    <include name="langpack_\d+" />
                </targetset>
            </hlm:imakerconfiguration>
        </hlm:imaker>
        <au:assertLogContains text="Loading template:" />
        <au:assertLogContains text="cust.mk.ftl" />
        <au:assertFileExists file="${epocroot.temp}/output.log" />
    </target>

</project>
