more tests fixes
authorAndrey Pavlenko <andrey.pavlenko@itseez.com>
Fri, 11 Jan 2013 05:13:25 +0000 (09:13 +0400)
committerAndrey Pavlenko <andrey.pavlenko@itseez.com>
Fri, 11 Jan 2013 05:13:25 +0000 (09:13 +0400)
modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java
modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java
modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java
modules/java/java_test/src/org/opencv/test/OpenCVTestCase.java

index b24d858..59fcc27 100644 (file)
@@ -1,8 +1,10 @@
 package org.opencv.test;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
@@ -426,24 +428,19 @@ public class OpenCVTestCase extends TestCase {
     }
 
     protected static String readFile(String path) {
-        FileInputStream stream = null;
         try {
-            stream = new FileInputStream(new File(path));
-            FileChannel fc = stream.getChannel();
-            MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
-                    fc.size());
-            return Charset.defaultCharset().decode(bb).toString();
+        BufferedReader br = new BufferedReader(new FileReader(path));
+        String line;
+        StringBuffer result = new StringBuffer();
+        while ((line = br.readLine()) != null) {
+            result.append(line);
+            result.append("\n");
+        }
+        return result.toString();
         } catch (IOException e) {
             OpenCVTestRunner.Log("Failed to read file \"" + path
                     + "\". Exception is thrown: " + e);
             return null;
-        } finally {
-            if (stream != null)
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                    OpenCVTestRunner.Log("Exception is thrown: " + e);
-                }
         }
     }
 
index e9b65d1..4ccf098 100644 (file)
@@ -100,7 +100,9 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
         extractor.write(filename);
 
         String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.ORB</name>\n<WTA_K>2</WTA_K>\n<edgeThreshold>31</edgeThreshold>\n<firstLevel>0</firstLevel>\n<nFeatures>500</nFeatures>\n<nLevels>8</nLevels>\n<patchSize>31</patchSize>\n<scaleFactor>1.2000000476837158e+00</scaleFactor>\n<scoreType>0</scoreType>\n</opencv_storage>\n";
-        assertEquals(truth, readFile(filename));
+        String actual = readFile(filename);
+        actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
+        assertEquals(truth, actual);
     }
 
     public void testWriteYml() {
@@ -109,7 +111,9 @@ public class ORBDescriptorExtractorTest extends OpenCVTestCase {
         extractor.write(filename);
 
         String truth = "%YAML:1.0\nname: \"Feature2D.ORB\"\nWTA_K: 2\nedgeThreshold: 31\nfirstLevel: 0\nnFeatures: 500\nnLevels: 8\npatchSize: 31\nscaleFactor: 1.2000000476837158e+00\nscoreType: 0\n";
-        assertEquals(truth, readFile(filename));
+        String actual = readFile(filename);
+        actual = actual.replaceAll("e\\+000", "e+00"); // NOTE: workaround for different platforms double representation
+        assertEquals(truth, actual);
     }
 
 }
index 2fd83eb..8add9f4 100644 (file)
@@ -87,7 +87,9 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
         extractor.write(filename);
 
         String truth = "<?xml version=\"1.0\"?>\n<opencv_storage>\n<name>Feature2D.SIFT</name>\n<contrastThreshold>4.0000000000000001e-02</contrastThreshold>\n<edgeThreshold>10.</edgeThreshold>\n<nFeatures>0</nFeatures>\n<nOctaveLayers>3</nOctaveLayers>\n<sigma>1.6000000000000001e+00</sigma>\n</opencv_storage>\n";
-        assertEquals(truth, readFile(filename));
+        String actual = readFile(filename);
+        actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
+        assertEquals(truth, actual);
     }
 
     public void testWriteYml() {
@@ -96,7 +98,9 @@ public class SIFTDescriptorExtractorTest extends OpenCVTestCase {
         extractor.write(filename);
 
         String truth = "%YAML:1.0\nname: \"Feature2D.SIFT\"\ncontrastThreshold: 4.0000000000000001e-02\nedgeThreshold: 10.\nnFeatures: 0\nnOctaveLayers: 3\nsigma: 1.6000000000000001e+00\n";
-        assertEquals(truth, readFile(filename));
+        String actual = readFile(filename);
+        actual = actual.replaceAll("e([+-])0(\\d\\d)", "e$1$2"); // NOTE: workaround for different platforms double representation
+        assertEquals(truth, actual);
     }
 
 }
index 75e240d..15ff735 100644 (file)
@@ -2,9 +2,11 @@
 
 package org.opencv.test;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.IOException;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
@@ -94,31 +96,31 @@ public class OpenCVTestCase extends TestCase {
     protected void setUp() throws Exception {
         super.setUp();
 
-       try {
-           System.loadLibrary("opencv_java");  
-       } catch (SecurityException e) {
-           System.out.println(e.toString());
-           System.exit(-1);
-       } catch (UnsatisfiedLinkError e) {
-           System.out.println(e.toString());
-           System.exit(-1);
-       }       
-
-       String pwd;
-       try {
-           pwd = new File(".").getCanonicalPath() + File.separator;
-       } catch (IOException e) {
-           System.out.println(e);
-           return;
-       }
-
-       OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg";
-       OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg";
-       OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml";
-
-       assert(new File(OpenCVTestRunner.LENA_PATH).exists());
-       assert(new File(OpenCVTestRunner.CHESS_PATH).exists());
-       assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists());
+    try {
+        System.loadLibrary("opencv_java");
+    } catch (SecurityException e) {
+        System.out.println(e.toString());
+        System.exit(-1);
+    } catch (UnsatisfiedLinkError e) {
+        System.out.println(e.toString());
+        System.exit(-1);
+    }
+
+    String pwd;
+    try {
+        pwd = new File(".").getCanonicalPath() + File.separator;
+    } catch (IOException e) {
+        System.out.println(e);
+        return;
+    }
+
+    OpenCVTestRunner.LENA_PATH = pwd + "res/drawable/lena.jpg";
+    OpenCVTestRunner.CHESS_PATH = pwd + "res/drawable/chessboard.jpg";
+    OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH = pwd + "res/raw/lbpcascade_frontalface.xml";
+
+    assert(new File(OpenCVTestRunner.LENA_PATH).exists());
+    assert(new File(OpenCVTestRunner.CHESS_PATH).exists());
+    assert(new File(OpenCVTestRunner.LBPCASCADE_FRONTALFACE_PATH).exists());
 
         dst = new Mat();
         assertTrue(dst.empty());
@@ -452,24 +454,19 @@ public class OpenCVTestCase extends TestCase {
     }
 
     protected static String readFile(String path) {
-        FileInputStream stream = null;
         try {
-            stream = new FileInputStream(new File(path));
-            FileChannel fc = stream.getChannel();
-            MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
-                    fc.size());
-            return Charset.defaultCharset().decode(bb).toString();
+        BufferedReader br = new BufferedReader(new FileReader(path));
+        String line;
+        StringBuffer result = new StringBuffer();
+        while ((line = br.readLine()) != null) {
+            result.append(line);
+            result.append("\n");
+        }
+        return result.toString();
         } catch (IOException e) {
             OpenCVTestRunner.Log("Failed to read file \"" + path
                     + "\". Exception is thrown: " + e);
             return null;
-        } finally {
-            if (stream != null)
-                try {
-                    stream.close();
-                } catch (IOException e) {
-                    OpenCVTestRunner.Log("Exception is thrown: " + e);
-                }
         }
     }