Java DTV API 1.3
18-Nov-2009

com.sun.dtv.test
Class TestHarness

java.lang.Object
  extended by com.sun.dtv.test.TestHarness

public class TestHarness
extends Object

Provides an entry point and a set of tooling for test cases.

Test Code Example

A test should also define main as follows:
 import com.sun.dtv.Report;
 import com.sun.dtv.TestHarness;
 import com.sun.dtv.TestCase;

 public class MyTest implements TestCase {

      private int id = 1234;
      private String title = "Arithmetic Test";

      public MyTest() {
      }

      public static void main(String[] args) {
          // Start the corresponding TestCase's main method
          TestHarness.start(new MyTest(), args);
      }

      public int getTestId() {
          // Return the id of the test (either the hardcoded one or
          // that passed through -testid <id>)
          return id;
      }

      public String getTestTitle() {
          // Return the title of the test (either the hardcoded one or
          // that passed through -testtitle <test>)
          return title;
      }

      public Report run(String[] args) {
          // 1. evaluate 'args' to particular parameter specific to this
                testcase and to extract the testid and/or testtitle
                If -testid <id>, then copy value into id
                If -testtitle <title>, then copy value into title
                ...

          // 2. (depending on test) synchronize with server
          TestHarness.sendTrigger(TestHarness.TRIGGER_SYNCHRONIZE,
                                  getTestId(),
                                  "[SYNC#2881] Switch transport stream encoding NOW!");

          // 3. test code that does something with that other encoding
          if (1 + 1 == 2)
             return Report.passed(this, "OK");
          else
             return Report.failed(this, "1 + 1 did not make 2");
      }
 }


Field Summary
static PrintStream log
          The default output stream on a given platform to store test reports.
static int TRIGGER_SYNCHRONIZE
          A triggerType used to request synchronization on a given event between the test client and the test server.
static int TRIGGER_TERMINATED
          A triggerType used to signal that the test identified by testId is now considered finished.
 
Constructor Summary
TestHarness()
           
 
Method Summary
static void sendReport(int testid, Report report)
          This alias method allows to send the report of the given testcase back to the test server.
static void sendTrigger(int triggerType, int testId, String message)
          This generic method allows to send a specific trigger to the test server.
static void start(TestCase test, String[] args)
          This method is responsible for launching a given test case, handling the resulting report and ending the current test application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRIGGER_SYNCHRONIZE

public static final int TRIGGER_SYNCHRONIZE
A triggerType used to request synchronization on a given event between the test client and the test server.

It means that the test client has reached a specific state required for the test and that it is awaiting acknowledgment to continue the test. Consequently, the implementation of sendTrigger(triggerType, testId, message) will wait until such a confirmation is received before returning.

Along with the triggerType and the testId, the application may use the message argument to specify which synchronization milestone it has reached. It is recommended to compose that message with a part that can be parsed (for example an integer code) and a human readable part (i.e. a short description) to allow both a automated (test server) and/or human supported implementation of this feature.

See Also:
sendTrigger(int,int,String), Constant Field Values

TRIGGER_TERMINATED

public static final int TRIGGER_TERMINATED
A triggerType used to signal that the test identified by testId is now considered finished.

Along with the triggerType and the testId when calling sendTrigger(triggerType, testId, message), the application must supply the resulting Report in the message argument by calling the corresponding Report.toString() method.

See Also:
sendTrigger(int,int,String), Constant Field Values

log

public static final PrintStream log
The default output stream on a given platform to store test reports. It is left to the implementation where and how to store this log stream. Implementations may choose to store it as a file on the file system or to forward this stream on a serial or networking interface that is connected to the test server.

This log must be configured with autoFlush=true.

See Also:
java.io#PrintStream(OutputStream, boolean)
Constructor Detail

TestHarness

public TestHarness()
Method Detail

sendTrigger

public static void sendTrigger(int triggerType,
                               int testId,
                               String message)
                        throws UnsupportedOperationException
This generic method allows to send a specific trigger to the test server. Depending on triggerType, the method will behave differently.

Currently the following two triggers must be supported by the implementation. This specification may define new triggers in subsequent versions:

It is left to the implementation how to provide the communication mean between the test client and the test server. It may use one of the following technologies: Serial, USB, Networking, ...

However, at last resort and in conjunction with any communication mean between client and server, the implementation shall display a dialog with the corresponding message to the user or test operator on the screen of the platform.

Parameters:
triggerType - one of any TRIGGER_ constant defined in this class.
testId - an integer value identifying the test. This value can be defined by the test case itself or via arguments (see TestCase).
message - depending on the triggerType, this string may have different meaning. This argument may be null.
Throws:
UnsupportedOperationException - if triggerType is no supported by the platform.

sendReport

public static void sendReport(int testid,
                              Report report)
                       throws NullPointerException
This alias method allows to send the report of the given testcase back to the test server. If no return channel is defined, according to the description of TestHarness.TRIGGER_TERMINATED, the report string will be displayed on the screen.

This method is equivalent to calling:

 TestHarness.sendTrigger(TestHarness.TRIGGER_TERMINATED, 
                         testid, 
                         report.toString());

Parameters:
testid - an integer value identifying the test. This value can be defined by the test case itself or via arguments (see TestCase).
report - The report to be sent.
Throws:
NullPointerException - if report is null

start

public static void start(TestCase test,
                         String[] args)
This method is responsible for launching a given test case, handling the resulting report and ending the current test application.

If the platform provides a return channel, it will return the report to the test server using sendReport() allowing thereby the server to start the next test.

The implementation must call at last Report.exit() method which consequently provokes the application to end.

An implementation is likely to be based on:

 if (test != null) {
    Report r = test.run(args);
    TestHarness.sendReport(test.getTestId(), r);
    r.exit();
 }

Parameters:
test - The test case instance to be launched.
args - The list of argument that are passed to the test cases. Usually are those from the command line.

Java DTV API 1.3
18-Nov-2009

Copyright © 2008-2009 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.

U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.Products covered by and information contained in this service manual are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Use of this document is subject to license terms.