Commit 8e22b179 authored by Alexander Alekhin's avatar Alexander Alekhin

java: backport test changes from master

parent af8e6b06
...@@ -26,6 +26,11 @@ import org.opencv.highgui.Highgui; ...@@ -26,6 +26,11 @@ import org.opencv.highgui.Highgui;
import android.util.Log; import android.util.Log;
public class OpenCVTestCase extends TestCase { public class OpenCVTestCase extends TestCase {
public static class TestSkipException extends RuntimeException {
public TestSkipException() {}
}
//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;
...@@ -182,12 +187,40 @@ public class OpenCVTestCase extends TestCase { ...@@ -182,12 +187,40 @@ public class OpenCVTestCase extends TestCase {
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
// Do nothing if the precondition does not hold. // Do nothing if the precondition does not hold.
if (isTestCaseEnabled) { if (isTestCaseEnabled) {
super.runTest(); try {
super.runTest();
} catch (TestSkipException ex) {
Log.w(TAG, "Test case \"" + this.getClass().getName() + "\" skipped!");
assertTrue(true);
}
} else { } else {
Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!"); Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!");
} }
} }
public void runBare() throws Throwable {
Throwable exception = null;
try {
setUp();
} catch (TestSkipException ex) {
Log.w(TAG, "Test case \"" + this.getClass().getName() + "\" skipped!");
assertTrue(true);
return;
}
try {
runTest();
} catch (Throwable running) {
exception = running;
} finally {
try {
tearDown();
} catch (Throwable tearingDown) {
if (exception == null) exception = tearingDown;
}
}
if (exception != null) throw exception;
}
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));
...@@ -205,6 +238,10 @@ public class OpenCVTestCase extends TestCase { ...@@ -205,6 +238,10 @@ public class OpenCVTestCase extends TestCase {
TestCase.fail(msg); TestCase.fail(msg);
} }
public static void assertGE(double v1, double v2) {
assertTrue("Failed: " + v1 + " >= " + v2, v1 >= v2);
}
public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) { public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -419,10 +456,10 @@ public class OpenCVTestCase extends TestCase { ...@@ -419,10 +456,10 @@ public class OpenCVTestCase extends TestCase {
if (isEqualityMeasured) if (isEqualityMeasured)
assertTrue("Max difference between expected and actiual Mats is "+ maxDiff + ", that bigger than " + eps, assertTrue("Max difference between expected and actiual Mats is "+ maxDiff + ", that bigger than " + eps,
Core.checkRange(diff, true, 0.0, eps)); maxDiff <= eps);
else else
assertFalse("Max difference between expected and actiual Mats is "+ maxDiff + ", that less than " + eps, assertFalse("Max difference between expected and actiual Mats is "+ maxDiff + ", that less than " + eps,
Core.checkRange(diff, true, 0.0, eps)); maxDiff <= eps);
} }
protected static String readFile(String path) { protected static String readFile(String path) {
......
...@@ -2052,7 +2052,7 @@ public class CoreTest extends OpenCVTestCase { ...@@ -2052,7 +2052,7 @@ public class CoreTest extends OpenCVTestCase {
}; };
Mat roots = new Mat(); Mat roots = new Mat();
assertEquals(0.0, Core.solvePoly(coeffs, roots)); assertGE(1e-6, Math.abs(Core.solvePoly(coeffs, roots)));
truth = new Mat(3, 1, CvType.CV_32FC2) { truth = new Mat(3, 1, CvType.CV_32FC2) {
{ {
......
...@@ -488,13 +488,13 @@ public class MatTest extends OpenCVTestCase { ...@@ -488,13 +488,13 @@ public class MatTest extends OpenCVTestCase {
public void testIsContinuous() { public void testIsContinuous() {
assertTrue(gray0.isContinuous()); assertTrue(gray0.isContinuous());
Mat subMat = gray0.submat(0, 0, gray0.rows() / 2, gray0.cols() / 2); Mat subMat = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols() / 2);
assertFalse(subMat.isContinuous()); assertFalse(subMat.isContinuous());
} }
public void testIsSubmatrix() { public void testIsSubmatrix() {
assertFalse(gray0.isSubmatrix()); assertFalse(gray0.isSubmatrix());
Mat subMat = gray0.submat(0, 0, gray0.rows() / 2, gray0.cols() / 2); Mat subMat = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols() / 2);
assertTrue(subMat.isSubmatrix()); assertTrue(subMat.isSubmatrix());
} }
......
...@@ -165,7 +165,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -165,7 +165,7 @@ public class ImgprocTest extends OpenCVTestCase {
double arcLength = Imgproc.arcLength(curve, false); double arcLength = Imgproc.arcLength(curve, false);
assertEquals(5.656854152679443, arcLength); assertEquals(5.656854152679443, arcLength, EPS);
} }
public void testBilateralFilterMatMatIntDoubleDouble() { public void testBilateralFilterMatMatIntDoubleDouble() {
...@@ -367,7 +367,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -367,7 +367,7 @@ public class ImgprocTest extends OpenCVTestCase {
double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL); double distance = Imgproc.compareHist(H1, H2, Imgproc.CV_COMP_CORREL);
assertEquals(1., distance); assertEquals(1., distance, EPS);
} }
public void testContourAreaMat() { public void testContourAreaMat() {
...@@ -376,7 +376,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -376,7 +376,7 @@ public class ImgprocTest extends OpenCVTestCase {
double area = Imgproc.contourArea(contour); double area = Imgproc.contourArea(contour);
assertEquals(45., area); assertEquals(45., area, EPS);
} }
public void testContourAreaMatBoolean() { public void testContourAreaMatBoolean() {
...@@ -385,7 +385,7 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -385,7 +385,7 @@ public class ImgprocTest extends OpenCVTestCase {
double area = Imgproc.contourArea(contour, true); double area = Imgproc.contourArea(contour, true);
assertEquals(45., area); assertEquals(45., area, EPS);
// TODO_: write better test // TODO_: write better test
} }
......
<project> <project>
<property file="ant-${opencv.build.type}.properties"/> <property file="ant-${opencv.build.type}.properties"/>
<property name="test.dir" value="testResults"/>
<property name="build.dir" value="build"/>
<path id="master-classpath"> <path id="master-classpath">
<fileset dir="lib"> <fileset dir="lib">
...@@ -12,7 +14,7 @@ ...@@ -12,7 +14,7 @@
<target name="clean"> <target name="clean">
<delete dir="build"/> <delete dir="build"/>
<delete dir="testResults"/> <delete dir="${test.dir}"/>
</target> </target>
<target name="compile"> <target name="compile">
...@@ -34,8 +36,8 @@ ...@@ -34,8 +36,8 @@
</target> </target>
<target name="test"> <target name="test">
<mkdir dir="testResults"/> <mkdir dir="${test.dir}"/>
<junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="false" logfailedtests="true" maxmemory="256m"> <junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="true" logfailedtests="true" maxmemory="256m">
<sysproperty key="java.library.path" path="${opencv.lib.path}"/> <sysproperty key="java.library.path" path="${opencv.lib.path}"/>
<env key="PATH" path="${opencv.lib.path}"/> <env key="PATH" path="${opencv.lib.path}"/>
<classpath refid="master-classpath"/> <classpath refid="master-classpath"/>
...@@ -45,12 +47,18 @@ ...@@ -45,12 +47,18 @@
<formatter type="xml"/> <formatter type="xml"/>
<batchtest fork="yes" todir="testResults"> <batchtest fork="yes" todir="${test.dir}">
<zipfileset src="build/jar/opencv-test.jar" includes="**/*.class" excludes="**/OpenCVTest*"> <zipfileset src="build/jar/opencv-test.jar" includes="**/*.class" excludes="**/OpenCVTest*">
<exclude name="**/*$*.class"/> <exclude name="**/*$*.class"/>
</zipfileset> </zipfileset>
</batchtest> </batchtest>
</junit> </junit>
<junitreport todir="${test.dir}">
<fileset dir="${test.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="noframes" todir="${test.dir}"/>
</junitreport>
</target> </target>
<target name="build"> <target name="build">
......
...@@ -28,6 +28,11 @@ import org.opencv.features2d.KeyPoint; ...@@ -28,6 +28,11 @@ import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui; import org.opencv.highgui.Highgui;
public class OpenCVTestCase extends TestCase { public class OpenCVTestCase extends TestCase {
public static class TestSkipException extends RuntimeException {
public TestSkipException() {}
}
//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;
...@@ -212,12 +217,40 @@ public class OpenCVTestCase extends TestCase { ...@@ -212,12 +217,40 @@ public class OpenCVTestCase extends TestCase {
protected void runTest() throws Throwable { protected void runTest() throws Throwable {
// Do nothing if the precondition does not hold. // Do nothing if the precondition does not hold.
if (isTestCaseEnabled) { if (isTestCaseEnabled) {
super.runTest(); try {
super.runTest();
} catch (TestSkipException ex) {
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" skipped!");
assertTrue(true);
}
} else { } else {
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" disabled!"); OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" disabled!");
} }
} }
public void runBare() throws Throwable {
Throwable exception = null;
try {
setUp();
} catch (TestSkipException ex) {
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" skipped!");
assertTrue(true);
return;
}
try {
runTest();
} catch (Throwable running) {
exception = running;
} finally {
try {
tearDown();
} catch (Throwable tearingDown) {
if (exception == null) exception = tearingDown;
}
}
if (exception != null) throw exception;
}
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));
...@@ -235,6 +268,10 @@ public class OpenCVTestCase extends TestCase { ...@@ -235,6 +268,10 @@ public class OpenCVTestCase extends TestCase {
TestCase.fail(msg); TestCase.fail(msg);
} }
public static void assertGE(double v1, double v2) {
assertTrue("Failed: " + v1 + " >= " + v2, v1 >= v2);
}
public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) { public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -449,10 +486,10 @@ public class OpenCVTestCase extends TestCase { ...@@ -449,10 +486,10 @@ public class OpenCVTestCase extends TestCase {
if (isEqualityMeasured) if (isEqualityMeasured)
assertTrue("Max difference between expected and actiual Mats is "+ maxDiff + ", that bigger than " + eps, assertTrue("Max difference between expected and actiual Mats is "+ maxDiff + ", that bigger than " + eps,
Core.checkRange(diff, true, 0.0, eps)); maxDiff <= eps);
else else
assertFalse("Max difference between expected and actiual Mats is "+ maxDiff + ", that less than " + eps, assertFalse("Max difference between expected and actiual Mats is "+ maxDiff + ", that less than " + eps,
Core.checkRange(diff, true, 0.0, eps)); maxDiff <= eps);
} }
protected static String readFile(String path) { protected static String readFile(String path) {
......
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