인터페이스에 삭제 된 copy-ctor가있는 객체를 만드는 함수가 있다면이 함수를 모의하는 방법은 무엇입니까? Gmock은 개체의 복사 생성자를 내부적으로 사용하는 것으로 보입니다.모의 메소드는 삭제 된 copy-ctor가있는 객체를 반환합니까?
예.
// The object with deleted copy-ctor and copy-assignment
class TTest
{
public:
TTest() = delete;
TTest(const TTest&) = delete;
TTest& operator=(const TTest&) = delete;
TTest(TTest&&) = default;
TTest& operator=(TTest&&) = default;
explicit TTest(int) {
}
};
// My interface to mock
class MyInterface
{
public:
virtual ~MyInterface() {}
virtual TTest GetUniqueTest() = 0;
};
// The mock
class MockMyInterface: public MyInterface{
public:
MOCK_METHOD0(GetUniqueTest, TTest());
}
컴파일 오류가 말한다 :이 방법은 std::unique_ptr<T>
을 반환
gmock/gmock-spec-builders.h:1330:20: error: use of deleted function 'TTest::TTest(const TTest&)'
T retval(value_);
...
gmock/gmock-actions.h:190:52: error: use of deleted function 'TTest::TTest(const TTest&)'
internal::BuiltInDefaultValue<T>::Get() : *value_;
...
gmock/internal/gmock-internal-utils.h:371:71: error: use of deleted function 'TTest::TTest(const TTest&)'
*static_cast<volatile typename remove_reference<T>::type*>(NULL));
경우 std::unique_ptr<T>
뿐만 아니라 복사의 ctor를 삭제 한 이후, 오류가 동일합니다.
내 질문은 : 어떻게 삭제 된 복사 - ctors와 함께 개체를 반환 같은 방법 모의?
저는 googletest v1.7, GCC 5.3.0 및 Ubuntu 14.04.1을 사용하고 있습니다.
멋진 대답은, 그것을 잘 작동합니다! – Mine
Google 테스트 ** 1이 나에게 온다.8 **는 이러한 기능 조롱을 지원합니다. https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#mocking-methods-that-use-move-only-types googletest v1.8로 업데이트하는 것이 좋습니다. – Mine
@Mine 예, 나도 나중에 발견했는데 확인할 시간이 없었습니다 :) 아마도 당신이 자기 결정을 할 수 있다고 확신 할 때) – BartoszKP