ipc/ipdl/test/cxx/TestSanity.cpp
author Kan-Ru Chen <kanru@kanru.info>
Tue, 15 Nov 2016 04:26:00 +0100
changeset 322595 39ac4382a2c019178604b90acd816753fe142908
parent 102997 a16372ce30b5f6b747246b01fcd215a4bf3b6342
child 450554 09c71a7cf75aeaf2963050e315276fb9a866fd62
permissions -rw-r--r--
Bug 1314254 - Add mozilla::ipc::IPCResult type and convert IPDL handlers to use new return type. r=billm We will use the new type for the generated IPDL message handler prototype to make sure correct error handling method is called. MozReview-Commit-ID: AzVbApxFGZ0

#include "TestSanity.h"

#include "IPDLUnitTests.h"      // fail etc.

namespace mozilla {
namespace _ipdltest {

//-----------------------------------------------------------------------------
// parent

TestSanityParent::TestSanityParent()
{
    MOZ_COUNT_CTOR(TestSanityParent);
}

TestSanityParent::~TestSanityParent()
{
    MOZ_COUNT_DTOR(TestSanityParent);
}

void
TestSanityParent::Main()
{
    if (!SendPing(0, 0.5f, 0))
        fail("sending Ping");
}


mozilla::ipc::IPCResult
TestSanityParent::RecvPong(const int& one, const float& zeroPtTwoFive,
                           const uint8_t&/*unused*/)
{
    if (1 != one)
        fail("invalid argument `%d', should have been `1'", one);

    if (0.25f != zeroPtTwoFive)
        fail("invalid argument `%g', should have been `0.25'", zeroPtTwoFive);

    Close();

    return IPC_OK();
}


//-----------------------------------------------------------------------------
// child

TestSanityChild::TestSanityChild()
{
    MOZ_COUNT_CTOR(TestSanityChild);
}

TestSanityChild::~TestSanityChild()
{
    MOZ_COUNT_DTOR(TestSanityChild);
}

mozilla::ipc::IPCResult
TestSanityChild::RecvPing(const int& zero, const float& zeroPtFive,
                          const int8_t&/*unused*/)
{
    if (0 != zero)
        fail("invalid argument `%d', should have been `0'", zero);

    if (0.5f != zeroPtFive)
        fail("invalid argument `%g', should have been `0.5'", zeroPtFive);

    if (!SendPong(1, 0.25f, 0))
        fail("sending Pong");
    return IPC_OK();
}


} // namespace _ipdltest
} // namespace mozilla