auto import from //branches/cupcake/...@137873

This commit is contained in:
The Android Open Source Project
2009-03-11 12:11:54 -07:00
parent 692ab02175
commit 243d18eb22
42 changed files with 954 additions and 671 deletions

View File

@@ -5,6 +5,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="lib" path="kxml2-2.3.0.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/>
<classpathentry kind="lib" path="/adt/sdklib.jar" sourcepath="/SdkLib"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -1,97 +0,0 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.common.project;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import junit.framework.TestCase;
public class AndroidManifestHelperTest extends TestCase {
private File mFile;
private AndroidManifestHelper mManifest;
@Override
protected void setUp() throws Exception {
super.setUp();
mFile = File.createTempFile("androidManifest", "xml"); //$NON-NLS-1$ //$NON-NLS-2$
assertNotNull(mFile);
FileWriter fw = new FileWriter(mFile);
fw.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); //$NON-NLS-1$
fw.write("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"); //$NON-NLS-1$
fw.write(" package=\"com.android.testapp\">\n"); //$NON-NLS-1$
fw.write(" <application android:icon=\"@drawable/icon\">\n"); //$NON-NLS-1$
fw.write(" <activity android:name=\".MainActivity\" android:label=\"@string/app_name\">\n"); //$NON-NLS-1$
fw.write(" <intent-filter>\n"); //$NON-NLS-1$
fw.write(" <action android:name=\"android.intent.action.MAIN\" />\n"); //$NON-NLS-1$
fw.write(" <category android:name=\"android.intent.category.LAUNCHER\" />\"\n"); //$NON-NLS-1$
fw.write(" <category android:name=\"android.intent.category.DEFAULT\" />\n"); //$NON-NLS-1$
fw.write(" </intent-filter>\n"); //$NON-NLS-1$
fw.write(" </activity>\n"); //$NON-NLS-1$
fw.write(" <activity android:name=\".OptionsActivity\" android:label=\"@string/options\"\n"); //$NON-NLS-1$
fw.write(" android:theme=\"@style/Theme.Floating\">\n"); //$NON-NLS-1$
fw.write(" <intent-filter>\n"); //$NON-NLS-1$
fw.write(" <action android:name=\"com.android.mandelbrot.action.EDIT_OPTIONS\" />\n"); //$NON-NLS-1$
fw.write(" <category android:name=\"android.intent.category.PREFERENCE_CATEGORY\" />\n"); //$NON-NLS-1$
fw.write(" </intent-filter>\n"); //$NON-NLS-1$
fw.write(" </activity>\n"); //$NON-NLS-1$
fw.write(" <activity android:name=\".InfoActivity\" android:label=\"@string/options\"\n"); //$NON-NLS-1$
fw.write(" android:theme=\"@style/Theme.Floating\">\n"); //$NON-NLS-1$
fw.write(" <intent-filter>\n"); //$NON-NLS-1$
fw.write(" <action android:name=\"com.android.mandelbrot.action.DISPLAY_INFO\" />\n"); //$NON-NLS-1$
fw.write(" </intent-filter>\n"); //$NON-NLS-1$
fw.write(" </activity>\n"); //$NON-NLS-1$
fw.write(" </application>\n"); //$NON-NLS-1$
fw.write("</manifest>\n"); //$NON-NLS-1$
fw.flush();
fw.close();
mManifest = new AndroidManifestHelper(mFile.getAbsolutePath());
}
@Override
protected void tearDown() throws Exception {
assertTrue(mFile.delete());
super.tearDown();
}
public void testExists() {
assertTrue(mManifest.exists());
}
public void testNotExists() throws IOException {
File f = File.createTempFile("androidManifest2", "xml"); //$NON-NLS-1$ //$NON-NLS-2$
assertTrue(f.delete());
AndroidManifestHelper manifest = new AndroidManifestHelper(f.getAbsolutePath());
assertFalse(manifest.exists());
}
public void testGetPackageName() {
assertEquals("com.android.testapp", mManifest.getPackageName());
}
public void testGetActivityName() {
assertEquals("", mManifest.getActivityName(0)); //$NON-NLS-1$
assertEquals(".MainActivity", mManifest.getActivityName(1)); //$NON-NLS-1$
assertEquals(".OptionsActivity", mManifest.getActivityName(2)); //$NON-NLS-1$
assertEquals(".InfoActivity", mManifest.getActivityName(3)); //$NON-NLS-1$
assertEquals("", mManifest.getActivityName(4)); //$NON-NLS-1$
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.common.project;
import junit.framework.TestCase;
import com.android.ide.eclipse.mock.FileMock;
/**
* Tests for {@link AndroidManifestParser}
*/
public class AndroidManifestParserTest extends TestCase {
private AndroidManifestParser mManifest;
private static final String PACKAGE_NAME = "com.android.testapp"; //$NON-NLS-1$
private static final String ACTIVITY_NAME = "com.android.testapp.MainActivity"; //$NON-NLS-1$
private static final String LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
private static final String INSTRUMENTATION_NAME = "android.test.InstrumentationTestRunner"; //$NON-NLS-1$
@Override
protected void setUp() throws Exception {
super.setUp();
// create the test data
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); //$NON-NLS-1$
sb.append("<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n"); //$NON-NLS-1$
sb.append(" package=\""); //$NON-NLS-1$
sb.append(PACKAGE_NAME);
sb.append("\">\n"); //$NON-NLS-1$
sb.append(" <application android:icon=\"@drawable/icon\">\n"); //$NON-NLS-1$
sb.append(" <activity android:name=\""); //$NON-NLS-1$
sb.append(ACTIVITY_NAME);
sb.append("\" android:label=\"@string/app_name\">\n"); //$NON-NLS-1$
sb.append(" <intent-filter>\n"); //$NON-NLS-1$
sb.append(" <action android:name=\"android.intent.action.MAIN\" />\n"); //$NON-NLS-1$
sb.append(" <category android:name=\"android.intent.category.LAUNCHER\" />\"\n"); //$NON-NLS-1$
sb.append(" <category android:name=\"android.intent.category.DEFAULT\" />\n"); //$NON-NLS-1$
sb.append(" </intent-filter>\n"); //$NON-NLS-1$
sb.append(" </activity>\n"); //$NON-NLS-1$
sb.append(" <uses-library android:name=\""); //$NON-NLS-1$
sb.append(LIBRARY_NAME);
sb.append("\" />\n"); //$NON-NLS-1$
sb.append(" </application>"); //$NON-NLS-1$
sb.append(" <instrumentation android:name=\""); //$NON-NLS-1$
sb.append(INSTRUMENTATION_NAME);
sb.append("\"\n");
sb.append(" android:targetPackage=\"com.example.android.apis\"\n");
sb.append(" android:label=\"Tests for Api Demos.\"/>\n");
sb.append("</manifest>\n"); //$NON-NLS-1$
FileMock mockFile = new FileMock("AndroidManifest.xml", sb.toString().getBytes());
mManifest = AndroidManifestParser.parseForData(mockFile);
assertNotNull(mManifest);
}
public void testGetPackage() {
assertEquals("com.android.testapp", mManifest.getPackage());
}
public void testGetActivities() {
assertEquals(1, mManifest.getActivities().length);
assertEquals(ACTIVITY_NAME, mManifest.getActivities()[0]);
}
public void testGetLauncherActivity() {
assertEquals(ACTIVITY_NAME, mManifest.getLauncherActivity());
}
public void testGetUsesLibraries() {
assertEquals(1, mManifest.getUsesLibraries().length);
assertEquals(LIBRARY_NAME, mManifest.getUsesLibraries()[0]);
}
public void testGetInstrumentations() {
assertEquals(1, mManifest.getInstrumentations().length);
assertEquals(INSTRUMENTATION_NAME, mManifest.getInstrumentations()[0]);
}
}

