FileDocCategorySizeDatePackage
TestTxMasterStyleAtom.javaAPI DocApache Poi 3.0.18331Sun Mar 11 12:59:32 GMT 2007org.apache.poi.hslf.record

TestTxMasterStyleAtom

public class TestTxMasterStyleAtom extends TestCase
Test TestTxMasterStyleAtom record. Check master style for the empty ppt which is created by the default constructor of SlideShow
author
Yegor Kozlov

Fields Summary
protected SlideShow
_ppt
Constructors Summary
Methods Summary
private voidcheckBodyType(org.apache.poi.hslf.record.TxMasterStyleAtom txmaster)
Test styles for type=TextHeaderAtom.BODY_TYPE

        TextPropCollection props;
        TextProp prop;

        TextPropCollection[] prstyles = txmaster.getParagraphStyles();
        TextPropCollection[] chstyles = txmaster.getCharacterStyles();
        assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
                "must contain styles for 5 indentation levels", 5, prstyles.length);
        assertEquals("TxMasterStyleAtom for TextHeaderAtom.BODY_TYPE " +
                "must contain styles for 5 indentation levels", 5, chstyles.length);

        //paragraph styles
        props = prstyles[0];

        prop = props.findByName("alignment");
        assertEquals(0, prop.getValue());


        for (int i = 0; i < prstyles.length; i++) {
            assertNotNull("text.offset is null for indentation level " + i, prstyles[i].findByName("text.offset"));
            assertNotNull("bullet.offset is null for indentation level " + i, prstyles[i].findByName("bullet.offset"));
        }

        //character styles
        props = chstyles[0];

        prop = props.findByName("font.color");
        assertEquals(0x1000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(36, prop.getValue());
    
private voidcheckNotesType(org.apache.poi.hslf.record.TxMasterStyleAtom txmaster)
Test styles for type=TextHeaderAtom.NOTES_TYPE

        TextPropCollection props;
        TextProp prop;

        //paragraph styles
        props = txmaster.getParagraphStyles()[0];

        prop = props.findByName("alignment");
        assertEquals(0, prop.getValue()); //title has center alignment

        //character styles
        props = txmaster.getCharacterStyles()[0];

        prop = props.findByName("font.color");
        assertEquals(0x1000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(12, prop.getValue());

    
private voidcheckOtherType(org.apache.poi.hslf.record.TxMasterStyleAtom txmaster)
Test styles for type=TextHeaderAtom.OTHER_TYPE

        TextPropCollection props;
        TextProp prop;

        //paragraph styles
        props = txmaster.getParagraphStyles()[0];

        prop = props.findByName("alignment");
        assertEquals(0, prop.getValue());

        //character styles
        props = txmaster.getCharacterStyles()[0];

        prop = props.findByName("font.color");
        assertEquals(0x1000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(24, prop.getValue());
    
private voidcheckTitleType(org.apache.poi.hslf.record.TxMasterStyleAtom txmaster)
Test styles for type=TextHeaderAtom.TITLE_TYPE

        TextPropCollection props;
        TextProp prop;

        //paragraph styles
        props = txmaster.getParagraphStyles()[0];

        prop = props.findByName("alignment");
        assertEquals(1, prop.getValue()); //title has center alignment

        //character styles
        props = txmaster.getCharacterStyles()[0];

        prop = props.findByName("font.color");
        assertEquals(0x3000000, prop.getValue());

        prop = props.findByName("font.index");
        assertEquals(0, prop.getValue());

        prop = props.findByName("font.size");
        assertEquals(49, prop.getValue());

    
protected org.apache.poi.hslf.record.TxMasterStyleAtom[]getMasterStyles()
Collect all TxMasterStyleAtom records contained in the supplied slide show. There must be a TxMasterStyleAtom per each type of text defined in TextHeaderAtom

        ArrayList lst = new ArrayList();

        Record[] core = _ppt.getMostRecentCoreRecords();
        for (int i = 0; i < core.length; i++) {
            if(core[i].getRecordType() == RecordTypes.MainMaster.typeID){
                Record[] rec = core[i].getChildRecords();
                int cnt = 0;
                for (int j = 0; j < rec.length; j++) {
                    if (rec[j] instanceof TxMasterStyleAtom) {
                        lst.add(rec[j]);
                        cnt++;
                    }
                }
                assertEquals("MainMaster must contain 7 TxMasterStyleAtoms ", 7, cnt);
            } else if(core[i].getRecordType() == RecordTypes.Document.typeID){
                TxMasterStyleAtom txstyle = null;
                Document doc = (Document)core[i];
                Record[] rec = doc.getEnvironment().getChildRecords();
                for (int j = 0; j < rec.length; j++) {
                    if (rec[j] instanceof TxMasterStyleAtom) {
                        if (txstyle != null)  fail("Document.Environment must contain 1 TxMasterStyleAtom");
                        txstyle = (TxMasterStyleAtom)rec[j];
                    }
                }
                assertNotNull("TxMasterStyleAtom not found in Document.Environment", txstyle);

                assertEquals("Document.Environment must contain TxMasterStyleAtom  with type=TextHeaderAtom.OTHER_TYPE",
                        TextHeaderAtom.OTHER_TYPE, txstyle.getTextType());
                lst.add(txstyle);
            }
        }

        return (TxMasterStyleAtom[])lst.toArray(new TxMasterStyleAtom[lst.size()]);
    
public voidsetUp()

        _ppt = new SlideShow();

    
public voidtestDefaultStyles()

        TxMasterStyleAtom[] txmaster = getMasterStyles();
        for (int i = 0; i < txmaster.length; i++) {
            int txtype = txmaster[i].getTextType();
            switch (txtype){
                case TextHeaderAtom.TITLE_TYPE:
                    checkTitleType(txmaster[i]);
                    break;
                case TextHeaderAtom.BODY_TYPE:
                    checkBodyType(txmaster[i]);
                    break;
                case TextHeaderAtom.NOTES_TYPE:
                    checkNotesType(txmaster[i]);
                    break;
                case TextHeaderAtom.OTHER_TYPE:
                    checkOtherType(txmaster[i]);
                    break;
                case TextHeaderAtom.CENTRE_BODY_TYPE:
                    break;
                case TextHeaderAtom.CENTER_TITLE_TYPE:
                    break;
                case TextHeaderAtom.HALF_BODY_TYPE:
                    break;
                case TextHeaderAtom.QUARTER_BODY_TYPE:
                    break;
                default:
                    fail("Unknown text type: " + txtype);
            }

        }