java tests: now only OpenCVTestRunner contains android specific stuff
authorKirill Kornyakov <no@email>
Tue, 5 Jul 2011 14:03:28 +0000 (14:03 +0000)
committerKirill Kornyakov <no@email>
Tue, 5 Jul 2011 14:03:28 +0000 (14:03 +0000)
modules/java/android_test/AndroidManifest.xml
modules/java/android_test/src/org/opencv/test/MatTest.java
modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java
modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java [new file with mode: 0644]
modules/java/android_test/src/org/opencv/test/coreTest.java
modules/java/android_test/src/org/opencv/test/highguiTest.java
modules/java/android_test/src/org/opencv/test/utils.java [deleted file]

index a88053f..236cb47 100644 (file)
@@ -5,7 +5,8 @@
       android:versionName="1.0">
       
     <uses-sdk android:minSdkVersion="8" />
-    <instrumentation android:targetPackage="org.opencv.test" android:name="android.test.InstrumentationTestRunner" />
+    <instrumentation android:targetPackage="org.opencv.test" android:name="OpenCVTestRunner"></instrumentation>
+    
     <application android:icon="@drawable/icon" android:label="@string/app_name">
         <uses-library android:name="android.test.runner" />
     </application>
index 3f21525..72fe31b 100644 (file)
@@ -10,7 +10,7 @@ public class MatTest extends OpenCVTestCase {
 
        public void testChannels() {
                //fail("Not yet implemented");
-               utils.Log(grayRnd.dump());
+               //utils.Log(grayRnd.dump());
        }
 
        public void testClone() {
index 6aa7402..c45dbdd 100644 (file)
@@ -8,9 +8,7 @@ import org.opencv.highgui;
 
 
 public class OpenCVTestCase extends TestCase {
-    
-    static String LENA = "/data/data/org.opencv.test/files/lena.jpg";
-    
+       
     static int matSize = 10;
     
     static Mat dst;
@@ -72,11 +70,11 @@ public class OpenCVTestCase extends TestCase {
         
         gray0_64f = new Mat(matSize, matSize, Mat.CvType.CV_64FC1); gray0_64f.setTo(0.0);
         gray0_64f_1d = new Mat(1, matSize, Mat.CvType.CV_64FC1); gray0_64f_1d.setTo(0.0);
-        
-        rgbLena = highgui.imread(LENA);
-        
+               
         rgba0 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba0.setTo(0, 0, 0, 0);
         rgba128 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba128.setTo(128, 128, 128, 128);
+        
+        rgbLena = highgui.imread(OpenCVTestRunner.LENA_PATH);
     }
 
     public static void assertMatEqual(Mat m1, Mat m2) {
@@ -93,10 +91,8 @@ public class OpenCVTestCase extends TestCase {
     }
 
     public void test_1(String label) {
-        utils.Log("================================================");
-        utils.Log("=============== " + label);
-        utils.Log("================================================");
-        
-        new utils().ExportLena();
+       OpenCVTestRunner.Log("================================================");
+       OpenCVTestRunner.Log("=============== " + label);
+       OpenCVTestRunner.Log("================================================");
     }
 }
diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java
new file mode 100644 (file)
index 0000000..c03c16e
--- /dev/null
@@ -0,0 +1,59 @@
+package org.opencv.test;
+
+import java.io.FileOutputStream;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Bitmap.CompressFormat;
+import android.graphics.BitmapFactory;
+import android.test.AndroidTestRunner;
+import android.test.InstrumentationTestRunner;
+import android.util.Log;
+
+/**  
+ * This only class is Android specific.
+ * The original idea about test order randomization is from marek.defecinski blog.
+ */  
+
+public class OpenCVTestRunner extends InstrumentationTestRunner {
+       
+    public static String LENA_PATH = "/data/data/org.opencv.test/files/lena.jpg";
+       
+       private AndroidTestRunner androidTestRunner;    
+       private static String TAG = "opencv_test_java";
+       
+       static public void Log(String message) {
+               Log.e(TAG, message);
+       }
+       
+    @Override  
+    public void onStart() {
+       ExportLena();
+               
+        List<TestCase> testCases = androidTestRunner.getTestCases();
+        Collections.shuffle(testCases); //shuffle the tests order
+        super.onStart();
+    }
+    
+    @Override  
+    protected AndroidTestRunner getAndroidTestRunner() {  
+         androidTestRunner = super.getAndroidTestRunner();  
+         return androidTestRunner;  
+    }
+    
+       private void ExportLena() {
+               try {
+                       Bitmap mBitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.lena);
+                       FileOutputStream fos = this.getContext().openFileOutput("lena.jpg", Context.MODE_WORLD_READABLE);
+                       mBitmap.compress(CompressFormat.JPEG, 100, fos);
+                       fos.flush();
+                       fos.close();
+               }
+               catch (Exception e) {
+                       Log("Tried to write lena.jpg, but: " + e.toString());
+               }
+       }
+}
index 89aad46..7566b10 100644 (file)
@@ -35,8 +35,9 @@ public class coreTest extends OpenCVTestCase {
        }
 
        public void testAddWeightedMatDoubleMatDoubleDoubleMatInt() {
-               core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, gray255_32f.depth());
-               assertTrue(core.CV_32F == dst.depth());
+               fail("Not yet implemented");
+               //core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, gray255_32f.depth());
+               //assertTrue(core.CV_32F == dst.depth());
        }
 
        public void testBitwise_andMatMatMat() {
index d6a9b2d..d1f0700 100644 (file)
@@ -31,7 +31,7 @@ public class highguiTest extends OpenCVTestCase {
        }
        
        public void testImreadString() {                
-               dst = highgui.imread(LENA);
+               dst = highgui.imread(OpenCVTestRunner.LENA_PATH);
                assertTrue(!dst.empty());
                assertEquals(3, dst.channels());
                assertTrue(512 == dst.cols());
@@ -39,7 +39,7 @@ public class highguiTest extends OpenCVTestCase {
        }
 
        public void testImreadStringInt() {
-               dst = highgui.imread(LENA, 0);
+               dst = highgui.imread(OpenCVTestRunner.LENA_PATH, 0);
                assertTrue(!dst.empty());
                assertEquals(1, dst.channels());
                assertTrue(512 == dst.cols());
diff --git a/modules/java/android_test/src/org/opencv/test/utils.java b/modules/java/android_test/src/org/opencv/test/utils.java
deleted file mode 100644 (file)
index 1de9541..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.opencv.test;
-
-import java.io.FileOutputStream;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Bitmap.CompressFormat;
-import android.test.AndroidTestCase;
-
-import android.util.Log;
-
-public class utils extends AndroidTestCase {
-       
-       static String TAG = "opencv_test_java";
-       
-       static public void Log(String message) {
-               Log.e(TAG, message);
-       }
-       
-       public void ExportLena() {
-        //TODO: can we run this code just once, not for every test case?
-               try {
-            Bitmap mBitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.lena);
-            FileOutputStream fos = this.getContext().openFileOutput("lena.jpg", Context.MODE_WORLD_READABLE);
-            mBitmap.compress(CompressFormat.JPEG, 100, fos);
-            fos.flush();
-            fos.close();
-               }
-               catch (Exception e) {
-                  Log.e(TAG, "Tried to write lena.jpg, but: " + e.toString());
-               }
-       }       
-
-}