javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt_uirobot/stringitem/HyperLinkTest.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
--- a/javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt_uirobot/stringitem/HyperLinkTest.java	Mon May 03 12:27:20 2010 +0300
+++ b/javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt_uirobot/stringitem/HyperLinkTest.java	Fri May 14 15:47:24 2010 +0300
@@ -11,7 +11,7 @@
 *
 * Contributors:
 *
-* Description: 
+* Description:
 *
 */
 package com.nokia.openlcdui.mt_uirobot.stringitem;
@@ -32,12 +32,14 @@
  * <br>
  * Created: 2008-10-20
  */
-public class HyperLinkTest extends ItemUITestBase {
+public class HyperLinkTest extends ItemUITestBase
+{
 
     /**
      * Constructor.
      */
-    public HyperLinkTest() {
+    public HyperLinkTest()
+    {
     }
 
     /**
@@ -46,27 +48,31 @@
      * @param sTestName Test name.
      * @param rTestMethod Test method.
      */
-    public HyperLinkTest(String sTestName) {
+    public HyperLinkTest(String sTestName)
+    {
         super(sTestName);
     }
 
-    public static Test suite() {
+    public static Test suite()
+    {
         TestSuite suite = new TestSuite();
 
         java.util.Vector methodNames;
-	    java.util.Enumeration e;
+        java.util.Enumeration e;
 
-	    // Add widget tests
-	    methodNames = HyperLinkTest.methodNames();
-	    e = methodNames.elements();
-	    while (e.hasMoreElements()) {
-	        suite.addTest(new HyperLinkTest((String)e.nextElement()));
-	    }
-        
+        // Add widget tests
+        methodNames = HyperLinkTest.methodNames();
+        e = methodNames.elements();
+        while(e.hasMoreElements())
+        {
+            suite.addTest(new HyperLinkTest((String)e.nextElement()));
+        }
+
         return suite;
     }
 
-    public static java.util.Vector methodNames() {
+    public static java.util.Vector methodNames()
+    {
         java.util.Vector methodNames = new java.util.Vector();
         methodNames.addElement("testCommands");
         methodNames.addElement("testAppearanceModeChangePlain");
@@ -79,293 +85,312 @@
         methodNames.addElement("testLongHyperlinkWithMSK");
         return methodNames;
     }
-    
-    public void runTest() throws Throwable {
-        if (getName().equals("testCommands")) testCommands();
-        else if (getName().equals("testAppearanceModeChangePlain")) {
-        	testAppearanceModeChange(StringItem.PLAIN);
+
+    public void runTest() throws Throwable
+    {
+        if(getName().equals("testCommands")) testCommands();
+        else if(getName().equals("testAppearanceModeChangePlain"))
+        {
+            testAppearanceModeChange(StringItem.PLAIN);
         }
-        else if (getName().equals("testAppearanceModeChangeButton")) {
-        	testAppearanceModeChange(StringItem.BUTTON);
+        else if(getName().equals("testAppearanceModeChangeButton"))
+        {
+            testAppearanceModeChange(StringItem.BUTTON);
         }
-        else if (getName().equals("testAppearanceModeChangeHyperlink")) {
-        	testAppearanceModeChange(StringItem.HYPERLINK);
+        else if(getName().equals("testAppearanceModeChangeHyperlink"))
+        {
+            testAppearanceModeChange(StringItem.HYPERLINK);
         }
-        else if (getName().equals("testFocusInAppearanceModeChangePlain")) {
-        	testFocusInAppearanceModeChange(StringItem.PLAIN);
+        else if(getName().equals("testFocusInAppearanceModeChangePlain"))
+        {
+            testFocusInAppearanceModeChange(StringItem.PLAIN);
         }
-        else if (getName().equals("testFocusInAppearanceModeChangeButton")) {
-        	testFocusInAppearanceModeChange(StringItem.BUTTON);
+        else if(getName().equals("testFocusInAppearanceModeChangeButton"))
+        {
+            testFocusInAppearanceModeChange(StringItem.BUTTON);
         }
-        else if (getName().equals("testFocusInAppearanceModeChangeHyperlink")) {
-        	testFocusInAppearanceModeChange(StringItem.HYPERLINK);
+        else if(getName().equals("testFocusInAppearanceModeChangeHyperlink"))
+        {
+            testFocusInAppearanceModeChange(StringItem.HYPERLINK);
         }
-        else if (getName().equals("testLongHyperlinkWithLSK")) {
-        	testLongHyperlink(Key.CBA1);
+        else if(getName().equals("testLongHyperlinkWithLSK"))
+        {
+            testLongHyperlink(Key.CBA1);
         }
-        else if (getName().equals("testLongHyperlinkWithMSK")) {
-        	testLongHyperlink(Key.Select);
+        else if(getName().equals("testLongHyperlinkWithMSK"))
+        {
+            testLongHyperlink(Key.Select);
         }
 
         else super.runTest();
-    }    
- 
+    }
+
+
+    /**
+     * Tests the basic functionality of command added to Hyperlink.
+     */
+    public void testCommands()
+    {
+        StringItem hyperlink = new StringItem("label", "url",
+                                              StringItem.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);
+
+        // 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);
+
+        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);
+
+        block(CHANGE_DISPLAYABLE_DELAY);
+
+        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);
+    }
+
+    /**
+     * 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);
+
+        form.append(stringItem);
+        stringItem.addCommand(ok);
+        stringItem.setItemCommandListener(this);
+
+        setCurrent(form);
+
+        // 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);
+
+        // Add command again and verify it works:
+        stringItem.addCommand(ok);
+        block(CHANGE_DISPLAYABLE_DELAY);
+
+        key(Key.CBA1);
+        assertItemCmdListener("", ok, stringItem);
+    }
 
     /**
-	 * Tests the basic functionality of command added to Hyperlink.
-	 */
-	public void testCommands() {
-		StringItem hyperlink = new StringItem("label", "url",
-				StringItem.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);
-
-		// 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.
+     * 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;
+        }
 
-		Command ok = new Command("Ok", "", Command.ITEM, 0);
+        StringItem stringItem = new StringItem(null, "url", mode);
 
-		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);
+        StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
+        StringItem button2 = new StringItem(null, "button2", Item.BUTTON);
 
-		block(CHANGE_DISPLAYABLE_DELAY);
-
-		key(Key.RightArrow);
-		key(Key.CBA1);
-		assertItemCmdListener("hyperlink focus transfer test, case 1", ok,
-				hyperlink3);
+        Command ok = new Command("giamcc1", "", Command.ITEM, 0);
+        Command buttonCommand1 = new Command("giamcc12", "", Command.ITEM, 0);
+        Command buttonCommand2 = new Command("giamcc13", "", Command.ITEM, 0);
 
-		key(Key.RightArrow);
-		key(Key.LeftArrow);
-		key(Key.CBA1);
-		assertItemCmdListener("hyperlink focus transfer test, case 2", ok,
-				hyperlink3);
-	}
+        form.append(button1);
+        form.append(stringItem);
+        form.append(button2);
 
-	/**
-	 * 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;
-		}
+        // 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);
 
-		StringItem stringItem = new StringItem("label", "url", mode);
-		Command ok = new Command("Ok", "", Command.ITEM, 0);
+        // 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);
 
-		form.append(stringItem);
-		stringItem.addCommand(ok);
-		stringItem.setItemCommandListener(this);
+        stringItem.addCommand(ok);
+        block(CHANGE_DISPLAYABLE_DELAY);
 
-		setCurrent(form);
+        key(Key.LeftArrow);
 
-		// Remove command and make sure the command is not working anymore:
-		stringItem.removeCommand(ok);
-		block(CHANGE_DISPLAYABLE_DELAY);
+        assertItemCmdListener("case1", ok, stringItem);
 
-		key(Key.CBA1);
-		assertItemCmdListener("cmd activated after removing", null, null);
+        // 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);
 
-		// Add command again and verify it works:
-		stringItem.addCommand(ok);
-		block(CHANGE_DISPLAYABLE_DELAY);
-
-		key(Key.CBA1);
-		assertItemCmdListener("", ok, stringItem);
-	}
+        key(Key.CBA1);
+        assertItemCmdListener("case2", buttonCommand2, button2);
 
-	/**
-	 * 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;
-		}
+        key(Key.LeftArrow);
+
+        key(Key.CBA1);
+        assertItemCmdListener("case3", buttonCommand1, button1);
 
-		StringItem stringItem = new StringItem(null, "url", mode);
+        // Now add command back to StringItem again and make sure it
+        // works:
+        stringItem.addCommand(ok);
+        block(CHANGE_DISPLAYABLE_DELAY);
 
-		StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
-		StringItem button2 = new StringItem(null, "button2", Item.BUTTON);
+        key(Key.RightArrow);
 
-		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);
-
-		// Set listener but do not add commands yet:
-		stringItem.setItemCommandListener(this);
-		button1.addCommand(buttonCommand1);
-		button2.addCommand(buttonCommand2);
-		button1.setItemCommandListener(this);
-		button2.setItemCommandListener(this);
+        key(Key.CBA1);
+        assertItemCmdListener("case4", ok, stringItem);
 
-		setCurrent(form);
+        // And verify also the functionality of second button after
+        // these changes:
+        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);
-
-		key(Key.LeftArrow);
-
-		assertItemCmdListener("case1", ok, stringItem);
+        key(Key.CBA1);
+        assertItemCmdListener("case5", buttonCommand2, button2);
+    }
 
-		// 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.LeftArrow);
-
-		key(Key.CBA1);
-		assertItemCmdListener("case3", buttonCommand1, button1);
+    /**
+     * 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);
 
-		// Now add command back to StringItem again and make sure it
-		// works:
-		stringItem.addCommand(ok);
-		block(CHANGE_DISPLAYABLE_DELAY);
-
-		key(Key.RightArrow);
+        Command ok = new Command("lhlc1", "", Command.ITEM, 0);
 
-		key(Key.CBA1);
-		assertItemCmdListener("case4", ok, stringItem);
+        StringItem button1 = new StringItem(null, "button1", Item.BUTTON);
+        Command buttonCommand1 = new Command("lhlc2", "", Command.ITEM, 0);
 
-		// And verify also the functionality of second button after
-		// these changes:
-		key(Key.RightArrow);
-
-		key(Key.CBA1);
-		assertItemCmdListener("case5", buttonCommand2, button2);
-	}
+        form.append(stringItem);
+        stringItem.addCommand(ok);
+        stringItem.setItemCommandListener(this);
 
-	/**
-	 * 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);
+        form.append(button1);
+        button1.addCommand(buttonCommand1);
+        button1.setItemCommandListener(this);
+
+        setCurrent(form);
 
-		Command ok = new Command("lhlc1", "", 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(button1);
-		button1.addCommand(buttonCommand1);
-		button1.setItemCommandListener(this);
+        //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);
 
-		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);
+        // 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);
+        }
+    }
 
 }