EventSequencepublic class EventSequence extends Object EventSequence is a class that encapsulates the semantics
of a single MIDP event.
This class is designed to automate UI testing. It is the representation
of a sequence of events and the corresponding screen capture taken at
the end of those events. |
Fields Summary |
---|
private byte[] | capture | private ByteArrayInputStream | inputStreamAn input stream of bytes represents events
that have been recorded previously and that are
passed to this EventSequence | private byte[] | byteArrayThe byte array associated with the event sequence. | private ByteArrayOutputStream | outputStreamThe output stream represents events that are
to be recorded in this EventSequence | static final int | EVENT_START_MARKER | static final int | CAPTURE_START_MARKER | static final int | END_OF_EVENT_SEQUENCE |
Constructors Summary |
---|
EventSequence()
// set up the empty input stream and byte array
byteArray = new byte[0];
inputStream = new ByteArrayInputStream(byteArray);
outputStream = new ByteArrayOutputStream();
| public EventSequence(byte[] input)Recreate a stored event sequence and its associated screen
capture from the given input stream.
byteArray = input;
inputStream = new ByteArrayInputStream(byteArray);
outputStream = new ByteArrayOutputStream();
| public EventSequence(EventSequence[] sequences)Create a new EventSequence Object based on a set of other
EventSequences. This will create a composite EventSequence
object which will be treated as a single sequence by the
AutomatedHandler when testing. That is, a call to
replayEventSequence() with a composite EventSequence Object
will test each sub sequence and its screen capture. If any
sub sequence fails, it will return false. If all of the sub
sequences pass, it will return true.
try {
for (int i = 0; i < sequences.length; i++) {
this.outputStream.write(sequences[i].toByteArray());
}
} catch (IOException e) {
// System.out.println("Exception in writing to stream");
}
| public EventSequence(Vector sequences)Create a new EventSequence Object based on a set of other
EventSequences. This will create a composite EventSequence
object which will be treated as a single sequence by the
AutomatedHandler when testing. That is, a call to
replayEventSequence() with a composite EventSequence Object
will test each sub sequence and its screen capture. If any
sub sequence fails, it will return false. If all of the sub
sequences pass, it will return true.
int length = sequences.size();
EventSequence q;
try {
for (int i = 0; i < length; i++) {
q = (EventSequence)sequences.elementAt(i);
this.outputStream.write(q.toByteArray());
}
} catch (IOException e) {
// System.out.println("Exception in writing to stream");
}
|
Methods Summary |
---|
void | appendEvent(RecordedEvent event)
try {
outputStream.write(EVENT_START_MARKER);
outputStream.write(event.lengthOfByteRep());
outputStream.write(event.getAsByte());
} catch (java.io.IOException e) {
System.out.println("EXCEPTION!");
// EXCEPTION!
}
| public void | appendSequence(com.sun.midp.lcdui.EventSequence sequence)Append the given EventSequence to this sequence and create
a composite event sequence as a result.
try {
this.outputStream.write(sequence.toByteArray());
} catch (IOException e) {
// System.out.println("Exception in writing to stream");
}
| byte[] | getCapture()
int length = inputStream.read();
byte[] captureByteArray = new byte[length];
inputStream.read(captureByteArray, 0, length);
return captureByteArray;
| RecordedEvent | getNextEvent()
RecordedEvent event = null;
int length = inputStream.read();
if (length == 0xFF) {
// if the length byte's value is 0xFF,
// then the length is greater than 127 and
// needs to be read as an int.
// using this as most events' length will
// be small engouh, that a byte is sufficient
// to represent it.
}
byte[] eventByteArray = new byte[length];
inputStream.read(eventByteArray, 0, length);
event = RecordedEvent.recreateRecordedEvent(eventByteArray,
0, length);
return event;
| int | getNextObjectType()
return (inputStream.read());
// returns -1 if end of input stream is reached.
| void | initializeReplay()
byte[] tempByteArray = new byte[byteArray.length +
outputStream.toByteArray().length];
// Copy existing bytes in the byteArray to tempByteArray
System.arraycopy(byteArray,
0,
tempByteArray,
0,
byteArray.length);
// Append bytes from the output streams' byte array
// to tempByteArray
// byteArray.length is the offset to start from in the dst
System.arraycopy(outputStream.toByteArray(),
0,
tempByteArray,
byteArray.length,
outputStream.toByteArray().length);
// now tempByteArray holds all the bytes!
// make it the byteArray!
byteArray = tempByteArray;
// reset the output stream
outputStream.reset();
inputStream = new ByteArrayInputStream(byteArray);
// input stream now points at 0 index in the byteArray
| void | setScreenCapture(byte[] capture)
this.capture = capture;
outputStream.write(CAPTURE_START_MARKER);
outputStream.write(capture.length);
for (int byteCounter = 0; byteCounter < capture.length;
byteCounter++) {
outputStream.write(capture[byteCounter]);
}
| public byte[] | toByteArray()Store this EventSequence and its corresponding screen
capture to the designated output stream.
// the entire eventSequence consists of the original input sequence
// null if there was no original input sequence
// plus the events that were appended
// therefore when we are returning the byte representation,
// we actually do three things.
// 1. append any existing bytes in the output array to the input array.
// 2. reset the output array
// 3. return the bytearray
byte[] tempByteArray = new byte[byteArray.length +
outputStream.toByteArray().length];
// Copy existing bytes in the byteArray to tempByteArray
System.arraycopy(byteArray,
0,
tempByteArray,
0,
byteArray.length);
// Append bytes from the output streams' byte array
// to tempByteArray
// byteArray.length is the offset to start from in the dst
System.arraycopy(outputStream.toByteArray(),
0,
tempByteArray,
byteArray.length,
outputStream.toByteArray().length);
// now tempByteArray holds all the bytes!
// make it the byteArray!
byteArray = tempByteArray;
// reset the output stream
outputStream.reset();
return byteArray;
|
|