RecordedEventpublic class RecordedEvent extends Object RecordedEvent 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 single event which will comprise a larger event sequence. |
Fields Summary |
---|
static final byte | KEY_EVENT | static final byte | INPUT_METHOD_EVENT | static final byte | MENU_EVENT | static final byte | PEN_EVENT | static final byte | COMMAND_EVENT | static final byte | DELAY_DUMMY_EVENT | byte | typeThe byte representation of an event is :
type 1 byte
timeDelay 4 bytes
val1/inputString 4 bytes
[val2] 4 bytes
[val3] 4 bytes | int | timeDelay | String | inputString | int | val1 | int | val2 | int | val3 | private int | lengthInBytes |
Constructors Summary |
---|
RecordedEvent(int timeDelay)Creates a RecordedEvent for a DELAY_DUMMY_EVENT with the
given time
This is a dummy event used to create a delay.
// --- constructors ---
this.type = DELAY_DUMMY_EVENT;
this.timeDelay = timeDelay;
lengthInBytes = 5; // this.type(1) + timeDelay(4)
| RecordedEvent(int timeDelay, String input)Creates a RecordedEvent for an INPUT_METHOD_EVENT with the
given type and input string.
this.type = INPUT_METHOD_EVENT;
this.timeDelay = timeDelay;
inputString = input;
lengthInBytes = 5 + input.length(); // this.type(1) + timeDelay(4)
// + String.length()
| RecordedEvent(int timeDelay, int type, int code)Creates a RecordedEvent for a KEY_EVENT with the
given type and key code.
this.type = KEY_EVENT;
this.timeDelay = timeDelay;
val1 = type;
val2 = code;
lengthInBytes = 13; // this.type(1) + timeDelay(4) + val1(4) + val2(4)
| RecordedEvent(int timeDelay, int type, int x, int y)Creates a RecordedEvent for a PEN_EVENT with the
given type and coordinate location
this.type = PEN_EVENT;
this.timeDelay = timeDelay;
val1 = type;
val2 = x;
val3 = y;
lengthInBytes = 17; // this.type(1) + timeDelay(4)
// + val1(4) + val2(4) + val3(4)
| RecordedEvent(int timeDelay, int type)Creates a RecordedEvent for a COMMAND event with
the given Command type (or index)
this.type = COMMAND_EVENT;
this.timeDelay = timeDelay;
val1 = type;
lengthInBytes = 9; // this.type(1) + timeDelay(4) + val1(4)
|
Methods Summary |
---|
private static int | bytesToInt(byte[] byteArray, int offsetInByteArray)Converts 4 bytes to an int
int retVal = 0;
retVal =
(((int)(byteArray[offsetInByteArray]) & (0xFF)) << 24) |
(((int)(byteArray[offsetInByteArray+1]) & (0xFF)) << 16) |
(((int)(byteArray[offsetInByteArray+2]) & (0xFF)) << 8) |
(((int)(byteArray[offsetInByteArray+3]) & (0xFF)) << 0);
return retVal;
| public byte[] | getAsByte()Return an array of bytes containing the byte representation
of this RecordedEvent
byte[] rawBytes = new byte[lengthInBytes];
int indexInByteArray;
// byte 0 is the type of event
rawBytes[0] = this.type;
indexInByteArray = 1;
// byte 1-4 is the timeDelay
indexInByteArray += intIntoBytes(rawBytes, timeDelay,
indexInByteArray);
// bytes specific to the type of event
switch (this.type) {
case KEY_EVENT:
indexInByteArray += intIntoBytes(rawBytes, val1,
indexInByteArray);
indexInByteArray += intIntoBytes(rawBytes, val2,
indexInByteArray);
break;
case INPUT_METHOD_EVENT:
indexInByteArray += stringIntoBytes(rawBytes, inputString,
indexInByteArray);
break;
case MENU_EVENT:
// NYI
for (int i = 0; i < (lengthInBytes-5); i++) {
rawBytes[indexInByteArray++] = 0x00;
}
break;
case PEN_EVENT:
indexInByteArray += intIntoBytes(rawBytes, val1,
indexInByteArray);
indexInByteArray += intIntoBytes(rawBytes, val2,
indexInByteArray);
indexInByteArray += intIntoBytes(rawBytes, val3,
indexInByteArray);
break;
case COMMAND_EVENT:
indexInByteArray += intIntoBytes(rawBytes, val1,
indexInByteArray);
break;
case DELAY_DUMMY_EVENT:
// no extra bytes needed.
break;
default:
throw new IllegalArgumentException();
}
return rawBytes;
| int | getTimeDelay()
return this.timeDelay;
| byte | getType()
return this.type;
| private static int | intIntoBytes(byte[] byteArray, int intToConvert, int indexInByteArray)Copies the 4 individual bytes of an into
the array starting from the specified
offset
byteArray[indexInByteArray] = (byte)((intToConvert >> 24) & 0xFF);
byteArray[indexInByteArray+1] = (byte)((intToConvert >> 16) & 0xFF);
byteArray[indexInByteArray+2] = (byte)((intToConvert >> 8) & 0xFF);
byteArray[indexInByteArray+3] = (byte)((intToConvert >> 0) & 0xFF);
return 4;
| int | lengthOfByteRep()Return the length of the byte representation of this
RecordedEvent
return this.lengthInBytes;
| static com.sun.midp.lcdui.RecordedEvent | recreateRecordedEvent(byte[] byteArray, int offset, int length)Creates a RecordedEvent from an array of bytes.
This is called from EventSequence to recreate
a RecordedEvent from storage.
RecordedEvent returnEvent = null;
int timeDelay = bytesToInt(byteArray, offset+1);
switch (byteArray[offset+0]) {
case KEY_EVENT:
returnEvent = new RecordedEvent(timeDelay,
bytesToInt(byteArray, offset+5),
bytesToInt(byteArray, offset+9));
break;
case INPUT_METHOD_EVENT:
returnEvent = new RecordedEvent(timeDelay,
new String(byteArray,
offset+5,
length));
break;
case MENU_EVENT:
break;
case PEN_EVENT:
returnEvent = new RecordedEvent(timeDelay,
bytesToInt(byteArray, offset+5),
bytesToInt(byteArray, offset+9),
bytesToInt(byteArray, offset+13));
break;
case COMMAND_EVENT:
returnEvent = new RecordedEvent(timeDelay,
bytesToInt(byteArray, offset+5));
break;
case DELAY_DUMMY_EVENT:
returnEvent = new RecordedEvent(timeDelay);
break;
default:
throw new IllegalArgumentException();
}
return returnEvent;
| private static int | stringIntoBytes(byte[] byteArray, java.lang.String string, int offsetInByteArray)Copies the byte representation of the String
into the array starting from the specified
array offset
System.arraycopy((Object)string.getBytes(), // src
0, // src_position
(Object)byteArray, // dest
offsetInByteArray, // dest_position
string.length());
return string.length();
|
|