TestTransferpublic class TestTransfer extends com.sun.midp.i3test.TestCase Tests simple exchange of different types of messages (data, data subrange,
and String) within the same isolate. Covers simple cases only, with
one receiver thread and one sender thread. Covers receive-then-send as well
as send-then-receive, for each kind of message. |
Methods Summary |
---|
public void | runTests()Runs all tests.
declare("testReceiveString");
testReceiveString();
declare("testSendString");
testSendString();
declare("testReceiveData");
testReceiveData();
declare("testSendData");
testSendData();
declare("testReceiveDataRange");
testReceiveDataRange();
declare("testSendDataRange");
testSendDataRange();
| void | testReceiveData()Tests receive-then-send of a byte array.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
Receiver receiver = new Receiver(link);
byte[] sendarr = new byte[100];
Utils.fillRandom(sendarr);
link.send(LinkMessage.newDataMessage(sendarr));
receiver.await();
assertTrue("receiver should be done", receiver.done);
assertNull("receiver should have no exceptions", receiver.exception);
assertNotNull("receiver should have received a message", receiver.msg);
byte[] recvarr = receiver.msg.extractData();
assertTrue("arrays shouldn't be identical", sendarr != recvarr);
assertTrue("arrays should be equal",
Utils.bytesEqual(sendarr, recvarr));
| void | testReceiveDataRange()Tests receive-then-send of a byte array subrange.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
Receiver receiver = new Receiver(link);
byte[] sendarr = new byte[100];
Utils.fillRandom(sendarr);
link.send(LinkMessage.newDataMessage(sendarr, 17, 32));
receiver.await();
assertTrue("receiver should be done", receiver.done);
assertNull("receiver should have no exceptions", receiver.exception);
assertNotNull("receiver should have received a message", receiver.msg);
byte[] recvarr = receiver.msg.extractData();
assertTrue("arrays shouldn't be identical", sendarr != recvarr);
assertTrue("arrays should be equal",
Utils.bytesEqual(sendarr, 17, 32, recvarr));
| void | testReceiveString()Tests receive-then-send of a String.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
Receiver receiver = new Receiver(link);
String sendstr = "bar";
link.send(LinkMessage.newStringMessage(sendstr));
receiver.await();
assertTrue("receiver should be done", receiver.done);
assertNull("receiver should have no exceptions", receiver.exception);
assertNotNull("receiver should have received a message", receiver.msg);
String recvstr = receiver.msg.extractString();
assertTrue("strings shouldn't be identical", sendstr != recvstr);
assertEquals("strings should be equal", sendstr, recvstr);
| void | testSendData()Tests send-then-receive of a byte array.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
byte[] sendarr = new byte[100];
Utils.fillRandom(sendarr);
Sender sender = new Sender(link,
LinkMessage.newDataMessage(sendarr));
LinkMessage lm = link.receive();
sender.await();
assertTrue("sender should be done", sender.done);
assertNull("sender should have no exceptions", sender.exception);
byte[] recvarr = lm.extractData();
assertTrue("arrays shouldn't be identical", sendarr != recvarr);
assertTrue("arrays should be equal",
Utils.bytesEqual(sendarr, recvarr));
| void | testSendDataRange()Tests send-then-receive of a byte array subrange.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
byte[] sendarr = new byte[100];
Utils.fillRandom(sendarr);
Sender sender = new Sender(link,
LinkMessage.newDataMessage(sendarr, 47, 22));
LinkMessage lm = link.receive();
sender.await();
assertTrue("sender should be done", sender.done);
assertNull("sender should have no exceptions", sender.exception);
byte[] recvarr = lm.extractData();
assertTrue("arrays shouldn't be identical", sendarr != recvarr);
assertTrue("arrays should be equal",
Utils.bytesEqual(sendarr, 47, 22, recvarr));
| void | testSendString()Tests send-then-receive of a String.
Isolate i = Isolate.currentIsolate();
Link link = Link.newLink(i, i);
String sendstr = "foo";
Sender sender = new Sender(link,
LinkMessage.newStringMessage(sendstr));
LinkMessage lm = link.receive();
sender.await();
assertTrue("sender should be done", sender.done);
assertNull("sender should have no exceptions", sender.exception);
String recvstr = lm.extractString();
assertTrue("strings shouldn't be identical", sendstr != recvstr);
assertEquals("strings should be equal", sendstr, recvstr);
|
|