baseclientjava.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 214 行
SVN-BASE
214 行
@@PACKAGE_HEADER@@
import java.io.IOException;
import java.io.PrintStream;
import java.util.Vector;
import java.util.Enumeration;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Screen;
import javax.microedition.lcdui.TextField;
import com.sun.tck.cldc.lib.MultiTest;
import com.sun.tck.cldc.lib.Status;
import com.sun.tck.midp.javatest.agent.MIDletAgent;
import com.sun.tck.j2me.services.messagingService.J2MEDistributedTest;
public abstract class MIDPDistributedInteractiveTest extends J2MEDistributedTest {
private Status status;
private String title = "Initializing ...";
private String question;
private Form infoForm; // Description/Introduction form
private Displayable testDisplayable; // First display of test class
public Display display = null;
protected boolean done = false;
private String from;
private boolean received = false;
public synchronized void waitForMessage() {
try {
while (!received)
wait(10000);
received = false;
} catch (InterruptedException e) {
}
}
public synchronized void waitForMessage(int timeout) {
try {
while (!received)
wait(timeout);
received = false;
} catch (InterruptedException e) {
}
}
public synchronized void messageReceived() {
received = true;
notifyAll();
}
public MIDPDistributedInteractiveTest(String name) {
super(name);
}
public Status run(String[] argv, PrintStream log, PrintStream ref) {
setUp();
Status allTestStatus = super.run(argv, log, ref);
try {
send(from, new String[] {"endRun"});
waitForMessage();
} catch (IOException e) {
}
return allTestStatus;
}
/**
* General set up method.
*/
protected void setUp() {
display = MIDletAgent.getContextDisplay();
infoForm = new Form(title);
}
/**
* Checks the test's result and declares pass/fail.
* Overridden by self-checking tests to determine the test result after
* user presses the Finish button.
* This method should be overriden if the derived test uses the Done user
* interface. The checkResult method should invoke setStatus after
* determining the test result.
*/
protected void checkResult() {
setStatus(Status.failed("No result checking was performed by test."));
}
/**
* Add another test into the set for consideration.
*
* @param status The outcome of this test case. It will be ignored.
*/
protected void addStatus(Status s) {
boolean passed = false;
done = false;
display.setCurrent(infoForm);
// Ignores input parameter
passed = waitForDone();
super.addStatus(passed ? Status.passed("OKAY") :
Status.failed("Some problems occured. See log"
+ " for details."));
cleanUp();
}
/**
* Sets titles of info and end forms.
*
* @param title Title to be displayed.
*/
protected void setFormTitle(String title) {
infoForm.setTitle(title);
}
/**
* Updates info form with new instructions.
*
* @param info Instruction for a current test.
*/
protected void addInfo(String info) {
for (int i = 0; i < infoForm.size(); i++) {
infoForm.delete(i);
}
infoForm.append(info);
}
/**
* Called when the test is done.
*/
protected void cleanUp() {
status = null;
display.setCurrent(new Form(null));
doTestCleanUp();
}
/**
* Performs cleanup that is specific to the derived test.
* Test should override this method if the test needs to do cleanup
* before exiting.
*/
protected void doTestCleanUp() {}
/**
* Waits for the user to indicate test completion.
* Times out if the user doesn't respond within the timeout limit.
*
* @exception InterruptedException If another thread has interrupted the
* current thread.
*/
public boolean waitForDone() {
// wait until server is done
synchronized (this) {
try {
while (!done) {
wait(100);
}
}
catch (InterruptedException e) {
log.println(e.toString());
return false;
}
}
return true;
}
/**
* This method is called when message client has been closed.
* It sets <code>done</code> variable to true to notify that test execution
* completed.
*/
public synchronized void handle_done(String from, String[] args) {
this.from = from;
ref.println("This test done");
done = true;
notifyAll();
}
public synchronized void handle_endRun(String from, String[] args) {
ref.println("All tests done");
notifyAll();
}
/**
* Sets pass/fail test status.
* Called by listener when the user indicates that the test is done by
* pressing the Yes button, the No button.
*
* @see javasoft.sqe.javatest.Status
*
* @param status Pass/Fail status.
*/
protected synchronized void setStatus(Status status) {
this.status = status;
notify();
}
/**
* Message printed if test passes.
* Set by invoking setStatusMessages().
*/
protected String passMessage = "";
/**
* Message printed if test fails.
* Set by invoking setStatusMessages().
*/
protected String failMessage = "";
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?