buildframework/helium/tools/common/test/test_common.ant.xml
author wbernard
Tue, 27 Apr 2010 08:33:08 +0300
changeset 587 85df38eb4012
parent 217 0f5e3a7fb6af
child 588 c7c26511138f
permissions -rw-r--r--
helium_9.0-a7879c935424

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

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="test_common" xmlns:au="org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
    <description>
    Testing targets.
    </description>
    
    <property environment="env"/>
    
    <property name="helium.dir" location="../../.." />
    <import file="../../../helium.ant.xml"/>
        
    <target name="test-text-config">
        <hlm:configuration file="${helium.dir}/tests/data/ant_config_test.txt"/>
        <au:assertPropertyEquals name="text.a" value="text.value.A"/>
        <au:assertPropertyEquals name="text.b" value="text.value.B"/>
        <au:assertPropertyEquals name="text.c" value="text.value.A"/>
    </target>

    
    <target name="test-xml-config">
        <hlm:configuration file="${helium.dir}/tests/data/ant_config_test.xml"/>
        <au:assertPropertyEquals name="xml.c" value="C"/>
        <au:assertPropertyEquals name="xml.d" value="D"/>
    </target>
    
    
    <target name="test-text-config-from-fileset">
        <hlm:configuration>
            <fileset file="../../../tests/data/ant_config_test.txt"/>
        </hlm:configuration>
        <au:assertPropertyEquals name="text.a" value="text.value.A"/>
        <au:assertPropertyEquals name="text.b" value="text.value.B"/>
    </target>
    
    
    <target name="test-xml-config-from-fileset">
        <hlm:configuration>
            <fileset file="../../../tests/data/ant_config_test.xml"/>
        </hlm:configuration>
        <au:assertPropertyEquals name="xml.c" value="C"/>
        <au:assertPropertyEquals name="xml.d" value="D"/>
    </target>
    
    
    <target name="test-password-log-filtering">
        <property name="password" value="foobarbaz"/>
        <if>
            <available file="${build.output.dir}" type="dir"/>
            <then>
                <record name="${build.log}" action="start"/>
                <echo>Before password filtering</echo>
                <hlm:filterRecordStartMacro pattern="${password}"/>
                <echo>Logging password: ${password}</echo>
                <hlm:filterRecordStopMacro/>
                <echo>After password filtering</echo>
                <record name="${build.log}" action="stop"/>
            </then>
        </if>
    </target>
    
    
    <target name="test-record">
        <echo file="${helium.dir}/record-test.txt">foo</echo>
        <record name="${helium.dir}/record-test.txt" action="stop" append="true"/>
        <loadfile srcFile="${helium.dir}/record-test.txt" property="record.test"/>
        <au:assertPropertyEquals name="record.test" value="foo"/>
        <delete file="${helium.dir}/record-test.txt"/>
    </target>
    
    <target name="test-assert">
        <assert>
            <bool>
                <isset property="foobar"/>    
            </bool>
        </assert>
    </target>
    
    
    <target name="test-hlm-assert">
        <hlm:assert>
            <isset property="foobar"/>
        </hlm:assert>
        <au:assertLogContains text="Warning: "/>        
    </target>
            
    <target name="test-hlm-assertFileExists">
        <hlm:assertFileExists file="missingFile.txt"/>
        <au:assertLogContains text="Warning: "/>
        <property name="hlm.enable.asserts" value="true"/>
        <trycatch property="hlm-assertFileExists.thrown">
            <try>
                <hlm:assertFileExists file="missingFile.txt"/>
            </try>
        </trycatch>
        <au:assertPropertySet name="hlm-assertFileExists.thrown"/>
        <echo file="assert_test_tempFile.txt">Foobar</echo>
        <hlm:assertFileExists file="assert_test_tempFile.txt"/>
        <delete file="assert_test_tempFile.txt"/>
    </target>
    
    
    <target name="test-jython">
        <script language="jython" setbeans="false">
print "It works!"
print dir(project)
print project.getName()
import re
print re.match(r"foo(?=bar)", r"foobar")

import net.sf.antcontrib.logic
runtarget = net.sf.antcontrib.logic.RunTargetTask()
print runtarget
runtarget.setProject(project)
runtarget.setTarget('hello')
runtarget.execute()

#from java.lang import Class
#tasks = project.getTaskDefinitions()
#signal_macro_def = tasks.get('signal')
#signal_macro = signal_macro_def.newInstance()
#signal_macro.setDynamicAttribute('name', 'foobar')
#signal_macro.setProject(project)
#print signal_macro
#print dir(signal_macro)
#signal_macro = signal_macro.cast('MacroInstance')
#signal_macro = project.createTask('org.apache.tools.ant.taskdefs.MacroInstance')
#print dir(signal_macro)
#signal_macro.execute()
        </script>
    </target>

    
    <target name="try-xmltask">
        <xmltask dest="xmltask_test.xml">
            <insert path="/"  >
            <![CDATA[
            <test/>
            ]]>
            </insert>
        </xmltask>
        <script language="jython" setbeans="false">
