2012-02-22 2 views
3

내 클래스가 적절한 인수를 사용하여 조롱 된 클래스에서 메소드를 호출하는지 테스트하고 있습니다. 기본 기대치를 설정했습니다 :출력 매개 변수에 대한 googlemock matcher

// 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_ValueaValue에두고 그 값을 검사하는 정규 표현을 정의 할 수 있습니다 ?

답변

3

당신은 같은 것을 시도해 볼 수도 있습니다 : 것을 확인할 수 있습니다

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; 
} 

를 예를 들면,

EXPECT_CALL(this->mListener, OnChanged(CheckValue(7))) 
    .Times(1); 
+0

완벽하게, 감사합니다! googlemock 요리 책 페이지에는 맞춤 matchers에 대한 정보가 있습니다. http://code.google.com/p/googlemock/wiki/CookBook#Writing_New_Parameterized_Matchers_Quickly –

+0

또한 맞춤 테스트 코드를 추가하여 테스트에 실패하면 일부 숫자가 표시됩니다. 내 개체의 처음 몇 바이트. http://code.google.com/p/googletest/wiki/AdvancedGuide#Teaching_Google_Test_How_to_Print_Your_Values –

관련 문제