From 8c4b5b6a70c97614460dd069496e30dad7f2414e Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 28 Mar 2018 15:51:07 +0300 Subject: [PATCH] core(test): parallel_for test with exception --- modules/core/test/test_misc.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index 4c120c9ef3..3f62ed199d 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -157,4 +157,36 @@ TEST(Core_Copy, repeat_regression_8972) }); } + +class ThrowErrorParallelLoopBody : public cv::ParallelLoopBody +{ +public: + ThrowErrorParallelLoopBody(cv::Mat& dst, int i) : dst_(dst), i_(i) {} + ~ThrowErrorParallelLoopBody() {} + void operator()(const cv::Range& r) const + { + for (int i = r.start; i < r.end; i++) + { + CV_Assert(i != i_); + dst_.row(i).setTo(1); + } + } +protected: + Mat dst_; + int i_; +}; + +TEST(Core_Parallel, propagate_exceptions) +{ + Mat dst1(1000, 100, CV_8SC1, Scalar::all(0)); + ASSERT_NO_THROW({ + parallel_for_(cv::Range(0, dst1.rows), ThrowErrorParallelLoopBody(dst1, -1)); + }); + + Mat dst2(1000, 100, CV_8SC1, Scalar::all(0)); + ASSERT_THROW({ + parallel_for_(cv::Range(0, dst2.rows), ThrowErrorParallelLoopBody(dst2, dst2.rows / 2)); + }, cv::Exception); +} + }} // namespace