DataTestpublic class DataTest extends com.sun.midp.i3test.TestCase This test class verifies Java Card RMI Client API. |
Fields Summary |
---|
byte[] | byteValues | boolean[] | booleanValues | short[] | shortValues | String | appletURL |
Methods Summary |
---|
public void | runTests()Run tests.
try {
declare("testData");
testData();
declare("testException");
testException();
}
catch (Throwable t) {
fail("" + t);
}
| public void | testData()Tests data transfer.
JavaCardRMIConnection con = null;
Remote1 rem;
boolean stub_flag = false;
try {
SlotFactory.init();
}
catch (CardDeviceException e) {
if (e.getMessage().equals("stub")) {
stub_flag = true;
} else {
throw e;
}
}
if (!stub_flag) {
con = (JavaCardRMIConnection)
new com.sun.midp.io.j2me.jcrmi.Protocol();
((com.sun.midp.io.j2me.jcrmi.Protocol)con)
.openPrim(appletURL, 0, false);
rem = (Remote1)con.getInitialReference();
assertNotNull("Initial reference", rem);
rem.voidMethod();
assertTrue("void method", true);
byte[] b = rem.getByteArray(byteValues);
if (b == null || b.length != byteValues.length) {
assertTrue("byte[] method(byte[]) bad return value", false);
} else {
for (int i = 0; i < b.length; i++) {
if (b[i] != byteValues[i]) {
assertEquals("byte array", b[i], byteValues[i]);
break;
}
}
assertTrue("byte[] method(byte[])", true);
}
short[] s = rem.getShortArray(shortValues);
if (s == null || s.length != shortValues.length) {
assertTrue("short[] method(short[]) bad return value", false);
} else {
for (int i = 0; i < s.length; i++) {
if (s[i] != shortValues[i]) {
assertEquals("short array", s[i], shortValues[i]);
break;
}
}
assertTrue("short[] method(short[])", true);
}
boolean[] l = rem.getBooleanArray(booleanValues);
if (l == null || l.length != booleanValues.length) {
assertTrue("boolean[] method(boolean[]) bad return value", false);
} else {
for (int i = 0; i < l.length; i++) {
if (l[i] != booleanValues[i]) {
assertTrue("boolean array", (l[i] == booleanValues[i]));
break;
}
}
assertTrue("boolean[] method(boolean[])", true);
}
con.close();
}
assertTrue(true);
| public void | testException()Tests exception handling.
JavaCardRMIConnection con = null;
Remote1 rem;
boolean stub_flag = false;
try {
SlotFactory.init();
}
catch (CardDeviceException e) {
if (e.getMessage().equals("stub")) {
stub_flag = true;
} else {
throw e;
}
}
if (!stub_flag) {
con = (JavaCardRMIConnection)
new com.sun.midp.io.j2me.jcrmi.Protocol();
((com.sun.midp.io.j2me.jcrmi.Protocol)con)
.openPrim(appletURL, 0, false);
rem = (Remote1)con.getInitialReference();
assertNotNull("Initial reference", rem);
try {
rem.throwException((short)12);
}
catch (java.rmi.RemoteException e) {
assertTrue("proper exception", true);
}
catch (Throwable e1) {
assertTrue("improper exception: " + e1, false);
}
try {
rem.throwException((short)22);
}
catch (javacard.framework.service.ServiceException e) {
assertTrue("proper exception", true);
}
catch (Throwable e1) {
assertTrue("improper exception: " + e1, false);
}
try {
rem.throwException((short)11);
}
catch (java.io.IOException e) {
assertTrue("proper exception", true);
}
catch (Throwable e1) {
assertTrue("improper exception: " + e1, false);
}
try {
rem.throwSubclass((short)11);
}
catch (java.io.IOException e) {
assertTrue("proper exception", true);
}
catch (Throwable e1) {
assertTrue("improper exception: " + e1, false);
}
con.close();
} else {
assertTrue(true);
}
|
|