<?xml version="1.0"?>
<project default="cleanup" basedir=".">

  <macrodef name="compare">
    <attribute name="expected" />
    <attribute name="output" />
    <sequential>
      <loadfile property="expected" srcfile="@{expected}">
        <filterchain><striplinebreaks /></filterchain>
      </loadfile>
      <loadfile property="output" srcfile="@{output}">
        <filterchain><striplinebreaks /></filterchain>
      </loadfile>
      <fail message="${output} not = ${expected}">
        <condition>
          <not>
            <equals arg1="${output}" arg2="${expected}" />
          </not>
        </condition>
      </fail>
    </sequential>
  </macrodef>

  <target name="cleanup">
    <delete file="../asf-logo.gif.MD5" />
    <delete file="../asf-logo.gif.md5" />
    <delete file="../asf-logo.gif.MD5SUM" />
    <delete file="../asf-logo.gif.md5sum" />
    <delete file="../asf-logo.gif.SVF" />
    <delete file="../asf-logo.gif.svf" />
    <delete file="../asf-logo.gif.pattern" />
    <delete file="../asf-logo.gif.PATTERN" />
    <delete>
      <fileset dir="checksum">
        <include name="**/*.MD5"/>
      </fileset>
    </delete>
    <delete dir="checksum/checksums" />
  </target>

  <target name="createMd5">
    <checksum file="../asf-logo.gif" fileext=".MD5" />
    <compare expected="expected/asf-logo.gif.md5" output="../asf-logo.gif.MD5" />
  </target>

  <target name="createMD5SUMformat">
    <checksum file="../asf-logo.gif" format="MD5SUM" fileext=".MD5SUM" />
    <compare expected="expected/asf-logo.gif.md5sum" output="../asf-logo.gif.MD5SUM" />
  </target>

  <target name="createSVFformat">
    <checksum file="../asf-logo.gif" format="SVF" fileext=".SVF" />
    <compare expected="expected/asf-logo.gif.svf" output="../asf-logo.gif.SVF" />
  </target>

  <target name="createPattern">
    <checksum file="../asf-logo.gif" pattern="foo{0}bar" fileext=".PATTERN" />
    <compare expected="expected/asf-logo.gif.pattern" output="../asf-logo.gif.PATTERN" />
  </target>

  <target name="setProperty">
    <checksum file="../asf-logo.gif" property="logo.MD5" />
  </target>

  <target name="verifyAsTask">
    <copy file="expected/asf-logo.gif.md5" todir=".." />
    <checksum file="../asf-logo.gif" fileext=".md5"
              verifyproperty="logo.MD5" />

    <copy file="checksum.xml" tofile="../asf-logo.gif.MD5"
          overwrite="true" />
    <checksum file="../asf-logo.gif" fileext=".MD5"
              verifyproperty="no.logo.MD5" />
  </target>

  <target name="verifyMD5SUMAsTask">
    <copy file="expected/asf-logo.gif.md5sum" todir=".." />
    <checksum file="../asf-logo.gif" fileext=".md5sum"
              verifyproperty="logo.MD5" format="MD5SUM"/>

    <copy file="checksum.xml" tofile="../asf-logo.gif.MD5SUM"
          overwrite="true" />
    <checksum file="../asf-logo.gif" fileext=".MD5SUM"
              verifyproperty="no.logo.MD5" format="MD5SUM"/>
  </target>

  <target name="verifyAsCondition">
    <copy file="expected/asf-logo.gif.md5" todir=".." />
    <condition property="logo.MD5">
      <checksum file="../asf-logo.gif" fileext=".md5" />
    </condition>

    <copy file="checksum.xml" tofile="../asf-logo.gif.MD5"
          overwrite="true" />
    <condition property="no.logo.MD5">
      <checksum file="../asf-logo.gif" fileext=".MD5" />
    </condition>
  </target>

  <target name="verifyFromProperty">
    <checksum property="checksum" file="checksum.xml"/>
    <checksum property="${checksum}" file="checksum.xml"
              verifyproperty="verify"/>
  </target>

  <target name="verifyTotal">
    <checksum totalproperty="total">
      <fileset dir="${basedir}/checksum">
        <exclude name="**/*.MD5"/>
      </fileset>
    </checksum>
  </target>

  <target name="verifyChecksumdir">
    <checksum totalproperty="total" todir="${basedir}/checksum/checksums">
      <fileset dir="${basedir}/checksum">
        <exclude name="**/*.MD5"/>
      </fileset>
    </checksum>
  </target>
    <!-- bug report 25606 -->
    <target name="verifyChecksumdirNoTotal">
      <checksum todir="${basedir}/checksum/checksums">
        <fileset dir="${basedir}/checksum">
          <exclude name="**/*.MD5"/>
        </fileset>
      </checksum>
    </target>
</project>
