Skip to content

Commit fe29080

Browse files
committed
java: skip test in case of missed classes from opencv_contrib
1 parent 8d662a1 commit fe29080

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
import static junit.framework.Assert.assertTrue;
3030

3131
public class OpenCVTestCase extends TestCase {
32+
33+
public static class TestSkipException extends RuntimeException {
34+
public TestSkipException() {}
35+
}
36+
3237
//change to 'true' to unblock fail on fail("Not yet implemented")
3338
public static final boolean passNYI = true;
3439

@@ -188,12 +193,40 @@ protected void tearDown() throws Exception {
188193
protected void runTest() throws Throwable {
189194
// Do nothing if the precondition does not hold.
190195
if (isTestCaseEnabled) {
191-
super.runTest();
196+
try {
197+
super.runTest();
198+
} catch (TestSkipException ex) {
199+
Log.w(TAG, "Test case \"" + this.getClass().getName() + "\" skipped!");
200+
assertTrue(true);
201+
}
192202
} else {
193203
Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!");
194204
}
195205
}
196206

207+
public void runBare() throws Throwable {
208+
Throwable exception = null;
209+
try {
210+
setUp();
211+
} catch (TestSkipException ex) {
212+
Log.w(TAG, "Test case \"" + this.getClass().getName() + "\" skipped!");
213+
assertTrue(true);
214+
return;
215+
}
216+
try {
217+
runTest();
218+
} catch (Throwable running) {
219+
exception = running;
220+
} finally {
221+
try {
222+
tearDown();
223+
} catch (Throwable tearingDown) {
224+
if (exception == null) exception = tearingDown;
225+
}
226+
}
227+
if (exception != null) throw exception;
228+
}
229+
197230
protected Mat getMat(int type, double... vals)
198231
{
199232
return new Mat(matSize, matSize, type, new Scalar(vals));
@@ -497,6 +530,10 @@ protected <T> T createClassInstance(String cname, String factoryName, Class cPar
497530
}
498531
}
499532
catch(Exception ex) {
533+
if (cname.startsWith(XFEATURES2D))
534+
{
535+
throw new TestSkipException();
536+
}
500537
message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage();
501538
}
502539

modules/java/pure_test/build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
<target name="test">
3939
<mkdir dir="${test.dir}"/>
40-
<junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="false" logfailedtests="true" maxmemory="256m">
40+
<junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="true" logfailedtests="true" maxmemory="256m">
4141
<sysproperty key="java.library.path" path="${opencv.lib.path}"/>
4242
<env key="PATH" path="${opencv.lib.path}"/>
4343
<classpath refid="master-classpath"/>

modules/java/pure_test/src/org/opencv/test/OpenCVTestCase.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
import org.opencv.imgcodecs.Imgcodecs;
2828

2929
public class OpenCVTestCase extends TestCase {
30+
31+
public static class TestSkipException extends RuntimeException {
32+
public TestSkipException() {}
33+
}
34+
3035
//change to 'true' to unblock fail on fail("Not yet implemented")
3136
public static final boolean passNYI = true;
3237

@@ -214,12 +219,40 @@ protected void tearDown() throws Exception {
214219
protected void runTest() throws Throwable {
215220
// Do nothing if the precondition does not hold.
216221
if (isTestCaseEnabled) {
217-
super.runTest();
222+
try {
223+
super.runTest();
224+
} catch (TestSkipException ex) {
225+
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" skipped!");
226+
assertTrue(true);
227+
}
218228
} else {
219229
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" disabled!");
220230
}
221231
}
222232

233+
public void runBare() throws Throwable {
234+
Throwable exception = null;
235+
try {
236+
setUp();
237+
} catch (TestSkipException ex) {
238+
OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" skipped!");
239+
assertTrue(true);
240+
return;
241+
}
242+
try {
243+
runTest();
244+
} catch (Throwable running) {
245+
exception = running;
246+
} finally {
247+
try {
248+
tearDown();
249+
} catch (Throwable tearingDown) {
250+
if (exception == null) exception = tearingDown;
251+
}
252+
}
253+
if (exception != null) throw exception;
254+
}
255+
223256
protected Mat getMat(int type, double... vals)
224257
{
225258
return new Mat(matSize, matSize, type, new Scalar(vals));
@@ -523,6 +556,10 @@ protected <T> T createClassInstance(String cname, String factoryName, Class cPar
523556
}
524557
}
525558
catch(Exception ex) {
559+
if (cname.startsWith(XFEATURES2D))
560+
{
561+
throw new TestSkipException();
562+
}
526563
message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage();
527564
}
528565

0 commit comments

Comments
 (0)