FileDocCategorySizeDatePackage
TestReflect.javaAPI DocphoneME MR2 API (J2ME)3298Wed May 02 18:00:00 BST 2007com.sun.midp.test

TestReflect

public class TestReflect extends TestCase

Fields Summary
static final String
slave
com.sun.cldc.isolate.Isolate
iso
Constructors Summary
Methods Summary
public voidrunTests()

        declare("one");
        testOne();
    
voidsetUp()


      

        // Make sure we can find the slave class.  This isn't strictly
        // necessary, but it serves as a useful cross-check to ensure
        // that the class is visible to both the master and slave
        // isolates.  It also helps if the classname is wrong for
        // some reason: you get a useful error message instead of
        // an obscure isolate startup error.

        try {
            Class.forName(slave);
        } catch (ClassNotFoundException cnfe) {
            throw new RuntimeException(
                "Class.forName() can't find slave class " + slave);
        }

        // Initialize the isolate synchronization mechanism.
        // This must be done before the other isolate is started.
        // This must be called ONLY in the "master" isolate.

        IsolateSynch.init();

        // Create the slave isolate and start it.

        try {
            iso = new Isolate(slave, new String[0]);
            iso.start();
        } catch (IsolateStartupException ise) {
            throw new RuntimeException("can't start isolate");
        }

        // Wait for the slave isolate to become ready.

        IsolateSynch.awaitReady();
    
voidtearDown()

        // Tell the other isolate to continue.

        IsolateSynch.signalContinue();

        // Alternatively, kill the other isolate instead of
        // telling it to continue.  Do one or the other, but not both.
        /* iso.exit(0); */

        // Wait for the other isolate to exit.

        iso.waitForExit();

        // Clean up isolate synchronization mechanism.

        IsolateSynch.fini();
    
voidtestOne()

        setUp();
        int x = Reflect.getStaticIntValue(iso, slave, "integerValue");
        assertEquals(17, ReflectSlave.integerValue);
        assertEquals(42, x);
        tearDown();