Merge pull request #26101 from mshabunin:cpp-error-ts

C-API cleanup: moved cvErrorStr to new interface, minor ts changes #26101

Merge with opencv/opencv_contrib#3786

**Note:** `toString` might be too generic name (even though it is in `cv::Error::` namespace), another variant is `codeToString` (we have `typeToString` and `depthToString` in check.hpp).

**Note:** _ts_ module seem to have no other C API usage except for `ArrayTest` class which requires refactoring.
This commit is contained in:
Maksim Shabunin
2024-09-06 12:05:47 +03:00
committed by GitHub
parent babc669dba
commit f73560293f
20 changed files with 438 additions and 452 deletions

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
#include <opencv2/core/utils/configuration.private.hpp>
#include "opencv2/core/core_c.h"
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
@@ -308,7 +306,7 @@ void BaseTest::safe_run( int start_from )
}
catch (const cv::Exception& exc)
{
const char* errorStr = cvErrorStr(exc.code);
const char* errorStr = exc.codeMessage();
char buf[1 << 16];
const char* delim = exc.err.find('\n') == cv::String::npos ? "" : "\n";
@@ -522,7 +520,7 @@ string TS::str_from_code( const TS::FailureCode code )
case FAIL_GENERIC: return "Generic/Unknown";
case FAIL_MISSING_TEST_DATA: return "No test data";
case FAIL_INVALID_TEST_DATA: return "Invalid test data";
case FAIL_ERROR_IN_CALLED_FUNC: return "cvError invoked";
case FAIL_ERROR_IN_CALLED_FUNC: return "Error invoked";
case FAIL_EXCEPTION: return "Hardware/OS exception";
case FAIL_MEMORY_EXCEPTION: return "Invalid memory access";
case FAIL_ARITHM_EXCEPTION: return "Arithmetic exception";
@@ -544,7 +542,7 @@ static int tsErrorCallback( int status, const char* func_name, const char* err_m
{
TS* ts = (TS*)data;
const char* delim = std::string(err_msg).find('\n') == std::string::npos ? "" : "\n";
ts->printf(TS::LOG, "OpenCV Error:\n\t%s (%s%s) in %s, file %s, line %d\n", cvErrorStr(status), delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
ts->printf(TS::LOG, "OpenCV Error:\n\t%d (%s%s) in %s, file %s, line %d\n", status, delim, err_msg, func_name[0] != 0 ? func_name : "unknown function", file_name, line);
return 0;
}
@@ -638,7 +636,6 @@ void TS::update_context( BaseTest* test, int test_case_idx, bool update_ts_conte
current_test_info.test = test;
current_test_info.test_case_idx = test_case_idx;
current_test_info.code = 0;
cvSetErrStatus( cv::Error::StsOk );
}