<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed 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

          http://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.
-->

<!--  Contains the schema definition for Android test definitions xml -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://schemas.android.com/testrunner/test_defs/1.0"
    xmlns="http://schemas.android.com/testrunner/test_defs/1.0"
    elementFormDefault="qualified">

    <xs:element name="test-definitions">
        <xs:complexType>
            <xs:sequence>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="test" type="javaTestType" />
                    <xs:element name="test-native" type="nativeTestType" />
                    <xs:element name="test-host" type="hostTestType" />
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!-- Generic, abstract test definition. Contains attributes common to all
    test types. -->
    <xs:complexType name="testType">

        <!-- Self-descriptive name used to uniquely identify the test. -->
        <xs:attribute name="name" type="xs:string" use="required" />

        <!-- File system path, relative to Android build root, to this
        package's Android.mk file. -->
        <xs:attribute name="build_path" type="xs:string" use="required" />

        <!-- Include test in continuous test system. -->
        <xs:attribute name="continuous" type="xs:boolean" use="optional"
            default="false" />

        <!-- Include test as part of named suite. -->
        <xs:attribute name="suite" type="xs:string" use="optional" />

        <!--  Short description (typically less than 60 characters) about this
        test. -->
        <xs:attribute name="description" type="xs:string" use="optional" />

        <!--  Extra arguments to append to build command when building this
        test. -->
        <xs:attribute name="extra_build_args" type="xs:string"
                    use="optional" />
    </xs:complexType>

    <!-- Java on device instrumentation test.

      The test attributes map to the following commands:
      (if class is defined)
          adb shell am instrument -w <package>/<runner>
      (else)
          adb shell am instrument -w -e class <class> <package>/<runner>
    -->
    <xs:complexType name="javaTestType">
        <xs:complexContent>
            <xs:extension base="testType">

                <!--  Android application package that contains the tests. -->
                <xs:attribute name="package" type="xs:string" use="required" />

                <!-- Fully qualified Java test class to run. -->
                <xs:attribute name="class" type="xs:string" use="optional" />

                <!-- Fully qualified InstrumentationTestRunner to execute. -->
                <xs:attribute name="runner" type="xs:string" use="optional"
                    default="android.test.InstrumentationTestRunner" />

                <!-- Build name of Android package this test targets. These
                targets are defined in the coverage_targets.xml file.  Used as
                basis for code coverage metrics. If omitted, code coverage will
                not be supported for this test. -->
                <xs:attribute name="coverage_target" type="xs:string"
                    use="optional" />

            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Native (C/C++) on device tests.

    The native test attributes map to the following commands:
        make <build_path>/Android.mk <extra_build_args>
        adb sync
        for test_prog in <tests built>; do
            adb shell "/system/bin/${test_prog} >/dev/null 2>&1;echo \$?"
            adb shell "rm /system/bin/${test_prog}"
        done
    -->
    <xs:complexType name="nativeTestType">
        <xs:complexContent>
            <xs:extension base="testType" />
            <!-- no additional attributes -->
        </xs:complexContent>
    </xs:complexType>

    <!-- Host java tests.

    Uses hosttestlib to execute tests on host. Maps to following command:
        java -cp <libs>:jar_name com.android.hosttest.DeviceTestRunner \
            <class> -s <device serial> -p <app build path>
    -->
    <xs:complexType name="hostTestType">
        <xs:complexContent>
            <xs:extension base="testType">

                <!--  The test class to run. Must extend DeviceTestSuite, and
                implement a public static suite() method that returns a Test to
                run. -->
                <xs:attribute name="class" type="xs:string" use="required" />

                <!-- built jar name of host library that includes the tests. -->
                <xs:attribute name="jar_name" type="xs:string" use="required" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>