From fe29080d59cb86d4dd06b2aa6b0b44e969130cdd Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 22 Nov 2016 19:49:55 +0300 Subject: [PATCH] java: skip test in case of missed classes from opencv_contrib --- .../src/org/opencv/test/OpenCVTestCase.java | 39 +++++++++++++++++++++- modules/java/pure_test/build.xml | 2 +- .../src/org/opencv/test/OpenCVTestCase.java | 39 +++++++++++++++++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 54bb79e..70d0744 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -29,6 +29,11 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; public class OpenCVTestCase extends TestCase { + + public static class TestSkipException extends RuntimeException { + public TestSkipException() {} + } + //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; @@ -188,12 +193,40 @@ public class OpenCVTestCase extends TestCase { protected void runTest() throws Throwable { // Do nothing if the precondition does not hold. if (isTestCaseEnabled) { - super.runTest(); + try { + super.runTest(); + } catch (TestSkipException ex) { + Log.w(TAG, "Test case \"" + this.getClass().getName() + "\" skipped!"); + assertTrue(true); + } } else { 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) { return new Mat(matSize, matSize, type, new Scalar(vals)); @@ -497,6 +530,10 @@ public class OpenCVTestCase extends TestCase { } } catch(Exception ex) { + if (cname.startsWith(XFEATURES2D)) + { + throw new TestSkipException(); + } message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage(); } diff --git a/modules/java/pure_test/build.xml b/modules/java/pure_test/build.xml index 4b25a3c..dac4d4b 100644 --- a/modules/java/pure_test/build.xml +++ b/modules/java/pure_test/build.xml @@ -37,7 +37,7 @@ - + diff --git a/modules/java/pure_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/pure_test/src/org/opencv/test/OpenCVTestCase.java index 98b1448..400338d 100644 --- a/modules/java/pure_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/pure_test/src/org/opencv/test/OpenCVTestCase.java @@ -27,6 +27,11 @@ import org.opencv.core.KeyPoint; import org.opencv.imgcodecs.Imgcodecs; public class OpenCVTestCase extends TestCase { + + public static class TestSkipException extends RuntimeException { + public TestSkipException() {} + } + //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; @@ -214,12 +219,40 @@ public class OpenCVTestCase extends TestCase { protected void runTest() throws Throwable { // Do nothing if the precondition does not hold. if (isTestCaseEnabled) { - super.runTest(); + try { + super.runTest(); + } catch (TestSkipException ex) { + OpenCVTestRunner.Log(TAG + " :: " + "Test case \"" + this.getClass().getName() + "\" skipped!"); + assertTrue(true); + } } else { 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) { return new Mat(matSize, matSize, type, new Scalar(vals)); @@ -523,6 +556,10 @@ public class OpenCVTestCase extends TestCase { } } catch(Exception ex) { + if (cname.startsWith(XFEATURES2D)) + { + throw new TestSkipException(); + } message = TAG + " :: " + "could not instantiate " + cname + "! Exception: " + ex.getMessage(); } -- 2.7.4