2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.internal.resources;
20 import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo;
21 import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo.Format;
22 import com.android.ide.eclipse.tests.AdtTestData;
24 import org.w3c.dom.Document;
26 import java.lang.reflect.Method;
29 import junit.framework.TestCase;
31 public class AttrsXmlParserTest extends TestCase {
33 private AttrsXmlParser mParser;
34 private String mFilePath;
36 private static final String MOCK_DATA_PATH =
37 "com/android/ide/eclipse/testdata/mock_attrs.xml"; //$NON-NLS-1$
40 public void setUp() throws Exception {
41 mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH); //$NON-NLS-1$
42 mParser = new AttrsXmlParser(mFilePath);
46 public void tearDown() throws Exception {
49 public final void testGetDocument() throws Exception {
50 assertNotNull(_getDocument());
53 public void testGetOsAttrsXmlPath() throws Exception {
54 assertEquals(mFilePath, mParser.getOsAttrsXmlPath());
57 public final void testPreload() throws Exception {
58 assertSame(mParser, mParser.preload());
62 public final void testLoadViewAttributes() throws Exception {
64 ViewClassInfo info = new ViewClassInfo(
66 "mock_android.something.Theme", //$NON-NLS-1$
67 "Theme"); //$NON-NLS-1$
68 mParser.loadViewAttributes(info);
70 assertEquals("These are the standard attributes that make up a complete theme.", //$NON-NLS-1$
72 AttributeInfo[] attrs = info.getAttributes();
73 assertEquals(1, attrs.length);
74 assertEquals("scrollbarSize", info.getAttributes()[0].getName());
75 assertEquals(1, info.getAttributes()[0].getFormats().length);
76 assertEquals(Format.DIMENSION, info.getAttributes()[0].getFormats()[0]);
79 public final void testEnumFlagValues() throws Exception {
80 /* The XML being read contains:
81 <!-- Standard orientation constant. -->
82 <attr name="orientation">
83 <!-- Defines an horizontal widget. -->
84 <enum name="horizontal" value="0" />
85 <!-- Defines a vertical widget. -->
86 <enum name="vertical" value="1" />
91 Map<String, Map<String, Integer>> attrMap = mParser.getEnumFlagValues();
92 assertTrue(attrMap.containsKey("orientation"));
94 Map<String, Integer> valueMap = attrMap.get("orientation");
95 assertTrue(valueMap.containsKey("horizontal"));
96 assertTrue(valueMap.containsKey("vertical"));
97 assertEquals(Integer.valueOf(0), valueMap.get("horizontal"));
98 assertEquals(Integer.valueOf(1), valueMap.get("vertical"));
101 public final void testDeprecated() throws Exception {
104 DeclareStyleableInfo dep = mParser.getDeclareStyleableList().get("DeprecatedTest");
107 AttributeInfo[] attrs = dep.getAttributes();
108 assertEquals(4, attrs.length);
110 assertEquals("deprecated-inline", attrs[0].getName());
111 assertEquals("In-line deprecated.", attrs[0].getDeprecatedDoc());
112 assertEquals("Deprecated comments using delimiters.", attrs[0].getJavaDoc());
114 assertEquals("deprecated-multiline", attrs[1].getName());
115 assertEquals("Multi-line version of deprecated that works till the next tag.",
116 attrs[1].getDeprecatedDoc());
117 assertEquals("Deprecated comments on their own line.", attrs[1].getJavaDoc());
119 assertEquals("deprecated-not", attrs[2].getName());
120 assertEquals(null, attrs[2].getDeprecatedDoc());
121 assertEquals("This attribute is not deprecated.", attrs[2].getJavaDoc());
123 assertEquals("deprecated-no-javadoc", attrs[3].getName());
124 assertEquals("There is no other javadoc here.", attrs[3].getDeprecatedDoc());
125 assertEquals("", attrs[3].getJavaDoc());
128 //---- access to private methods
130 private Document _getDocument() throws Exception {
131 Method method = AttrsXmlParser.class.getDeclaredMethod("getDocument"); //$NON-NLS-1$
132 method.setAccessible(true);
133 return (Document) method.invoke(mParser);