Контекст: Я пытаюсь смоделировать класс OpenCV-C ++ с помощью GMock.
Проблема:
Я не могу использовать метод EXPECT_CALL для функции, которая принимает cv :: Mat и возвращает cv :: Mat.Компилятор говорит, что gmock-matcher не может преобразовать из cv :: MatExpr в bool в ответ .
Ниже приведены подробные сообщения об ошибках во время компиляции.
In file included from /home/arun/Documents /LaneDetection/test/../vendor/googletest/googlemock/include/gmock/gmock-spec-builders.h:75:0,
from /home/arun/Documents/LaneDetection/test/../vendor/googletest/googlemock/include/gmock/gmock-generated-function-mockers.h:43,
from /home/arun/Documents/LaneDetection/test/../vendor/googletest/googlemock/include/gmock/gmock.h:61,
from /home/arun/Documents/LaneDetection/test/test.cpp:32:
/home/arun/Documents/LaneDetection/test/../vendor /googletest/googlemock/include/gmock/gmock-matchers.h: In instantiation of ‘bool
testing::internal::AnyEq::operator()(const A&, const B&) const [with A = cv::Mat; B = cv::Mat]’:
/home/arun/Documents/LaneDetection/test/../vendor/googletest/googlemock/include/gmock/gmock-matchers.h:908:18:
required from ‘bool testing::internal::ComparisonBase<D, Rhs, Op>::Impl<Lhs>::MatchAndExplain(Lhs, testing::MatchResultListener*) const [with Lhs = cv::Mat; D = testing::internal::EqMatcher<cv::Mat>; Rhs = cv::Mat; Op = testing::internal::AnyEq]’
/home/arun/Documents/LaneDetection/test/test.cpp:77:39: required from here
/home/arun/Documents/LaneDetection/test/../vendor/googletest/googlemock/include/gmock/gmock-matchers.h:204:63: error: cannot convert ‘cv::MatExpr’ to ‘bool’ in return
bool operator()(const A& a, const B& b) const { return a == b; }
^
test/CMakeFiles/cpp-test.dir/build.make:86: recipe for target 'test/CMakeFiles/cpp-test.dir/test.cpp.o' failed
make[2]: *** [test/CMakeFiles/cpp-test.dir/test.cpp.o] Error 1
CMakeFiles/Makefile2:178: recipe for target 'test/CMakeFiles/cpp-test.dir/all' failed
make[1]: *** [test/CMakeFiles/cpp-test.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Вот мой издевательский класс:
Thresholder.hpp
class Thresholder {
public:
Thresholder() {}
virtual ~Thresholder() {}
virtual cv::Mat convertToLab(cv::Mat smoothImg);
private:
cv::Mat inputImg; // < Container used for storing input image
cv::Mat labImage; // < Container for LAB converted input image
};
Thresholder.cpp
cv::Mat Thresholder::convertToLab(cv::Mat smoothImg) {
inputImg = smoothImg;
cv::cvtColor(inputImg, labImage, cv::COLOR_BGR2Lab);
return labImage;
}
test.cpp
class MockThresholder : public Thresholder {
public:
MOCK_METHOD1(convertToLab, cv::Mat(cv::Mat smoothImg));
};
/*
*@brief : Creating test cases for mock class
*/
TEST(MockTest, ThreshTest) {
MockThresholder ThreshMock;
cv::Mat dummyXY = cv::Mat::ones(100, 100, CV_8UC3);
EXPECT_CALL(ThreshMock, convertToLab(dummyXY))
.Times(1)
.WillOnce(::testing::Return(dummyXY));}
Вопрос:
Похоже, нет онлайн-ресурса, который демонстрировал бы, как эффективно использовать OpenCV и C ++ сgmock.Можно ли поделиться некоторыми демонстрациями того, как тестировать метод класса C ++, который возвращает cv :: Mat в GMock?