diff -r 2a9601315dfc -r 98ccebc37403 javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/stringitem/HyperLinkTest.java --- a/javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/stringitem/HyperLinkTest.java Mon May 03 12:27:20 2010 +0300 +++ b/javauis/lcdui_qt/tsrc/uitestsrc/t_uirobot/stringitem/HyperLinkTest.java Fri May 14 15:47:24 2010 +0300 @@ -11,7 +11,7 @@ * * Contributors: * -* Description: +* Description: * */ package t_uirobot.stringitem; @@ -32,12 +32,14 @@ *
* Created: 2008-10-20 */ -public class HyperLinkTest extends ItemUITestBase { +public class HyperLinkTest extends ItemUITestBase +{ /** * Constructor. */ - public HyperLinkTest() { + public HyperLinkTest() + { } /** @@ -46,7 +48,8 @@ * @param sTestName Test name. * @param rTestMethod Test method. */ - public HyperLinkTest(String sTestName, TestMethod rTestMethod) { + public HyperLinkTest(String sTestName, TestMethod rTestMethod) + { super(sTestName, rTestMethod); } @@ -56,338 +59,367 @@ * * @return New testsuite. */ - public Test suite() { + public Test suite() + { TestSuite aSuite = new TestSuite(); aSuite.addTest(new HyperLinkTest("testCommands", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc).testCommands(); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc).testCommands(); + } + })); aSuite.addTest(new HyperLinkTest("testAppearanceModeChangePlain", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testAppearanceModeChange(StringItem.PLAIN); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testAppearanceModeChange(StringItem.PLAIN); + } + })); aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeButton", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testAppearanceModeChange(StringItem.BUTTON); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testAppearanceModeChange(StringItem.BUTTON); + } + })); aSuite.addTest(new HyperLinkTest("testAppearanceModeChangeHyperlink", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testAppearanceModeChange(StringItem.HYPERLINK); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testAppearanceModeChange(StringItem.HYPERLINK); + } + })); aSuite.addTest(new HyperLinkTest("testFocusInAppearanceModeChangePlain", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testFocusInAppearanceModeChange(StringItem.PLAIN); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testFocusInAppearanceModeChange(StringItem.PLAIN); + } + })); aSuite.addTest(new HyperLinkTest( - "testFocusInAppearanceModeChangeButton", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testFocusInAppearanceModeChange(StringItem.BUTTON); - } - })); + "testFocusInAppearanceModeChangeButton", + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testFocusInAppearanceModeChange(StringItem.BUTTON); + } + })); aSuite.addTest(new HyperLinkTest( - "testFocusInAppearanceModeChangeHyperlink", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc). - testFocusInAppearanceModeChange(StringItem.HYPERLINK); - } - })); + "testFocusInAppearanceModeChangeHyperlink", + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc). + testFocusInAppearanceModeChange(StringItem.HYPERLINK); + } + })); aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithLSK", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc).testLongHyperlink(Key.CBA1); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc).testLongHyperlink(Key.CBA1); + } + })); aSuite.addTest(new HyperLinkTest("testLongHyperlinkWithMSK", - new TestMethod() { - public void run(TestCase tc) { - ((HyperLinkTest) tc).testLongHyperlink(Key.Select); - } - })); + new TestMethod() + { + public void run(TestCase tc) + { + ((HyperLinkTest) tc).testLongHyperlink(Key.Select); + } + })); return aSuite; } /** - * Tests the basic functionality of command added to Hyperlink. - */ - public void testCommands() { - StringItem hyperlink = new StringItem("label", "url", - StringItem.HYPERLINK); + * Tests the basic functionality of command added to Hyperlink. + */ + public void testCommands() + { + StringItem hyperlink = new StringItem("label", "url", + StringItem.HYPERLINK); - testCommand(hyperlink); + testCommand(hyperlink); - // Because focus transfer in case of hyperlink is different than - // in normal cases it is good to test that commands works when - // moving focus from previous item to hyperlink as well as when - // moving focus from next item: - form.deleteAll(); - StringItem button1 = new StringItem(null, "button1", StringItem.BUTTON); - StringItem button2 = new StringItem(null, "button2", StringItem.BUTTON); - Command dummyCommand = new Command("dummy", "", Command.ITEM, 0); - button1.addCommand(dummyCommand); - button2.addCommand(dummyCommand); - button1.setItemCommandListener(this); - button2.setItemCommandListener(this); + // Because focus transfer in case of hyperlink is different than + // in normal cases it is good to test that commands works when + // moving focus from previous item to hyperlink as well as when + // moving focus from next item: + form.deleteAll(); + StringItem button1 = new StringItem(null, "button1", StringItem.BUTTON); + StringItem button2 = new StringItem(null, "button2", StringItem.BUTTON); + Command dummyCommand = new Command("dummy", "", Command.ITEM, 0); + button1.addCommand(dummyCommand); + button2.addCommand(dummyCommand); + button1.setItemCommandListener(this); + button2.setItemCommandListener(this); - // Some typical url-characters are replaced with 'x'-chars to avoid - // some problems in eSWT/AVKON implementation. Those problems should - // go away when using QT-based eSWT. + // Some typical url-characters are replaced with 'x'-chars to avoid + // some problems in eSWT/AVKON implementation. Those problems should + // go away when using QT-based eSWT. - Command ok = new Command("Ok", "", Command.ITEM, 0); + Command ok = new Command("Ok", "", Command.ITEM, 0); - StringItem hyperlink3 = new StringItem(null, - "xxxx://this.link.should.be.wrapped.to.many" - + ".lines.info/index.php?wrapped=truexi=hope", - StringItem.HYPERLINK); - hyperlink3.addCommand(ok); - hyperlink3.setItemCommandListener(this); + StringItem hyperlink3 = new StringItem(null, + "xxxx://this.link.should.be.wrapped.to.many" + + ".lines.info/index.php?wrapped=truexi=hope", + StringItem.HYPERLINK); + hyperlink3.addCommand(ok); + hyperlink3.setItemCommandListener(this); - form.append(button1); - form.append(hyperlink3); - form.append(button2); + form.append(button1); + form.append(hyperlink3); + form.append(button2); - block(CHANGE_DISPLAYABLE_DELAY); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.RightArrow); - key(Key.CBA1); - assertItemCmdListener("hyperlink focus transfer test, case 1", ok, - hyperlink3); + key(Key.RightArrow); + key(Key.CBA1); + assertItemCmdListener("hyperlink focus transfer test, case 1", ok, + hyperlink3); - key(Key.RightArrow); - key(Key.LeftArrow); - key(Key.CBA1); - assertItemCmdListener("hyperlink focus transfer test, case 2", ok, - hyperlink3); - } + key(Key.RightArrow); + key(Key.LeftArrow); + key(Key.CBA1); + assertItemCmdListener("hyperlink focus transfer test, case 2", ok, + hyperlink3); + } - /** - * Tests that commands are working as expected when commands - * are added or removed dynamically. - * - * @param mode Appearancemode of StringItem. - */ - public void testAppearanceModeChange(int mode) { - switch (mode) { - case StringItem.PLAIN: - print("Running test with appearance mode PLAIN."); - break; - case StringItem.BUTTON: - print("Running test with appearance mode BUTTON."); - break; - case StringItem.HYPERLINK: - print("Running test with appearance mode HYPERLINK."); - break; - default: - fail("Invalid test (incorrect appearance mode)."); - break; - } + /** + * Tests that commands are working as expected when commands + * are added or removed dynamically. + * + * @param mode Appearancemode of StringItem. + */ + public void testAppearanceModeChange(int mode) + { + switch(mode) + { + case StringItem.PLAIN: + print("Running test with appearance mode PLAIN."); + break; + case StringItem.BUTTON: + print("Running test with appearance mode BUTTON."); + break; + case StringItem.HYPERLINK: + print("Running test with appearance mode HYPERLINK."); + break; + default: + fail("Invalid test (incorrect appearance mode)."); + break; + } - StringItem stringItem = new StringItem("label", "url", mode); - Command ok = new Command("Ok", "", Command.ITEM, 0); + StringItem stringItem = new StringItem("label", "url", mode); + Command ok = new Command("Ok", "", Command.ITEM, 0); - form.append(stringItem); - stringItem.addCommand(ok); - stringItem.setItemCommandListener(this); + form.append(stringItem); + stringItem.addCommand(ok); + stringItem.setItemCommandListener(this); - setCurrent(form); + setCurrent(form); - // Remove command and make sure the command is not working anymore: - stringItem.removeCommand(ok); - block(CHANGE_DISPLAYABLE_DELAY); + // Remove command and make sure the command is not working anymore: + stringItem.removeCommand(ok); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.CBA1); - assertItemCmdListener("cmd activated after removing", null, null); + key(Key.CBA1); + assertItemCmdListener("cmd activated after removing", null, null); - // Add command again and verify it works: - stringItem.addCommand(ok); - block(CHANGE_DISPLAYABLE_DELAY); + // Add command again and verify it works: + stringItem.addCommand(ok); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.CBA1); - assertItemCmdListener("", ok, stringItem); - } + key(Key.CBA1); + assertItemCmdListener("", ok, stringItem); + } - /** - * Tests that focus transfer works when commands are added/removed - * dynamically. - * - * @param mode Appearancemode of StringItem. - */ - public void testFocusInAppearanceModeChange(int mode) { - switch (mode) { - case StringItem.PLAIN: - print("Running test with appearance mode PLAIN."); - break; - case StringItem.BUTTON: - print("Running test with appearance mode BUTTON."); - break; - case StringItem.HYPERLINK: - print("Running test with appearance mode HYPERLINK."); - break; - default: - fail("Invalid test (incorrect appearance mode)."); - break; - } + /** + * Tests that focus transfer works when commands are added/removed + * dynamically. + * + * @param mode Appearancemode of StringItem. + */ + public void testFocusInAppearanceModeChange(int mode) + { + switch(mode) + { + case StringItem.PLAIN: + print("Running test with appearance mode PLAIN."); + break; + case StringItem.BUTTON: + print("Running test with appearance mode BUTTON."); + break; + case StringItem.HYPERLINK: + print("Running test with appearance mode HYPERLINK."); + break; + default: + fail("Invalid test (incorrect appearance mode)."); + break; + } - StringItem stringItem = new StringItem(null, "url", mode); + StringItem stringItem = new StringItem(null, "url", mode); - StringItem button1 = new StringItem(null, "button1", Item.BUTTON); - StringItem button2 = new StringItem(null, "button2", Item.BUTTON); + StringItem button1 = new StringItem(null, "button1", Item.BUTTON); + StringItem button2 = new StringItem(null, "button2", Item.BUTTON); - Command ok = new Command("giamcc1", "", Command.ITEM, 0); - Command buttonCommand1 = new Command("giamcc12", "", Command.ITEM, 0); - Command buttonCommand2 = new Command("giamcc13", "", Command.ITEM, 0); + Command ok = new Command("giamcc1", "", Command.ITEM, 0); + Command buttonCommand1 = new Command("giamcc12", "", Command.ITEM, 0); + Command buttonCommand2 = new Command("giamcc13", "", Command.ITEM, 0); - form.append(button1); - form.append(stringItem); - form.append(button2); + form.append(button1); + form.append(stringItem); + form.append(button2); - // Set listener but do not add commands yet: - stringItem.setItemCommandListener(this); - button1.addCommand(buttonCommand1); - button2.addCommand(buttonCommand2); - button1.setItemCommandListener(this); - button2.setItemCommandListener(this); + // Set listener but do not add commands yet: + stringItem.setItemCommandListener(this); + button1.addCommand(buttonCommand1); + button2.addCommand(buttonCommand2); + button1.setItemCommandListener(this); + button2.setItemCommandListener(this); - setCurrent(form); + setCurrent(form); - // At this point there are two buttons and plain stringItem - // in middle of them. Focus is in first button. - // Move to second button, add command to StringItem, move - // to StringItem and verify command works: - key(Key.RightArrow); + // At this point there are two buttons and plain stringItem + // in middle of them. Focus is in first button. + // Move to second button, add command to StringItem, move + // to StringItem and verify command works: + key(Key.RightArrow); - stringItem.addCommand(ok); - block(CHANGE_DISPLAYABLE_DELAY); + stringItem.addCommand(ok); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.LeftArrow); + key(Key.LeftArrow); - assertItemCmdListener("case1", ok, stringItem); + assertItemCmdListener("case1", ok, stringItem); - // Now remove command from StringItem. Test assumes that in this - // case focus is moved to next item which is the second button. - // Verify that happens and also make sure it is possible to move - // to first button also: - stringItem.removeCommand(ok); - block(CHANGE_DISPLAYABLE_DELAY); + // Now remove command from StringItem. Test assumes that in this + // case focus is moved to next item which is the second button. + // Verify that happens and also make sure it is possible to move + // to first button also: + stringItem.removeCommand(ok); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.CBA1); - assertItemCmdListener("case2", buttonCommand2, button2); + key(Key.CBA1); + assertItemCmdListener("case2", buttonCommand2, button2); - key(Key.LeftArrow); + key(Key.LeftArrow); - key(Key.CBA1); - assertItemCmdListener("case3", buttonCommand1, button1); + key(Key.CBA1); + assertItemCmdListener("case3", buttonCommand1, button1); - // Now add command back to StringItem again and make sure it - // works: - stringItem.addCommand(ok); - block(CHANGE_DISPLAYABLE_DELAY); + // Now add command back to StringItem again and make sure it + // works: + stringItem.addCommand(ok); + block(CHANGE_DISPLAYABLE_DELAY); - key(Key.RightArrow); + key(Key.RightArrow); - key(Key.CBA1); - assertItemCmdListener("case4", ok, stringItem); + key(Key.CBA1); + assertItemCmdListener("case4", ok, stringItem); - // And verify also the functionality of second button after - // these changes: - key(Key.RightArrow); + // And verify also the functionality of second button after + // these changes: + key(Key.RightArrow); - key(Key.CBA1); - assertItemCmdListener("case5", buttonCommand2, button2); - } + key(Key.CBA1); + assertItemCmdListener("case5", buttonCommand2, button2); + } - /** - * Tests that Hyperlink works as expected when its size exceeds - * screen height. - * - * @param key Keycode which is used to verify the hyperlink command - * works. - */ - public void testLongHyperlink(int key) { - StringItem stringItem = new StringItem( - "label", - "The quick brown fox jumps over the lazy dog and realizes" - + " that this hyperlink text is repeated several times to make" - + " sure the size of the hyperlink exceeds screen height. " - + "The quick brown fox jumps over the lazy dog and realizes" - + " that this hyperlink text is repeated several times to make" - + " sure the size of the hyperlink exceeds screen height. " - + "The quick brown fox jumps over the lazy dog and realizes" - + " that this hyperlink text is repeated several times to make" - + " sure the size of the hyperlink exceeds screen height. ", - StringItem.HYPERLINK); + /** + * Tests that Hyperlink works as expected when its size exceeds + * screen height. + * + * @param key Keycode which is used to verify the hyperlink command + * works. + */ + public void testLongHyperlink(int key) + { + StringItem stringItem = new StringItem( + "label", + "The quick brown fox jumps over the lazy dog and realizes" + + " that this hyperlink text is repeated several times to make" + + " sure the size of the hyperlink exceeds screen height. " + + "The quick brown fox jumps over the lazy dog and realizes" + + " that this hyperlink text is repeated several times to make" + + " sure the size of the hyperlink exceeds screen height. " + + "The quick brown fox jumps over the lazy dog and realizes" + + " that this hyperlink text is repeated several times to make" + + " sure the size of the hyperlink exceeds screen height. ", + StringItem.HYPERLINK); - Command ok = new Command("lhlc1", "", Command.ITEM, 0); + Command ok = new Command("lhlc1", "", Command.ITEM, 0); - StringItem button1 = new StringItem(null, "button1", Item.BUTTON); - Command buttonCommand1 = new Command("lhlc2", "", Command.ITEM, 0); + StringItem button1 = new StringItem(null, "button1", Item.BUTTON); + Command buttonCommand1 = new Command("lhlc2", "", Command.ITEM, 0); - form.append(stringItem); - stringItem.addCommand(ok); - stringItem.setItemCommandListener(this); + form.append(stringItem); + stringItem.addCommand(ok); + stringItem.setItemCommandListener(this); - form.append(button1); - button1.addCommand(buttonCommand1); - button1.setItemCommandListener(this); + form.append(button1); + button1.addCommand(buttonCommand1); + button1.setItemCommandListener(this); - setCurrent(form); + setCurrent(form); - //TODO: When running all tests and the key is LSK and in following loop - //the i is 0, latestCommand is buttonCommand1 and latestItem is null. - //If button is not added to the form then the latestCommand also - //will be null. - //Problem has something to do with timing, because - //adding debugprints to this test will sometimes make it pass. - //For example following delay will make the test pass: - block(CHANGE_DISPLAYABLE_DELAY); + //TODO: When running all tests and the key is LSK and in following loop + //the i is 0, latestCommand is buttonCommand1 and latestItem is null. + //If button is not added to the form then the latestCommand also + //will be null. + //Problem has something to do with timing, because + //adding debugprints to this test will sometimes make it pass. + //For example following delay will make the test pass: + block(CHANGE_DISPLAYABLE_DELAY); + + // Scroll down and after each keydown-press make sure the hyperlink + // is still focused: + final int rounds = 10; + final int roundsInHyperlink = 3; + for(int i = 0; i < rounds; i++) + { + key(key); - // Scroll down and after each keydown-press make sure the hyperlink - // is still focused: - final int rounds = 10; - final int roundsInHyperlink = 3; - for (int i = 0; i < rounds; i++) { - key(key); + if(i < roundsInHyperlink) + { + // Code assumes that it takes at least three + // keypresses to reach button which is located below hyperlink: + assertItemCmdListener("clicking hyperlink. i=" + i, ok, + stringItem); + } + else if(i >= (rounds - 1)) + { + // After 10 keypresses button should be focused: + assertItemCmdListener("clicking button. i=" + i, + buttonCommand1, button1); + } - if (i < roundsInHyperlink) { - // Code assumes that it takes at least three - // keypresses to reach button which is located below hyperlink: - assertItemCmdListener("clicking hyperlink. i=" + i, ok, - stringItem); - } else if (i >= (rounds - 1)) { - // After 10 keypresses button should be focused: - assertItemCmdListener("clicking button. i=" + i, - buttonCommand1, button1); - } - - key(Key.RightArrow); - block(CHANGE_DISPLAYABLE_DELAY); - } - } + key(Key.RightArrow); + block(CHANGE_DISPLAYABLE_DELAY); + } + } }