Bug 739415 - Add ability to have raw files as test assets. r=jmaher

This commit is contained in:
Kartikaya Gupta 2012-03-27 16:16:13 -04:00
parent 46f7cfbdbd
commit d0da20efa2
3 changed files with 15 additions and 3 deletions

View File

@ -127,8 +127,8 @@ classes.dex: $(_JAVA_TESTS)
$(JAVAC) $(JAVAC_FLAGS) -d classes $(JAVAFILES) $(_JAVA_HARNESS) $(addprefix $(DEPTH)/mobile/android/base/tests/,$(_JAVA_TESTS))
$(DX) --dex --output=$@ classes $(ROBOTIUM_PATH)
robocop.ap_: AndroidManifest.xml
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -I . -S res -F $@ -J ./
robocop.ap_: AndroidManifest.xml $(TESTPATH)/assets/*
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -I . -S res -A $(TESTPATH)/assets -F $@ -J ./
robocop.apk: robocop.ap_ classes.dex
cp $(TESTPATH)/robocop.ini robocop.ini

View File

@ -6,12 +6,15 @@ import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.app.Instrumentation;
import android.database.Cursor;
import android.content.ContentValues;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.util.HashMap;
@ -204,4 +207,9 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
}
return true;
}
public InputStream getAsset(String filename) throws IOException {
AssetManager assets = getInstrumentation().getContext().getAssets();
return assets.open(filename);
}
}

View File

@ -0,0 +1,4 @@
You can place test assets in this file.
They can be read as raw InputStreams with the getAsset() method in BaseTest.
(This file is a placeholder to ensure that the assets/ directory exists, as it is referenced in the robocop Makefile.)