どのように模擬分子を鋳型とした方法です模擬?
-
26-09-2019 - |
質問
うことにより模擬、鋳型法です。
このクラスを含む方法を模擬:
class myClass
{
public:
virtual ~myClass() {}
template<typename T>
void myMethod(T param);
}
たいのですが模擬方法のmyMethod用模擬?
解決
旧バージョンのGoogleの模擬できる模擬仮想機能には、 文書 プロジェクトのページです。
最近のバージョンを許して模擬 非仮想方法, を使っていうの こんにちは-ケ依存性射出.
として congusbongus
状態:
Googleの模擬に依存して追加メンバ変数への支援方法を嘲笑うからできませんの作成テンプレート変数の委員は難模擬テンプレート機能
回避策、マハリントンのgooglegroupsのリンクからのコメントするのは、専門のテンプレート法と呼正常に機能できる(*_*)正.な解決に一般の場合でも動作試験をします。
struct Foo
{
MOCK_METHOD1(GetValueString, void(std::string& value));
template <typename ValueType>
void GetValue(ValueType& value);
template <>
void GetValue(std::string& value) {
GetValueString(value);
}
};
他のヒント
ここではオリジナルのポストは、理解を助けるためにコメントして再びます:
struct Foo
{
// Our own mocked method that the templated call will end up calling.
MOCK_METHOD3(GetNextValueStdString, void(const std::string& name, std::string& value, const unsigned int streamIndex));
// If we see any calls with these two parameter list types throw and error as its unexpected in the unit under test.
template< typename ValueType >
void GetNextValue( const std::string& name, ValueType& value, const unsigned int streamIndex )
{
throw "Unexpected call.";
}
template< typename ValueType >
void GetNextValue( const std::string& name, ValueType& value )
{
throw "Unexpected call.";
}
// These are the only two templated calls expected, notice the difference in the method parameter list. Anything outside
// of these two flavors is considerd an error.
template<>
void GetNextValue< std::string >( const std::string& name, std::string& value, const unsigned int streamIndex )
{
GetNextValueStdString( name, value, streamIndex );
}
template<>
void GetNextValue< std::string >( const std::string& name, std::string& value )
{
GetNextValue< std::string >( name, value, 0 );
}
};
所属していません StackOverflow