4

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

// 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ですか?

4

1 に答える 1

4

次のようなものを試すことができます:

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);
于 2012-02-22T22:44:54.667 に答える