1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef __OPENCV_GTESTCV_HPP__ 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define __OPENCV_GTESTCV_HPP__ 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/cvdef.h" 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include <stdarg.h> // for va_list 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "cvconfig.h" 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef WINRT 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef _MSC_VER 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#pragma warning( disable: 4127 ) // conditional expression is constant 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#pragma warning( disable: 4503 ) // decorated name length exceeded, name was truncated 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_FAIL 0 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_SUCCEED 0 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_EQ 0 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_NE 0 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_LE 0 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_LT 0 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_GE 0 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_ASSERT_GT 0 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define GTEST_DONT_DEFINE_TEST 0 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/ts/ts_gtest.h" 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/ts/ts_ext.hpp" 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef GTEST_USES_SIMPLE_RE 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler# define GTEST_USES_SIMPLE_RE 0 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef GTEST_USES_POSIX_RE 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler# define GTEST_USES_POSIX_RE 0 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core.hpp" 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/core/utility.hpp" 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cvtest 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing std::vector; 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing std::string; 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::RNG; 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::Mat; 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::Scalar; 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::Size; 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::Point; 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::Rect; 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::InputArray; 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing cv::noArray; 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS TS; 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int64 readSeed(const char* str); 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void randUni( RNG& rng, Mat& a, const Scalar& param1, const Scalar& param2 ); 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinline unsigned randInt( RNG& rng ) 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (unsigned)rng; 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinline double randReal( RNG& rng ) 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return (double)rng; 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS const char* getTypeName( int type ); 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int typeByName( const char* type_name ); 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS string vec2str(const string& sep, const int* v, size_t nelems); 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerinline int clipInt( int val, int min_val, int max_val ) 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if( val < min_val ) 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler val = min_val; 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if( val > max_val ) 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler val = max_val; 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return val; 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double getMinVal(int depth); 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double getMaxVal(int depth); 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Size randomSize(RNG& rng, double maxSizeLog); 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz); 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels); 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Mat randomMat(RNG& rng, Size size, int type, double minVal, double maxVal, bool useRoi); 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Mat randomMat(RNG& rng, const vector<int>& size, int type, double minVal, double maxVal, bool useRoi); 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void add(const Mat& a, double alpha, const Mat& b, double beta, 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler Scalar gamma, Mat& c, int ctype, bool calcAbs=false); 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void multiply(const Mat& a, const Mat& b, Mat& c, double alpha=1); 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void divide(const Mat& a, const Mat& b, Mat& c, double alpha=1); 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void convert(const Mat& src, cv::OutputArray dst, int dtype, double alpha=1, double beta=0); 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void copy(const Mat& src, Mat& dst, const Mat& mask=Mat(), bool invertMask=false); 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat()); 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// working with multi-channel arrays 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void extract( const Mat& a, Mat& plane, int coi ); 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void insert( const Mat& plane, Mat& a, int coi ); 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// checks that the array does not have NaNs and/or Infs and all the elements are 108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// within [min_val,max_val). idx is the index of the first "bad" element. 109793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int check( const Mat& data, double min_val, double max_val, vector<int>* idx ); 110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// modifies values that are close to zero 112793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void patchZeros( Mat& mat, double level ); 113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 114793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void transpose(const Mat& src, Mat& dst); 115793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void erode(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1), 116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int borderType=0, const Scalar& borderValue=Scalar()); 117793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void dilate(const Mat& src, Mat& dst, const Mat& _kernel, Point anchor=Point(-1,-1), 118793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int borderType=0, const Scalar& borderValue=Scalar()); 119793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel, 120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler Point anchor, double delta, int borderType, 121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const Scalar& borderValue=Scalar()); 122793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right, 123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int borderType, const Scalar& borderValue=Scalar()); 124793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Mat calcSobelKernel2D( int dx, int dy, int apertureSize, int origin=0 ); 125793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Mat calcLaplaceKernel2D( int aperture_size ); 126793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 127793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void initUndistortMap( const Mat& a, const Mat& k, Size sz, Mat& mapx, Mat& mapy ); 128793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 129793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void minMaxLoc(const Mat& src, double* minval, double* maxval, 130793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vector<int>* minloc, vector<int>* maxloc, const Mat& mask=Mat()); 131793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double norm(InputArray src, int normType, InputArray mask=noArray()); 132793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray()); 133793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS Scalar mean(const Mat& src, const Mat& mask=Mat()); 134793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double PSNR(InputArray src1, InputArray src2); 135793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 136793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector<int>* idx); 137793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 138793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// compares two arrays. max_diff is the maximum actual difference, 139793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// success_err_level is maximum allowed difference, idx is the index of the first 140793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// element for which difference is >success_err_level 141793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (or index of element with the maximum difference) 142793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int cmpEps( const Mat& data, const Mat& refdata, double* max_diff, 143793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double success_err_level, vector<int>* idx, 144793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool element_wise_relative_error ); 145793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 146793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// a wrapper for the previous function. in case of error prints the message to log file. 147793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int cmpEps2( TS* ts, const Mat& data, const Mat& refdata, double success_err_level, 148793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool element_wise_relative_error, const char* desc ); 149793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 150793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS int cmpEps2_64f( TS* ts, const double* val, const double* refval, int len, 151793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double eps, const char* param_name ); 152793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 153793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c); 154793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c); 155793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void min(const Mat& src1, const Mat& src2, Mat& dst); 156793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void min(const Mat& src, double s, Mat& dst); 157793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void max(const Mat& src1, const Mat& src2, Mat& dst); 158793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void max(const Mat& src, double s, Mat& dst); 159793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 160793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop); 161793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void compare(const Mat& src, double s, Mat& dst, int cmpop); 162793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void gemm(const Mat& src1, const Mat& src2, double alpha, 163793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const Mat& src3, double beta, Mat& dst, int flags); 164793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CV_EXPORTS void transform( const Mat& src, Mat& dst, const Mat& transmat, const Mat& shift ); 165793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS double crossCorr(const Mat& src1, const Mat& src2); 166793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 167793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct CV_EXPORTS MatInfo 168793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 169793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MatInfo(const Mat& _m) : m(&_m) {} 170793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const Mat* m; 171793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 172793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 173793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS std::ostream& operator << (std::ostream& out, const MatInfo& m); 174793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 175793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct CV_EXPORTS MatComparator 176793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 177793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic: 178793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MatComparator(double maxdiff, int context); 179793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 180793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ::testing::AssertionResult operator()(const char* expr1, const char* expr2, 181793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const Mat& m1, const Mat& m2); 182793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 183793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double maxdiff; 184793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double realmaxdiff; 185793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vector<int> loc0; 186793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int context; 187793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 188793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 189793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 190793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 191793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass BaseTest; 192793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass TS; 193793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 194793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS BaseTest 195793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 196793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic: 197793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // constructor(s) and destructor 198793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler BaseTest(); 199793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual ~BaseTest(); 200793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 201793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the main procedure of the test 202793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void run( int start_from ); 203793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 204793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the wrapper for run that cares of exceptions 205793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void safe_run( int start_from=0 ); 206793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 207793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const string& get_name() const { return name; } 208793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 209793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // returns true if and only if the different test cases do not depend on each other 210793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // (so that test system could get right to a problematic test case) 211793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual bool can_do_fast_forward(); 212793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 213793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // deallocates all the memory. 214793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // called by init() (before initialization) and by the destructor 215793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void clear(); 216793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 217793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprotected: 218793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int test_case_count; // the total number of test cases 219793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 220793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // read test params 221793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int read_params( CvFileStorage* fs ); 222793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 223793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // returns the number of tests or -1 if it is unknown a-priori 224793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int get_test_case_count(); 225793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 226793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // prepares data for the next test case. rng seed is updated by the function 227793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int prepare_test_case( int test_case_idx ); 228793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 229793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // checks if the test output is valid and accurate 230793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int validate_test_results( int test_case_idx ); 231793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 232793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // calls the tested function. the method is called from run_test_case() 233793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void run_func(); // runs tested func(s) 234793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 235793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // updates progress bar 236793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int update_progress( int progress, int test_case_idx, int count, double dt ); 237793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 238793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // finds test parameter 239793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const CvFileNode* find_param( CvFileStorage* fs, const char* param_name ); 240793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 241793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // name of the test (it is possible to locate a test by its name) 242793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler string name; 243793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 244793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // pointer to the system that includes the test 245793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TS* ts; 246793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 247793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 248793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 249793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*****************************************************************************************\ 250793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler* Information about a failed test * 251793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\*****************************************************************************************/ 252793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 253793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct TestInfo 254793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 255793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TestInfo(); 256793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 257793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // pointer to the test 258793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler BaseTest* test; 259793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 260793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // failure code (TS::FAIL_*) 261793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int code; 262793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 263793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // seed value right before the data for the failed test case is prepared. 264793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler uint64 rng_seed; 265793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 266793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // seed value right before running the test 267793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler uint64 rng_seed0; 268793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 269793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // index of test case, can be then passed to BaseTest::proceed_to_test_case() 270793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int test_case_idx; 271793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 272793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 273793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*****************************************************************************************\ 274793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler* Base Class for test system * 275793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\*****************************************************************************************/ 276793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 277793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// common parameters: 278793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct CV_EXPORTS TSParams 279793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 280793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TSParams(); 281793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 282793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // RNG seed, passed to and updated by every test executed. 283793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler uint64 rng_seed; 284793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 285793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // whether to use IPP, MKL etc. or not 286793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool use_optimized; 287793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 288793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // extensivity of the tests, scale factor for test_case_count 289793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double test_case_count_scale; 290793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 291793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 292793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 293793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS TS 294793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 295793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic: 296793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // constructor(s) and destructor 297793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TS(); 298793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual ~TS(); 299793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 300793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler enum 301793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 302793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler NUL=0, 303793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler SUMMARY_IDX=0, 304793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler SUMMARY=1 << SUMMARY_IDX, 305793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler LOG_IDX=1, 306793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler LOG=1 << LOG_IDX, 307793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CSV_IDX=2, 308793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CSV=1 << CSV_IDX, 309793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CONSOLE_IDX=3, 310793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CONSOLE=1 << CONSOLE_IDX, 311793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler MAX_IDX=4 312793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 313793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 314793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler static TS* ptr(); 315793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 316793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // initialize test system before running the first test 317793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void init( const string& modulename ); 318793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 319793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // low-level printing functions that are used by individual tests and by the system itself 320793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void printf( int streams, const char* fmt, ... ); 321793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void vprintf( int streams, const char* fmt, va_list arglist ); 322793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 323793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // updates the context: current test, test case, rng state 324793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void update_context( BaseTest* test, int test_case_idx, bool update_ts_context ); 325793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 326793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const TestInfo* get_current_test_info() { return ¤t_test_info; } 327793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 328793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // sets information about a failed test 329793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void set_failed_test_info( int fail_code ); 330793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 331793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void set_gtest_status(); 332793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 333793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // test error codes 334793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler enum FailureCode 335793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 336793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // everything is Ok 337793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler OK=0, 338793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 339793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // generic error: stub value to be used 340793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // temporarily if the error's cause is unknown 341793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_GENERIC=-1, 342793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 343793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the test is missing some essential data to proceed further 344793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MISSING_TEST_DATA=-2, 345793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 346793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function raised an error via cxcore error handler 347793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_ERROR_IN_CALLED_FUNC=-3, 348793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 349793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // an exception has been raised; 350793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // for memory and arithmetic exception 351793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // there are two specialized codes (see below...) 352793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_EXCEPTION=-4, 353793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 354793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // a memory exception 355793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // (access violation, access to missed page, stack overflow etc.) 356793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MEMORY_EXCEPTION=-5, 357793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 358793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // arithmetic exception (overflow, division by zero etc.) 359793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_ARITHM_EXCEPTION=-6, 360793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 361793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function corrupted memory (no exception have been raised) 362793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MEMORY_CORRUPTION_BEGIN=-7, 363793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MEMORY_CORRUPTION_END=-8, 364793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 365793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function (or test ifself) do not deallocate some memory 366793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MEMORY_LEAK=-9, 367793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 368793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function returned invalid object, e.g. matrix, containing NaNs, 369793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // structure with NULL or out-of-range fields (while it should not) 370793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_INVALID_OUTPUT=-10, 371793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 372793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function returned valid object, but it does not match to 373793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the original (or produced by the test) object 374793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_MISMATCH=-11, 375793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 376793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function returned valid object (a single number or numerical array), 377793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // but it differs too much from the original (or produced by the test) object 378793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_BAD_ACCURACY=-12, 379793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 380793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the tested function hung. Sometimes, can be determined by unexpectedly long 381793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // processing time (in this case there should be possibility to interrupt such a function 382793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_HANG=-13, 383793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 384793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // unexpected response on passing bad arguments to the tested function 385793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // (the function crashed, proceed successfully (while it should not), or returned 386793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // error code that is different from what is expected) 387793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_BAD_ARG_CHECK=-14, 388793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 389793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the test data (in whole or for the particular test case) is invalid 390793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL_INVALID_TEST_DATA=-15, 391793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 392793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the test has been skipped because it is not in the selected subset of the tests to run, 393793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // because it has been run already within the same run with the same parameters, or because 394793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // of some other reason and this is not considered as an error. 395793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // Normally TS::run() (or overridden method in the derived class) takes care of what 396793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // needs to be run, so this code should not occur. 397793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler SKIPPED=1 398793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler }; 399793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 400793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // get file storage 401793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler CvFileStorage* get_file_storage(); 402793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 403793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // get RNG to generate random input data for a test 404793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler RNG& get_rng() { return rng; } 405793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 406793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // returns the current error code 407793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TS::FailureCode get_err_code() { return TS::FailureCode(current_test_info.code); } 408793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 409793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // returns the test extensivity scale 410793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler double get_test_case_count_scale() { return params.test_case_count_scale; } 411793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 412793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const string& get_data_path() const { return data_path; } 413793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 414793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // returns textual description of failure code 415793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler static string str_from_code( const TS::FailureCode code ); 416793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 417793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprotected: 418793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 419793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // these are allocated within a test to try keep them valid in case of stack corruption 420793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler RNG rng; 421793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 422793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // information about the current test 423793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TestInfo current_test_info; 424793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 425793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // the path to data files used by tests 426793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler string data_path; 427793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 428793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TSParams params; 429793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler std::string output_buf[MAX_IDX]; 430793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 431793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 432793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 433793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*****************************************************************************************\ 434793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler* Subclass of BaseTest for testing functions that process dense arrays * 435793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler\*****************************************************************************************/ 436793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 437793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS ArrayTest : public BaseTest 438793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 439793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic: 440793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // constructor(s) and destructor 441793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ArrayTest(); 442793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual ~ArrayTest(); 443793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 444793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void clear(); 445793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 446793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprotected: 447793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 448793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int read_params( CvFileStorage* fs ); 449793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int prepare_test_case( int test_case_idx ); 450793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int validate_test_results( int test_case_idx ); 451793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 452793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void prepare_to_validation( int test_case_idx ); 453793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types ); 454793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void fill_array( int test_case_idx, int i, int j, Mat& arr ); 455793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void get_minmax_bounds( int i, int j, int type, Scalar& low, Scalar& high ); 456793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual double get_success_error_level( int test_case_idx, int i, int j ); 457793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 458793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool cvmat_allowed; 459793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool iplimage_allowed; 460793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool optional_mask; 461793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool element_wise_relative_error; 462793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 463793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int min_log_array_size; 464793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int max_log_array_size; 465793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 466793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler enum { INPUT, INPUT_OUTPUT, OUTPUT, REF_INPUT_OUTPUT, REF_OUTPUT, TEMP, MASK, MAX_ARR }; 467793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 468793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vector<vector<void*> > test_array; 469793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler vector<vector<Mat> > test_mat; 470793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float buf[4]; 471793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 472793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 473793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 474793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerclass CV_EXPORTS BadArgTest : public BaseTest 475793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 476793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerpublic: 477793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler // constructor(s) and destructor 478793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler BadArgTest(); 479793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual ~BadArgTest(); 480793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 481793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerprotected: 482793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual int run_test_case( int expected_code, const string& descr ); 483793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void run_func(void) = 0; 484793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int test_case_idx; 485793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 486793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template<class F> 487793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int run_test_case( int expected_code, const string& _descr, F f) 488793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 489793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int errcount = 0; 490793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool thrown = false; 491793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const char* descr = _descr.c_str() ? _descr.c_str() : ""; 492793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 493793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler try 494793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 495793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler f(); 496793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 497793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler catch(const cv::Exception& e) 498793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 499793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler thrown = true; 500793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if( e.code != expected_code ) 501793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 502793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ts->printf(TS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n", 503793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler descr, test_case_idx, e.code, expected_code); 504793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler errcount = 1; 505793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 506793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 507793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler catch(...) 508793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 509793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler thrown = true; 510793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ts->printf(TS::LOG, "%s (test case #%d): unknown exception was thrown (the function has likely crashed)\n", 511793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler descr, test_case_idx); 512793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler errcount = 1; 513793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 514793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if(!thrown) 515793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 516793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ts->printf(TS::LOG, "%s (test case #%d): no expected exception was thrown\n", 517793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler descr, test_case_idx); 518793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler errcount = 1; 519793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 520793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler test_case_idx++; 521793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 522793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return errcount; 523793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 524793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 525793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 526793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerstruct CV_EXPORTS DefaultRngAuto 527793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 528793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const uint64 old_state; 529793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 530793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler DefaultRngAuto() : old_state(cv::theRNG().state) { cv::theRNG().state = (uint64)-1; } 531793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ~DefaultRngAuto() { cv::theRNG().state = old_state; } 532793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 533793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler DefaultRngAuto& operator=(const DefaultRngAuto&); 534793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 535793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 536793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 537793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 538793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cvtest 539793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 540793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 541793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// test images generation functions 542793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void fillGradient(Mat& img, int delta = 5); 543793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void smoothBorder(Mat& img, const Scalar& color, int delta = 3); 544793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 545793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCV_EXPORTS void printVersionInfo(bool useStdOut = true); 546793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} //namespace cvtest 547793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 548793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifndef __CV_TEST_EXEC_ARGS 549793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#if defined(_MSC_VER) && (_MSC_VER <= 1400) 550793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define __CV_TEST_EXEC_ARGS(...) \ 551793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler while (++argc >= (--argc,-1)) {__VA_ARGS__; break;} /*this ugly construction is needed for VS 2005*/ 552793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#else 553793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define __CV_TEST_EXEC_ARGS(...) \ 554793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __VA_ARGS__; 555793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 556793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 557793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 558793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef HAVE_OPENCL 559793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace cvtest { namespace ocl { 560793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid dumpOpenCLDevice(); 561793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} } 562793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TEST_DUMP_OCL_INFO cvtest::ocl::dumpOpenCLDevice(); 563793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#else 564793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define TEST_DUMP_OCL_INFO 565793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 566793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 567793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslervoid parseCustomOptions(int argc, char **argv); 568793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 569793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define CV_TEST_MAIN(resourcesubdir, ...) \ 570793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerint main(int argc, char **argv) \ 571793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ \ 572793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler __CV_TEST_EXEC_ARGS(__VA_ARGS__) \ 573793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cvtest::TS::ptr()->init(resourcesubdir); \ 574793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ::testing::InitGoogleTest(&argc, argv); \ 575793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cvtest::printVersionInfo(); \ 576793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler TEST_DUMP_OCL_INFO \ 577793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler parseCustomOptions(argc, argv); \ 578793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler return RUN_ALL_TESTS(); \ 579793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 580793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 581793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This usually only makes sense in perf tests with several implementations, 582793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// some of which are not available. 583793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#define CV_TEST_FAIL_NO_IMPL() do { \ 584793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ::testing::Test::RecordProperty("custom_status", "noimpl"); \ 585793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler FAIL() << "No equivalent implementation."; \ 586793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} while (0) 587793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 588793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif 589793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 590793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "opencv2/ts/ts_perf.hpp" 591