FileDocCategorySizeDatePackage
AttrsXmlParserTest.javaAPI DocAndroid 1.5 API5095Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.common.resources

AttrsXmlParserTest

public class AttrsXmlParserTest extends TestCase

Fields Summary
private AttrsXmlParser
mParser
private String
mFilePath
Constructors Summary
Methods Summary
private org.w3c.dom.Document_getDocument()

        Method method = AttrsXmlParser.class.getDeclaredMethod("getDocument"); //$NON-NLS-1$
        method.setAccessible(true);
        return (Document) method.invoke(mParser);
    
public voidsetUp()

        mFilePath = AdtTestData.getInstance().getTestFilePath("mock_attrs.xml"); //$NON-NLS-1$
        mParser = new AttrsXmlParser(mFilePath);
    
public voidtearDown()

    
public final voidtestDeprecated()

        mParser.preload();
        
        DeclareStyleableInfo dep = mParser.getDeclareStyleableList().get("DeprecatedTest");
        assertNotNull(dep);
        
        AttributeInfo[] attrs = dep.getAttributes();
        assertEquals(4, attrs.length);

        assertEquals("deprecated-inline", attrs[0].getName());
        assertEquals("In-line deprecated.", attrs[0].getDeprecatedDoc());
        assertEquals("Deprecated comments using delimiters.", attrs[0].getJavaDoc());
        
        assertEquals("deprecated-multiline", attrs[1].getName());
        assertEquals("Multi-line version of deprecated that works till the next tag.",
                attrs[1].getDeprecatedDoc());
        assertEquals("Deprecated comments on their own line.", attrs[1].getJavaDoc());
        
        assertEquals("deprecated-not", attrs[2].getName());
        assertEquals(null, attrs[2].getDeprecatedDoc());
        assertEquals("This attribute is not deprecated.", attrs[2].getJavaDoc());

        assertEquals("deprecated-no-javadoc", attrs[3].getName());
        assertEquals("There is no other javadoc here.", attrs[3].getDeprecatedDoc());
        assertEquals("", attrs[3].getJavaDoc());
    
public final voidtestEnumFlagValues()

        /* The XML being read contains:
            <!-- Standard orientation constant. -->
            <attr name="orientation">
                <!-- Defines an horizontal widget. -->
                <enum name="horizontal" value="0" />
                <!-- Defines a vertical widget. -->
                <enum name="vertical" value="1" />
            </attr>
         */

        mParser.preload();
        Map<String, Map<String, Integer>> attrMap = mParser.getEnumFlagValues();
        assertTrue(attrMap.containsKey("orientation"));
        
        Map<String, Integer> valueMap = attrMap.get("orientation");
        assertTrue(valueMap.containsKey("horizontal"));
        assertTrue(valueMap.containsKey("vertical"));
        assertEquals(Integer.valueOf(0), valueMap.get("horizontal"));
        assertEquals(Integer.valueOf(1), valueMap.get("vertical"));
    
public final voidtestGetDocument()

        assertNotNull(_getDocument());
    
public voidtestGetOsAttrsXmlPath()

        assertEquals(mFilePath, mParser.getOsAttrsXmlPath());
    
public final voidtestLoadViewAttributes()

        mParser.preload();
        ViewClassInfo info = new ViewClassInfo(
                false /* isLayout */,
                "mock_android.something.Theme",      //$NON-NLS-1$
                "Theme");                            //$NON-NLS-1$
        mParser.loadViewAttributes(info);
        
        assertEquals("These are the standard attributes that make up a complete theme.", //$NON-NLS-1$
                info.getJavaDoc());
        AttributeInfo[] attrs = info.getAttributes();
        assertEquals(1, attrs.length);
        assertEquals("scrollbarSize", info.getAttributes()[0].getName());
        assertEquals(1, info.getAttributes()[0].getFormats().length);
        assertEquals(Format.DIMENSION, info.getAttributes()[0].getFormats()[0]);
    
public final voidtestPreload()

        assertSame(mParser, mParser.preload());