2 * Copyright (C) 2007 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.project;
19 import com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper;
20 import com.android.ide.eclipse.tests.AdtTestData;
21 import com.android.sdklib.xml.ManifestData;
23 import junit.framework.TestCase;
26 * Tests for {@link AndroidManifestHelper}
28 public class AndroidManifestParserTest extends TestCase {
29 private ManifestData mManifestTestApp;
30 private ManifestData mManifestInstrumentation;
32 private static final String TESTDATA_PATH =
33 "com/android/ide/eclipse/testdata/"; //$NON-NLS-1$
34 private static final String INSTRUMENTATION_XML = TESTDATA_PATH +
35 "AndroidManifest-instrumentation.xml"; //$NON-NLS-1$
36 private static final String TESTAPP_XML = TESTDATA_PATH +
37 "AndroidManifest-testapp.xml"; //$NON-NLS-1$
38 private static final String PACKAGE_NAME = "com.android.testapp"; //$NON-NLS-1$
39 private static final Integer VERSION_CODE = 42;
40 private static final String ACTIVITY_NAME = "com.android.testapp.MainActivity"; //$NON-NLS-1$
41 private static final String LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
42 private static final String INSTRUMENTATION_NAME = "android.test.InstrumentationTestRunner"; //$NON-NLS-1$
43 private static final String INSTRUMENTATION_TARGET = "com.android.AndroidProject"; //$NON-NLS-1$
46 protected void setUp() throws Exception {
49 String testFilePath = AdtTestData.getInstance().getTestFilePath(TESTAPP_XML);
50 mManifestTestApp = AndroidManifestHelper.parseForData(testFilePath);
51 assertNotNull(mManifestTestApp);
53 testFilePath = AdtTestData.getInstance().getTestFilePath(INSTRUMENTATION_XML);
54 mManifestInstrumentation = AndroidManifestHelper.parseForData(testFilePath);
55 assertNotNull(mManifestInstrumentation);
58 public void testGetInstrumentationInformation() {
59 assertEquals(1, mManifestInstrumentation.getInstrumentations().length);
60 assertEquals(INSTRUMENTATION_NAME,
61 mManifestInstrumentation.getInstrumentations()[0].getName());
62 assertEquals(INSTRUMENTATION_TARGET,
63 mManifestInstrumentation.getInstrumentations()[0].getTargetPackage());
66 public void testGetPackage() {
67 assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());
70 public void testGetVersionCode() {
71 assertEquals(VERSION_CODE, mManifestTestApp.getVersionCode());
72 assertEquals(null, mManifestInstrumentation.getVersionCode());
75 public void testMinSdkVersion() {
76 assertEquals("7", mManifestTestApp.getApiLevelRequirement());
79 public void testGetActivities() {
80 assertEquals(1, mManifestTestApp.getActivities().length);
81 ManifestData.Activity activity = mManifestTestApp.getActivities()[0];
82 assertEquals(ACTIVITY_NAME, activity.getName());
83 assertTrue(activity.hasAction());
84 assertTrue(activity.isHomeActivity());
85 assertTrue(activity.hasAction());
86 assertEquals(activity, mManifestTestApp.getActivities()[0]);
89 public void testGetLauncherActivity() {
90 ManifestData.Activity activity = mManifestTestApp.getLauncherActivity();
91 assertEquals(ACTIVITY_NAME, activity.getName());
92 assertTrue(activity.hasAction());
93 assertTrue(activity.isHomeActivity());
96 private void assertEquals(ManifestData.Activity lhs, ManifestData.Activity rhs) {
97 assertTrue(lhs == rhs || (lhs != null && rhs != null));
98 if (lhs != null && rhs != null) {
99 assertEquals(lhs.getName(), rhs.getName());
100 assertEquals(lhs.isExported(), rhs.isExported());
101 assertEquals(lhs.hasAction(), rhs.hasAction());
102 assertEquals(lhs.isHomeActivity(), rhs.isHomeActivity());
106 public void testGetUsesLibraries() {
107 assertEquals(1, mManifestTestApp.getUsesLibraries().length);
108 assertEquals(LIBRARY_NAME, mManifestTestApp.getUsesLibraries()[0]);
111 public void testGetPackageName() {
112 assertEquals(PACKAGE_NAME, mManifestTestApp.getPackage());