Fields Summary |
---|
private final String | TEST_NAMEThe fully qualified name of this test. |
private final String | MMS_TO_DEVICE_IDThe device ID ("phone number") of the recipient. |
private final String | MMS_TO_APP_IDThe application ID of the recipient. |
private final String | MMS_TO_ADDRESSThe MMS address to which the message will be sent. |
private final String | MMS_FROM_DEVICE_IDThe device ID ("phone number") of the sender. |
private final String | MMS_FROM_APP_IDThe application ID of the sender. |
private final String | MMS_FROM_ADDRESSThe MMS address from which the message will be sent. |
private final String | MMS_CLIENT_ADDRESSThe MMS client address. |
private final int | MAX_FRAGMENT_SIZEThe maximum size of a fragment. |
private final int | MAX_TOTAL_SIZEThe maximum number of bytes permitted in an MMS message (30k). |
private javax.wireless.messaging.MessageConnection | conThe MMS connection. |
private boolean | passedTest passed/failed flag. |
Methods Summary |
---|
void | cleanUp()Provide clean-up services, following the run of this test.
closeConnection();
|
private void | closeConnection()Close the MMS connection.
try {
con.close();
} catch (IOException ioe) {
// Fail silently.
} catch (Exception e) {
// Fail silently.
}
|
private void | createClientConnection(java.lang.String clientAddress)Create and open an MMS connection.
con = (MessageConnection)Connector.open(clientAddress);
|
private javax.wireless.messaging.MultipartMessage | createCompleteMessage(java.lang.String toAddress, java.lang.String fromAddress, byte[] content)Create the MMS message to be sent.
// The MIME type for this message.
String mimeType = "mms:";
// The unique content ID.
String contentID = "message1";
// No content location.
String contentLocation = null;
// No encoding.
String encoding = null;
MessagePart part = new MessagePart(content, 0, content.length,
mimeType, contentID, contentLocation, encoding);
MultipartObject mm = new MultipartObject(toAddress);
mm.addMessagePart(part);
mm.setFromAddress(fromAddress);
return mm;
|
int | numberOfMMSSegments(byte[] msgBuffer)Compute the number of segments required to send the message. This will be
matched against the number of segments computed by the actual code.
/** The maximum fragment size for each segment to be sent. */
final int FRAGMENT_SIZE = 1200;
/** The actual fragment size. */
int fragmentSize = FRAGMENT_SIZE;
/** Extra header size for concatenated messages. */
int headerSize = 7;
/** The number of segments required to send the message. */
int segments = 0;
if (msgBuffer == null) {
return 1;
}
int msgLen = msgBuffer.length;
if (msgLen < FRAGMENT_SIZE) {
segments = 1;
} else {
fragmentSize = fragmentSize - headerSize;
segments = (msgLen + fragmentSize - 1) / fragmentSize;
}
return segments;
|
public void | run()Compute transport-layer segment counts for varying message lengths.
try {
// Make sure that an SMS text object can't be used here.
String smsAddress = "sms://+5551111:1234";
Message smsMessage = new TextObject(smsAddress);
int segs = con.numberOfSegments(smsMessage);
if (segs != 0) {
throw new IllegalArgumentException(
"TextMessage cannot be used in MMS connection " +
"(Segments cannot be computed.).");
}
// Make sure that an SMS binary object can't be used here.
smsMessage = new BinaryObject(smsAddress);
segs = con.numberOfSegments(smsMessage);
if (segs != 0) {
throw new IllegalArgumentException(
"BinaryMessage cannot be used in MMS connection " +
"(Segments cannot be computed.).");
}
// Lower bounds test: This should not fail.
testMessageLengthOf(0);
// The following message sizes should not fail:
testMessageLengthOf(1);
testMessageLengthOf(MAX_FRAGMENT_SIZE - 1);
testMessageLengthOf(MAX_FRAGMENT_SIZE);
testMessageLengthOf(MAX_FRAGMENT_SIZE + 1);
testMessageLengthOf(MAX_TOTAL_SIZE - 1);
testMessageLengthOf(MAX_TOTAL_SIZE);
// Upper bounds test: This should fail.
try {
testMessageLengthOf(MAX_TOTAL_SIZE + 1);
} catch (SizeExceededException see) {
// ignore
}
closeConnection();
passed = true;
assertTrue("Indicate that the test passed.", passed);
} catch (Exception e) {
// Test failure!
e.printStackTrace();
}
|
public void | runTests()Main entry point.
setUp();
declare(TEST_NAME);
run();
cleanUp();
|
void | setUp()Set up the physical connection.
try {
createClientConnection(MMS_CLIENT_ADDRESS);
} catch (IOException ioe) {
System.out.println(TEST_NAME + " set-up failed:");
ioe.printStackTrace();
}
|
private void | testMessageLengthOf(int msgLen)Create a message of the given length. Then compute both the actual and
test segment counts required to send that message. If there is a
difference between the counts, flag this as a problem.
// Create the message content.
StringBuffer sb = new StringBuffer(msgLen);
for (int i = 0; i < msgLen; i++) {
sb.append('x");
}
String mmsContent = sb.toString();
// Create an MMS multipart object and compute its segment count.
MultipartMessage mm =
createCompleteMessage(MMS_TO_ADDRESS, MMS_FROM_ADDRESS,
mmsContent.getBytes());
int segs = con.numberOfSegments(mm);
// Perform an independent segment computation for comparison.
byte[] msgBytes = ((MultipartObject)mm).getAsByteArray();
int compareSegs = numberOfMMSSegments(msgBytes);
// Bail out if there are discrepancies.
if (segs < compareSegs) {
throw new IllegalArgumentException("Actual segment count of " + segs
+ " is lower than comparison count of " + compareSegs + ".");
} else if (segs > compareSegs) {
throw new IllegalArgumentException("Actual segment count of " + segs
+ " is higher than comparison count of " + compareSegs + ".");
}
|