Merging pull request #167 from asmorkalov:java_api_manager_test

This commit is contained in:
Andrey Kamaev 2012-11-20 17:53:06 +04:00 committed by OpenCV Buildbot
commit d3397a1d6d
3 changed files with 70 additions and 37 deletions

View File

@ -23,15 +23,20 @@ import org.opencv.features2d.DMatch;
import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui;
public class OpenCVTestCase extends TestCase {
import android.util.Log;
public class OpenCVTestCase extends TestCase {
//change to 'true' to unblock fail on fail("Not yet implemented")
public static final boolean passNYI = true;
protected static boolean isTestCaseEnabled = true;
protected static final int matSize = 10;
protected static final double EPS = 0.001;
protected static final double weakEPS = 0.5;
private static final String TAG = "OpenCVTestCase";
protected Mat dst;
protected Mat truth;
@ -173,6 +178,16 @@ public class OpenCVTestCase extends TestCase {
super.tearDown();
}
@Override
protected void runTest() throws Throwable {
// Do nothing if the precondition does not hold.
if (isTestCaseEnabled) {
super.runTest();
} else {
Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!");
}
}
protected Mat getMat(int type, double... vals)
{
return new Mat(matSize, matSize, type, new Scalar(vals));

View File

@ -2,11 +2,11 @@ package org.opencv.test;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
@ -23,8 +23,7 @@ import android.util.Log;
public class OpenCVTestRunner extends InstrumentationTestRunner {
static { System.loadLibrary("opencv_java"); }
private static final long MANAGER_TIMEOUT = 3000;
public static String LENA_PATH;
public static String CHESS_PATH;
public static String LBPCASCADE_FRONTALFACE_PATH;
@ -33,6 +32,26 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
private AndroidTestRunner androidTestRunner;
private static String TAG = "opencv_test_java";
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(getContext()) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log("OpenCV loaded successfully");
synchronized (this) {
notify();
}
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public static String getTempFileName(String extension)
{
File cache = context.getCacheDir();
@ -59,6 +78,25 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
@Override
public void onStart() {
// try to load internal libs
if (!OpenCVLoader.initDebug()) {
// There is no internal OpenCV libs
// Using OpenCV Manager for initialization;
Log("Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, getContext(), mLoaderCallback);
synchronized (this) {
try {
wait(MANAGER_TIMEOUT);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
Log("OpenCV library found inside test package. Using it!");
}
context = getContext();
Assert.assertTrue("Context can't be 'null'", context != null);
LENA_PATH = Utils.exportResource(context, R.drawable.lena);
@ -72,17 +110,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
//List<TestCase> testCases = androidTestRunner.getTestCases();
//Collections.shuffle(testCases); //shuffle the tests order
if(OpenCVTestCase.passNYI) {
// turn off problematic camera tests
Iterator<TestCase> it = androidTestRunner.getTestCases().iterator();
while (it.hasNext()) {
String name = it.next().toString();
if (name.contains("VideoCaptureTest"))
it.remove();
}
}
super.onStart();
}

View File

@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase {
super.setUp();
capture = null;
isTestCaseEnabled = false;
isSucceed = false;
isOpened = false;
}
public void testGet() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH);
assertTrue(0 != frameWidth);
@ -35,8 +35,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testGetSupportedPreviewSizes() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
List<Size> sizes = capture.getSupportedPreviewSizes();
assertNotNull(sizes);
@ -68,8 +67,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testIsOpenedRealCamera() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
isOpened = capture.isOpened();
assertTrue(isOpened);
@ -79,8 +77,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testOpen() {
try
{
try {
capture = new VideoCapture();
capture.open(Highgui.CV_CAP_ANDROID);
isOpened = capture.isOpened();
@ -91,8 +88,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testRead() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
isSucceed = capture.read(dst);
assertTrue(isSucceed);
@ -104,8 +100,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testRelease() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.release();
assertFalse(capture.isOpened());
@ -116,8 +111,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testRetrieveMat() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.grab();
isSucceed = capture.retrieve(dst);
@ -130,8 +124,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testRetrieveMatInt() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.grab();
isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME);
@ -144,8 +137,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testSet() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480);
@ -165,8 +157,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
}
public void testVideoCaptureInt() {
try
{
try {
capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
assertNotNull(capture);
assertTrue(capture.isOpened());