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

TestSizeChanged

public class TestSizeChanged extends TestCase
This test case is meant to verify that the sizeChanged method of a Canvas is called correctly in every instance where it is required by the MIDP specification. It is triggered by the addition or removal of a title, ticker, or both. It may also be triggered in the event that the full screen and non-full screen display is toggled. sizeChanged should be called when the canvas is visible, or in the event the canvas is not shown, sizeChanged should be called before paint is called.

Fields Summary
static final String
testName
Name for this test grouping
protected static int
STD_WIDTH
Width of the screen in non fullscreen mode
protected static int
STD_HEIGHT
Height of the screen in non fullscreen mode
protected static int
FS_HEIGHT
Height of the screen in fulscreen mode
protected static int
TITLE_HEIGHT
Height of the title bar
protected static int
TICKER_HEIGHT
Height of the ticker
protected static int
SOFTBTN_HEIGHT
Height of the soft button bar
protected Display
display
The Display to use to view our test canvases
protected Ticker
ticker
Test ticker, used for sizing only
Constructors Summary
public TestSizeChanged()
Construct a new SizeChanged test. The constructor initializes all sizing constants from the chameleon skin files.

    
                         
      
        // Initialize the constants
        
        STD_WIDTH = ScreenSkin.WIDTH;
        STD_HEIGHT = ScreenSkin.HEIGHT;
        FS_HEIGHT = ScreenSkin.FULLHEIGHT;
        TITLE_HEIGHT = TitleSkin.HEIGHT;
        TICKER_HEIGHT = TickerSkin.HEIGHT;
        SOFTBTN_HEIGHT = SoftButtonSkin.HEIGHT;

        ticker = new Ticker("Canvas sizeChanged() tests...");
    
Methods Summary
protected voidcheckCanvasSizeChanged(javax.microedition.lcdui.TestSizeChanged$TestCanvas canvas, int WIDTH, int HEIGHT)
This is a utility method which checks values passed by sizeChanged against passed in values. It ensures that the method should have been called by waiting for the canvas to be visible on the screen.

param
canvas the canvas to test
param
WIDTH the correct width the canvas should be after the most recent sizeChanged call
param
HEIGHT the correct height the canvas should be after the most recent sizeChanged call

        synchronized (canvas) {
            display.setCurrent(canvas);
            try {
                canvas.wait();
            } catch (InterruptedException ie) {
            } catch (IllegalMonitorStateException im) {
                fail("Unexpected monitor exception");
                return;
            }
        }
        
        // Now the canvas should be showing on the screen, we test
        // our assertions about <code>sizeChanged</code> being called
        assertEquals("Checking for Canvas.sizeChanged() width update", 
                     WIDTH, canvas.checkSizeWidth());
        assertEquals("Checking for Canvas.sizeChanged() height update", 
                     HEIGHT, canvas.checkSizeHeight());
    
protected voidcheckCurrentCanvasSizeChanged(javax.microedition.lcdui.TestSizeChanged$TestCanvas canvas, int WIDTH, int HEIGHT)
This is a utility method which checks values passed by sizeChanged against passed in values. It ensures that the method should have been called by waiting for the canvas to be visible on the screen.

param
canvas the canvas to test
param
WIDTH the correct width the canvas should be after the most recent sizeChanged call
param
HEIGHT the correct height the canvas should be after the most recent sizeChanged call

        synchronized (canvas) {
            //display.setCurrent(canvas);
            try {
                canvas.wait();
            } catch (InterruptedException ie) {
            } catch (IllegalMonitorStateException im) {
                fail("Unexpected monitor exception");
                return;
            }
        }
        
        // Now the canvas should be showing on the screen, we test
        // our assertions about <code>sizeChanged</code> being called
        assertEquals("Checking for Canvas.sizeChanged() width update", 
                     WIDTH, canvas.checkSizeWidth());
        assertEquals("Checking for Canvas.sizeChanged() height update", 
                     HEIGHT, canvas.checkSizeHeight());
    
public voidrunTests()
Overridden from TestCase parent. This method will kick off each individual test

        
        MIDletStateHandler msHandler = MIDletStateHandler.getMidletStateHandler();
        // Start a new instance of DummyMIDlet
        try {
            msHandler.startMIDlet("com.sun.midp.util.DummyMIDlet",
                                  "DummyMIDlet");
        } catch (Exception cnf) {
            return;
        }
        
        // Wait for async request to be processed 
        while (DummyMIDlet.midlet == null) {
            try { Thread.sleep(100); } catch (InterruptedException ie) {;}
        }

        MIDlet midlet = DummyMIDlet.midlet;
        display = Display.getDisplay(midlet);
        
        testOne();   
        testTwo();
        testThree();
        testFour();
        testFive();
        testSix();
        testSeven();
        testEight();
        testNine();
        testTen();
        testEleven();
        testTwelve();
        testThirteen();
        
        // Notify the system that our midlet is done
        midlet.notifyDestroyed();
        try {
            ((DummyMIDlet)midlet).destroyApp(true);
        } catch (MIDletStateChangeException ignore) {
        }
    
protected voidtestEight()
This test is for a canvas with a title and ticker set in standard screen mode. The ticker and title are removed, and the canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 8: bg->fg: std-screen, with title & ticker." + 
                "  remove both ticker and title");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();
        
        display.setCurrent(canvas);
        
        canvas.setTitle("SizeChanged Test 8");
        canvas.setTicker(ticker);
        
        display.setCurrent(tmpCanvas);
        
        canvas.setTicker(null);
        canvas.setTitle(null);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT);
    
