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.editors.layout.gscripts.IAttributeInfo.Format;
21 import com.android.ide.eclipse.tests.AdtTestData;
23 import org.w3c.dom.Document;
25 import java.lang.reflect.Method;
28 import junit.framework.TestCase;
30 public class AttrsXmlParserTest extends TestCase {
32 private AttrsXmlParser mParser;
33 private String mFilePath;
35 private static final String MOCK_DATA_PATH =
36 "com/android/ide/eclipse/testdata/mock_attrs.xml"; //$NON-NLS-1$
39 public void setUp() throws Exception {
40 mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH); //$NON-NLS-1$
41 mParser = new AttrsXmlParser(mFilePath);
45 public void tearDown() throws Exception {
48 public final void testGetDocument() throws Exception {
49 assertNotNull(_getDocument());
52 public void testGetOsAttrsXmlPath() throws Exception {
53 assertEquals(mFilePath, mParser.getOsAttrsXmlPath());
56 public final void testPreload() throws Exception {
57 assertSame(mParser, mParser.preload());
61 public final void testLoadViewAttributes() throws Exception {
63 ViewClassInfo info = new ViewClassInfo(
65 "mock_android.something.Theme", //$NON-NLS-1$
66 "Theme"); //$NON-NLS-1$
67 mParser.loadViewAttributes(info);
69 assertEquals("These are the standard attributes that make up a complete theme.", //$NON-NLS-1$
71 AttributeInfo[] attrs = info.getAttributes();
72 assertEquals(1, attrs.length);
73 assertEquals("scrollbarSize", info.getAttributes()[0].getName());
74 assertEquals(1, info.getAttributes()[0].getFormats().length);
75 assertEquals(Format.DIMENSION, info.getAttributes()[0].getFormats()[0]);
78 public final void testEnumFlagValues() throws Exception {
79 /* The XML being read contains:
80 <!-- Standard orientation constant. -->
81 <attr name="orientation">
82 <!-- Defines an horizontal widget. -->
83 <enum name="horizontal" value="0" />
84 <!-- Defines a vertical widget. -->
85 <enum name="vertical" value="1" />
90 Map<String, Map<String, Integer>> attrMap = mParser.getEnumFlagValues();
91 assertTrue(attrMap.containsKey("orientation"));
93 Map<String, Integer> valueMap = attrMap.get("orientation");
94 assertTrue(valueMap.containsKey("horizontal"));
95 assertTrue(valueMap.containsKey("vertical"));
96 assertEquals(Integer.valueOf(0), valueMap.get("horizontal"));
97 assertEquals(Integer.valueOf(1), valueMap.get("vertical"));
100 public final void testDeprecated() throws Exception {
103 DeclareStyleableInfo dep = mParser.getDeclareStyleableList().get("DeprecatedTest");
106 AttributeInfo[] attrs = dep.getAttributes();
107 assertEquals(4, attrs.length);
109 assertEquals("deprecated-inline", attrs[0].getName());
110 assertEquals("In-line deprecated.", attrs[0].getDeprecatedDoc());
111 assertEquals("Deprecated comments using delimiters.", attrs[0].getJavaDoc());
113 assertEquals("deprecated-multiline", attrs[1].getName());
114 assertEquals("Multi-line version of deprecated that works till the next tag.",
115 attrs[1].getDeprecatedDoc());
116 assertEquals("Deprecated comments on their own line.", attrs[1].getJavaDoc());
118 assertEquals("deprecated-not", attrs[2].getName());
119 assertEquals(null, attrs[2].getDeprecatedDoc());
120 assertEquals("This attribute is not deprecated.", attrs[2].getJavaDoc());
122 assertEquals("deprecated-no-javadoc", attrs[3].getName());
123 assertEquals("There is no other javadoc here.", attrs[3].getDeprecatedDoc());
124 assertEquals("", attrs[3].getJavaDoc());
127 //---- access to private methods
129 private Document _getDocument() throws Exception {
130 Method method = AttrsXmlParser.class.getDeclaredMethod("getDocument"); //$NON-NLS-1$
131 method.setAccessible(true);
132 return (Document) method.invoke(mParser);