result = ",".join([str(i) for i in range(10000)])
project.setProperty("xml.test.list", str(result))
        </script>
        <echo>${xml.test.list}</echo>
        <for param="number" list="${xml.test.list}">
            <sequential>
                <xmltask source="xmltask_test.xml"
                         dest="xmltask_test.xml">
                    <insert path="/test">
                       <![CDATA[
            <element>@{number}</element>
            ]]>
                   </insert>
                </xmltask>
            </sequential>
        </for>
    </target>
    
    
    <!-- Tests the assertXmlEqual task. -->
    <target name="test-assertXmlEqual">
        <string id="control.xml" value="&lt;foo/&gt;"/>
        <string id="test_good.xml" value="&lt;foo/&gt;"/>
        <string id="test_bad.xml" value="&lt;foobar/&gt;"/>
        <hlm:assertXmlEqual control="control.xml" test="test_good.xml" failonerror="false"/>
        <trycatch property="hlm-assertXmlEqual.thrown">
            <try>
                <hlm:assertXmlEqual control="control.xml" test="test_bad.xml"/>
            </try>
        </trycatch>
        <au:assertPropertySet name="hlm-assertXmlEqual.thrown"/>
    </target>
    
    <!--<target name="test-ccm-task">
        <ccm/>
    </target>-->
    
    <!-- Tests the touch functionality. -->
    <target name="test-hlm-touch">
        <hlm:touch>
            <path>
                <pathelement path="${helium.build.dir}"/>
            </path>
        </hlm:touch>
    </target>

    
    <!-- Test user flow graph creation -->
    <target name="test-helium-user-graph">
        <runtarget target="helium-user-graph"/>
        <au:assertFileExists file="${basedir}/build/doc/user_graph.dot.png"/>
        <delete dir="${basedir}/build/doc"/>
    </target>


    <target name="test-sisfiles">
        <delete dir="${build.cache.dir}/helium/temp_drive/output/logs/${build.id}_metadata_db"/>
        <tempfile destdir="${build.cache.dir}" property="sisfiles.tempconfig.file" suffix=".xml"/>
        <tempfile destdir="${build.cache.dir}" property="sis.config.file.parsed" suffix=".xml"/>
        <condition property="echocmd" value="${helium.dir}/tools/common/test/echo.bat" else="echo">
            <os family='windows'/>
        </condition>
        <echoxml  file="${sisfiles.tempconfig.file}">
            <build>
                <config abstract="true">
                    <set name="makesis.tool" value="${echocmd}"/>
                    <set name="signsis.tool" value="${echocmd}"/>
                    <set name="build.sisfiles.dir" value="${build.cache.dir}/sisfilestest"/>
                    <set name="key" value=""/>
                    <set name="cert" value=""/>
                    <config>
                        <set name="name" value=""/>
                        <set name="path" value=""/>
                    </config>
                </config>
            </build>
        </echoxml>
        <antcall target="sisfiles">
            <param name="sis.config.file" value="${sisfiles.tempconfig.file}"/>
            <param name="sis.config.file.parsed" value="${sis.config.file.parsed}"/>
            <param name="build.sisfiles.dir" value="${build.cache.dir}/helium/temp_drive/output/sisfiles"/>
            <param name="temp.build.dir" value="${build.cache.dir}/helium/temp_drive/output/temp_build_files"/>
            <param name="build.drive" value="${build.cache.dir}/helium/temp_drive/"/>
            <param name="build.cache.log.dir" value="${build.cache.dir}/helium/temp_drive/output/logs"/>
            <param name="metadata.dbfile" value="${build.cache.dir}/helium/temp_drive/output/logs/${build.id}_metadata_db"/>
            <param name="build.log.dir" value="${build.cache.dir}/helium/temp_drive/output/logs"/>            
            <param name="post.log.dir" value="${build.cache.dir}/helium/temp_drive/output/logs/post"/>
        </antcall>
        <au:assertFileExists file="${build.cache.dir}/helium/temp_drive/output/temp_build_files/sis_build.ant.xml"/>
        <delete file="${sisfiles.tempconfig.file}"/>
        <delete file="${sis.config.file.parsed}"/>
    </target>

    <target name="test-exec">
        <au:expectfailure>
            <hlm:exec executable="123"/>
        </au:expectfailure>
        <hlm:exec executable="perl" outputproperty="testexec">
            <arg value="-e"/>
            <arg value="print 'hi'"/>
        </hlm:exec>
        <au:assertPropertyEquals name="testexec" value="hi"/>
    </target>
    
    
    <target name="test-grep-macro">
        <hlm:grepMacro filename="${helium.dir}/tests/data/logs/test_log.log" regexp="([^\\]*.confml)$" output="confml.file.list"/>
        <au:assertPropertySet name="confml.file.list"/>
    </target>

</project>