FileDocCategorySizeDatePackage
CustomItemTest.javaAPI DocphoneME MR2 API (J2ME)10425Wed May 02 18:00:22 BST 2007javax.microedition.lcdui

CustomItemTest

public class CustomItemTest extends TestCase

Fields Summary
FormLFImpl
ownerLFImpl
int
vpY_beforeScroll
int
vpY_AfterScroll
Constructors Summary
Methods Summary
public voidrunTests()
check that the viewport scrolls to make the returned vis_Rect from traverse method visible This test is specific to platform_widget. Enable it only for platform-widget if possible. void testCustomItemInternalTraversal2() { Display display = DisplayTestUtils.createDisplay(); Form mainForm = new Form("CustomItem 2 Demo"); TextField tf = new TextField("Text Field", "some text", 100, 0); CustomItemImpl customItem1 = new CustomItemImpl("CustomItem1", 80, display, false); customItem1.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_NEWLINE_AFTER); CustomItemImpl customItem2 = new CustomItemImpl("CustomItem2", 80, display, false); customItem2.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_NEWLINE_AFTER); StringItem si = new StringItem("a string", "some text"); mainForm.append(tf); mainForm.append(customItem1); mainForm.append(si); mainForm.append(customItem2); display.setCurrentItem(customItem2); // make sure the form is visible try { Thread.sleep(2000); } catch (Exception e) {} assertSame(display.getCurrent(), mainForm); // part of the custom item is made visible CustomItemLF customItemLF = customItem2.customItemLF; Item myitem = ((CustomItemLFImpl)customItemLF).item; Screen owner = myitem.owner; if (owner != null) { ownerLFImpl = (FormLFImpl)owner.getLF(); } // vpY1 the y coordinate of the top left visible pixel // current scroll position vpY_beforeScroll = ownerLFImpl.getScrollPosition0(); // call key down // KEYCODE_DOWN Value="-2" ((CustomItemLFImpl)customItemLF).uCallKeyPressed(-2); ((CustomItemLFImpl)customItemLF).uCallKeyReleased(-2); assertTrue("traverse not called: first call", customItem2.traverse_flag); ((CustomItemLFImpl)customItemLF).uCallKeyPressed(-2); ((CustomItemLFImpl)customItemLF).uCallKeyReleased(-2); assertTrue("traverse not called: second call", customItem2.traverse_flag); // check that the viewport scrolls to make the // returned vis_Rect visible // vpY1 the y coordinate of the top left visible pixel vpY_AfterScroll = ownerLFImpl.getScrollPosition0(); boolean screenScrolled = vpY_AfterScroll > vpY_beforeScroll ? true : false; assertTrue("screen not Scrolled", screenScrolled); Display.displayManagerImpl.uRequestForegroundNone(); assertSame(Display.displayManagerImpl.noForeground, Display.displayManagerImpl.foreground); }

        declare("testCustomItemInternalTraversal");
        testCustomItemInternalTraversal();

	/*
	 * This test is platform_widget specific.
	 *
        declare("testCustomItemInternalTraversal2");
        testCustomItemInternalTraversal2();
	 */
    
voidtestCustomItemInternalTraversal()



      
	Display display = DisplayTestUtils.createDisplay();
        Form mainForm = new Form("CustomItem Demo");
	CustomItemImpl customItem = 
                new CustomItemImpl("CustomItem", 80, display, false); 
        mainForm.append(customItem);
        display.setCurrent(mainForm);

	// make sure the form is visible
	try {
	    Thread.sleep(2000);
	} catch (Exception e) {}

	assertSame(display.getCurrent(), mainForm);

	CustomItemLF customItemLF = customItem.customItemLF;
	Item myitem = ((CustomItemLFImpl)customItemLF).item;

	// call keypress with "up" keyCode -1
	((CustomItemLFImpl)customItemLF).uCallKeyPressed(-1);
	((CustomItemLFImpl)customItemLF).uCallKeyReleased(-1);

	assertTrue("traverse not called", customItem.traverse_flag);
        Display.displayManagerImpl.uRequestForegroundNone();	
	assertSame(Display.displayManagerImpl.noForeground, 
                             Display.displayManagerImpl.foreground);