Methods Summary |
---|
boolean | isCommandInMenu(Command c)Checks the command in Menu
Command[] soft2 = display.getWindow().getSoftTwo();
if (soft2 == null) {
return false;
}
for (int i = 0; i < soft2.length; i++) {
if (soft2[i] == c) {
return true;
}
}
return false;
|
public void | runTests()Overridden from TestCase parent. This method will kick off each
individual test
setUp();
testShow();
testSetConstraints();
testTraverse();
tearDown();
|
void | setUp()Starts the test
display = new StubDisplay();
scb = new SerialCallback(display);
form = new Form("Form");
tf = new TextField("TextField", longtext, 256, TextField.ANY);
form.append(tf);
form.append(new DateField("DateField", DateField.TIME));
|
void | tearDown()destroy test
|
void | testSetConstraints()Tests setConstraints method
declare("testSetUneditable");
tf.setConstraints(TextField.ANY | TextField.UNEDITABLE);
verifyInputStates();
declare("testSetNumeric");
// Change input constraints from ANY to NUMERIC editable
tf.setConstraints(TextField.NUMERIC);
verifyInputStates();
// Expect AlphaNumeric input mode does not exist
verifyAvailableInputModes(true);
|
void | testShow()Show the form on the display
declare("testShow");
// Make form shown
display.setCurrent(form);
scb.invokeAndWait();
assertTrue(form.isShown());
// Expect textfield1 in focus
verifyInputStates();
// Expect both AlphaNumeric and Numeric input modes are available
verifyAvailableInputModes(false);
|
void | testTraverse()Tests traverse in/ traverse out
EventQueue eventQueue = EventQueue.getEventQueue();
NativeEvent event;
// Restore textfield to ANY editable
tf.setConstraints(TextField.ANY);
tf.setString(longtext);
FormLFImpl formlf = (FormLFImpl)form.formLF;
TextFieldLFImpl tfLF = (TextFieldLFImpl)tf.textFieldLF;
declare("testTraverseOut");
event = new NativeEvent(EventTypes.KEY_EVENT);
event.intParam1 = EventConstants.PRESSED;
event.intParam2 = Constants.KEYCODE_DOWN;
event.intParam4 = display.displayId;
eventQueue.post(event);
// wait till the focus is transferred
scb.invokeAndWait();
assertFalse(tfLF.hasFocus);
verifyInputStates();
declare("testTraverseIn");
event = new NativeEvent(EventTypes.KEY_EVENT);
event.intParam1 = EventConstants.PRESSED;
event.intParam2 = Constants.KEYCODE_UP;
event.intParam4 = display.displayId;
eventQueue.post(event);
// wait till the focus is transferred
scb.invokeAndWait();
assertTrue(tfLF.hasFocus);
verifyInputStates();
|
void | verifyAvailableInputModes(boolean isNumericOnly)Verifies available input modes
TextFieldLFImpl lf = (TextFieldLFImpl)tf.textFieldLF;
Command[] cmds = lf.inputMenu.getSubCommands();
boolean hasAlpha = false, hasNumeric = false;
AlphaNumericInputMode alphaIM = new AlphaNumericInputMode();
NumericInputMode numericIM = new NumericInputMode();
if (cmds != null) {
for (int i = 0; i < cmds.length; i++) {
if (alphaIM.getName().equals(cmds[i].getLabel())) {
hasAlpha = true;
} else if (numericIM.getName().equals(cmds[i].getLabel())) {
hasNumeric = true;
}
}
}
assertTrue("Numeric IM", hasNumeric);
assertTrue("AlphaNumeric IM", isNumericOnly || hasAlpha);
|
void | verifyInputStates()Checks the input states
TextFieldLFImpl lf = (TextFieldLFImpl)tf.textFieldLF;
if (lf.hasFocus) {
if (lf.editable) {
// Input mode indicator layer exists
assertSame("Indicator layer",
display.getWindow().getTopMostPopup(),
lf.inputModeIndicator);
// Input session should have been started
assertTrue("Input session",
lf.inputSession.getCurrentInputMode() != null);
// At least one input mode available for constaint ANY
assertTrue("Available IMs",
lf.inputSession.getAvailableModes().length >= 1);
// Input mode selection command exists in menu
assertTrue("InputSubMenu", isCommandInMenu(lf.inputMenu));
// cursor is visible
assertTrue("Cursor", lf.cursor.visible);
// No active autoscrolling task
assertTrue("AutoScrolling", lf.textScrollPainter == null);
} else {
// cursor is invisible
assertTrue("Cursor", !lf.cursor.visible);
// if contents too long, autoscrolling should be activated
assertTrue("AutoScrolling",
lf.textWidth <= lf.scrollWidth ||
lf.textScrollPainter != null);
// input session is ended
assertTrue("Input session",
lf.inputSession.getCurrentInputMode() == null);
// Input mode selection command doesn't exist in menu
assertTrue("InputSubMenu", !isCommandInMenu(lf.inputMenu));
}
} else {
// autoscrolling is not activated
assertTrue("AutoScrolling", lf.textScrollPainter == null);
// input mode selection command doesn't exist in menu
assertTrue("InputSubMenu", !isCommandInMenu(lf.inputMenu));
}
|