5 #define __OPENCV_TESTS 1
8 #include "opencv2/opencv_modules.hpp"
10 #include "opencv2/core.hpp"
11 #include "opencv2/imgproc.hpp"
12 #include "opencv2/imgcodecs.hpp"
13 #include "opencv2/videoio.hpp"
14 #include "opencv2/highgui.hpp"
16 #include "opencv2/core/utility.hpp"
18 #include "opencv2/core/utils/trace.hpp"
20 #include "opencv2/core/hal/hal.hpp"
22 #include <stdarg.h> // for va_list
42 #ifndef OPENCV_32BIT_CONFIGURATION
43 # if defined(INTPTR_MAX) && defined(INT32_MAX) && INTPTR_MAX == INT32_MAX
44 # define OPENCV_32BIT_CONFIGURATION 1
45 # elif defined(_WIN32) && !defined(_WIN64)
46 # define OPENCV_32BIT_CONFIGURATION 1
49 # if OPENCV_32BIT_CONFIGURATION == 0
50 # undef OPENCV_32BIT_CONFIGURATION
56 // most part of OpenCV tests are fit into 200Mb limit, but some tests are not:
57 // Note: due memory fragmentation real limits are usually lower on 20-25% (400Mb memory usage goes into mem_1Gb class)
58 #define CV_TEST_TAG_MEMORY_512MB "mem_512mb" // used memory: 200..512Mb - enabled by default
59 #define CV_TEST_TAG_MEMORY_1GB "mem_1gb" // used memory: 512Mb..1Gb - enabled by default
60 #define CV_TEST_TAG_MEMORY_2GB "mem_2gb" // used memory: 1..2Gb - enabled by default on 64-bit configuration (32-bit - disabled)
61 #define CV_TEST_TAG_MEMORY_6GB "mem_6gb" // used memory: 2..6Gb - disabled by default
62 #define CV_TEST_TAG_MEMORY_14GB "mem_14gb" // used memory: 6..14Gb - disabled by default
64 // Large / huge video streams or complex workloads
65 #define CV_TEST_TAG_LONG "long" // 5+ seconds on modern desktop machine (single thread)
66 #define CV_TEST_TAG_VERYLONG "verylong" // 20+ seconds on modern desktop machine (single thread)
68 // Large / huge video streams or complex workloads for debug builds
69 #define CV_TEST_TAG_DEBUG_LONG "debug_long" // 10+ seconds on modern desktop machine (single thread)
70 #define CV_TEST_TAG_DEBUG_VERYLONG "debug_verylong" // 40+ seconds on modern desktop machine (single thread)
72 // Lets skip processing of high resolution images via instrumentation tools (valgrind/coverage/sanitizers).
73 // It is enough to run lower resolution (VGA: 640x480) tests.
74 #define CV_TEST_TAG_SIZE_HD "size_hd" // 720p+, enabled
75 #define CV_TEST_TAG_SIZE_FULLHD "size_fullhd" // 1080p+, enabled (disable these tests for valgrind/coverage run)
76 #define CV_TEST_TAG_SIZE_4K "size_4k" // 2160p+, enabled (disable these tests for valgrind/coverage run)
78 // Other misc test tags
79 #define CV_TEST_TAG_TYPE_64F "type_64f" // CV_64F, enabled (disable these tests on low power embedded devices)
81 // Kernel-based image processing
82 #define CV_TEST_TAG_FILTER_SMALL "filter_small" // Filtering with kernels <= 3x3
83 #define CV_TEST_TAG_FILTER_MEDIUM "filter_medium" // Filtering with kernels: 3x3 < kernel <= 5x5
84 #define CV_TEST_TAG_FILTER_LARGE "filter_large" // Filtering with kernels: 5x5 < kernel <= 9x9
85 #define CV_TEST_TAG_FILTER_HUGE "filter_huge" // Filtering with kernels: > 9x9
87 // Other tests categories
88 #define CV_TEST_TAG_OPENCL "opencl" // Tests with OpenCL
93 #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
97 #pragma warning( disable: 4503 ) // decorated name length exceeded, name was truncated
100 #define GTEST_DONT_DEFINE_FAIL 0
101 #define GTEST_DONT_DEFINE_SUCCEED 0
102 #define GTEST_DONT_DEFINE_ASSERT_EQ 0
103 #define GTEST_DONT_DEFINE_ASSERT_NE 0
104 #define GTEST_DONT_DEFINE_ASSERT_LE 0
105 #define GTEST_DONT_DEFINE_ASSERT_LT 0
106 #define GTEST_DONT_DEFINE_ASSERT_GE 0
107 #define GTEST_DONT_DEFINE_ASSERT_GT 0
108 #define GTEST_DONT_DEFINE_TEST 0
110 #ifndef GTEST_LANG_CXX11
111 #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && !(_MSVC_LANG < 201103))
112 # define GTEST_LANG_CXX11 1
113 # define GTEST_HAS_TR1_TUPLE 0
114 # define GTEST_HAS_COMBINE 1
118 #if defined(__OPENCV_BUILD) && defined(__clang__)
119 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
121 #if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
122 //#pragma GCC diagnostic push
123 #pragma GCC diagnostic ignored "-Wsuggest-override"
125 #include "opencv2/ts/ts_gtest.h"
126 #if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
127 //#pragma GCC diagnostic pop
129 #include "opencv2/ts/ts_ext.hpp"
131 #ifndef GTEST_USES_SIMPLE_RE
132 # define GTEST_USES_SIMPLE_RE 0
134 #ifndef GTEST_USES_POSIX_RE
135 # define GTEST_USES_POSIX_RE 0
138 #define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< testing::tuple< __VA_ARGS__ > >
139 #define GET_PARAM(k) testing::get< k >(GetParam())
147 using std::stringstream;
153 using std::numeric_limits;
155 using std::make_pair;
156 using testing::TestWithParam;
157 using testing::Values;
158 using testing::ValuesIn;
159 using testing::Combine;
164 using cv::InputArray;
165 using cv::OutputArray;
175 // Tuple stuff from Google Tests
177 using testing::make_tuple;
178 using testing::tuple;
179 using testing::tuple_size;
180 using testing::tuple_element;
183 class SkipTestException: public cv::Exception
186 int dummy; // workaround for MacOSX Xcode 7.3 bug (don't make class "empty")
187 SkipTestException() : dummy(0) {}
188 SkipTestException(const cv::String& message) : dummy(0) { this->msg = message; }
191 /** Apply tag to the current test
193 Automatically apply corresponding additional tags (for example, 4K => FHD => HD => VGA).
195 If tag is in skip list, then SkipTestException is thrown
197 void applyTestTag(const std::string& tag);
199 /** Run postponed checks of applied test tags
201 If tag is in skip list, then SkipTestException is thrown
203 void checkTestTags();
205 void applyTestTag_(const std::string& tag);
207 static inline void applyTestTag(const std::string& tag1, const std::string& tag2)
208 { applyTestTag_(tag1); applyTestTag_(tag2); checkTestTags(); }
209 static inline void applyTestTag(const std::string& tag1, const std::string& tag2, const std::string& tag3)
210 { applyTestTag_(tag1); applyTestTag_(tag2); applyTestTag_(tag3); checkTestTags(); }
211 static inline void applyTestTag(const std::string& tag1, const std::string& tag2, const std::string& tag3, const std::string& tag4)
212 { applyTestTag_(tag1); applyTestTag_(tag2); applyTestTag_(tag3); applyTestTag_(tag4); checkTestTags(); }
217 int64 readSeed(const char* str);
219 void randUni( RNG& rng, Mat& a, const Scalar& param1, const Scalar& param2 );
221 inline unsigned randInt( RNG& rng )
223 return (unsigned)rng;
226 inline double randReal( RNG& rng )
232 const char* getTypeName( int type );
233 int typeByName( const char* type_name );
235 string vec2str(const string& sep, const int* v, size_t nelems);
237 inline int clipInt( int val, int min_val, int max_val )
246 double getMinVal(int depth);
247 double getMaxVal(int depth);
249 Size randomSize(RNG& rng, double maxSizeLog);
250 void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz);
251 int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels);
252 Mat randomMat(RNG& rng, Size size, int type, double minVal, double maxVal, bool useRoi);
253 Mat randomMat(RNG& rng, const vector<int>& size, int type, double minVal, double maxVal, bool useRoi);
254 void add(const Mat& a, double alpha, const Mat& b, double beta,
255 Scalar gamma, Mat& c, int ctype, bool calcAbs=false);
256 void multiply(const Mat& a, const Mat& b, Mat& c, double alpha=1);
257 void divide(const Mat& a, const Mat& b, Mat& c, double alpha=1);
259 void convert(const Mat& src, cv::OutputArray dst, int dtype, double alpha=1, double beta=0);
260 void copy(const Mat& src, Mat& dst, const Mat& mask=Mat(), bool invertMask=false);
261 void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat());
263 // working with multi-channel arrays
264 void extract( const Mat& a, Mat& plane, int coi );
265 void insert( const Mat& plane, Mat& a, int coi );
267 // checks that the array does not have NaNs and/or Infs and all the elements are
268 // within [min_val,max_val). idx is the index of the first "bad" element.
269 int check( const Mat& data, double min_val, double max_val, vector<int>* idx );
271 // modifies values that are close to zero
272 void patchZeros( Mat& mat, double level );
274 void transpose(const Mat& src, Mat& dst);
275 void erode(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
276 int borderType=0, const Scalar& borderValue=Scalar());
277 void dilate(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
278 int borderType=0, const Scalar& borderValue=Scalar());
279 void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel,
280 Point anchor, double delta, int borderType,
281 const Scalar& borderValue=Scalar());
282 void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right,
283 int borderType, const Scalar& borderValue=Scalar());
284 Mat calcSobelKernel2D( int dx, int dy, int apertureSize, int origin=0 );
285 Mat calcLaplaceKernel2D( int aperture_size );
287 void initUndistortMap( const Mat& a, const Mat& k, Size sz, Mat& mapx, Mat& mapy );
289 void minMaxLoc(const Mat& src, double* minval, double* maxval,
290 vector<int>* minloc, vector<int>* maxloc, const Mat& mask=Mat());
291 double norm(InputArray src, int normType, InputArray mask=noArray());
292 double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray());
293 Scalar mean(const Mat& src, const Mat& mask=Mat());
294 double PSNR(InputArray src1, InputArray src2);
296 bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector<int>* idx);
298 // compares two arrays. max_diff is the maximum actual difference,
299 // success_err_level is maximum allowed difference, idx is the index of the first
300 // element for which difference is >success_err_level
301 // (or index of element with the maximum difference)
302 int cmpEps( const Mat& data, const Mat& refdata, double* max_diff,
303 double success_err_level, vector<int>* idx,
304 bool element_wise_relative_error );
306 // a wrapper for the previous function. in case of error prints the message to log file.
307 int cmpEps2( TS* ts, const Mat& data, const Mat& refdata, double success_err_level,
308 bool element_wise_relative_error, const char* desc );
310 int cmpEps2_64f( TS* ts, const double* val, const double* refval, int len,
311 double eps, const char* param_name );
313 void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c);
314 void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c);
315 void min(const Mat& src1, const Mat& src2, Mat& dst);
316 void min(const Mat& src, double s, Mat& dst);
317 void max(const Mat& src1, const Mat& src2, Mat& dst);
318 void max(const Mat& src, double s, Mat& dst);
320 void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop);
321 void compare(const Mat& src, double s, Mat& dst, int cmpop);
322 void gemm(const Mat& src1, const Mat& src2, double alpha,
323 const Mat& src3, double beta, Mat& dst, int flags);
324 void transform( const Mat& src, Mat& dst, const Mat& transmat, const Mat& shift );
325 double crossCorr(const Mat& src1, const Mat& src2);
326 void threshold( const Mat& src, Mat& dst, double thresh, double maxval, int thresh_type );
327 void minMaxIdx( InputArray _img, double* minVal, double* maxVal,
328 Point* minLoc, Point* maxLoc, InputArray _mask );
332 MatInfo(const Mat& _m) : m(&_m) {}
336 std::ostream& operator << (std::ostream& out, const MatInfo& m);
341 MatComparator(double maxdiff, int context);
343 ::testing::AssertionResult operator()(const char* expr1, const char* expr2,
344 const Mat& m1, const Mat& m2);
360 // constructor(s) and destructor
364 // the main procedure of the test
365 virtual void run( int start_from );
367 // the wrapper for run that cares of exceptions
368 virtual void safe_run( int start_from=0 );
370 const string& get_name() const { return name; }
372 // returns true if and only if the different test cases do not depend on each other
373 // (so that test system could get right to a problematic test case)
374 virtual bool can_do_fast_forward();
376 // deallocates all the memory.
377 // called by init() (before initialization) and by the destructor
378 virtual void clear();
381 int test_case_count; // the total number of test cases
384 virtual int read_params( CvFileStorage* fs );
386 // returns the number of tests or -1 if it is unknown a-priori
387 virtual int get_test_case_count();
389 // prepares data for the next test case. rng seed is updated by the function
390 virtual int prepare_test_case( int test_case_idx );
392 // checks if the test output is valid and accurate
393 virtual int validate_test_results( int test_case_idx );
395 // calls the tested function. the method is called from run_test_case()
396 virtual void run_func(); // runs tested func(s)
398 // updates progress bar
399 virtual int update_progress( int progress, int test_case_idx, int count, double dt );
401 // finds test parameter
402 const CvFileNode* find_param( CvFileStorage* fs, const char* param_name );
404 // name of the test (it is possible to locate a test by its name)
407 // pointer to the system that includes the test
412 /*****************************************************************************************\
413 * Information about a failed test *
414 \*****************************************************************************************/
420 // pointer to the test
423 // failure code (TS::FAIL_*)
426 // seed value right before the data for the failed test case is prepared.
429 // seed value right before running the test
432 // index of test case, can be then passed to BaseTest::proceed_to_test_case()
436 /*****************************************************************************************\
437 * Base Class for test system *
438 \*****************************************************************************************/
440 // common parameters:
445 // RNG seed, passed to and updated by every test executed.
448 // whether to use IPP, MKL etc. or not
451 // extensivity of the tests, scale factor for test_case_count
452 double test_case_count_scale;
466 SUMMARY=1 << SUMMARY_IDX,
472 CONSOLE=1 << CONSOLE_IDX,
478 // initialize test system before running the first test
479 virtual void init( const string& modulename );
481 // low-level printing functions that are used by individual tests and by the system itself
482 virtual void printf( int streams, const char* fmt, ... );
483 virtual void vprintf( int streams, const char* fmt, va_list arglist );
485 // updates the context: current test, test case, rng state
486 virtual void update_context( BaseTest* test, int test_case_idx, bool update_ts_context );
488 const TestInfo* get_current_test_info() { return ¤t_test_info; }
490 // sets information about a failed test
491 virtual void set_failed_test_info( int fail_code );
493 virtual void set_gtest_status();
501 // generic error: stub value to be used
502 // temporarily if the error's cause is unknown
505 // the test is missing some essential data to proceed further
506 FAIL_MISSING_TEST_DATA=-2,
508 // the tested function raised an error via cxcore error handler
509 FAIL_ERROR_IN_CALLED_FUNC=-3,
511 // an exception has been raised;
512 // for memory and arithmetic exception
513 // there are two specialized codes (see below...)
516 // a memory exception
517 // (access violation, access to missed page, stack overflow etc.)
518 FAIL_MEMORY_EXCEPTION=-5,
520 // arithmetic exception (overflow, division by zero etc.)
521 FAIL_ARITHM_EXCEPTION=-6,
523 // the tested function corrupted memory (no exception have been raised)
524 FAIL_MEMORY_CORRUPTION_BEGIN=-7,
525 FAIL_MEMORY_CORRUPTION_END=-8,
527 // the tested function (or test itself) do not deallocate some memory
530 // the tested function returned invalid object, e.g. matrix, containing NaNs,
531 // structure with NULL or out-of-range fields (while it should not)
532 FAIL_INVALID_OUTPUT=-10,
534 // the tested function returned valid object, but it does not match
535 // the original (or produced by the test) object
538 // the tested function returned valid object (a single number or numerical array),
539 // but it differs too much from the original (or produced by the test) object
540 FAIL_BAD_ACCURACY=-12,
542 // the tested function hung. Sometimes, it can be determined by unexpectedly long
543 // processing time (in this case there should be possibility to interrupt such a function
546 // unexpected response on passing bad arguments to the tested function
547 // (the function crashed, proceed successfully (while it should not), or returned
548 // error code that is different from what is expected)
549 FAIL_BAD_ARG_CHECK=-14,
551 // the test data (in whole or for the particular test case) is invalid
552 FAIL_INVALID_TEST_DATA=-15,
554 // the test has been skipped because it is not in the selected subset of the tests to run,
555 // because it has been run already within the same run with the same parameters, or because
556 // of some other reason and this is not considered as an error.
557 // Normally TS::run() (or overridden method in the derived class) takes care of what
558 // needs to be run, so this code should not occur.
562 // get RNG to generate random input data for a test
563 RNG& get_rng() { return rng; }
565 // returns the current error code
566 TS::FailureCode get_err_code() { return TS::FailureCode(current_test_info.code); }
568 // returns the test extensivity scale
569 double get_test_case_count_scale() { return params.test_case_count_scale; }
571 const string& get_data_path() const { return data_path; }
573 // returns textual description of failure code
574 static string str_from_code( const TS::FailureCode code );
576 std::vector<std::string> data_search_path;
577 std::vector<std::string> data_search_subdir;
580 // these are allocated within a test to try to keep them valid in case of stack corruption
583 // information about the current test
584 TestInfo current_test_info;
586 // the path to data files used by tests
590 std::string output_buf[MAX_IDX];
594 /*****************************************************************************************\
595 * Subclass of BaseTest for testing functions that process dense arrays *
596 \*****************************************************************************************/
598 class ArrayTest : public BaseTest
601 // constructor(s) and destructor
603 virtual ~ArrayTest();
605 virtual void clear() CV_OVERRIDE;
609 virtual int read_params( CvFileStorage* fs ) CV_OVERRIDE;
610 virtual int prepare_test_case( int test_case_idx ) CV_OVERRIDE;
611 virtual int validate_test_results( int test_case_idx ) CV_OVERRIDE;
613 virtual void prepare_to_validation( int test_case_idx );
614 virtual void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
615 virtual void fill_array( int test_case_idx, int i, int j, Mat& arr );
616 virtual void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
617 virtual double get_success_error_level( int test_case_idx, int i, int j );
620 bool iplimage_allowed;
622 bool element_wise_relative_error;
624 int min_log_array_size;
625 int max_log_array_size;
627 enum { INPUT, INPUT_OUTPUT, OUTPUT, REF_INPUT_OUTPUT, REF_OUTPUT, TEMP, MASK, MAX_ARR };
629 vector<vector<void*> > test_array;
630 vector<vector<Mat> > test_mat;
635 class BadArgTest : public BaseTest
638 // constructor(s) and destructor
640 virtual ~BadArgTest();
643 virtual int run_test_case( int expected_code, const string& descr );
644 virtual void run_func(void) CV_OVERRIDE = 0;
648 int run_test_case( int expected_code, const string& _descr, F f)
652 const char* descr = _descr.c_str() ? _descr.c_str() : "";
658 catch(const cv::Exception& e)
661 if( e.code != expected_code )
663 ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
664 descr, test_case_idx, e.code, expected_code);
671 ts->printf(TS::LOG, "%s (test case #%d): unknown exception was thrown (the function has likely crashed)\n",
672 descr, test_case_idx);
677 ts->printf(TS::LOG, "%s (test case #%d): no expected exception was thrown\n",
678 descr, test_case_idx);
687 extern uint64 param_seed;
689 struct DefaultRngAuto
691 const uint64 old_state;
693 DefaultRngAuto() : old_state(cv::theRNG().state) { cv::theRNG().state = cvtest::param_seed; }
694 ~DefaultRngAuto() { cv::theRNG().state = old_state; }
696 DefaultRngAuto& operator=(const DefaultRngAuto&);
700 // test images generation functions
701 void fillGradient(Mat& img, int delta = 5);
702 void smoothBorder(Mat& img, const Scalar& color, int delta = 3);
706 void addDataSearchPath(const std::string& path);
707 void addDataSearchSubDirectory(const std::string& subdir);
709 /*! @brief Try to find requested data file
713 0. TS::data_search_path (search sub-directories are not used)
714 1. OPENCV_TEST_DATA_PATH environment variable
716 a. OpenCV testdata based on build location: "./" + "share/OpenCV/testdata"
717 b. OpenCV testdata at install location: CMAKE_INSTALL_PREFIX + "share/OpenCV/testdata"
719 Search sub-directories:
721 - addDataSearchSubDirectory()
722 - modulename from TS::init()
725 std::string findDataFile(const std::string& relative_path, bool required = true);
727 /*! @brief Try to find requested data directory
730 std::string findDataDirectory(const std::string& relative_path, bool required = true);
734 class SystemInfoCollector : public testing::EmptyTestEventListener
737 virtual void OnTestProgramStart(const testing::UnitTest&);
740 #ifndef __CV_TEST_EXEC_ARGS
741 #if defined(_MSC_VER) && (_MSC_VER <= 1400)
742 #define __CV_TEST_EXEC_ARGS(...) \
743 while (++argc >= (--argc,-1)) {__VA_ARGS__; break;} /*this ugly construction is needed for VS 2005*/
745 #define __CV_TEST_EXEC_ARGS(...) \
750 void parseCustomOptions(int argc, char **argv);
752 #define CV_TEST_INIT0_NOOP (void)0
754 #define CV_TEST_MAIN(resourcesubdir, ...) CV_TEST_MAIN_EX(resourcesubdir, NOOP, __VA_ARGS__)
756 #define CV_TEST_MAIN_EX(resourcesubdir, INIT0, ...) \
757 int main(int argc, char **argv) \
759 CV_TRACE_FUNCTION(); \
760 { CV_TRACE_REGION("INIT"); \
761 using namespace cvtest; \
762 TS* ts = TS::ptr(); \
763 ts->init(resourcesubdir); \
764 __CV_TEST_EXEC_ARGS(CV_TEST_INIT0_ ## INIT0) \
765 ::testing::InitGoogleTest(&argc, argv); \
766 ::testing::UnitTest::GetInstance()->listeners().Append(new SystemInfoCollector); \
767 __CV_TEST_EXEC_ARGS(__VA_ARGS__) \
768 parseCustomOptions(argc, argv); \
770 return RUN_ALL_TESTS(); \
773 // This usually only makes sense in perf tests with several implementations,
774 // some of which are not available.
775 #define CV_TEST_FAIL_NO_IMPL() do { \
776 ::testing::Test::RecordProperty("custom_status", "noimpl"); \
777 FAIL() << "No equivalent implementation."; \
782 #include "opencv2/ts/ts_perf.hpp"
785 using perf::MatDepth;
790 #ifndef __FSTREAM_EMULATED__
791 #define __FSTREAM_EMULATED__
798 #define ifstream ifstream_emulated
799 #define ofstream ofstream_emulated
803 class ifstream : public stringstream
807 ifstream(const char* filename, ios_base::openmode mode = ios_base::in)
811 printf("Open file (read): %s\n", filename);
812 if (mode & ios_base::binary)
814 f = fopen(filename, modeStr.c_str());
818 printf("Can't open file: %s\n", filename);
821 fseek(f, 0, SEEK_END);
822 size_t sz = ftell(f);
825 char* buf = (char*) malloc(sz);
826 fseek(f, 0, SEEK_SET);
827 if (fread(buf, 1, sz, f) == sz)
829 this->str(std::string(buf, sz));
835 ~ifstream() { close(); }
836 bool is_open() const { return f != NULL; }
846 class ofstream : public stringstream
850 ofstream(const char* filename, ios_base::openmode mode = ios_base::out)
853 open(filename, mode);
855 ~ofstream() { close(); }
856 void open(const char* filename, ios_base::openmode mode = ios_base::out)
858 string modeStr("w+");
859 if (mode & ios_base::trunc)
861 if (mode & ios_base::binary)
863 f = fopen(filename, modeStr.c_str());
864 printf("Open file (write): %s\n", filename);
867 printf("Can't open file (write): %s\n", filename);
871 bool is_open() const { return f != NULL; }
876 fwrite(reinterpret_cast<const char *>(this->str().c_str()), this->str().size(), 1, f);
885 #endif // __FSTREAM_EMULATED__
889 namespace opencv_test {
890 using namespace cvtest;
894 #define CVTEST_GUARD_SYMBOL(name) \
895 class required_namespace_specificatin_here_for_symbol_ ## name {}; \
896 using name = required_namespace_specificatin_here_for_symbol_ ## name;
898 #define CVTEST_GUARD_SYMBOL(name) /* nothing */
901 CVTEST_GUARD_SYMBOL(norm)
902 CVTEST_GUARD_SYMBOL(add)
903 CVTEST_GUARD_SYMBOL(multiply)
904 CVTEST_GUARD_SYMBOL(divide)
905 CVTEST_GUARD_SYMBOL(transpose)
906 CVTEST_GUARD_SYMBOL(copyMakeBorder)
907 CVTEST_GUARD_SYMBOL(filter2D)
908 CVTEST_GUARD_SYMBOL(compare)
909 CVTEST_GUARD_SYMBOL(minMaxIdx)
910 CVTEST_GUARD_SYMBOL(threshold)
912 extern bool required_opencv_test_namespace; // compilation check for non-refactored tests
915 #endif // OPENCV_TS_HPP