Domanda

Sto testando se la mia classe chiama un metodo in una classe derisa, con l'argomento corretto. Ho impostato un'aspettativa di base:

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

Questo va bene, ma voglio anche verificare l'argomento. È un oggetto che ha solo accessori che utilizzano i parametri di output:

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

Come posso definire un matcher che ispezionerà il valore che get_Value mette in aValue?

È stato utile?

Soluzione

Potresti provare qualcosa come:

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

che potrebbe verificare che EG aValue == 7 facendo:

EXPECT_CALL(this->mListener, OnChanged(CheckValue(7)))
    .Times(1);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top