protected voidtestEleven()
Test 11 involves removing components from a Canvas which is the current display, and checking to see that the proper sizeChanged() occurs after each removal

        declare(testName + " 11: in fg: std-screen, with title & ticker." +
                " remove title, then ticker.");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();

        display.setCurrent(tmpCanvas);

        canvas.setTitle("SizeChanged test 11");
        canvas.setTicker(ticker);

        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT -
                               TITLE_HEIGHT - TICKER_HEIGHT); 

        canvas.setTitle(null);
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - 
                                      SOFTBTN_HEIGHT - TICKER_HEIGHT); 

        canvas.setTicker(null);
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT); 
    
protected voidtestFive()
This test is for a canvas with a title and a ticker set in standard screen mode. The canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 5: bg->fg: std-screen, with title & ticker");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();

        display.setCurrent(canvas);

        canvas.setTitle("SizeChanged test 5");
        canvas.setTicker(ticker);

        display.setCurrent(tmpCanvas);

        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT -
                               TITLE_HEIGHT - TICKER_HEIGHT); 
    
protected voidtestFour()
This test is for a canvas with a ticker set in standard screen mode. The canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 4: bg->fg: std-screen, add ticker");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTicker(ticker);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, 
                               STD_HEIGHT - SOFTBTN_HEIGHT - TICKER_HEIGHT);
    
protected voidtestNine()
This test is for a canvas with a title and ticker set in standard screen mode. FullScreen mode is then set on the Canvas and it is set to the current display causing sizeChanged to be called.

        declare(testName + " 9: bg->fg: std-screen, with title & ticker." + 
                "  set fullscreen mode");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();
        
        display.setCurrent(canvas);
        
        canvas.setTitle("SizeChanged Test 9");
        canvas.setTicker(ticker);
        
        display.setCurrent(tmpCanvas);
        
        canvas.toggleFullscreen(true);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, FS_HEIGHT - SOFTBTN_HEIGHT);
    
protected voidtestOne()
This test is for a canvas with no title and no ticker set in standard screen mode. The canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 1: bg->fg: std-screen, no title, no ticker");
        
        TestCanvas canvas = new TestCanvas();

        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT); 
    
protected voidtestSeven()
This test is for a canvas with a title and ticker set in standard screen mode. The title is removed, and the canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 7: bg->fg: std-screen, with title & ticker." + 
                "  remove title");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();

        display.setCurrent(canvas);

        canvas.setTitle("SizeChanged Test 7");
        canvas.setTicker(ticker);

        display.setCurrent(tmpCanvas);

        canvas.setTitle(null);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT 
                               - TICKER_HEIGHT);
    
protected voidtestSix()
This test is for a canvas with a title and ticker set in standard screen mode. The ticker is removed, and the canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 6: bg->fg: std-screen, with title & ticker." + 
                "  remove ticker");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();

        display.setCurrent(canvas);

        canvas.setTitle("SizeChanged Test 6");
        canvas.setTicker(ticker);

        display.setCurrent(tmpCanvas);

        canvas.setTicker(null);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT 
                               - TITLE_HEIGHT);
    
protected voidtestTen()
This test is for a canvas with a title and ticker set in full screen mode. Standard mode is then set on the Canvas and it is set to the current display causing sizeChanged to be called.

        declare(testName + " 10: bg->fg: full-screen, with title & ticker." + 
                "  set std-screen mode");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();
        
        display.setCurrent(canvas);

        canvas.toggleFullscreen(true);  
        canvas.setTitle("SizeChanged Test 10");
        canvas.setTicker(ticker);

        
        display.setCurrent(tmpCanvas);
        
        canvas.toggleFullscreen(false);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, FS_HEIGHT - SOFTBTN_HEIGHT -
                               TICKER_HEIGHT - TITLE_HEIGHT);
    
protected voidtestThirteen()
Test 13 involves changing to fullScreen mode and back on a canvas which is the current display, and checking to see that the proper sizeChanged call occurs after each change.

        declare(testName + " 13: in fg: std-screen, with title & ticker." +
                " remove title, then ticker.");
        
        TestCanvas tmpCanvas = new TestCanvas();
        TestCanvas canvas = new TestCanvas();

        display.setCurrent(tmpCanvas);

        canvas.setTitle("SizeChanged test 13");
        canvas.setTicker(ticker);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT -
                               TITLE_HEIGHT - TICKER_HEIGHT); 

        canvas.toggleFullscreen(true);
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT); 

        canvas.toggleFullscreen(false);
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT
                                      - TITLE_HEIGHT - TICKER_HEIGHT); 
    
protected voidtestThree()
This test is for a canvas with a title and ticker set in standard screen mode. The canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 3: bg->fg: std-screen, add title, add ticker");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("sizeChanged Test 3");
        canvas.setTicker(ticker);
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT 
                               - TICKER_HEIGHT - TITLE_HEIGHT);
    
protected voidtestTwelve()
Test 12 involves adding components from a canvas which is current display, and checking to see that the proper sizeChanged call occurs after each addition.

        declare(testName + " 12: in fg: std-screen.  add title, then ticker");
        
        TestCanvas canvas = new TestCanvas();
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT); 
        
        canvas.setTitle("SizeChanged Test 12");
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - 
                                      SOFTBTN_HEIGHT - TITLE_HEIGHT); 
        
        canvas.setTicker(ticker);
        checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT - 
                                      SOFTBTN_HEIGHT - TITLE_HEIGHT - 
                                      TICKER_HEIGHT); 
    
protected voidtestTwo()
This test is for a canvas with a title set in standard screen mode. The canvas is set to the current display causing sizeChanged to be called.

        declare(testName + " 2: bg->fg: std-screen, add title");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("SizeChanged Test 2");
        
        checkCanvasSizeChanged(canvas, STD_WIDTH, 
                               STD_HEIGHT - SOFTBTN_HEIGHT - TITLE_HEIGHT);