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

TestStringItemNoLabelSizing

public class TestStringItemNoLabelSizing extends TestCase

Fields Summary
private final int
ITEM_PAD
private final int
I_W_TEXT
private final int
TEXT_FONT_H
Constructors Summary
Methods Summary
private voidcheckNonemptySizes(java.lang.String content, int expectedConW, int expectedConH)

        checkSizes(new StringItem(null, content),
                   ITEM_PAD + expectedConW + ITEM_PAD,
                   ITEM_PAD + expectedConH + ITEM_PAD);
    
private voidcheckSizes(StringItem si, int expectedW, int expectedH)

        int w = getW(si);
        int h = getH(si);
        assertEquals("w: " + expectedW + " != " + w, expectedW, w);
        assertEquals("h: " + expectedH + " != " + h, expectedH, h);
    
private intgetH(StringItem strItem)

        return strItem.stringItemLF.lGetPreferredHeight(-1);
    
private intgetW(StringItem strItem)

        return strItem.stringItemLF.lGetPreferredWidth(-1);
    
private java.lang.StringmakeString(int count, char ch)


    // make a string with count repetitions of ch
          
        char arr[] = new char[count];
        for (int i = 0; i < count; i++) {
            arr[i] = ch;
        }
        return new String(arr);
    
private java.lang.StringmakeStringThatFits(char ch, int char_width, int width)

        char arr[] = new char[width/char_width];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = ch;
        }
        return new String(arr);
    
public voidrunTests()


        // null content
        declare("testNull");
        checkSizes(new StringItem(null, null), 0, 0);

        // empty content
        declare("testEmpty");
        checkSizes(new StringItem(null, ""), 0, 0);

        // nonemtpy content, no newline,fits on one line
        declare("testI");
        checkNonemptySizes("i", I_W_TEXT, TEXT_FONT_H);

        // nonempty content, no newline, just fits on one line
        declare("test70i");
        checkNonemptySizes(makeString(70, 'i"),
                           70*I_W_TEXT,
                           TEXT_FONT_H);

        // nonempty content, has newline => multiline
        // content consists just of "\n" (width is 0 but height is not)
        declare("test\\n");
        checkNonemptySizes("\n", 0, 2*TEXT_FONT_H);

        // nonempty content, has newline => multiline
        // content consists of "\ni" (first line is empty)
        declare("test\\ni");
        checkNonemptySizes("\ni", I_W_TEXT, 2*TEXT_FONT_H);

        // nonempty content, has newline => multiline
        // content consists of "i\n"  (second line is empty)
        declare("testI\\n");
        checkNonemptySizes("i\n", I_W_TEXT, 2*TEXT_FONT_H);

        // nonempty content, has newline => multiline
        // content consists of "i\nii" (second line is longer)
        declare("testI\\nii");
        checkNonemptySizes("i\nii", 2*I_W_TEXT, 2*TEXT_FONT_H);

        // nonempty content, has newline => multiline
        // content consists of "ii\ni" (first line is longer)
        declare("testIi\\ni");
        checkNonemptySizes("ii\ni", 2*I_W_TEXT, 2*TEXT_FONT_H);


        // nonempty very long content without newline which has to wrap
        declare("test75i");
        String strFitsInWidth = 
            makeStringThatFits('i", I_W_TEXT, 
                               Constants.NORMALWIDTH - 
                               Constants.VERT_SCROLLBAR_WIDTH - 
                               ITEM_PAD - ITEM_PAD);

        checkNonemptySizes(strFitsInWidth + "ii",
                           strFitsInWidth.length()*I_W_TEXT,
                           2*TEXT_FONT_H);