Commit d3397a1d authored by Andrey Kamaev's avatar Andrey Kamaev Committed by OpenCV Buildbot

Merging pull request #167 from asmorkalov:java_api_manager_test

parents f172947e 66a1ea76
...@@ -23,15 +23,20 @@ import org.opencv.features2d.DMatch; ...@@ -23,15 +23,20 @@ import org.opencv.features2d.DMatch;
import org.opencv.features2d.KeyPoint; import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui; 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") //change to 'true' to unblock fail on fail("Not yet implemented")
public static final boolean passNYI = true; public static final boolean passNYI = true;
protected static boolean isTestCaseEnabled = true;
protected static final int matSize = 10; protected static final int matSize = 10;
protected static final double EPS = 0.001; protected static final double EPS = 0.001;
protected static final double weakEPS = 0.5; protected static final double weakEPS = 0.5;
private static final String TAG = "OpenCVTestCase";
protected Mat dst; protected Mat dst;
protected Mat truth; protected Mat truth;
...@@ -173,6 +178,16 @@ public class OpenCVTestCase extends TestCase { ...@@ -173,6 +178,16 @@ public class OpenCVTestCase extends TestCase {
super.tearDown(); 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) protected Mat getMat(int type, double... vals)
{ {
return new Mat(matSize, matSize, type, new Scalar(vals)); return new Mat(matSize, matSize, type, new Scalar(vals));
......
...@@ -2,11 +2,11 @@ package org.opencv.test; ...@@ -2,11 +2,11 @@ package org.opencv.test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import junit.framework.TestCase;
import junit.framework.Assert; 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.android.Utils;
import org.opencv.core.Mat; import org.opencv.core.Mat;
...@@ -23,8 +23,7 @@ import android.util.Log; ...@@ -23,8 +23,7 @@ import android.util.Log;
public class OpenCVTestRunner extends InstrumentationTestRunner { 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 LENA_PATH;
public static String CHESS_PATH; public static String CHESS_PATH;
public static String LBPCASCADE_FRONTALFACE_PATH; public static String LBPCASCADE_FRONTALFACE_PATH;
...@@ -33,6 +32,26 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { ...@@ -33,6 +32,26 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
private AndroidTestRunner androidTestRunner; private AndroidTestRunner androidTestRunner;
private static String TAG = "opencv_test_java"; 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) public static String getTempFileName(String extension)
{ {
File cache = context.getCacheDir(); File cache = context.getCacheDir();
...@@ -59,6 +78,25 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { ...@@ -59,6 +78,25 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
@Override @Override
public void onStart() { 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(); context = getContext();
Assert.assertTrue("Context can't be 'null'", context != null); Assert.assertTrue("Context can't be 'null'", context != null);
LENA_PATH = Utils.exportResource(context, R.drawable.lena); LENA_PATH = Utils.exportResource(context, R.drawable.lena);
...@@ -72,17 +110,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { ...@@ -72,17 +110,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
//List<TestCase> testCases = androidTestRunner.getTestCases(); //List<TestCase> testCases = androidTestRunner.getTestCases();
//Collections.shuffle(testCases); //shuffle the tests order //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(); super.onStart();
} }
......
...@@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase {
super.setUp(); super.setUp();
capture = null; capture = null;
isTestCaseEnabled = false;
isSucceed = false; isSucceed = false;
isOpened = false; isOpened = false;
} }
public void testGet() { public void testGet() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH);
assertTrue(0 != frameWidth); assertTrue(0 != frameWidth);
...@@ -35,8 +35,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -35,8 +35,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testGetSupportedPreviewSizes() { public void testGetSupportedPreviewSizes() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
List<Size> sizes = capture.getSupportedPreviewSizes(); List<Size> sizes = capture.getSupportedPreviewSizes();
assertNotNull(sizes); assertNotNull(sizes);
...@@ -68,8 +67,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -68,8 +67,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testIsOpenedRealCamera() { public void testIsOpenedRealCamera() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
isOpened = capture.isOpened(); isOpened = capture.isOpened();
assertTrue(isOpened); assertTrue(isOpened);
...@@ -79,8 +77,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -79,8 +77,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testOpen() { public void testOpen() {
try try {
{
capture = new VideoCapture(); capture = new VideoCapture();
capture.open(Highgui.CV_CAP_ANDROID); capture.open(Highgui.CV_CAP_ANDROID);
isOpened = capture.isOpened(); isOpened = capture.isOpened();
...@@ -91,8 +88,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -91,8 +88,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testRead() { public void testRead() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
isSucceed = capture.read(dst); isSucceed = capture.read(dst);
assertTrue(isSucceed); assertTrue(isSucceed);
...@@ -104,8 +100,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -104,8 +100,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testRelease() { public void testRelease() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.release(); capture.release();
assertFalse(capture.isOpened()); assertFalse(capture.isOpened());
...@@ -116,8 +111,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -116,8 +111,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testRetrieveMat() { public void testRetrieveMat() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.grab(); capture.grab();
isSucceed = capture.retrieve(dst); isSucceed = capture.retrieve(dst);
...@@ -130,8 +124,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -130,8 +124,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testRetrieveMatInt() { public void testRetrieveMatInt() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.grab(); capture.grab();
isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME); isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME);
...@@ -144,8 +137,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -144,8 +137,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testSet() { public void testSet() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640); capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480); capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480);
...@@ -165,8 +157,7 @@ public class VideoCaptureTest extends OpenCVTestCase { ...@@ -165,8 +157,7 @@ public class VideoCaptureTest extends OpenCVTestCase {
} }
public void testVideoCaptureInt() { public void testVideoCaptureInt() {
try try {
{
capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture = new VideoCapture(Highgui.CV_CAP_ANDROID);
assertNotNull(capture); assertNotNull(capture);
assertTrue(capture.isOpened()); assertTrue(capture.isOpened());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment