more strict checks and reseting state
authorIlya Lavrenov <ilya.lavrenov@itseez.com>
Sun, 2 Feb 2014 11:31:14 +0000 (15:31 +0400)
committerKonstantin Matskevich <konstantin.matskevich@itseez.com>
Mon, 3 Feb 2014 10:32:25 +0000 (14:32 +0400)
modules/core/test/test_umat.cpp

index 270de13..4c3f09a 100644 (file)
@@ -40,6 +40,7 @@
 //M*/
 
 #include "test_precomp.hpp"
+#include "opencv2/ts/ocl_test.hpp"
 
 #include <string>
 #include <iostream>
@@ -249,8 +250,13 @@ TEST(UMat, Sync)
     EXPECT_EQ(0, cv::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF));
 }
 
+#define EXPECT_MAT_NEAR(m1, m2) ASSERT_EQ(0, cv::norm(m1, m1, cv::NORM_INF))
+
 TEST(UMat, setOpenCL)
 {
+    // save the current state
+    bool useOCL = ocl::useOpenCL();
+
     Mat m = (Mat_<uchar>(3,3)<<0,1,2,3,4,5,6,7,8);
 
     ocl::setUseOpenCL(true);
@@ -264,12 +270,25 @@ TEST(UMat, setOpenCL)
     ocl::setUseOpenCL(true);
     countNonZero(um1);
     countNonZero(um2);
+
     um1.copyTo(um2);
+    EXPECT_MAT_NEAR(um1, um2);
+    EXPECT_MAT_NEAR(um1, m);
     um2.copyTo(um1);
+    EXPECT_MAT_NEAR(um1, m);
+    EXPECT_MAT_NEAR(um1, um2);
 
     ocl::setUseOpenCL(false);
     countNonZero(um1);
     countNonZero(um2);
+
     um1.copyTo(um2);
+    EXPECT_MAT_NEAR(um1, um2);
+    EXPECT_MAT_NEAR(um1, m);
     um2.copyTo(um1);
+    EXPECT_MAT_NEAR(um1, um2);
+    EXPECT_MAT_NEAR(um1, m);
+
+    // reset state to the previous one
+    ocl::setUseOpenCL(useOCL);
 }