1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #include "test_precomp.hpp"
44 namespace opencv_test { namespace {
46 class Core_ConcatenationTest : public cvtest::BaseTest
49 Core_ConcatenationTest(bool horizontal, bool firstEmpty, bool secondEmpty);
51 int prepare_test_case( int );
53 int validate_test_results( int );
70 static bool areEqual(const Mat& m1, const Mat& m2);
74 Core_ConcatenationTest::Core_ConcatenationTest(bool horizontal_, bool firstEmpty_, bool secondEmpty_)
75 : horizontal(horizontal_)
76 , firstEmpty(firstEmpty_)
77 , secondEmpty(secondEmpty_)
81 mat0x5 = Mat::ones(0,5, CV_8U);
82 mat10x5 = Mat::ones(10,5, CV_8U);
83 mat20x5 = Mat::ones(20,5, CV_8U);
85 mat5x0 = Mat::ones(5,0, CV_8U);
86 mat5x10 = Mat::ones(5,10, CV_8U);
87 mat5x20 = Mat::ones(5,20, CV_8U);
90 int Core_ConcatenationTest::prepare_test_case( int test_case_idx )
92 cvtest::BaseTest::prepare_test_case( test_case_idx );
96 void Core_ConcatenationTest::run_func()
100 cv::hconcat((firstEmpty ? mat5x0 : mat5x10),
101 (secondEmpty ? mat5x0 : mat5x10),
104 cv::vconcat((firstEmpty ? mat0x5 : mat10x5),
105 (secondEmpty ? mat0x5 : mat10x5),
110 int Core_ConcatenationTest::validate_test_results( int )
114 if (firstEmpty && secondEmpty)
115 expected = (horizontal ? mat5x0 : mat0x5);
116 else if ((firstEmpty && !secondEmpty) || (!firstEmpty && secondEmpty))
117 expected = (horizontal ? mat5x10 : mat10x5);
119 expected = (horizontal ? mat5x20 : mat20x5);
121 if (areEqual(expected, result))
123 return cvtest::TS::OK;
126 ts->printf( cvtest::TS::LOG, "Concatenation failed");
127 ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
130 return cvtest::TS::OK;
133 bool Core_ConcatenationTest::areEqual(const Mat &m1, const Mat &m2)
135 return m1.size() == m2.size()
136 && m1.type() == m2.type()
137 && countNonZero(m1 != m2) == 0;
140 TEST(Core_Concatenation, hconcat_empty_nonempty) { Core_ConcatenationTest test(true, true, false); test.safe_run(); }
141 TEST(Core_Concatenation, hconcat_nonempty_empty) { Core_ConcatenationTest test(true, false, true); test.safe_run(); }
142 TEST(Core_Concatenation, hconcat_empty_empty) { Core_ConcatenationTest test(true, true, true); test.safe_run(); }
144 TEST(Core_Concatenation, vconcat_empty_nonempty) { Core_ConcatenationTest test(false, true, false); test.safe_run(); }
145 TEST(Core_Concatenation, vconcat_nonempty_empty) { Core_ConcatenationTest test(false, false, true); test.safe_run(); }
146 TEST(Core_Concatenation, vconcat_empty_empty) { Core_ConcatenationTest test(false, true, true); test.safe_run(); }