TestEchopublic 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 |
Methods Summary |
---|
public void | runTests()Runs all tests.
declare("testString");
setUp();
testString();
tearDown();
declare("testData");
setUp();
testData();
tearDown();
declare("testDataRange");
setUp();
testDataRange();
tearDown();
declare("testLink");
setUp();
testLink();
tearDown();
| void | setUp()
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 });
| void | tearDown()
LinkPortal.setLinks(them, null);
them.exit(0);
them.waitForExit();
us = null;
them = null;
to = null;
from = null;
| void | testData()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));
| void | testDataRange()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));
| void | testLink()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);
| void | testString()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);
|
|