mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
ts: added findDataFile() utility function and SkipTestException
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef OPENCV_GTESTCV_HPP
|
||||
#define OPENCV_GTESTCV_HPP
|
||||
#ifndef OPENCV_TS_HPP
|
||||
#define OPENCV_TS_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
#include <stdarg.h> // for va_list
|
||||
@@ -55,6 +55,14 @@ using cv::Rect;
|
||||
using cv::InputArray;
|
||||
using cv::noArray;
|
||||
|
||||
class SkipTestException: public cv::Exception
|
||||
{
|
||||
public:
|
||||
int dummy; // workaround for MacOSX Xcode 7.3 bug (don't make class "empty")
|
||||
SkipTestException() : dummy(0) {}
|
||||
SkipTestException(const cv::String& message) : dummy(0) { this->msg = message; }
|
||||
};
|
||||
|
||||
class CV_EXPORTS TS;
|
||||
|
||||
CV_EXPORTS int64 readSeed(const char* str);
|
||||
@@ -420,6 +428,8 @@ public:
|
||||
// returns textual description of failure code
|
||||
static string str_from_code( const TS::FailureCode code );
|
||||
|
||||
std::vector<std::string> data_search_path;
|
||||
std::vector<std::string> data_search_subdir;
|
||||
protected:
|
||||
|
||||
// these are allocated within a test to try keep them valid in case of stack corruption
|
||||
@@ -539,17 +549,37 @@ struct CV_EXPORTS DefaultRngAuto
|
||||
DefaultRngAuto& operator=(const DefaultRngAuto&);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace cvtest
|
||||
{
|
||||
|
||||
// test images generation functions
|
||||
CV_EXPORTS void fillGradient(Mat& img, int delta = 5);
|
||||
CV_EXPORTS void smoothBorder(Mat& img, const Scalar& color, int delta = 3);
|
||||
|
||||
CV_EXPORTS void printVersionInfo(bool useStdOut = true);
|
||||
} //namespace cvtest
|
||||
|
||||
|
||||
// Utility functions
|
||||
|
||||
CV_EXPORTS void addDataSearchPath(const std::string& path);
|
||||
CV_EXPORTS void addDataSearchSubDirectory(const std::string& subdir);
|
||||
|
||||
/*! @brief Try to find requested data file
|
||||
|
||||
Search directories:
|
||||
|
||||
0. TS::data_search_path (search sub-directories are not used)
|
||||
1. OPENCV_TEST_DATA_PATH environment variable
|
||||
2. One of these:
|
||||
a. OpenCV testdata based on build location: "./" + "share/OpenCV/testdata"
|
||||
b. OpenCV testdata at install location: CMAKE_INSTALL_PREFIX + "share/OpenCV/testdata"
|
||||
|
||||
Search sub-directories:
|
||||
|
||||
- addDataSearchSubDirectory()
|
||||
- modulename from TS::init()
|
||||
|
||||
*/
|
||||
CV_EXPORTS std::string findDataFile(const std::string& relative_path, bool required = true);
|
||||
|
||||
|
||||
#ifndef __CV_TEST_EXEC_ARGS
|
||||
#if defined(_MSC_VER) && (_MSC_VER <= 1400)
|
||||
@@ -562,9 +592,9 @@ CV_EXPORTS void printVersionInfo(bool useStdOut = true);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
namespace cvtest { namespace ocl {
|
||||
namespace ocl {
|
||||
void dumpOpenCLDevice();
|
||||
} }
|
||||
}
|
||||
#define TEST_DUMP_OCL_INFO cvtest::ocl::dumpOpenCLDevice();
|
||||
#else
|
||||
#define TEST_DUMP_OCL_INFO
|
||||
@@ -575,11 +605,13 @@ void parseCustomOptions(int argc, char **argv);
|
||||
#define CV_TEST_MAIN(resourcesubdir, ...) \
|
||||
int main(int argc, char **argv) \
|
||||
{ \
|
||||
__CV_TEST_EXEC_ARGS(__VA_ARGS__) \
|
||||
cvtest::TS::ptr()->init(resourcesubdir); \
|
||||
using namespace cvtest; \
|
||||
TS* ts = TS::ptr(); \
|
||||
ts->init(resourcesubdir); \
|
||||
::testing::InitGoogleTest(&argc, argv); \
|
||||
cvtest::printVersionInfo(); \
|
||||
TEST_DUMP_OCL_INFO \
|
||||
__CV_TEST_EXEC_ARGS(__VA_ARGS__) \
|
||||
parseCustomOptions(argc, argv); \
|
||||
return RUN_ALL_TESTS(); \
|
||||
}
|
||||
@@ -591,7 +623,9 @@ int main(int argc, char **argv) \
|
||||
FAIL() << "No equivalent implementation."; \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
} //namespace cvtest
|
||||
|
||||
#endif // OPENCV_TS_HPP
|
||||
|
||||
#include "opencv2/ts/ts_perf.hpp"
|
||||
|
||||
|
||||
@@ -8,7 +8,25 @@
|
||||
#ifndef OPENCV_TS_EXT_HPP
|
||||
#define OPENCV_TS_EXT_HPP
|
||||
|
||||
namespace cvtest {
|
||||
void checkIppStatus();
|
||||
}
|
||||
|
||||
#define CV_TEST_INIT cv::ipp::setIppStatus(0);
|
||||
#define CV_TEST_CLEANUP ::cvtest::checkIppStatus();
|
||||
#define CV_TEST_BODY_IMPL \
|
||||
{ \
|
||||
try { \
|
||||
CV_TEST_INIT \
|
||||
Body(); \
|
||||
CV_TEST_CLEANUP \
|
||||
} \
|
||||
catch (cvtest::SkipTestException& e) \
|
||||
{ \
|
||||
printf("[ SKIP ] %s\n", e.what()); \
|
||||
} \
|
||||
} \
|
||||
|
||||
|
||||
#undef TEST
|
||||
#define TEST(test_case_name, test_name) \
|
||||
@@ -33,7 +51,7 @@ void checkIppStatus();
|
||||
::testing::Test::TearDownTestCase, \
|
||||
new ::testing::internal::TestFactoryImpl<\
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() CV_TEST_BODY_IMPL \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body()
|
||||
|
||||
#undef TEST_F
|
||||
@@ -59,7 +77,7 @@ void checkIppStatus();
|
||||
test_fixture::TearDownTestCase, \
|
||||
new ::testing::internal::TestFactoryImpl<\
|
||||
GTEST_TEST_CLASS_NAME_(test_fixture, test_name)>);\
|
||||
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \
|
||||
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::TestBody() CV_TEST_BODY_IMPL \
|
||||
void GTEST_TEST_CLASS_NAME_(test_fixture, test_name)::Body()
|
||||
|
||||
#undef TEST_P
|
||||
@@ -91,7 +109,7 @@ void checkIppStatus();
|
||||
int GTEST_TEST_CLASS_NAME_(test_case_name, \
|
||||
test_name)::gtest_registering_dummy_ = \
|
||||
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() { cv::ipp::setIppStatus(0); Body(); checkIppStatus(); } \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() CV_TEST_BODY_IMPL \
|
||||
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::Body()
|
||||
|
||||
#endif // OPENCV_TS_EXT_HPP
|
||||
|
||||
Reference in New Issue
Block a user