ipc/ipdl/test/cxx/TestNestedLoops.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/ipdl/test/cxx/TestNestedLoops.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +#include "base/basictypes.h"
     1.5 +
     1.6 +#include "nsThreadUtils.h"
     1.7 +
     1.8 +#include "TestNestedLoops.h"
     1.9 +
    1.10 +#include "IPDLUnitTests.h"      // fail etc.
    1.11 +
    1.12 +template<>
    1.13 +struct RunnableMethodTraits<mozilla::_ipdltest::TestNestedLoopsParent>
    1.14 +{
    1.15 +    static void RetainCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { }
    1.16 +    static void ReleaseCallee(mozilla::_ipdltest::TestNestedLoopsParent* obj) { }
    1.17 +};
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace _ipdltest {
    1.21 +
    1.22 +//-----------------------------------------------------------------------------
    1.23 +// parent
    1.24 +
    1.25 +TestNestedLoopsParent::TestNestedLoopsParent() : mBreakNestedLoop(false)
    1.26 +{
    1.27 +    MOZ_COUNT_CTOR(TestNestedLoopsParent);
    1.28 +}
    1.29 +
    1.30 +TestNestedLoopsParent::~TestNestedLoopsParent()
    1.31 +{
    1.32 +    MOZ_COUNT_DTOR(TestNestedLoopsParent);
    1.33 +}
    1.34 +
    1.35 +void
    1.36 +TestNestedLoopsParent::Main()
    1.37 +{
    1.38 +    if (!SendStart())
    1.39 +        fail("sending Start");
    1.40 +
    1.41 +    // sigh ... spin for a while to let Nonce arrive
    1.42 +    puts(" (sleeping to wait for nonce ... sorry)");
    1.43 +    PR_Sleep(5000);
    1.44 +
    1.45 +    // while waiting for the reply to R, we'll receive Nonce
    1.46 +    if (!CallR())
    1.47 +        fail("calling R");
    1.48 +
    1.49 +    Close();
    1.50 +}
    1.51 +
    1.52 +bool
    1.53 +TestNestedLoopsParent::RecvNonce()
    1.54 +{
    1.55 +    // if we have an OnMaybeDequeueOne waiting for us (we may not, due
    1.56 +    // to the inherent race condition in this test, then this event
    1.57 +    // must be ordered after it in the queue
    1.58 +    MessageLoop::current()->PostTask(
    1.59 +        FROM_HERE,
    1.60 +        NewRunnableMethod(this, &TestNestedLoopsParent::BreakNestedLoop));
    1.61 +
    1.62 +    // sigh ... spin for a while to let the reply to R arrive
    1.63 +    puts(" (sleeping to wait for reply to R ... sorry)");
    1.64 +    PR_Sleep(5000);
    1.65 +
    1.66 +    // sigh ... we have no idea when code might do this
    1.67 +    do {
    1.68 +        if (!NS_ProcessNextEvent(nullptr, false))
    1.69 +            fail("expected at least one pending event");
    1.70 +    } while (!mBreakNestedLoop);
    1.71 +
    1.72 +    return true;
    1.73 +}
    1.74 +
    1.75 +void
    1.76 +TestNestedLoopsParent::BreakNestedLoop()
    1.77 +{
    1.78 +    mBreakNestedLoop = true;
    1.79 +}
    1.80 +
    1.81 +//-----------------------------------------------------------------------------
    1.82 +// child
    1.83 +
    1.84 +TestNestedLoopsChild::TestNestedLoopsChild()
    1.85 +{
    1.86 +    MOZ_COUNT_CTOR(TestNestedLoopsChild);
    1.87 +}
    1.88 +
    1.89 +TestNestedLoopsChild::~TestNestedLoopsChild()
    1.90 +{
    1.91 +    MOZ_COUNT_DTOR(TestNestedLoopsChild);
    1.92 +}
    1.93 +
    1.94 +bool
    1.95 +TestNestedLoopsChild::RecvStart()
    1.96 +{
    1.97 +    if (!SendNonce())
    1.98 +        fail("sending Nonce");
    1.99 +    return true;
   1.100 +}
   1.101 +
   1.102 +bool
   1.103 +TestNestedLoopsChild::AnswerR()
   1.104 +{
   1.105 +    return true;
   1.106 +}
   1.107 +
   1.108 +} // namespace _ipdltest
   1.109 +} // namespace mozilla

mercurial