Fix ADT test data references.
- Remove reference to ADT from sdklib tests. - Move ADT test data to be closer to their test classes, and to make it obvious this data is only for ADT unit tests.
This commit is contained in:
@@ -21,18 +21,14 @@ import org.eclipse.core.runtime.FileLocator;
|
|||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for retrieving test data
|
* Helper class for retrieving test data
|
||||||
*
|
* <p/>
|
||||||
* All tests which need to retrieve test data files should go through this class
|
* All tests which need to retrieve paths to test data files should go through this class.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class AdtTestData {
|
public class AdtTestData {
|
||||||
|
|
||||||
@@ -40,12 +36,9 @@ public class AdtTestData {
|
|||||||
private static AdtTestData sInstance = null;
|
private static AdtTestData sInstance = null;
|
||||||
private static final Logger sLogger = Logger.getLogger(AdtTestData.class.getName());
|
private static final Logger sLogger = Logger.getLogger(AdtTestData.class.getName());
|
||||||
|
|
||||||
/** the absolute file path to the /data directory in this test
|
/** The absolute file path to the plugin's contents. */
|
||||||
* environment.
|
|
||||||
*/
|
|
||||||
private String mOsRootDataPath;
|
private String mOsRootDataPath;
|
||||||
|
|
||||||
|
|
||||||
private AdtTestData() {
|
private AdtTestData() {
|
||||||
// can set test_data env variable to override default behavior of
|
// can set test_data env variable to override default behavior of
|
||||||
// finding data using class loader
|
// finding data using class loader
|
||||||
@@ -55,7 +48,7 @@ public class AdtTestData {
|
|||||||
mOsRootDataPath = System.getProperty("test_data");
|
mOsRootDataPath = System.getProperty("test_data");
|
||||||
if (mOsRootDataPath == null) {
|
if (mOsRootDataPath == null) {
|
||||||
sLogger.info("Cannot find test_data environment variable, init to class loader");
|
sLogger.info("Cannot find test_data environment variable, init to class loader");
|
||||||
URL url = this.getClass().getClassLoader().getResource("data"); //$NON-NLS-1$
|
URL url = this.getClass().getClassLoader().getResource("."); //$NON-NLS-1$
|
||||||
|
|
||||||
if (Platform.isRunning()) {
|
if (Platform.isRunning()) {
|
||||||
sLogger.info("Running as an Eclipse Plug-in JUnit test, using FileLocator");
|
sLogger.info("Running as an Eclipse Plug-in JUnit test, using FileLocator");
|
||||||
@@ -71,7 +64,7 @@ public class AdtTestData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOsRootDataPath.equals(AndroidConstants.WS_SEP + "data")) {
|
if (mOsRootDataPath.equals(AndroidConstants.WS_SEP)) {
|
||||||
sLogger.warning("Resource data not found using class loader!, Defaulting to no path");
|
sLogger.warning("Resource data not found using class loader!, Defaulting to no path");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +83,9 @@ public class AdtTestData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the absolute file path to a file located in this plugins "data" directory
|
* Returns the absolute file path to a file located in this plugin.
|
||||||
*
|
*
|
||||||
* @param osRelativePath {@link String} path to file contained in /data. Must
|
* @param osRelativePath {@link String} path to file contained in plugin. Must
|
||||||
* use path separators appropriate to host OS
|
* use path separators appropriate to host OS
|
||||||
*
|
*
|
||||||
* @return absolute OS path to test file
|
* @return absolute OS path to test file
|
||||||
@@ -100,17 +93,4 @@ public class AdtTestData {
|
|||||||
public String getTestFilePath(String osRelativePath) {
|
public String getTestFilePath(String osRelativePath) {
|
||||||
return mOsRootDataPath + osRelativePath;
|
return mOsRootDataPath + osRelativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to get a {@link InputStream} to test data file.
|
|
||||||
*
|
|
||||||
* @param osRelativePath {@link String} path to file contained in /data. Must
|
|
||||||
* use path separators appropriate to host OS
|
|
||||||
*
|
|
||||||
* @return {@link InputStream} for test file
|
|
||||||
* @throws FileNotFoundException if test file could not be found
|
|
||||||
*/
|
|
||||||
public InputStream getTestFileStream(String osRelativePath) throws FileNotFoundException {
|
|
||||||
return new FileInputStream(getTestFilePath(osRelativePath));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,12 @@ public class AndroidManifestParserTest extends TestCase {
|
|||||||
private AndroidManifestParser mManifestTestApp;
|
private AndroidManifestParser mManifestTestApp;
|
||||||
private AndroidManifestParser mManifestInstrumentation;
|
private AndroidManifestParser mManifestInstrumentation;
|
||||||
|
|
||||||
private static final String INSTRUMENTATION_XML = "AndroidManifest-instrumentation.xml"; //$NON-NLS-1$
|
private static final String TESTDATA_PATH =
|
||||||
private static final String TESTAPP_XML = "AndroidManifest-testapp.xml"; //$NON-NLS-1$
|
"com/android/ide/eclipse/testdata/"; //$NON-NLS-1$
|
||||||
|
private static final String INSTRUMENTATION_XML = TESTDATA_PATH +
|
||||||
|
"AndroidManifest-instrumentation.xml"; //$NON-NLS-1$
|
||||||
|
private static final String TESTAPP_XML = TESTDATA_PATH +
|
||||||
|
"AndroidManifest-testapp.xml"; //$NON-NLS-1$
|
||||||
private static final String PACKAGE_NAME = "com.android.testapp"; //$NON-NLS-1$
|
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 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 LIBRARY_NAME = "android.test.runner"; //$NON-NLS-1$
|
||||||
@@ -41,13 +45,11 @@ public class AndroidManifestParserTest extends TestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
String testFilePath = AdtTestData.getInstance().getTestFilePath(
|
String testFilePath = AdtTestData.getInstance().getTestFilePath(TESTAPP_XML);
|
||||||
TESTAPP_XML);
|
|
||||||
mManifestTestApp = AndroidManifestParser.parseForData(testFilePath);
|
mManifestTestApp = AndroidManifestParser.parseForData(testFilePath);
|
||||||
assertNotNull(mManifestTestApp);
|
assertNotNull(mManifestTestApp);
|
||||||
|
|
||||||
testFilePath = AdtTestData.getInstance().getTestFilePath(
|
testFilePath = AdtTestData.getInstance().getTestFilePath(INSTRUMENTATION_XML);
|
||||||
INSTRUMENTATION_XML);
|
|
||||||
mManifestInstrumentation = AndroidManifestParser.parseForData(testFilePath);
|
mManifestInstrumentation = AndroidManifestParser.parseForData(testFilePath);
|
||||||
assertNotNull(mManifestInstrumentation);
|
assertNotNull(mManifestInstrumentation);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,6 @@
|
|||||||
package com.android.ide.eclipse.adt.internal.resources;
|
package com.android.ide.eclipse.adt.internal.resources;
|
||||||
|
|
||||||
|
|
||||||
import com.android.ide.eclipse.adt.internal.resources.AttrsXmlParser;
|
|
||||||
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo;
|
|
||||||
import com.android.ide.eclipse.adt.internal.resources.ViewClassInfo;
|
|
||||||
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo;
|
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo.Format;
|
import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo.Format;
|
||||||
import com.android.ide.eclipse.tests.AdtTestData;
|
import com.android.ide.eclipse.tests.AdtTestData;
|
||||||
@@ -36,9 +33,12 @@ public class AttrsXmlParserTest extends TestCase {
|
|||||||
private AttrsXmlParser mParser;
|
private AttrsXmlParser mParser;
|
||||||
private String mFilePath;
|
private String mFilePath;
|
||||||
|
|
||||||
|
private static final String MOCK_DATA_PATH =
|
||||||
|
"com/android/ide/eclipse/testdata/mock_attrs.xml"; //$NON-NLS-1$
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mFilePath = AdtTestData.getInstance().getTestFilePath("mock_attrs.xml"); //$NON-NLS-1$
|
mFilePath = AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH); //$NON-NLS-1$
|
||||||
mParser = new AttrsXmlParser(mFilePath);
|
mParser = new AttrsXmlParser(mFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ public class AndroidJarLoaderTest extends TestCase {
|
|||||||
/** Creates an instance of {@link AndroidJarLoader} on our test data JAR */
|
/** Creates an instance of {@link AndroidJarLoader} on our test data JAR */
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
String jarfilePath = AdtTestData.getInstance().getTestFilePath("jar_example.jar"); //$NON-NLS-1$
|
String jarfilePath = AdtTestData.getInstance().getTestFilePath(
|
||||||
|
"com/android/ide/eclipse/testdata/jar_example.jar"); //$NON-NLS-1$
|
||||||
mFrameworkClassLoader = new AndroidJarLoader(jarfilePath);
|
mFrameworkClassLoader = new AndroidJarLoader(jarfilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,15 +19,12 @@ package com.android.ide.eclipse.adt.internal.sdk;
|
|||||||
import com.android.ide.eclipse.adt.internal.resources.AttrsXmlParser;
|
import com.android.ide.eclipse.adt.internal.resources.AttrsXmlParser;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.ViewClassInfo;
|
import com.android.ide.eclipse.adt.internal.resources.ViewClassInfo;
|
||||||
import com.android.ide.eclipse.adt.internal.resources.ViewClassInfo.LayoutParamsInfo;
|
import com.android.ide.eclipse.adt.internal.resources.ViewClassInfo.LayoutParamsInfo;
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.AndroidJarLoader;
|
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetParser;
|
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.LayoutParamsParser;
|
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.AndroidJarLoader.ClassWrapper;
|
import com.android.ide.eclipse.adt.internal.sdk.AndroidJarLoader.ClassWrapper;
|
||||||
import com.android.ide.eclipse.adt.internal.sdk.IAndroidClassLoader.IClassDescriptor;
|
import com.android.ide.eclipse.adt.internal.sdk.IAndroidClassLoader.IClassDescriptor;
|
||||||
|
import com.android.ide.eclipse.tests.AdtTestData;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
@@ -44,6 +41,9 @@ import junit.framework.TestCase;
|
|||||||
*/
|
*/
|
||||||
public class LayoutParamsParserTest extends TestCase {
|
public class LayoutParamsParserTest extends TestCase {
|
||||||
|
|
||||||
|
private static final String MOCK_DATA_PATH =
|
||||||
|
"com/android/ide/eclipse/testdata/mock_attrs.xml"; //$NON-NLS-1$
|
||||||
|
|
||||||
private static class MockFrameworkClassLoader extends AndroidJarLoader {
|
private static class MockFrameworkClassLoader extends AndroidJarLoader {
|
||||||
MockFrameworkClassLoader() {
|
MockFrameworkClassLoader() {
|
||||||
super(null /* osFrameworkLocation */);
|
super(null /* osFrameworkLocation */);
|
||||||
@@ -56,18 +56,11 @@ public class LayoutParamsParserTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class MockAttrsXmlPath {
|
|
||||||
public String getPath() {
|
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
|
||||||
URL res = cl.getResource("data/mock_attrs.xml"); //$NON-NLS-1$
|
|
||||||
return res.getFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MockLayoutParamsParser extends LayoutParamsParser {
|
private static class MockLayoutParamsParser extends LayoutParamsParser {
|
||||||
public MockLayoutParamsParser() {
|
public MockLayoutParamsParser() {
|
||||||
super(new MockFrameworkClassLoader(),
|
super(new MockFrameworkClassLoader(),
|
||||||
new AttrsXmlParser(new MockAttrsXmlPath().getPath()).preload());
|
new AttrsXmlParser(
|
||||||
|
AdtTestData.getInstance().getTestFilePath(MOCK_DATA_PATH)).preload());
|
||||||
|
|
||||||
mTopViewClass = new ClassWrapper(mock_android.view.View.class);
|
mTopViewClass = new ClassWrapper(mock_android.view.View.class);
|
||||||
mTopGroupClass = new ClassWrapper(mock_android.view.ViewGroup.class);
|
mTopGroupClass = new ClassWrapper(mock_android.view.ViewGroup.class);
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.7 KiB |
@@ -1,49 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2008 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
android:id="@+id/bouton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="My Button Text"
|
|
||||||
>
|
|
||||||
</Button>
|
|
||||||
<View
|
|
||||||
android:id="@+id/surface"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_weight="2"
|
|
||||||
/>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/status"
|
|
||||||
android:paddingLeft="2dip"
|
|
||||||
android:layout_weight="0"
|
|
||||||
android:background="@drawable/black"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:lines="1"
|
|
||||||
android:gravity="center_vertical|center_horizontal"
|
|
||||||
android:text="My TextView Text"
|
|
||||||
/>
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.sdklib.repository;
|
package com.android.sdklib.repository;
|
||||||
|
|
||||||
import com.android.ide.eclipse.tests.AdtTestData;
|
|
||||||
|
|
||||||
import org.xml.sax.ErrorHandler;
|
import org.xml.sax.ErrorHandler;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.SAXParseException;
|
import org.xml.sax.SAXParseException;
|
||||||
@@ -125,8 +123,9 @@ public class TestSdkRepository extends TestCase {
|
|||||||
|
|
||||||
/** Validate a valid sample using an InputStream */
|
/** Validate a valid sample using an InputStream */
|
||||||
public void testValidateLocalRepositoryFile() throws Exception {
|
public void testValidateLocalRepositoryFile() throws Exception {
|
||||||
InputStream xmlStream = AdtTestData.getInstance().getTestFileStream(
|
InputStream xmlStream =
|
||||||
"repository_sample.xml");
|
this.getClass().getClassLoader().getResourceAsStream(
|
||||||
|
"com/android/sdklib/testdata/repository_sample.xml");
|
||||||
Source source = new StreamSource(xmlStream);
|
Source source = new StreamSource(xmlStream);
|
||||||
|
|
||||||
CaptureErrorHandler handler = new CaptureErrorHandler();
|
CaptureErrorHandler handler = new CaptureErrorHandler();
|
||||||
|
|||||||
Reference in New Issue
Block a user