質問

適切な引数で、クラスがモックされたクラスでメソッドを呼び出すかどうかをテストしています。私は基本的な期待を設定しました:

// mListener is a mocked object
// This expectation accepts any argument
EXPECT_CALL(this->mListener, OnChanged(_))
    .Times(1);

これは問題ありませんが、議論を確認したいと思います。これは、出力パラメーターを使用するアクセサーのみを持っているオブジェクトです。

// aValue is an output parameter
HRESULT get_Value(int* aValue);

値を検査するマッチャーを定義するにはどうすればよいですか get_Value 入力します aValue?

役に立ちましたか?

解決

あなたは次のようなことを試すことができます:

MATCHER_P(CheckValue,
          expected_value,
          std::string("get_Value ")
              + (negation ? "yields " : "doesn't yield ")
              + PrintToString(expected_value)
              + " as expected.") {
  int result;
  arg.get_Value(&result);
  return expected_value == result;
}

それはそれをチェックすることができます aValue == 7 することによって:

EXPECT_CALL(this->mListener, OnChanged(CheckValue(7)))
    .Times(1);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top