<?xml version="1.0" encoding="utf-8"?>
<!--
   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

       https://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="all" xmlns:au="antlib:org.apache.ant.antunit">

  <available property="jdk1.4+" classname="java.lang.CharSequence"/>  
  <condition property="some.regexp.support">
    <or>
      <isset property="jdk1.4+"/>
      <isset property="apache.regexp.present"/>
      <isset property="apache.oro.present"/>
    </or>
  </condition>    
    
  <target name="testname1">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <resource name="foo" />
            <resource name="bar" />
            <resource name="baz" />
            <resource name="boo" />
            <resource name="bang" />
          </resources>
          <name name="ba?" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testname2">
    <au:assertTrue>
      <resourcecount when="equal" count="3">
        <restrict>
          <resources>
            <file file="foo" />
            <resource name="foo" />
            <file file="foo" basedir="${basedir}" />
          </resources>
          <name name="foo" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="name" depends="testname1,testname2" />

  <target name="testexists">
    <au:assertTrue>
      <resourcecount when="equal" count="1">
        <restrict>
          <resources>
            <file file="idonotexist" />
            <resource name="foo" />
            <resource name="foo" exists="false" />
          </resources>
          <exists />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testinstanceoftype1">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <file file="foo" />
            <url url="https://ant.apache.org/index.html" />
            <resource name="foo" />
            <string value="foo" />
            <file file="bar" />
          </resources>
          <instanceof type="file" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testinstanceoftype2">
    <typedef name="file" uri="test"
             classname="org.apache.tools.ant.types.resources.FileResource" />
    <au:assertTrue>
      <resourcecount when="equal" count="1">
        <restrict>
          <resources>
            <url file="foo" />
            <file file="bar" xmlns="test" />
          </resources>
          <instanceof type="test:file" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testinstanceoftype3">
    <typedef name="file" uri="test"
             classname="org.apache.tools.ant.types.resources.FileResource" />
    <au:assertTrue>
      <resourcecount when="equal" count="1">
        <restrict>
          <resources>
            <url file="foo" />
            <file file="bar" xmlns="test" />
          </resources>
          <instanceof type="file" uri="test" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="instanceoftype"
    depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" />

  <target name="testinstanceofclass">
    <au:assertTrue>
      <resourcecount when="equal" count="7">
        <restrict>
          <resources>
            <filelist dir="${basedir}" files="a,b,c,d,e,f,g" />
          </resources>
          <instanceof class="org.apache.tools.ant.types.Resource" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="instanceof" depends="instanceoftype,testinstanceofclass" />

  <target name="testtype">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
             <file file="${basedir}" />
             <file file="${ant.file}" />
             <resource directory="true" />
             <resource directory="false" />
          </resources>
          <type type="dir" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testdate">
    <au:assertTrue>
      <resourcecount when="equal" count="3">
        <restrict>
          <resources>
             <resource lastmodified="4" />
             <resource lastmodified="5" />
             <resource lastmodified="6" />
             <resource lastmodified="7" />
             <resource lastmodified="8" />
          </resources>
          <date when="after" millis="5" granularity="0" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testsize">
    <au:assertTrue>
      <resourcecount when="equal" count="4">
        <restrict>
          <resources>
             <resource size="4" />
             <resource size="5" />
             <resource size="6" />
             <resource size="7" />
             <resource size="8" />
          </resources>
          <size when="le" size="7" />
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testand">
    <au:assertTrue>
      <resourcecount when="equal" count="1">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <name name="f?" />
            <size size="3" />
          </and>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testor">
    <au:assertTrue>
      <resourcecount when="equal" count="3">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <name name="f?" />
            <size size="3" />
          </or>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testnot">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <size size="3" />
          </not>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testnone">
    <au:assertTrue>
      <resourcecount when="equal" count="1">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <name name="f?" />
            <size size="3" />
          </none>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testmajority1">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <name name="f?" />
            <size size="3" />
            <instanceof type="string" />
          </majority>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testmajority2">
    <au:assertTrue>
      <resourcecount when="equal" count="3">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <majority>
            <name name="f?" />
            <size size="3" />
            <instanceof type="resource" />
          </majority>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testmajority3">
    <au:assertTrue>
      <resourcecount when="equal" count="3">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <majority allowtie="true">
            <name name="f?" />
            <size size="3" />
            <instanceof type="string" />
            <exists />
          </majority>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testmajority4">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <string value="fee" />
            <resource name="fi" size="3" />
            <resource name="fo" />
            <resource name="fum" />
          </resources>
          <majority allowtie="false">
            <name name="f?" />
            <size size="3" />
            <instanceof type="string" />
            <exists />
          </majority>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testcontains">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <string value="foo" />
            <string value="bar" />
            <string value="baz" />
          </resources>
          <contains text="b"/>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testcontainsregexp" if="some.regexp.support">
    <au:assertTrue>
      <resourcecount when="equal" count="2">
        <restrict>
          <resources>
            <string value="foo" />
            <string value="bar" />
            <string value="baz" />
          </resources>
          <containsregexp expression="^b..$"/>
        </restrict>
      </resourcecount>
    </au:assertTrue>
  </target>

  <target name="testcompare">
    <au:assertTrue>
      <and>
        <!-- basic test, natural ordering -->
        <resourcecount count="3">
          <restrict>
            <compare when="greater" against="each">
              <control><string value="b" /></control>
            </compare>
            <resources>
              <string value="a" />
              <string value="b" />
              <string value="c" />
              <string value="d" />
              <string value="e" />
            </resources>
          </restrict>
        </resourcecount>
        <!-- one comparator, default when/against -->
        <resourcecount count="5">
          <restrict>
            <compare>
              <control><string value="." /></control>
              <size />
            </compare>
            <resources>
              <string value="a" />
              <string value="b" />
              <string value="c" />
              <string value="d" />
              <string value="e" />
            </resources>
          </restrict>
        </resourcecount>
        <!-- multiple controls, comparators -->
        <resourcecount count="3">
          <restrict>
            <compare when="greater" against="each">
              <control>
                <string value="a" />
                <string value="b" />
                <string value="bb" />
                <string value="c" />
                <string value="ccc" />
              </control>
              <name />
              <size />
            </compare>
            <resources>
              <string value="a" />
              <string value="bbbb" />
              <string value="ccc" />
              <string value="cccc" />
              <string value="d" />
              <string value="e" />
            </resources>
          </restrict>
        </resourcecount>
      </and>
    </au:assertTrue>
  </target>

  <target name="majority"
          depends="testmajority1,testmajority2,testmajority3,testmajority4" />

  <target name="logical"
          depends="testand,testor,testnone,testnot,majority" />

  <target name="all"
    depends="name,testexists,instanceof,testtype,testdate,testsize,testcontains,testcontainsregexp,logical,testcompare" />

  <!-- 
    The tests for oata.types.selectors.ModifiedSelectorTest as 
    ResourceSelector are in its test-buildfile src\etc\testcases\types\selectors.xml. 
  -->

</project>
