J'ai eu EXPECT_CALL
en passant sur mes tests, jusqu'à ce que j'ajoute un en-tête pour envelopper le unsigned char *
je testais. Je comprends que le test tombe, car ce n'est pas le même unsigned char *
que prévu. Je ne suis pas sûr de savoir comment redessiner mes tests, donc le unsigned char *
assigné à fait passer le test.Comment résoudre l'échec gmock EXPECT_CALL, lorsque la variable passée à la fonction n'a pas d'importance
Mon test (avec initialisation des variables à l'écart):
EXPECT_CALL(networkConnectionMock, Transmit(packetData, dataSize));
packetManager.Update(0.01f);
packetManager.Send(packetData, dataSize);
La fonction en cours de test:
void PacketManager::Send(unsigned char *packetData, int packetSize)
{
if(this->secondSinceLastUpdate <= 1.0f)
packetsSent++;
else
{
packetsSent = 0;
this->secondSinceLastUpdate = 0.0f;
}
std::stringstream convert;
convert << htonl((uint32_t)packetSize);
Header *header = new Header;
header->name = "PKT_" + convert.str();
header->packetSize = packetSize;
header->packetData = packetData;
unsigned char * pktHeader = new unsigned char[sizeof(Header)];
pktHeader = (unsigned char*)header;
PKT_Header = pktHeader; // tried assigning to public variable,
// but would be assigned to after EXPECT_CALL is setup.
int totalPacketSize = packetSize; // rewrite to loop through que
if(header->packetSize <= 800 && totalPacketSize <= 1024 && packetsSent <= 30)
networkConnection->Transmit(pktHeader, packetSize);
}
sortie gmock:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from PacketManager
[ RUN ] PacketManager.SendsPacketsUnder1024
unknown file: Failure
Unexpected mock function call - returning directly.
Function call: Transmit(0x2096c10, 100)
Google Mock tried the following 1 expectation, but it didn't match:
/home/zerophase/ClionProjects/PacketManager/tests/basic_tests/basic_check.cpp:20: EXPECT_CALL(networkConnectionMock, Transmit(packetData, dataSize))...
Expected arg #0: is equal to 0x2096560
Actual: 0x2096c10
Expected: to be called once
Actual: never called - unsatisfied and active
/home/zerophase/ClionProjects/PacketManager/tests/basic_tests/basic_check.cpp:20: Failure
Actual function call count doesn't match EXPECT_CALL(networkConnectionMock, Transmit(packetData, dataSize))...
Expected: to be called once
Actual: never called - unsatisfied and active
[ FAILED ] PacketManager.SendsPacketsUnder1024 (0 ms)
[----------] 1 test from PacketManager (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] PacketManager.SendsPacketsUnder1024
Est-EXPECT_CALL encore ce que je veux utiliser pour tester Transmit
étant appelé?
Veuillez inclure la sortie appropriée de google mock. –
@ AntonioPérez J'ai ajouté la sortie gmock. – ZeroPhase