<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">

<stax>

  <defaultcall function="Main"/>

  <function name="Main">
    <testcase name="'Scenario XYZ'">
      <sequence>

        <script>
          # Set to the machine where the manual test should be displayed
          testMach = 'local'     

          # Set to the machine where the MTS service is running
          serviceMach = 'local'  

          manualTestName = 'Scenario XYZ'
          manualTestTitle = 'Scenario XYZ CD Verification Title'
          manualTestDesc = 'Scenario XYZ CD Verification Manual Sequence'

          step1 = ManualTestChoice(
                  'Select the platform you are running this test on:',
                  ['AIX', 'HP/UX', 'Linux', 'Solaris', 'Windows 2000', 'other'])

          step2 = ManualTestEntry('Enter your name:')
  
          step3 = ManualTestInstruction(
          """Enter this command:
            mount /cdrom (if Unix/Linux)
          OR
            do nothing (if Windows)""")

          step4 = ManualTestEntry(
                  'Paste the output from the above command into this field:')

          step5 = ManualTestDecision(
                  'Are there any files present other than those listed above?')
       
          stepList = [step1, step2, step3, step4, step5]
        </script>

        <call function="'RunManualTest'">
           { 'name': manualTestName, 'testMach': testMach,
             'title': manualTestTitle, 'description': manualTestDesc,
             'serviceMach': serviceMach, 'stepList': stepList } 
        </call>
  
      </sequence>
    </testcase>
  </function>

  <function name="RunManualTest" scope="local">

    <function-map-args>
      <function-required-arg name="name"/>
      <function-required-arg name="testMach"/>
      <function-required-arg name="title"/>
      <function-required-arg name="description"/>
      <function-required-arg name="stepList"/>
      <function-optional-arg name="serviceMach" default="'local'"/>
    </function-map-args>

    <block name="'Manual Test %s on Machine %s' % (name, testMach)">
      <sequence>

        <message>
          'Starting manual test %s on machine %s' % \
            (manualTestName, testMach)
        </message>

        <manual-test name="manualTestName" title = "title"
                     machine="testMach" servicemachine="serviceMach">
 
          <manual-test-description>description</manual-test-description>

          <manual-test-step-list>stepList</manual-test-step-list>

        </manual-test>

        <if expr="RC == 0">
          <sequence>

            <script>
              # Check the manual test results in STAXResult
              # For this manual test, it is successful if:
              #  - all steps were checked
              #  - all expected input was provided
              #  - and the positive radio button was selected for step 5

              result = 'pass'
              msg = ("""Manual Test %s on machine %s completed successfully.
                STAXResult=%s""" % (manualTestName, testMach, STAXResult))

              for step in STAXResult:
                if step['isChecked'] == '1' and step['isAnswered'] == '1':
                  if step['stepNumber'] == '5':
                    if step['answer'] != '1':
                      result = 'fail'
                      msg = ("""Manual Test %s on machine %s:  
                        Step 5 decision was 'No'
                        STAXResult=%s""" % (manualTestName, testMach, STAXResult))
                      break
                else:
                  result = 'fail'
                  msg = ("""Manual Test %s on machine %s:
                    Step %s is not checked and/or not answered
                    STAXResult=%s""" % \
                    (manualTestName, testMach, step['stepNumber'], STAXResult))
                  break

            </script>

            <tcstatus result="result">msg</tcstatus>

            <message>msg</message>

          </sequence>

          <else>
            <tcstatus result="'fail'">
              ("""Manual Test %s on machine %s failed with RC=%s STAFResult=%s
                STAXResult=%s""" % \
                (manualTestName, testMach, RC, STAFResult, STAXResult))
            </tcstatus>
          </else>

        </if>

      </sequence>
    </block>
  </function>

</stax>