View File

@@ -37,6 +37,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
import java.net.URI;
@@ -44,16 +45,28 @@ import java.util.Map;
/**
* Mock implementation of {@link IFile}.
*
* Optionally backed by an in-memory byte array
*
* <p/>Supported methods:
* <ul>
* <li>getName()</li>
* <li>getContents()</li>
* <li>getContents(boolean force)</li>
* </ul>
*/
public class FileMock implements IFile {
private String mName;
private byte[] mContentData;
public FileMock(String name) {
this(name, new byte[0]);
}
public FileMock(String name, byte[] fileData) {
mName = name;
mContentData = fileData;
}
// -------- MOCKED METHODS ----------------
@@ -62,6 +75,15 @@ public class FileMock implements IFile {
return mName;
}
public InputStream getContents() throws CoreException {
return new ByteArrayInputStream(mContentData);
}
public InputStream getContents(boolean force) throws CoreException {
// ignore force
return getContents();
}
// -------- UNIMPLEMENTED METHODS ----------------
public void appendContents(InputStream source, int updateFlags, IProgressMonitor monitor)
@@ -115,14 +137,6 @@ public class FileMock implements IFile {
throw new NotImplementedException();
}
public InputStream getContents() throws CoreException {
throw new NotImplementedException();
}
public InputStream getContents(boolean force) throws CoreException {
throw new NotImplementedException();
}
public int getEncoding() throws CoreException {
throw new NotImplementedException();
}
@@ -139,7 +153,8 @@ public class FileMock implements IFile {
throw new NotImplementedException();
}
public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor)
public void move(IPath destination, boolean force, boolean keepHistory,
IProgressMonitor monitor)
throws CoreException {
throw new NotImplementedException();
}
@@ -229,7 +244,8 @@ public class FileMock implements IFile {
throw new NotImplementedException();
}
public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException {
public void deleteMarkers(String type, boolean includeSubtypes, int depth)
throws CoreException {
throw new NotImplementedException();
}
@@ -424,26 +440,26 @@ public class FileMock implements IFile {
throw new NotImplementedException();
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public Map getPersistentProperties() throws CoreException {
throw new NotImplementedException();
}
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public Map getSessionProperties() throws CoreException {
throw new NotImplementedException();
}
}
public boolean isDerived(int options) {
public boolean isDerived(int options) {
throw new NotImplementedException();
}
}
public boolean isHidden() {
public boolean isHidden() {
throw new NotImplementedException();
}
}
public void setHidden(boolean isHidden) throws CoreException {
public void setHidden(boolean isHidden) throws CoreException {
throw new NotImplementedException();
}
}
}