Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      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
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     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.
     15  */
     16 
     17 package com.android.ide.common.resources.platform;
     18 
     19 import com.android.ide.eclipse.mock.TestLogger;
     20 import com.android.ide.eclipse.tests.AdtTestData;
     21 
     22 import java.util.Arrays;
     23 import java.util.Map;
     24 import java.util.TreeMap;
     25 
     26 import junit.framework.TestCase;
     27 
     28 public class AttrsXmlParserManifestTest extends TestCase {
     29 
     30     private AttrsXmlParser mParser;
     31     private String mFilePath;
     32 
     33     private static final String MOCK_DATA_PATH =
     34         "com/android/ide/eclipse/testdata/mock_manifest_attrs.xml"; //$NON-NLS-1$
     35 
     36     @Override
     37     public void setUp() throws Exception {
     38         mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH);
     39         mParser = new AttrsXmlParser(mFilePath, new TestLogger(), 100);
     40     }
     41 
     42     @Override
     43     public void tearDown() throws Exception {
     44     }
     45 
     46     public void testGetOsAttrsXmlPath() throws Exception {
     47         assertEquals(mFilePath, mParser.getOsAttrsXmlPath());
     48     }
     49 
     50     private Map<String, DeclareStyleableInfo> preloadAndGetStyleables() {
     51         assertSame(mParser, mParser.preload());
     52 
     53         Map<String, DeclareStyleableInfo> styleableList = mParser.getDeclareStyleableList();
     54         // For testing purposes, we want the strings sorted
     55         if (!(styleableList instanceof TreeMap<?, ?>)) {
     56             styleableList = new TreeMap<String, DeclareStyleableInfo>(styleableList);
     57         }
     58         return styleableList;
     59     }
     60 
     61     public final void testPreload() throws Exception {
     62         Map<String, DeclareStyleableInfo> styleableList = preloadAndGetStyleables();
     63 
     64         assertEquals(
     65                 "[AndroidManifest, " +
     66                 "AndroidManifestActivityAlias, " +
     67                 "AndroidManifestApplication, " +
     68                 "AndroidManifestNewElement, " +
     69                 "AndroidManifestNewParent, " +
     70                 "AndroidManifestPermission" +
     71                 "]",
     72                 Arrays.toString(styleableList.keySet().toArray()));
     73     }
     74 
     75     /**
     76      * Tests that AndroidManifestNewParentNewElement got renamed to AndroidManifestNewElement
     77      * and a parent named AndroidManifestNewParent was automatically created.
     78      */
     79     public final void testNewParent() throws Exception {
     80         Map<String, DeclareStyleableInfo> styleableList = preloadAndGetStyleables();
     81 
     82         DeclareStyleableInfo newElement = styleableList.get("AndroidManifestNewElement");
     83         assertNotNull(newElement);
     84         assertEquals("AndroidManifestNewElement", newElement.getStyleName());
     85         assertEquals("[AndroidManifestNewParent]",
     86                      Arrays.toString(newElement.getParents()));
     87 
     88         DeclareStyleableInfo newParent = styleableList.get("AndroidManifestNewParent");
     89         assertNotNull(newParent);
     90         assertEquals("[AndroidManifest]",
     91                      Arrays.toString(newParent.getParents()));
     92 
     93     }
     94 }
     95