FileDocCategorySizeDatePackage
AdtTestData.javaAPI DocAndroid 1.5 API3739Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.tests

AdtTestData

public class AdtTestData extends Object
Helper class for retrieving test data All tests which need to retrieve test data files should go through this class

Fields Summary
private static AdtTestData
sInstance
singleton instance
private static final Logger
sLogger
private String
mOsRootDataPath
the absolute file path to the /data directory in this test environment.
Constructors Summary
private AdtTestData()

    
   
      
        // can set test_data env variable to override default behavior of 
        // finding data using class loader
        // useful when running in plugin environment, where test data is inside 
        // bundled jar, and must be extracted to temp filesystem location to be 
        // accessed normally
        mOsRootDataPath = System.getProperty("test_data");
        if (mOsRootDataPath == null) {
            sLogger.info("Cannot find test_data environment variable, init to class loader");
            URL url = this.getClass().getClassLoader().getResource("data");  //$NON-NLS-1$

                if (Platform.isRunning()) {
                    sLogger.info("Running as an Eclipse Plug-in JUnit test, using FileLocator");
                    try {
                        mOsRootDataPath = FileLocator.resolve(url).getFile();
                    } catch (IOException e) {
                        sLogger.warning("IOException while using FileLocator, reverting to url");
                        mOsRootDataPath = url.getFile();
                    }
                } else {
                    sLogger.info("Running as an plain JUnit test, using url as-is");
                    mOsRootDataPath = url.getFile();                        
                }
        }
        
        if (mOsRootDataPath.equals(AndroidConstants.WS_SEP + "data")) {
            sLogger.warning("Resource data not found using class loader!, Defaulting to no path");
        }
        
        if (!mOsRootDataPath.endsWith(File.separator)) {
            sLogger.info("Fixing test_data env variable (does not end with path separator)");
            mOsRootDataPath = mOsRootDataPath.concat(File.separator);
        }
    
Methods Summary
public static com.android.ide.eclipse.tests.AdtTestDatagetInstance()
Get the singleton instance of AdtTestData

        if (sInstance == null) {
            sInstance = new AdtTestData();
        }
        return sInstance;
    
public java.lang.StringgetTestFilePath(java.lang.String osRelativePath)
Returns the absolute file path to a file located in this plugins "data" directory

param
osRelativePath - string path to file contained in /data. Must use path separators appropriate to host OS
return
String

        return mOsRootDataPath + osRelativePath;