Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/ts/include/opencv2/ts.hpp
16337 views
1
#ifndef OPENCV_TS_HPP
2
#define OPENCV_TS_HPP
3
4
#ifndef __OPENCV_TESTS
5
#define __OPENCV_TESTS 1
6
#endif
7
8
#include "opencv2/opencv_modules.hpp"
9
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"
15
16
#include "opencv2/core/utility.hpp"
17
18
#include "opencv2/core/utils/trace.hpp"
19
20
#include <stdarg.h> // for va_list
21
22
#include "cvconfig.h"
23
24
#include <cmath>
25
#include <vector>
26
#include <list>
27
#include <map>
28
#include <queue>
29
#include <string>
30
#include <iostream>
31
#include <fstream>
32
#include <iomanip>
33
#include <sstream>
34
#include <cstdio>
35
#include <iterator>
36
#include <limits>
37
#include <algorithm>
38
39
40
#ifndef OPENCV_32BIT_CONFIGURATION
41
# if defined(INTPTR_MAX) && defined(INT32_MAX) && INTPTR_MAX == INT32_MAX
42
# define OPENCV_32BIT_CONFIGURATION 1
43
# elif defined(_WIN32) && !defined(_WIN64)
44
# define OPENCV_32BIT_CONFIGURATION 1
45
# endif
46
#else
47
# if OPENCV_32BIT_CONFIGURATION == 0
48
# undef OPENCV_32BIT_CONFIGURATION
49
# endif
50
#endif
51
52
#ifdef WINRT
53
#pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
54
#endif
55
56
#ifdef _MSC_VER
57
#pragma warning( disable: 4503 ) // decorated name length exceeded, name was truncated
58
#endif
59
60
#define GTEST_DONT_DEFINE_FAIL 0
61
#define GTEST_DONT_DEFINE_SUCCEED 0
62
#define GTEST_DONT_DEFINE_ASSERT_EQ 0
63
#define GTEST_DONT_DEFINE_ASSERT_NE 0
64
#define GTEST_DONT_DEFINE_ASSERT_LE 0
65
#define GTEST_DONT_DEFINE_ASSERT_LT 0
66
#define GTEST_DONT_DEFINE_ASSERT_GE 0
67
#define GTEST_DONT_DEFINE_ASSERT_GT 0
68
#define GTEST_DONT_DEFINE_TEST 0
69
70
#ifndef GTEST_LANG_CXX11
71
#if __cplusplus >= 201103L || (defined(_MSVC_LANG) && !(_MSVC_LANG < 201103))
72
# define GTEST_LANG_CXX11 1
73
# define GTEST_HAS_TR1_TUPLE 0
74
# define GTEST_HAS_COMBINE 1
75
# endif
76
#endif
77
78
#if defined(__OPENCV_BUILD) && defined(__clang__)
79
#pragma clang diagnostic ignored "-Winconsistent-missing-override"
80
#endif
81
#if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
82
//#pragma GCC diagnostic push
83
#pragma GCC diagnostic ignored "-Wsuggest-override"
84
#endif
85
#include "opencv2/ts/ts_gtest.h"
86
#if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
87
//#pragma GCC diagnostic pop
88
#endif
89
#include "opencv2/ts/ts_ext.hpp"
90
91
#ifndef GTEST_USES_SIMPLE_RE
92
# define GTEST_USES_SIMPLE_RE 0
93
#endif
94
#ifndef GTEST_USES_POSIX_RE
95
# define GTEST_USES_POSIX_RE 0
96
#endif
97
98
#define PARAM_TEST_CASE(name, ...) struct name : testing::TestWithParam< testing::tuple< __VA_ARGS__ > >
99
#define GET_PARAM(k) testing::get< k >(GetParam())
100
101
namespace cvtest
102
{
103
104
using std::vector;
105
using std::map;
106
using std::string;
107
using std::stringstream;
108
using std::cout;
109
using std::cerr;
110
using std::endl;
111
using std::min;
112
using std::max;
113
using std::numeric_limits;
114
using std::pair;
115
using std::make_pair;
116
using testing::TestWithParam;
117
using testing::Values;
118
using testing::ValuesIn;
119
using testing::Combine;
120
121
using cv::Mat;
122
using cv::Mat_;
123
using cv::UMat;
124
using cv::InputArray;
125
using cv::OutputArray;
126
using cv::noArray;
127
128
using cv::Range;
129
using cv::Point;
130
using cv::Rect;
131
using cv::Size;
132
using cv::Scalar;
133
using cv::RNG;
134
135
// Tuple stuff from Google Tests
136
using testing::get;
137
using testing::make_tuple;
138
using testing::tuple;
139
using testing::tuple_size;
140
using testing::tuple_element;
141
142
143
class SkipTestException: public cv::Exception
144
{
145
public:
146
int dummy; // workaround for MacOSX Xcode 7.3 bug (don't make class "empty")
147
SkipTestException() : dummy(0) {}
148
SkipTestException(const cv::String& message) : dummy(0) { this->msg = message; }
149
};
150
151
class TS;
152
153
int64 readSeed(const char* str);
154
155
void randUni( RNG& rng, Mat& a, const Scalar& param1, const Scalar& param2 );
156
157
inline unsigned randInt( RNG& rng )
158
{
159
return (unsigned)rng;
160
}
161
162
inline double randReal( RNG& rng )
163
{
164
return (double)rng;
165
}
166
167
168
const char* getTypeName( int type );
169
int typeByName( const char* type_name );
170
171
string vec2str(const string& sep, const int* v, size_t nelems);
172
173
inline int clipInt( int val, int min_val, int max_val )
174
{
175
if( val < min_val )
176
val = min_val;
177
if( val > max_val )
178
val = max_val;
179
return val;
180
}
181
182
double getMinVal(int depth);
183
double getMaxVal(int depth);
184
185
Size randomSize(RNG& rng, double maxSizeLog);
186
void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz);
187
int randomType(RNG& rng, cv::_OutputArray::DepthMask typeMask, int minChannels, int maxChannels);
188
Mat randomMat(RNG& rng, Size size, int type, double minVal, double maxVal, bool useRoi);
189
Mat randomMat(RNG& rng, const vector<int>& size, int type, double minVal, double maxVal, bool useRoi);
190
void add(const Mat& a, double alpha, const Mat& b, double beta,
191
Scalar gamma, Mat& c, int ctype, bool calcAbs=false);
192
void multiply(const Mat& a, const Mat& b, Mat& c, double alpha=1);
193
void divide(const Mat& a, const Mat& b, Mat& c, double alpha=1);
194
195
void convert(const Mat& src, cv::OutputArray dst, int dtype, double alpha=1, double beta=0);
196
void copy(const Mat& src, Mat& dst, const Mat& mask=Mat(), bool invertMask=false);
197
void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat());
198
199
// working with multi-channel arrays
200
void extract( const Mat& a, Mat& plane, int coi );
201
void insert( const Mat& plane, Mat& a, int coi );
202
203
// checks that the array does not have NaNs and/or Infs and all the elements are
204
// within [min_val,max_val). idx is the index of the first "bad" element.
205
int check( const Mat& data, double min_val, double max_val, vector<int>* idx );
206
207
// modifies values that are close to zero
208
void patchZeros( Mat& mat, double level );
209
210
void transpose(const Mat& src, Mat& dst);
211
void erode(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
212
int borderType=0, const Scalar& borderValue=Scalar());
213
void dilate(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1),
214
int borderType=0, const Scalar& borderValue=Scalar());
215
void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel,
216
Point anchor, double delta, int borderType,
217
const Scalar& borderValue=Scalar());
218
void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right,
219
int borderType, const Scalar& borderValue=Scalar());
220
Mat calcSobelKernel2D( int dx, int dy, int apertureSize, int origin=0 );
221
Mat calcLaplaceKernel2D( int aperture_size );
222
223
void initUndistortMap( const Mat& a, const Mat& k, Size sz, Mat& mapx, Mat& mapy );
224
225
void minMaxLoc(const Mat& src, double* minval, double* maxval,
226
vector<int>* minloc, vector<int>* maxloc, const Mat& mask=Mat());
227
double norm(InputArray src, int normType, InputArray mask=noArray());
228
double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray());
229
Scalar mean(const Mat& src, const Mat& mask=Mat());
230
double PSNR(InputArray src1, InputArray src2);
231
232
bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector<int>* idx);
233
234
// compares two arrays. max_diff is the maximum actual difference,
235
// success_err_level is maximum allowed difference, idx is the index of the first
236
// element for which difference is >success_err_level
237
// (or index of element with the maximum difference)
238
int cmpEps( const Mat& data, const Mat& refdata, double* max_diff,
239
double success_err_level, vector<int>* idx,
240
bool element_wise_relative_error );
241
242
// a wrapper for the previous function. in case of error prints the message to log file.
243
int cmpEps2( TS* ts, const Mat& data, const Mat& refdata, double success_err_level,
244
bool element_wise_relative_error, const char* desc );
245
246
int cmpEps2_64f( TS* ts, const double* val, const double* refval, int len,
247
double eps, const char* param_name );
248
249
void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c);
250
void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c);
251
void min(const Mat& src1, const Mat& src2, Mat& dst);
252
void min(const Mat& src, double s, Mat& dst);
253
void max(const Mat& src1, const Mat& src2, Mat& dst);
254
void max(const Mat& src, double s, Mat& dst);
255
256
void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop);
257
void compare(const Mat& src, double s, Mat& dst, int cmpop);
258
void gemm(const Mat& src1, const Mat& src2, double alpha,
259
const Mat& src3, double beta, Mat& dst, int flags);
260
void transform( const Mat& src, Mat& dst, const Mat& transmat, const Mat& shift );
261
double crossCorr(const Mat& src1, const Mat& src2);
262
void threshold( const Mat& src, Mat& dst, double thresh, double maxval, int thresh_type );
263
void minMaxIdx( InputArray _img, double* minVal, double* maxVal,
264
Point* minLoc, Point* maxLoc, InputArray _mask );
265
266
struct MatInfo
267
{
268
MatInfo(const Mat& _m) : m(&_m) {}
269
const Mat* m;
270
};
271
272
std::ostream& operator << (std::ostream& out, const MatInfo& m);
273
274
struct MatComparator
275
{
276
public:
277
MatComparator(double maxdiff, int context);
278
279
::testing::AssertionResult operator()(const char* expr1, const char* expr2,
280
const Mat& m1, const Mat& m2);
281
282
double maxdiff;
283
double realmaxdiff;
284
vector<int> loc0;
285
int context;
286
};
287
288
289
290
class BaseTest;
291
class TS;
292
293
class BaseTest
294
{
295
public:
296
// constructor(s) and destructor
297
BaseTest();
298
virtual ~BaseTest();
299
300
// the main procedure of the test
301
virtual void run( int start_from );
302
303
// the wrapper for run that cares of exceptions
304
virtual void safe_run( int start_from=0 );
305
306
const string& get_name() const { return name; }
307
308
// returns true if and only if the different test cases do not depend on each other
309
// (so that test system could get right to a problematic test case)
310
virtual bool can_do_fast_forward();
311
312
// deallocates all the memory.
313
// called by init() (before initialization) and by the destructor
314
virtual void clear();
315
316
protected:
317
int test_case_count; // the total number of test cases
318
319
// read test params
320
virtual int read_params( CvFileStorage* fs );
321
322
// returns the number of tests or -1 if it is unknown a-priori
323
virtual int get_test_case_count();
324
325
// prepares data for the next test case. rng seed is updated by the function
326
virtual int prepare_test_case( int test_case_idx );
327
328
// checks if the test output is valid and accurate
329
virtual int validate_test_results( int test_case_idx );
330
331
// calls the tested function. the method is called from run_test_case()
332
virtual void run_func(); // runs tested func(s)
333
334
// updates progress bar
335
virtual int update_progress( int progress, int test_case_idx, int count, double dt );
336
337
// finds test parameter
338
const CvFileNode* find_param( CvFileStorage* fs, const char* param_name );
339
340
// name of the test (it is possible to locate a test by its name)
341
string name;
342
343
// pointer to the system that includes the test
344
TS* ts;
345
};
346
347
348
/*****************************************************************************************\
349
* Information about a failed test *
350
\*****************************************************************************************/
351
352
struct TestInfo
353
{
354
TestInfo();
355
356
// pointer to the test
357
BaseTest* test;
358
359
// failure code (TS::FAIL_*)
360
int code;
361
362
// seed value right before the data for the failed test case is prepared.
363
uint64 rng_seed;
364
365
// seed value right before running the test
366
uint64 rng_seed0;
367
368
// index of test case, can be then passed to BaseTest::proceed_to_test_case()
369
int test_case_idx;
370
};
371
372
/*****************************************************************************************\
373
* Base Class for test system *
374
\*****************************************************************************************/
375
376
// common parameters:
377
struct TSParams
378
{
379
TSParams();
380
381
// RNG seed, passed to and updated by every test executed.
382
uint64 rng_seed;
383
384
// whether to use IPP, MKL etc. or not
385
bool use_optimized;
386
387
// extensivity of the tests, scale factor for test_case_count
388
double test_case_count_scale;
389
};
390
391
392
class TS
393
{
394
TS();
395
virtual ~TS();
396
public:
397
398
enum
399
{
400
NUL=0,
401
SUMMARY_IDX=0,
402
SUMMARY=1 << SUMMARY_IDX,
403
LOG_IDX=1,
404
LOG=1 << LOG_IDX,
405
CSV_IDX=2,
406
CSV=1 << CSV_IDX,
407
CONSOLE_IDX=3,
408
CONSOLE=1 << CONSOLE_IDX,
409
MAX_IDX=4
410
};
411
412
static TS* ptr();
413
414
// initialize test system before running the first test
415
virtual void init( const string& modulename );
416
417
// low-level printing functions that are used by individual tests and by the system itself
418
virtual void printf( int streams, const char* fmt, ... );
419
virtual void vprintf( int streams, const char* fmt, va_list arglist );
420
421
// updates the context: current test, test case, rng state
422
virtual void update_context( BaseTest* test, int test_case_idx, bool update_ts_context );
423
424
const TestInfo* get_current_test_info() { return &current_test_info; }
425
426
// sets information about a failed test
427
virtual void set_failed_test_info( int fail_code );
428
429
virtual void set_gtest_status();
430
431
// test error codes
432
enum FailureCode
433
{
434
// everything is Ok
435
OK=0,
436
437
// generic error: stub value to be used
438
// temporarily if the error's cause is unknown
439
FAIL_GENERIC=-1,
440
441
// the test is missing some essential data to proceed further
442
FAIL_MISSING_TEST_DATA=-2,
443
444
// the tested function raised an error via cxcore error handler
445
FAIL_ERROR_IN_CALLED_FUNC=-3,
446
447
// an exception has been raised;
448
// for memory and arithmetic exception
449
// there are two specialized codes (see below...)
450
FAIL_EXCEPTION=-4,
451
452
// a memory exception
453
// (access violation, access to missed page, stack overflow etc.)
454
FAIL_MEMORY_EXCEPTION=-5,
455
456
// arithmetic exception (overflow, division by zero etc.)
457
FAIL_ARITHM_EXCEPTION=-6,
458
459
// the tested function corrupted memory (no exception have been raised)
460
FAIL_MEMORY_CORRUPTION_BEGIN=-7,
461
FAIL_MEMORY_CORRUPTION_END=-8,
462
463
// the tested function (or test itself) do not deallocate some memory
464
FAIL_MEMORY_LEAK=-9,
465
466
// the tested function returned invalid object, e.g. matrix, containing NaNs,
467
// structure with NULL or out-of-range fields (while it should not)
468
FAIL_INVALID_OUTPUT=-10,
469
470
// the tested function returned valid object, but it does not match
471
// the original (or produced by the test) object
472
FAIL_MISMATCH=-11,
473
474
// the tested function returned valid object (a single number or numerical array),
475
// but it differs too much from the original (or produced by the test) object
476
FAIL_BAD_ACCURACY=-12,
477
478
// the tested function hung. Sometimes, it can be determined by unexpectedly long
479
// processing time (in this case there should be possibility to interrupt such a function
480
FAIL_HANG=-13,
481
482
// unexpected response on passing bad arguments to the tested function
483
// (the function crashed, proceed successfully (while it should not), or returned
484
// error code that is different from what is expected)
485
FAIL_BAD_ARG_CHECK=-14,
486
487
// the test data (in whole or for the particular test case) is invalid
488
FAIL_INVALID_TEST_DATA=-15,
489
490
// the test has been skipped because it is not in the selected subset of the tests to run,
491
// because it has been run already within the same run with the same parameters, or because
492
// of some other reason and this is not considered as an error.
493
// Normally TS::run() (or overridden method in the derived class) takes care of what
494
// needs to be run, so this code should not occur.
495
SKIPPED=1
496
};
497
498
// get RNG to generate random input data for a test
499
RNG& get_rng() { return rng; }
500
501
// returns the current error code
502
TS::FailureCode get_err_code() { return TS::FailureCode(current_test_info.code); }
503
504
// returns the test extensivity scale
505
double get_test_case_count_scale() { return params.test_case_count_scale; }
506
507
const string& get_data_path() const { return data_path; }
508
509
// returns textual description of failure code
510
static string str_from_code( const TS::FailureCode code );
511
512
std::vector<std::string> data_search_path;
513
std::vector<std::string> data_search_subdir;
514
protected:
515
516
// these are allocated within a test to try to keep them valid in case of stack corruption
517
RNG rng;
518
519
// information about the current test
520
TestInfo current_test_info;
521
522
// the path to data files used by tests
523
string data_path;
524
525
TSParams params;
526
std::string output_buf[MAX_IDX];
527
};
528
529
530
/*****************************************************************************************\
531
* Subclass of BaseTest for testing functions that process dense arrays *
532
\*****************************************************************************************/
533
534
class ArrayTest : public BaseTest
535
{
536
public:
537
// constructor(s) and destructor
538
ArrayTest();
539
virtual ~ArrayTest();
540
541
virtual void clear() CV_OVERRIDE;
542
543
protected:
544
545
virtual int read_params( CvFileStorage* fs ) CV_OVERRIDE;
546
virtual int prepare_test_case( int test_case_idx ) CV_OVERRIDE;
547
virtual int validate_test_results( int test_case_idx ) CV_OVERRIDE;
548
549
virtual void prepare_to_validation( int test_case_idx );
550
virtual void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
551
virtual void fill_array( int test_case_idx, int i, int j, Mat& arr );
552
virtual void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high );
553
virtual double get_success_error_level( int test_case_idx, int i, int j );
554
555
bool cvmat_allowed;
556
bool iplimage_allowed;
557
bool optional_mask;
558
bool element_wise_relative_error;
559
560
int min_log_array_size;
561
int max_log_array_size;
562
563
enum { INPUT, INPUT_OUTPUT, OUTPUT, REF_INPUT_OUTPUT, REF_OUTPUT, TEMP, MASK, MAX_ARR };
564
565
vector<vector<void*> > test_array;
566
vector<vector<Mat> > test_mat;
567
float buf[4];
568
};
569
570
571
class BadArgTest : public BaseTest
572
{
573
public:
574
// constructor(s) and destructor
575
BadArgTest();
576
virtual ~BadArgTest();
577
578
protected:
579
virtual int run_test_case( int expected_code, const string& descr );
580
virtual void run_func(void) CV_OVERRIDE = 0;
581
int test_case_idx;
582
583
template<class F>
584
int run_test_case( int expected_code, const string& _descr, F f)
585
{
586
int errcount = 0;
587
bool thrown = false;
588
const char* descr = _descr.c_str() ? _descr.c_str() : "";
589
590
try
591
{
592
f();
593
}
594
catch(const cv::Exception& e)
595
{
596
thrown = true;
597
if( e.code != expected_code )
598
{
599
ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
600
descr, test_case_idx, e.code, expected_code);
601
errcount = 1;
602
}
603
}
604
catch(...)
605
{
606
thrown = true;
607
ts->printf(TS::LOG, "%s (test case #%d): unknown exception was thrown (the function has likely crashed)\n",
608
descr, test_case_idx);
609
errcount = 1;
610
}
611
if(!thrown)
612
{
613
ts->printf(TS::LOG, "%s (test case #%d): no expected exception was thrown\n",
614
descr, test_case_idx);
615
errcount = 1;
616
}
617
test_case_idx++;
618
619
return errcount;
620
}
621
};
622
623
extern uint64 param_seed;
624
625
struct DefaultRngAuto
626
{
627
const uint64 old_state;
628
629
DefaultRngAuto() : old_state(cv::theRNG().state) { cv::theRNG().state = cvtest::param_seed; }
630
~DefaultRngAuto() { cv::theRNG().state = old_state; }
631
632
DefaultRngAuto& operator=(const DefaultRngAuto&);
633
};
634
635
636
// test images generation functions
637
void fillGradient(Mat& img, int delta = 5);
638
void smoothBorder(Mat& img, const Scalar& color, int delta = 3);
639
640
// Utility functions
641
642
void addDataSearchPath(const std::string& path);
643
void addDataSearchSubDirectory(const std::string& subdir);
644
645
/*! @brief Try to find requested data file
646
647
Search directories:
648
649
0. TS::data_search_path (search sub-directories are not used)
650
1. OPENCV_TEST_DATA_PATH environment variable
651
2. One of these:
652
a. OpenCV testdata based on build location: "./" + "share/OpenCV/testdata"
653
b. OpenCV testdata at install location: CMAKE_INSTALL_PREFIX + "share/OpenCV/testdata"
654
655
Search sub-directories:
656
657
- addDataSearchSubDirectory()
658
- modulename from TS::init()
659
660
*/
661
std::string findDataFile(const std::string& relative_path, bool required = true);
662
663
/*! @brief Try to find requested data directory
664
@sa findDataFile
665
*/
666
std::string findDataDirectory(const std::string& relative_path, bool required = true);
667
668
// Test definitions
669
670
class SystemInfoCollector : public testing::EmptyTestEventListener
671
{
672
private:
673
virtual void OnTestProgramStart(const testing::UnitTest&);
674
};
675
676
#ifndef __CV_TEST_EXEC_ARGS
677
#if defined(_MSC_VER) && (_MSC_VER <= 1400)
678
#define __CV_TEST_EXEC_ARGS(...) \
679
while (++argc >= (--argc,-1)) {__VA_ARGS__; break;} /*this ugly construction is needed for VS 2005*/
680
#else
681
#define __CV_TEST_EXEC_ARGS(...) \
682
__VA_ARGS__;
683
#endif
684
#endif
685
686
void parseCustomOptions(int argc, char **argv);
687
688
#define CV_TEST_INIT0_NOOP (void)0
689
690
#define CV_TEST_MAIN(resourcesubdir, ...) CV_TEST_MAIN_EX(resourcesubdir, NOOP, __VA_ARGS__)
691
692
#define CV_TEST_MAIN_EX(resourcesubdir, INIT0, ...) \
693
int main(int argc, char **argv) \
694
{ \
695
CV_TRACE_FUNCTION(); \
696
{ CV_TRACE_REGION("INIT"); \
697
using namespace cvtest; \
698
TS* ts = TS::ptr(); \
699
ts->init(resourcesubdir); \
700
__CV_TEST_EXEC_ARGS(CV_TEST_INIT0_ ## INIT0) \
701
::testing::InitGoogleTest(&argc, argv); \
702
::testing::UnitTest::GetInstance()->listeners().Append(new SystemInfoCollector); \
703
__CV_TEST_EXEC_ARGS(__VA_ARGS__) \
704
parseCustomOptions(argc, argv); \
705
} \
706
return RUN_ALL_TESTS(); \
707
}
708
709
// This usually only makes sense in perf tests with several implementations,
710
// some of which are not available.
711
#define CV_TEST_FAIL_NO_IMPL() do { \
712
::testing::Test::RecordProperty("custom_status", "noimpl"); \
713
FAIL() << "No equivalent implementation."; \
714
} while (0)
715
716
} //namespace cvtest
717
718
#include "opencv2/ts/ts_perf.hpp"
719
720
namespace cvtest {
721
using perf::MatDepth;
722
using perf::MatType;
723
}
724
725
#ifdef WINRT
726
#ifndef __FSTREAM_EMULATED__
727
#define __FSTREAM_EMULATED__
728
#include <stdlib.h>
729
#include <fstream>
730
#include <sstream>
731
732
#undef ifstream
733
#undef ofstream
734
#define ifstream ifstream_emulated
735
#define ofstream ofstream_emulated
736
737
namespace std {
738
739
class ifstream : public stringstream
740
{
741
FILE* f;
742
public:
743
ifstream(const char* filename, ios_base::openmode mode = ios_base::in)
744
: f(NULL)
745
{
746
string modeStr("r");
747
printf("Open file (read): %s\n", filename);
748
if (mode & ios_base::binary)
749
modeStr += "b";
750
f = fopen(filename, modeStr.c_str());
751
752
if (f == NULL)
753
{
754
printf("Can't open file: %s\n", filename);
755
return;
756
}
757
fseek(f, 0, SEEK_END);
758
size_t sz = ftell(f);
759
if (sz > 0)
760
{
761
char* buf = (char*) malloc(sz);
762
fseek(f, 0, SEEK_SET);
763
if (fread(buf, 1, sz, f) == sz)
764
{
765
this->str(std::string(buf, sz));
766
}
767
free(buf);
768
}
769
}
770
771
~ifstream() { close(); }
772
bool is_open() const { return f != NULL; }
773
void close()
774
{
775
if (f)
776
fclose(f);
777
f = NULL;
778
this->str("");
779
}
780
};
781
782
class ofstream : public stringstream
783
{
784
FILE* f;
785
public:
786
ofstream(const char* filename, ios_base::openmode mode = ios_base::out)
787
: f(NULL)
788
{
789
open(filename, mode);
790
}
791
~ofstream() { close(); }
792
void open(const char* filename, ios_base::openmode mode = ios_base::out)
793
{
794
string modeStr("w+");
795
if (mode & ios_base::trunc)
796
modeStr = "w";
797
if (mode & ios_base::binary)
798
modeStr += "b";
799
f = fopen(filename, modeStr.c_str());
800
printf("Open file (write): %s\n", filename);
801
if (f == NULL)
802
{
803
printf("Can't open file (write): %s\n", filename);
804
return;
805
}
806
}
807
bool is_open() const { return f != NULL; }
808
void close()
809
{
810
if (f)
811
{
812
fwrite(reinterpret_cast<const char *>(this->str().c_str()), this->str().size(), 1, f);
813
fclose(f);
814
}
815
f = NULL;
816
this->str("");
817
}
818
};
819
820
} // namespace std
821
#endif // __FSTREAM_EMULATED__
822
#endif // WINRT
823
824
825
namespace opencv_test {
826
using namespace cvtest;
827
using namespace cv;
828
829
#ifdef CV_CXX11
830
#define CVTEST_GUARD_SYMBOL(name) \
831
class required_namespace_specificatin_here_for_symbol_ ## name {}; \
832
using name = required_namespace_specificatin_here_for_symbol_ ## name;
833
#else
834
#define CVTEST_GUARD_SYMBOL(name) /* nothing */
835
#endif
836
837
CVTEST_GUARD_SYMBOL(norm)
838
CVTEST_GUARD_SYMBOL(add)
839
CVTEST_GUARD_SYMBOL(multiply)
840
CVTEST_GUARD_SYMBOL(divide)
841
CVTEST_GUARD_SYMBOL(transpose)
842
CVTEST_GUARD_SYMBOL(copyMakeBorder)
843
CVTEST_GUARD_SYMBOL(filter2D)
844
CVTEST_GUARD_SYMBOL(compare)
845
CVTEST_GUARD_SYMBOL(minMaxIdx)
846
CVTEST_GUARD_SYMBOL(threshold)
847
848
extern bool required_opencv_test_namespace; // compilation check for non-refactored tests
849
}
850
851
#endif // OPENCV_TS_HPP
852
853