java tests: now only OpenCVTestRunner contains android specific stuff
This commit is contained in:
parent
3fc879075b
commit
ec6fb0bee2
@ -5,7 +5,8 @@
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
<instrumentation android:targetPackage="org.opencv.test" android:name="android.test.InstrumentationTestRunner" />
|
||||
<instrumentation android:targetPackage="org.opencv.test" android:name="OpenCVTestRunner"></instrumentation>
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
@ -10,7 +10,7 @@ public class MatTest extends OpenCVTestCase {
|
||||
|
||||
public void testChannels() {
|
||||
//fail("Not yet implemented");
|
||||
utils.Log(grayRnd.dump());
|
||||
//utils.Log(grayRnd.dump());
|
||||
}
|
||||
|
||||
public void testClone() {
|
||||
|
@ -8,9 +8,7 @@ import org.opencv.highgui;
|
||||
|
||||
|
||||
public class OpenCVTestCase extends TestCase {
|
||||
|
||||
static String LENA = "/data/data/org.opencv.test/files/lena.jpg";
|
||||
|
||||
|
||||
static int matSize = 10;
|
||||
|
||||
static Mat dst;
|
||||
@ -72,11 +70,11 @@ public class OpenCVTestCase extends TestCase {
|
||||
|
||||
gray0_64f = new Mat(matSize, matSize, Mat.CvType.CV_64FC1); gray0_64f.setTo(0.0);
|
||||
gray0_64f_1d = new Mat(1, matSize, Mat.CvType.CV_64FC1); gray0_64f_1d.setTo(0.0);
|
||||
|
||||
rgbLena = highgui.imread(LENA);
|
||||
|
||||
|
||||
rgba0 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba0.setTo(0, 0, 0, 0);
|
||||
rgba128 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba128.setTo(128, 128, 128, 128);
|
||||
|
||||
rgbLena = highgui.imread(OpenCVTestRunner.LENA_PATH);
|
||||
}
|
||||
|
||||
public static void assertMatEqual(Mat m1, Mat m2) {
|
||||
@ -93,10 +91,8 @@ public class OpenCVTestCase extends TestCase {
|
||||
}
|
||||
|
||||
public void test_1(String label) {
|
||||
utils.Log("================================================");
|
||||
utils.Log("=============== " + label);
|
||||
utils.Log("================================================");
|
||||
|
||||
new utils().ExportLena();
|
||||
OpenCVTestRunner.Log("================================================");
|
||||
OpenCVTestRunner.Log("=============== " + label);
|
||||
OpenCVTestRunner.Log("================================================");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package org.opencv.test;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.test.AndroidTestRunner;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* This only class is Android specific.
|
||||
* The original idea about test order randomization is from marek.defecinski blog.
|
||||
*/
|
||||
|
||||
public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
|
||||
public static String LENA_PATH = "/data/data/org.opencv.test/files/lena.jpg";
|
||||
|
||||
private AndroidTestRunner androidTestRunner;
|
||||
private static String TAG = "opencv_test_java";
|
||||
|
||||
static public void Log(String message) {
|
||||
Log.e(TAG, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
ExportLena();
|
||||
|
||||
List<TestCase> testCases = androidTestRunner.getTestCases();
|
||||
Collections.shuffle(testCases); //shuffle the tests order
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AndroidTestRunner getAndroidTestRunner() {
|
||||
androidTestRunner = super.getAndroidTestRunner();
|
||||
return androidTestRunner;
|
||||
}
|
||||
|
||||
private void ExportLena() {
|
||||
try {
|
||||
Bitmap mBitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.lena);
|
||||
FileOutputStream fos = this.getContext().openFileOutput("lena.jpg", Context.MODE_WORLD_READABLE);
|
||||
mBitmap.compress(CompressFormat.JPEG, 100, fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log("Tried to write lena.jpg, but: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
@ -35,8 +35,9 @@ public class coreTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testAddWeightedMatDoubleMatDoubleDoubleMatInt() {
|
||||
core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, gray255_32f.depth());
|
||||
assertTrue(core.CV_32F == dst.depth());
|
||||
fail("Not yet implemented");
|
||||
//core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, gray255_32f.depth());
|
||||
//assertTrue(core.CV_32F == dst.depth());
|
||||
}
|
||||
|
||||
public void testBitwise_andMatMatMat() {
|
||||
|
@ -31,7 +31,7 @@ public class highguiTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testImreadString() {
|
||||
dst = highgui.imread(LENA);
|
||||
dst = highgui.imread(OpenCVTestRunner.LENA_PATH);
|
||||
assertTrue(!dst.empty());
|
||||
assertEquals(3, dst.channels());
|
||||
assertTrue(512 == dst.cols());
|
||||
@ -39,7 +39,7 @@ public class highguiTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testImreadStringInt() {
|
||||
dst = highgui.imread(LENA, 0);
|
||||
dst = highgui.imread(OpenCVTestRunner.LENA_PATH, 0);
|
||||
assertTrue(!dst.empty());
|
||||
assertEquals(1, dst.channels());
|
||||
assertTrue(512 == dst.cols());
|
||||
|
@ -1,35 +0,0 @@
|
||||
package org.opencv.test;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class utils extends AndroidTestCase {
|
||||
|
||||
static String TAG = "opencv_test_java";
|
||||
|
||||
static public void Log(String message) {
|
||||
Log.e(TAG, message);
|
||||
}
|
||||
|
||||
public void ExportLena() {
|
||||
//TODO: can we run this code just once, not for every test case?
|
||||
try {
|
||||
Bitmap mBitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.lena);
|
||||
FileOutputStream fos = this.getContext().openFileOutput("lena.jpg", Context.MODE_WORLD_READABLE);
|
||||
mBitmap.compress(CompressFormat.JPEG, 100, fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e(TAG, "Tried to write lena.jpg, but: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user