Merge pull request #26883 from MaximSmolskiy:remove-code-duplication-from-test-for-filestorage-base64

### Pull Request Readiness Checklist

OpenCV extra: https://github.com/opencv/opencv_extra/pull/1234

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Maxim Smolskiy 2025-02-08 11:23:37 +03:00 committed by GitHub
parent bf6f6d2db8
commit 48a7d8efbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -611,28 +611,20 @@ static void test_filestorage_basic(int write_flags, const char* suffix_name, boo
{ /* init */
/* a normal mat u8 */
_2d_out_u8 = cv::Mat(10, 20, CV_8UC3, cv::Scalar(1U, 2U, 127U));
for (int i = 0; i < _2d_out_u8.rows; ++i)
for (int j = 0; j < _2d_out_u8.cols; ++j)
_2d_out_u8.at<cv::Vec3b>(i, j)[1] = (i + j) % 256;
_2d_out_u8 = Mat(10, 20, CV_8UC3);
cv::randu(_2d_out_u8, 0U, 255U);
/* a normal mat u32 */
_2d_out_u32 = cv::Mat(10, 20, CV_32UC3, cv::Scalar(1U, 2U, 2147483647U));
for (int i = 0; i < _2d_out_u32.rows; ++i)
for (int j = 0; j < _2d_out_u32.cols; ++j)
_2d_out_u32.at<cv::Vec<uint, 3>>(i, j)[1] = i + j;
_2d_out_u32 = Mat(10, 20, CV_32UC3);
cv::randu(_2d_out_u32, 0U, 2147483647U);
/* a normal mat i64 */
_2d_out_i64 = cv::Mat(10, 20, CV_64SC3, cv::Scalar(1LL, 2LL, 2251799813685247LL));
for (int i = 0; i < _2d_out_i64.rows; ++i)
for (int j = 0; j < _2d_out_i64.cols; ++j)
_2d_out_i64.at<cv::Vec3l>(i, j)[1] = i + j;
_2d_out_i64 = Mat(10, 20, CV_64SC3);
cv::randu(_2d_out_i64, -2251799813685247LL, 2251799813685247LL);
/* a normal mat u64 */
_2d_out_u64 = cv::Mat(10, 20, CV_64UC3, cv::Scalar(1ULL, 2ULL, 4503599627370495ULL));
for (int i = 0; i < _2d_out_u64.rows; ++i)
for (int j = 0; j < _2d_out_u64.cols; ++j)
_2d_out_u64.at<cv::Vec<uint64_t, 3>>(i, j)[1] = i + j;
_2d_out_u64 = Mat(10, 20, CV_64UC3);
cv::randu(_2d_out_u64, 0ULL, 4503599627370495ULL);
/* a 4d mat */
const int Size[] = {4, 4, 4, 4};
@ -756,93 +748,10 @@ static void test_filestorage_basic(int write_flags, const char* suffix_name, boo
EXPECT_EQ(_em_in.depth(), _em_out.depth());
EXPECT_TRUE(_em_in.empty());
ASSERT_EQ(_2d_in_u8.rows , _2d_out_u8.rows);
ASSERT_EQ(_2d_in_u8.cols , _2d_out_u8.cols);
ASSERT_EQ(_2d_in_u8.dims , _2d_out_u8.dims);
ASSERT_EQ(_2d_in_u8.depth(), _2d_out_u8.depth());
ASSERT_EQ(_2d_in_u32.rows , _2d_out_u32.rows);
ASSERT_EQ(_2d_in_u32.cols , _2d_out_u32.cols);
ASSERT_EQ(_2d_in_u32.dims , _2d_out_u32.dims);
ASSERT_EQ(_2d_in_u32.depth(), _2d_out_u32.depth());
ASSERT_EQ(_2d_in_i64.rows , _2d_out_i64.rows);
ASSERT_EQ(_2d_in_i64.cols , _2d_out_i64.cols);
ASSERT_EQ(_2d_in_i64.dims , _2d_out_i64.dims);
ASSERT_EQ(_2d_in_i64.depth(), _2d_out_i64.depth());
ASSERT_EQ(_2d_in_u64.rows , _2d_out_u64.rows);
ASSERT_EQ(_2d_in_u64.cols , _2d_out_u64.cols);
ASSERT_EQ(_2d_in_u64.dims , _2d_out_u64.dims);
ASSERT_EQ(_2d_in_u64.depth(), _2d_out_u64.depth());
errors = 0;
for(int i = 0; i < _2d_out_u8.rows; ++i)
{
for (int j = 0; j < _2d_out_u8.cols; ++j)
{
if (_2d_in_u8.at<cv::Vec3b>(i, j) != _2d_out_u8.at<cv::Vec3b>(i, j)) {
EXPECT_EQ(_2d_in_u8.at<cv::Vec3b>(i, j), _2d_out_u8.at<cv::Vec3b>(i, j));
printf("i = %d, j = %d\n", i, j);
if (++errors >= 3)
{
i = _2d_out_u8.rows;
break;
}
}
}
}
errors = 0;
for(int i = 0; i < _2d_out_u32.rows; ++i)
{
for (int j = 0; j < _2d_out_u32.cols; ++j)
{
if (_2d_in_u32.at<cv::Vec<uint, 3>>(i, j) != _2d_out_u32.at<cv::Vec<uint, 3>>(i, j)) {
EXPECT_EQ((_2d_in_u32.at<cv::Vec<uint, 3>>(i, j)), (_2d_out_u32.at<cv::Vec<uint, 3>>(i, j)));
printf("i = %d, j = %d\n", i, j);
if (++errors >= 3)
{
i = _2d_out_u32.rows;
break;
}
}
}
}
errors = 0;
for(int i = 0; i < _2d_out_i64.rows; ++i)
{
for (int j = 0; j < _2d_out_i64.cols; ++j)
{
if (_2d_in_i64.at<cv::Vec3l>(i, j) != _2d_out_i64.at<cv::Vec3l>(i, j)) {
EXPECT_EQ(_2d_in_i64.at<cv::Vec3l>(i, j), _2d_out_i64.at<cv::Vec3l>(i, j));
printf("i = %d, j = %d\n", i, j);
if (++errors >= 3)
{
i = _2d_out_i64.rows;
break;
}
}
}
}
errors = 0;
for(int i = 0; i < _2d_out_u64.rows; ++i)
{
for (int j = 0; j < _2d_out_u64.cols; ++j)
{
if (_2d_in_u64.at<cv::Vec<uint64_t, 3>>(i, j) != _2d_out_u64.at<cv::Vec<uint64_t, 3>>(i, j)) {
EXPECT_EQ((_2d_in_u64.at<cv::Vec<uint64_t, 3>>(i, j)), (_2d_out_u64.at<cv::Vec<uint64_t, 3>>(i, j)));
printf("i = %d, j = %d\n", i, j);
if (++errors >= 3)
{
i = _2d_out_u64.rows;
break;
}
}
}
}
EXPECT_MAT_NEAR(_2d_in_u8, _2d_out_u8, 0);
EXPECT_MAT_NEAR(_2d_in_u32, _2d_out_u32, 0);
EXPECT_MAT_NEAR(_2d_in_i64, _2d_out_i64, 0);
EXPECT_MAT_NEAR(_2d_in_u64, _2d_out_u64, 0);
ASSERT_EQ(_nd_in.rows , _nd_out.rows);
ASSERT_EQ(_nd_in.cols , _nd_out.cols);