FileDocCategorySizeDatePackage
TestHandleFatalError.javaAPI DocphoneME MR2 API (J2ME)4759Wed May 02 18:00:16 BST 2007com.sun.midp.events

TestHandleFatalError

public class TestHandleFatalError extends TestCase implements MIDletProxyListListener
Test that the if an event listener in an application isolate throws a runtime exception, that the isolate is killed.

Fields Summary
private static final int
TIMEOUT_PERIOD
Timeout period. In milliseconds.
private static final String
TEST_MIDLET
Class name of the test MIDlet.
private MIDletProxy
testMidlet
Holds a reference to the test MIDlet.
private MIDletProxyList
proxyList
Holds a reference to the MIDlet proxy list.
private boolean
testMidletRemovedFromList
True, if the test MIDlet was removed from the list of running MIDlets.
Constructors Summary
Methods Summary
public voidmidletAdded(MIDletProxy midlet)
Called when a MIDlet is added to the list.

param
midlet The proxy of the MIDlet being added

        if (TEST_MIDLET.equals(midlet.getClassName())) {
            testMidlet = midlet;
            return;
        }
    
public voidmidletRemoved(MIDletProxy midlet)
Called when a MIDlet is removed from the list.

param
midlet The proxy of the removed MIDlet

        if (midlet == testMidlet) {
            synchronized (this) {
                testMidletRemovedFromList = true;
                notifyAll();
            }
        }
    
public voidmidletStartError(int externalAppId, int suiteId, java.lang.String className, int errorCode, java.lang.String errorDetails)
Called when error occurred while starting a MIDlet object.

param
externalAppId ID assigned by the external application manager
param
suiteId Suite ID of the MIDlet
param
className Class name of the MIDlet
param
errorCode start error code
param
errorDetails start error code

public voidmidletUpdated(MIDletProxy midlet, int fieldId)
Called when the state of a MIDlet in the list is updated.

param
midlet The proxy of the MIDlet that was updated
param
fieldId code for which field of the proxy was updated

public voidrunTests()
Run all tests.

        declare("testMvmHandleFatalError");
        testMvmHandleFatalError();

        proxyList.removeListener(this);
    
voidtestMvmHandleFatalError()
Launch the test MIDlet and it it ends by the end of the time out period than consider the test passed.


                              
      
        boolean assertion;

        proxyList = MIDletProxyList.getMIDletProxyList();

        proxyList.addListener(this);

        if (MIDletSuiteUtils.execute(MIDletSuite.INTERNAL_SUITE_ID,
                TEST_MIDLET, "no name")) {
            // This is SVM mode, so cancel the execute and end the test.
            MIDletSuiteUtils.execute(MIDletSuite.INTERNAL_SUITE_ID,
                null, null);
            return;
        }

        synchronized (this) {
            try {
                wait(TIMEOUT_PERIOD);
            } catch (InterruptedException ie) {
            }
        }

        assertion = testMidlet != null;
        assertTrue(TEST_MIDLET + " not started", assertion);
        if (!assertion) {
            return;
        }

        if (!testMidletRemovedFromList) {
            fail(TEST_MIDLET + " not removed from list of running MIDlets");
            testMidlet.destroyMidlet();
            return;
        }