summaryrefslogtreecommitdiffstats
path: root/ipc/ipdl/test/cxx/TestMultiMgrs.cpp
blob: 422b3fea338f31e72fc3fcdefdc91785bdd8dc2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "TestMultiMgrs.h"

#include "IPDLUnitTests.h"      // fail etc.
#include "mozilla/ipc/ProtocolUtils.h"

namespace mozilla {
namespace _ipdltest {

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

void
TestMultiMgrsParent::Main()
{
    TestMultiMgrsLeftParent* leftie = new TestMultiMgrsLeftParent();
    if (!SendPTestMultiMgrsLeftConstructor(leftie))
        fail("error sending ctor");

    TestMultiMgrsRightParent* rightie = new TestMultiMgrsRightParent();
    if (!SendPTestMultiMgrsRightConstructor(rightie))
        fail("error sending ctor");

    TestMultiMgrsBottomParent* bottomL = new TestMultiMgrsBottomParent();
    if (!leftie->SendPTestMultiMgrsBottomConstructor(bottomL))
        fail("error sending ctor");

    TestMultiMgrsBottomParent* bottomR = new TestMultiMgrsBottomParent();
    if (!rightie->SendPTestMultiMgrsBottomConstructor(bottomR))
        fail("error sending ctor");

    if (!leftie->HasChild(bottomL))
        fail("leftie didn't have a child it was supposed to!");
    if (leftie->HasChild(bottomR))
        fail("leftie had rightie's child!");

    if (!rightie->HasChild(bottomR))
        fail("rightie didn't have a child it was supposed to!");
    if (rightie->HasChild(bottomL))
        fail("rightie had rightie's child!");

    if (!SendCheck())
        fail("couldn't kick off the child-side check");
}

bool
TestMultiMgrsParent::RecvOK()
{
    Close();
    return true;
}

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

bool
TestMultiMgrsLeftChild::RecvPTestMultiMgrsBottomConstructor(
    PTestMultiMgrsBottomChild* actor)
{
    static_cast<TestMultiMgrsChild*>(Manager())->mBottomL = actor;
    return true;
}

bool
TestMultiMgrsRightChild::RecvPTestMultiMgrsBottomConstructor(
    PTestMultiMgrsBottomChild* actor)
{
    static_cast<TestMultiMgrsChild*>(Manager())->mBottomR = actor;
    return true;
}

bool
TestMultiMgrsChild::RecvCheck()
{
    if (1 != ManagedPTestMultiMgrsLeftChild().Count())
        fail("where's leftie?");
    if (1 != ManagedPTestMultiMgrsRightChild().Count())
        fail("where's rightie?");

    TestMultiMgrsLeftChild* leftie =
        static_cast<TestMultiMgrsLeftChild*>(
            LoneManagedOrNullAsserts(ManagedPTestMultiMgrsLeftChild()));
    TestMultiMgrsRightChild* rightie =
        static_cast<TestMultiMgrsRightChild*>(
            LoneManagedOrNullAsserts(ManagedPTestMultiMgrsRightChild()));

    if (!leftie->HasChild(mBottomL))
        fail("leftie didn't have a child it was supposed to!");
    if (leftie->HasChild(mBottomR))
        fail("leftie had rightie's child!");

    if (!rightie->HasChild(mBottomR))
        fail("rightie didn't have a child it was supposed to!");
    if (rightie->HasChild(mBottomL))
        fail("rightie had leftie's child!");

    if (!SendOK())
        fail("couldn't send OK()");

    return true;
}


} // namespace _ipdltest
} // namespace mozilla