From: Alexander Alekhin Date: Mon, 23 Jul 2018 14:58:10 +0000 (+0300) Subject: ts: add findDataDirectory() function X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1^2~599^2~5^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e767e2376dd5d06f0c4e0da9cb54471ea284fda;p=platform%2Fupstream%2Fopencv.git ts: add findDataDirectory() function --- diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 7b3f732..5d88396 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -654,6 +654,11 @@ void addDataSearchSubDirectory(const std::string& subdir); */ std::string findDataFile(const std::string& relative_path, bool required = true); +/*! @brief Try to find requested data directory +@sa findDataFile + */ +std::string findDataDirectory(const std::string& relative_path, bool required = true); + #ifndef __CV_TEST_EXEC_ARGS #if defined(_MSC_VER) && (_MSC_VER <= 1400) diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp index 06f9118..b1ea96b 100644 --- a/modules/ts/src/ts.cpp +++ b/modules/ts/src/ts.cpp @@ -772,16 +772,24 @@ void addDataSearchSubDirectory(const std::string& subdir) TS::ptr()->data_search_subdir.push_back(subdir); } -std::string findDataFile(const std::string& relative_path, bool required) +static std::string findData(const std::string& relative_path, bool required, bool findDirectory) { #define TEST_TRY_FILE_WITH_PREFIX(prefix) \ { \ std::string path = path_join(prefix, relative_path); \ /*printf("Trying %s\n", path.c_str());*/ \ - FILE* f = fopen(path.c_str(), "rb"); \ - if(f) { \ - fclose(f); \ - return path; \ + if (findDirectory) \ + { \ + if (isDirectory(path)) \ + return path; \ + } \ + else \ + { \ + FILE* f = fopen(path.c_str(), "rb"); \ + if(f) { \ + fclose(f); \ + return path; \ + } \ } \ } @@ -842,11 +850,21 @@ std::string findDataFile(const std::string& relative_path, bool required) } #endif #endif + const char* type = findDirectory ? "directory" : "data file"; if (required) - CV_Error(cv::Error::StsError, cv::format("OpenCV tests: Can't find required data file: %s", relative_path.c_str())); - throw SkipTestException(cv::format("OpenCV tests: Can't find data file: %s", relative_path.c_str())); + CV_Error(cv::Error::StsError, cv::format("OpenCV tests: Can't find required %s: %s", type, relative_path.c_str())); + throw SkipTestException(cv::format("OpenCV tests: Can't find %s: %s", type, relative_path.c_str())); +} + +std::string findDataFile(const std::string& relative_path, bool required) +{ + return findData(relative_path, required, false); } +std::string findDataDirectory(const std::string& relative_path, bool required) +{ + return findData(relative_path, required, true); +} } //namespace cvtest