FileDocCategorySizeDatePackage
TestEcho.javaAPI DocphoneME MR2 API (J2ME)4673Wed May 02 18:00:02 BST 2007com.sun.midp.links

TestEcho

public class TestEcho extends com.sun.midp.i3test.TestCase
Tests sending messages to and receiving messages from another isolate. Starts the Echo program in another isolate and tests echoing of string, data, data range, and link messages.

Fields Summary
com.sun.cldc.isolate.Isolate
us
com.sun.cldc.isolate.Isolate
them
Link
to
Link
from
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.


        declare("testString");
        setUp();
        testString();
        tearDown();

        declare("testData");
        setUp();
        testData();
        tearDown();

        declare("testDataRange");
        setUp();
        testDataRange();
        tearDown();

        declare("testLink");
        setUp();
        testLink();
        tearDown();

    
voidsetUp()

        us = Isolate.currentIsolate();
        them = new Isolate("com.sun.midp.links.Echo", null);
        them.start();
        to = Link.newLink(us, them);
        from = Link.newLink(them, us);
        LinkPortal.setLinks(them, new Link[] { to, from });
    
voidtearDown()

        LinkPortal.setLinks(them, null);
        them.exit(0);
        them.waitForExit();

        us = null;
        them = null;
        to = null;
        from = null;
    
voidtestData()
Tests echoing of a data message.

        byte[] rdata;
        byte[] sdata;
        LinkMessage lm;

        sdata = new byte[50];
        Utils.fillRandom(sdata);
        to.send(LinkMessage.newDataMessage(sdata));
        lm = from.receive();

        assertTrue("contains data", lm.containsData());
        rdata = lm.extractData();
        assertNotSame("data not same", sdata, rdata);
        assertTrue("data equal", Utils.bytesEqual(sdata, rdata));
    
voidtestDataRange()
Tests echoing of a data subrange message.

        byte[] rdata;
        byte[] sdata;
        LinkMessage lm;

        sdata = new byte[60];
        Utils.fillRandom(sdata);
        to.send(LinkMessage.newDataMessage(sdata, 12, 23));
        lm = from.receive();

        assertTrue("contains data", lm.containsData());
        rdata = lm.extractData();
        assertNotSame("data not same", sdata, rdata);
        assertTrue("data equal", Utils.bytesEqual(sdata, 12, 23, rdata));
    
voidtestLink()
Tests echoing of a link message.

        Link rlink, slink;
        LinkMessage lm;

        slink = Link.newLink(us, us);
        to.send(LinkMessage.newLinkMessage(slink));
        lm = from.receive();

        assertTrue("contains link", lm.containsLink());
        rlink = lm.extractLink();
        assertNotSame("links not same", slink, rlink);
        assertEquals("links equal", slink, rlink);
    
voidtestString()
Tests echoing of a string message.

        String rs, ss;
        LinkMessage lm;

        ss = "What hath God wrought?";
        to.send(LinkMessage.newStringMessage(ss));
        lm = from.receive();

        assertTrue("contains string", lm.containsString());
        rs = lm.extractString();
        assertNotSame("strings not same", ss, rs);
        assertEquals("strings equal", ss, rs);