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

TestCanvasSizing

public class TestCanvasSizing extends com.sun.midp.i3test.TestCase
This test case does extensive testing on the proper sizing of Canvas. It validates the size reported to a Canvas under various conditions, such as a canvas with a title, a ticker, in standard screen mode, in fullscreen mode, as well as a canvas which is newly created versus showing on the screen.

Fields Summary
static final String
testName
Test Name
protected static int
STD_WIDTH
Screen width in normal mode
protected static int
STD_HEIGHT
Screen height in normal mode
protected static int
FS_WIDTH
Screen width in fullsize mode
protected static int
FS_HEIGHT
Screen height in fullsize mode
protected static int
TITLE_HEIGHT
Title height
protected static int
TICKER_HEIGHT
Ticker height
protected static int
SOFTBTN_HEIGHT
Softbutton height
protected Display
display
The Display to use to view our test canvases
protected Ticker
ticker
Test ticker, used for sizing only
Constructors Summary
public TestCanvasSizing()
Construct a new CanvasSizing test. The constructor initializes all sizing constants from the chameleon skin files.

    
                         
      
        // Initialize the constants
        
        STD_WIDTH = ScreenSkin.WIDTH;
        STD_HEIGHT = Constants.CHAM_HEIGHT;
        FS_WIDTH = Constants.CHAM_FULLWIDTH;
        FS_HEIGHT = Constants.CHAM_FULLHEIGHT;
        TITLE_HEIGHT = TitleSkin.HEIGHT;
        TICKER_HEIGHT = TickerSkin.HEIGHT;
        SOFTBTN_HEIGHT = SoftButtonSkin.HEIGHT;

        ticker = new Ticker("Canvas sizing test");
    
Methods Summary
protected voidcheckCanvasSize(javax.microedition.lcdui.TestCanvasSizing$TestCanvas canvas, int WIDTH, int HEIGHT)
This is a utility method which retrieves the canvas's size and validates it against the passed in values after making sure the canvas is visible on the screen.

param
canvas the canvas to test
param
WIDTH the correct width the canvas should be
param
HEIGHT the correct height the canvas should be

            
        display.setCurrent(canvas);

        if (!canvas.awaitPaint()) {
            fail("checkCanvasSize: canvas not visible");
            return;
        }
            
        int w = canvas.getWidth();
        int h = canvas.getHeight();
        assertEquals("Checking canvas width (shown):", WIDTH, w);
        assertEquals("Checking canvas height (shown):", HEIGHT, h);
    
public voidrunTests()
Overridden from TestCase parent. This method will kick off each individual test

        
        try {
            LcduiTestMIDlet.invoke();
            display = LcduiTestMIDlet.getDisplay();

            testOne();
            testTwo();
            testThree();
            testFour();
            testFive();
            testSix();
            testSeven();
            testEight();
        } finally {
            LcduiTestMIDlet.cleanup();
        }
    
protected voidtestEight()
This test is for a canvas with no ticker and no title set in fullscreen mode.

        declare(testName + " 8: Fullsize screen mode, plain.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.toggleFullscreen(true);
        
        // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
        // per the chameleon UI spec: that area is then used by the canvas
        checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
    
protected voidtestFive()
This test is for a canvas with a title and a ticker set in fullscreen mode.

        declare(testName + " 5: Fullsize screen mode with title and ticker.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("CanvasSizing Test 5");
        canvas.setTicker(ticker);
        canvas.toggleFullscreen(true);

        // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
        // per the chameleon UI spec: that area is then used by the canvas
        checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
    
protected voidtestFour()
This test is for a canvas with no title and no ticker set in standard screen mode.

        declare(testName + " 4: Standard screen mode, plain.");
        
        TestCanvas canvas = new TestCanvas();
        
        checkCanvasSize(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT);
    
protected voidtestOne()
This test is for a canvas with a title and a ticker set in standard screen mode.

        declare(testName + " 1: Standard screen mode with title and ticker.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("CanvasSizing Test 1");
        canvas.setTicker(ticker);
        
        checkCanvasSize(canvas, STD_WIDTH, 
            STD_HEIGHT - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
    
protected voidtestSeven()
This test is for a canvas with a ticker but no title set in fullscreen mode.

        declare(testName + " 7: Fullsize screen mode with ticker.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTicker(ticker);
        canvas.toggleFullscreen(true);
        
        // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
        // per the chameleon UI spec: that area is then used by the canvas
        checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
    
protected voidtestSix()
This test is for a canvas with a title but no ticker set in fullscreen mode.

        declare(testName + " 6: Fullsize screen mode with title.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("CanvasSizing Test 6");
        canvas.toggleFullscreen(true);
        
        // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
        // per the chameleon UI spec: that area is then used by the canvas
        checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
    
protected voidtestThree()
This test is for a canvas with a ticker but no title set in standard screen mode.

        declare(testName + " 3: Standard screen mode with ticker.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTicker(ticker);
        
        checkCanvasSize(canvas, STD_WIDTH,
            STD_HEIGHT - SOFTBTN_HEIGHT - TICKER_HEIGHT);
    
protected voidtestTwo()
This test is for a canvas with a title but no ticker set in standard screen mode.

        declare(testName + " 2: Standard screen mode with title.");
        
        TestCanvas canvas = new TestCanvas();
        canvas.setTitle("CanvasSizing Test 2");
        
        checkCanvasSize(canvas, STD_WIDTH, 
            STD_HEIGHT - SOFTBTN_HEIGHT - TITLE_HEIGHT);