diff --git a/ipc/ipdl/test/cxx/Makefile.in b/ipc/ipdl/test/cxx/Makefile.in index 2d573a0d42f..3349b3563ca 100644 --- a/ipc/ipdl/test/cxx/Makefile.in +++ b/ipc/ipdl/test/cxx/Makefile.in @@ -58,6 +58,7 @@ EXPORT_LIBRARY = 1 IPDLTESTS = \ + TestManyChildAllocs \ TestSanity \ $(NULL) diff --git a/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl b/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl new file mode 100644 index 00000000000..3ebc566fc90 --- /dev/null +++ b/ipc/ipdl/test/cxx/PTestManyChildAllocs.ipdl @@ -0,0 +1,21 @@ +include protocol "PTestManyChildAllocsSub.ipdl"; + +namespace mozilla { +namespace _ipdltest { + +protocol PTestManyChildAllocs { + manages PTestManyChildAllocsSub; + +child: + Go(); // start allocating + + ~PTestManyChildAllocsSub(); + +parent: + Done(); + + PTestManyChildAllocsSub(); +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl b/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl new file mode 100644 index 00000000000..a7871bb3047 --- /dev/null +++ b/ipc/ipdl/test/cxx/PTestManyChildAllocsSub.ipdl @@ -0,0 +1,16 @@ +include protocol "PTestManyChildAllocs.ipdl"; + +namespace mozilla { +namespace _ipdltest { + +protocol PTestManyChildAllocsSub { + manager PTestManyChildAllocs; + +parent: + Hello(); + + // empty +}; + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/README.txt b/ipc/ipdl/test/cxx/README.txt index 9e4cf664760..95fe22ebfa3 100644 --- a/ipc/ipdl/test/cxx/README.txt +++ b/ipc/ipdl/test/cxx/README.txt @@ -8,6 +8,8 @@ following files (for a test "TestFoo"): - TestFoo.cpp, defining the top-level actors + - (make sure all are in the namespace mozilla::_ipdltest) + Next - add PTestFoo.ipdl to ipdl.mk diff --git a/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp b/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp new file mode 100644 index 00000000000..34049e3fba4 --- /dev/null +++ b/ipc/ipdl/test/cxx/TestManyChildAllocs.cpp @@ -0,0 +1,110 @@ +#include "TestManyChildAllocs.h" + +#include "nsIAppShell.h" + +#include "nsCOMPtr.h" +#include "nsServiceManagerUtils.h" // do_GetService() +#include "nsWidgetsCID.h" // NS_APPSHELL_CID + +#include "IPDLUnitTests.h" // fail etc. + + +#define NALLOCS 10 + +namespace mozilla { +namespace _ipdltest { + +// parent code + +TestManyChildAllocsParent::TestManyChildAllocsParent() +{ + MOZ_COUNT_CTOR(TestManyChildAllocsParent); +} + +TestManyChildAllocsParent::~TestManyChildAllocsParent() +{ + MOZ_COUNT_DTOR(TestManyChildAllocsParent); +} + +void +TestManyChildAllocsParent::Main() +{ + if (!SendGo()) + fail("can't send Go()"); +} + +bool +TestManyChildAllocsParent::RecvDone() +{ + // should clean up ... + + passed("allocs were successfuly"); + + static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); + nsCOMPtr appShell (do_GetService(kAppShellCID)); + appShell->Exit(); + + return true; +} + +bool +TestManyChildAllocsParent::DeallocPTestManyChildAllocsSub( + PTestManyChildAllocsSubParent* __a) +{ + delete __a; return true; +} + +PTestManyChildAllocsSubParent* +TestManyChildAllocsParent::AllocPTestManyChildAllocsSub() +{ + return new TestManyChildAllocsSubParent(); +} + + +// child code + +TestManyChildAllocsChild::TestManyChildAllocsChild() +{ + MOZ_COUNT_CTOR(TestManyChildAllocsChild); +} + +TestManyChildAllocsChild::~TestManyChildAllocsChild() +{ + MOZ_COUNT_DTOR(TestManyChildAllocsChild); +} + +bool TestManyChildAllocsChild::RecvGo() +{ + for (int i = 0; i < 10; ++i) { + PTestManyChildAllocsSubChild* child = + SendPTestManyChildAllocsSubConstructor(); + + if (!child) + fail("can't send ctor()"); + + if (!child->SendHello()) + fail("can't send Hello()"); + } + + if (!SendDone()) + fail("can't send Done()"); + + return true; +} + +bool +TestManyChildAllocsChild::DeallocPTestManyChildAllocsSub( + PTestManyChildAllocsSubChild* __a) +{ + delete __a; return true; +} + +PTestManyChildAllocsSubChild* +TestManyChildAllocsChild::AllocPTestManyChildAllocsSub() +{ + return new TestManyChildAllocsSubChild(); +} + + +} // namespace _ipdltest +} // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestManyChildAllocs.h b/ipc/ipdl/test/cxx/TestManyChildAllocs.h new file mode 100644 index 00000000000..c2ff39ef00d --- /dev/null +++ b/ipc/ipdl/test/cxx/TestManyChildAllocs.h @@ -0,0 +1,73 @@ +#ifndef mozilla__ipdltest_TestManyChildAllocs_h +#define mozilla__ipdltest_TestManyChildAllocs_h 1 + +#include "mozilla/_ipdltest/PTestManyChildAllocsParent.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsChild.h" + +#include "mozilla/_ipdltest/PTestManyChildAllocsSubParent.h" +#include "mozilla/_ipdltest/PTestManyChildAllocsSubChild.h" + +namespace mozilla { +namespace _ipdltest { + +// top-level protocol + +class TestManyChildAllocsParent : + public PTestManyChildAllocsParent +{ +public: + TestManyChildAllocsParent(); + virtual ~TestManyChildAllocsParent(); + + void Main(); + +protected: + virtual bool RecvDone(); + virtual bool DeallocPTestManyChildAllocsSub(PTestManyChildAllocsSubParent* __a); + virtual PTestManyChildAllocsSubParent* AllocPTestManyChildAllocsSub(); +}; + + +class TestManyChildAllocsChild : + public PTestManyChildAllocsChild +{ +public: + TestManyChildAllocsChild(); + virtual ~TestManyChildAllocsChild(); + +protected: + virtual bool RecvGo(); + virtual bool DeallocPTestManyChildAllocsSub(PTestManyChildAllocsSubChild* __a); + virtual PTestManyChildAllocsSubChild* AllocPTestManyChildAllocsSub(); +}; + + +// do-nothing sub-protocol actors + +class TestManyChildAllocsSubParent : + public PTestManyChildAllocsSubParent +{ +public: + TestManyChildAllocsSubParent() { } + virtual ~TestManyChildAllocsSubParent() { } + +protected: + virtual bool RecvHello() { return true; } +}; + + +class TestManyChildAllocsSubChild : + public PTestManyChildAllocsSubChild +{ +public: + TestManyChildAllocsSubChild() { } + virtual ~TestManyChildAllocsSubChild() { } +}; + + + +} // namepsace _ipdltest +} // namespace mozilla + + +#endif // ifndef mozilla__ipdltest_TestManyChildAllocs_h diff --git a/ipc/ipdl/test/cxx/ipdl.mk b/ipc/ipdl/test/cxx/ipdl.mk index 9948cfbbd1e..2410552727b 100644 --- a/ipc/ipdl/test/cxx/ipdl.mk +++ b/ipc/ipdl/test/cxx/ipdl.mk @@ -1,3 +1,5 @@ IPDLSRCS = \ + PTestManyChildAllocs.ipdl \ + PTestManyChildAllocsSub.ipdl \ PTestSanity.ipdl \ $(NULL)