FileDocCategorySizeDatePackage
BridgeXmlBlockParserTest.javaAPI DocAndroid 1.5 API4721Wed May 06 22:42:02 BST 2009com.android.layoutlib.bridge

BridgeXmlBlockParserTest

public class BridgeXmlBlockParserTest extends TestCase

Fields Summary
private String
mXmlPath
private Document
mDoc
Constructors Summary
Methods Summary
private voiddump(org.w3c.dom.Node node, java.lang.String prefix)
Quick'n'dirty debug helper that dumps an XML structure to stdout.

        Node n;

        String[] types = {
                "unknown",
                "ELEMENT_NODE",
                "ATTRIBUTE_NODE",
                "TEXT_NODE",
                "CDATA_SECTION_NODE",
                "ENTITY_REFERENCE_NODE",
                "ENTITY_NODE",
                "PROCESSING_INSTRUCTION_NODE",
                "COMMENT_NODE",
                "DOCUMENT_NODE",
                "DOCUMENT_TYPE_NODE",
                "DOCUMENT_FRAGMENT_NODE",
                "NOTATION_NODE"
        };
        
        String s = String.format("%s<%s> %s %s",
                prefix,
                types[node.getNodeType()],
                node.getNodeName(),
                node.getNodeValue() == null ? "" : node.getNodeValue().trim());

        System.out.println(s);
        
        n = node.getFirstChild();
        if (n != null) {
            dump(n, prefix + "- ");
        }

        n = node.getNextSibling();
        if (n != null) {
            dump(n, prefix);
        }

    
private org.w3c.dom.DocumentgetXmlDocument(java.lang.String xmlFilePath)

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        
        // keep comments
        factory.setIgnoringComments(false);
        // don't validate our bogus DTD
        factory.setValidating(false);
        // we want namespaces
        factory.setNamespaceAware(true);
        
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(new File(xmlFilePath));
    
protected voidsetUp()

        super.setUp();
        URL url = this.getClass().getClassLoader().getResource("data/layout1.xml");
        mXmlPath = url.getFile();
        mDoc = getXmlDocument(mXmlPath);
    
protected voidtearDown()

        super.tearDown();
    
public voidtestXmlBlockParser()

        XmlPullParser parser = new KXmlParser();
        parser = new BridgeXmlBlockParser(parser, null, false /* platformResourceFlag */);
        parser.setInput(new FileReader(new File(mXmlPath)));

        assertEquals(XmlPullParser.START_DOCUMENT, parser.next());

        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("LinearLayout", parser.getName());

        assertEquals(XmlPullParser.TEXT, parser.next());

        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("Button", parser.getName());
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals(XmlPullParser.END_TAG, parser.next());

        assertEquals(XmlPullParser.TEXT, parser.next());

        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("View", parser.getName());
        assertEquals(XmlPullParser.END_TAG, parser.next());

        assertEquals(XmlPullParser.TEXT, parser.next());

        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("TextView", parser.getName());
        assertEquals(XmlPullParser.END_TAG, parser.next());

        assertEquals(XmlPullParser.TEXT, parser.next());

        assertEquals(XmlPullParser.END_TAG, parser.next());
        assertEquals(XmlPullParser.END_DOCUMENT, parser.next());