AutoTesterpublic class AutoTester extends AutoTesterBase implements AutoTesterInterfaceInstalls/Updates a test suite, runs the first MIDlet in the suite in a loop
specified number of iterations or until the new version of the suite is not
found, then removes the suite.
The MIDlet uses these application properties as arguments:
- arg-0: URL for the test suite
- arg-1: Used to override the default domain used when installing
an unsigned suite. The default is maximum to allow the runtime API tests
be performed automatically without tester interaction. The domain name
may be followed by a colon and a list of permissions that must be allowed
even if they are not listed in the MIDlet-Permissions attribute in the
application descriptor file. Instead of the list a keyword "all" can be
specified indicating that all permissions must be allowed, for example:
operator:all.
- arg-2: Integer number, specifying how many iterations to run
the suite. If argument is not given or less then zero, then suite
will be run until the new version of the suite is not found.
If arg-0 is not given then a form will be used to query the tester for
the arguments. |
Fields Summary |
---|
private static final String | AUTOTEST_STORESettings database name. | private static final int | URL_RECORD_IDRecord ID of URL. | private static final int | DOMAIN_RECORD_IDRecord ID of the security domain for unsigned suites. | private static final int | SUITE_ID_RECORD_IDRecord ID of suite ID. | private static final int | LOOP_COUNT_RECORD_IDRecord ID of loopCount | int | suiteIdID of installed test suite. |
Constructors Summary |
---|
public AutoTester()Create and initialize a new auto tester MIDlet.
super();
if (url != null) {
startBackgroundTester();
} else if (restoreSession()) {
// continuation of a previous session
startBackgroundTester();
} else {
/**
* No URL has been provided, ask the user.
*
* commandAction will subsequently call startBackgroundTester.
*/
getUrl();
}
|
Methods Summary |
---|
private void | endSession()End the testing session.
try {
RecordStore.deleteRecordStore(AUTOTEST_STORE);
} catch (Throwable ex) {
// ignore
}
notifyDestroyed();
| public void | installAndPerformTests(com.sun.midp.midletsuite.MIDletSuiteStorage midletSuiteStorage, Installer inp_installer, java.lang.String inp_url)Installs and performs the tests.
MIDletInfo midletInfo;
String message = null;
if (loopCount != 0) {
try {
// force an overwrite and remove the RMS data
suiteId = inp_installer.installJad(inp_url,
Constants.INTERNAL_STORAGE_ID, true, true, installListener);
midletInfo = getFirstMIDletOfSuite(suiteId,
midletSuiteStorage);
MIDletSuiteUtils.execute(suiteId,
midletInfo.classname, midletInfo.name);
// We want auto tester MIDlet to run after the test is run.
MIDletSuiteUtils.setLastSuiteToRun(
MIDletStateHandler.getMidletStateHandler().
getMIDletSuite().getID(),
getClass().getName(), null, null);
if (loopCount > 0) {
loopCount -= 1;
}
saveSession();
notifyDestroyed();
return;
} catch (Throwable t) {
handleInstallerException(suiteId, t);
}
}
if (midletSuiteStorage != null &&
suiteId != MIDletSuite.UNUSED_SUITE_ID) {
try {
midletSuiteStorage.remove(suiteId);
} catch (Throwable ex) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_AMS,
"Throwable in remove");
}
}
}
endSession();
| public boolean | restoreSession()Restore the data from the last session.
RecordStore settings = null;
ByteArrayInputStream bas;
DataInputStream dis;
byte[] data;
try {
settings = RecordStore.openRecordStore(AUTOTEST_STORE, false);
data = settings.getRecord(URL_RECORD_ID);
if (data == null) {
return false;
}
bas = new ByteArrayInputStream(data);
dis = new DataInputStream(bas);
url = dis.readUTF();
data = settings.getRecord(DOMAIN_RECORD_ID);
if (data != null && data.length > 0) {
bas = new ByteArrayInputStream(data);
dis = new DataInputStream(bas);
domain = dis.readUTF();
}
data = settings.getRecord(SUITE_ID_RECORD_ID);
if (data != null && data.length > 0) {
bas = new ByteArrayInputStream(data);
dis = new DataInputStream(bas);
suiteId = dis.readInt();
}
data = settings.getRecord(LOOP_COUNT_RECORD_ID);
if (data != null && data.length > 0) {
bas = new ByteArrayInputStream(data);
dis = new DataInputStream(bas);
loopCount = dis.readInt();
}
return true;
} catch (RecordStoreNotFoundException rsnfe) {
// This normal when no initial args are given, ignore
} catch (Exception ex) {
displayException(Resource.getString
(ResourceConstants.EXCEPTION), ex.toString());
} finally {
if (settings != null) {
try {
settings.closeRecordStore();
} catch (Exception ex) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_AMS,
"closeRecordStore threw an Exception");
}
}
}
}
return false;
| public void | run()Run the installer.
installAndPerformTests(midletSuiteStorage, installer, url);
| private void | saveSession()Save session data for next time.
RecordStore settings = null;
boolean newStore = false;
ByteArrayOutputStream bas;
DataOutputStream dos;
byte[] data;
if (url == null) {
return;
}
try {
settings = RecordStore.openRecordStore(AUTOTEST_STORE, true);
if (settings.getNextRecordID() == URL_RECORD_ID) {
newStore = true;
}
bas = new ByteArrayOutputStream();
dos = new DataOutputStream(bas);
dos.writeUTF(url);
data = bas.toByteArray();
if (newStore) {
settings.addRecord(data, 0, data.length);
} else {
settings.setRecord(URL_RECORD_ID, data, 0, data.length);
}
bas.reset();
dos.writeUTF(domain);
data = bas.toByteArray();
if (newStore) {
settings.addRecord(data, 0, data.length);
} else {
settings.setRecord(DOMAIN_RECORD_ID, data, 0, data.length);
}
bas.reset();
dos.writeInt(suiteId);
data = bas.toByteArray();
if (newStore) {
settings.addRecord(data, 0, data.length);
} else {
settings.setRecord(SUITE_ID_RECORD_ID, data, 0, data.length);
}
bas.reset();
dos.writeInt(loopCount);
data = bas.toByteArray();
if (newStore) {
settings.addRecord(data, 0, data.length);
} else {
settings.setRecord(LOOP_COUNT_RECORD_ID, data, 0, data.length);
}
} finally {
if (settings != null) {
try {
settings.closeRecordStore();
} catch (Exception ex) {
if (Logging.REPORT_LEVEL <= Logging.WARNING) {
Logging.report(Logging.WARNING, LogChannels.LC_AMS,
"closeRecordStore threw an exception");
}
}
}
}
|
|