gecko/ipc/ipdl/test/cxx/TestRacyRPCReplies.cpp
Chris Jones 6345658b6f Bug 521929, part 3: IPDL/C++ test.
--HG--
extra : transplant_source : %9E%82%3E%20E%81J%97r%CD%05%93%FC%E0%9C%877P%DF%EE
2010-01-21 20:04:11 -06:00

79 lines
1.6 KiB
C++

#include "TestRacyRPCReplies.h"
#include "IPDLUnitTests.h" // fail etc.
namespace mozilla {
namespace _ipdltest {
//-----------------------------------------------------------------------------
// parent
TestRacyRPCRepliesParent::TestRacyRPCRepliesParent()
{
MOZ_COUNT_CTOR(TestRacyRPCRepliesParent);
}
TestRacyRPCRepliesParent::~TestRacyRPCRepliesParent()
{
MOZ_COUNT_DTOR(TestRacyRPCRepliesParent);
}
void
TestRacyRPCRepliesParent::Main()
{
int replyNum = -1;
if (!CallR(&replyNum))
fail("calling R()");
if (1 != replyNum)
fail("this should have been the first reply to R()");
Close();
}
bool
TestRacyRPCRepliesParent::RecvA()
{
int replyNum = -1;
// this R() call races with the reply being generated by the other
// side to the R() call from Main(). This is a pretty nasty edge
// case for which one could argue we're breaking in-order message
// delivery, since this side will process the second reply to R()
// before the first.
if (!CallR(&replyNum))
fail("calling R()");
if (2 != replyNum)
fail("this should have been the second reply to R()");
return true;
}
//-----------------------------------------------------------------------------
// child
TestRacyRPCRepliesChild::TestRacyRPCRepliesChild() : mReplyNum(0)
{
MOZ_COUNT_CTOR(TestRacyRPCRepliesChild);
}
TestRacyRPCRepliesChild::~TestRacyRPCRepliesChild()
{
MOZ_COUNT_DTOR(TestRacyRPCRepliesChild);
}
bool
TestRacyRPCRepliesChild::AnswerR(int* replyNum)
{
*replyNum = ++mReplyNum;
if (1 == *replyNum)
SendA();
return true;
}
} // namespace _ipdltest
} // namespace mozilla