TestManyChildAllocs.cpp (2511B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /* 8 * Test that many child allocations work correctly. 9 */ 10 11 #include "gtest/gtest.h" 12 13 #include "mozilla/_ipdltest/IPDLUnitTest.h" 14 #include "mozilla/_ipdltest/PTestManyChildAllocsChild.h" 15 #include "mozilla/_ipdltest/PTestManyChildAllocsParent.h" 16 #include "mozilla/_ipdltest/PTestManyChildAllocsSubChild.h" 17 #include "mozilla/_ipdltest/PTestManyChildAllocsSubParent.h" 18 19 using namespace mozilla::ipc; 20 21 #define NALLOCS 10 22 23 namespace mozilla::_ipdltest { 24 25 class TestManyChildAllocsSubParent : public PTestManyChildAllocsSubParent { 26 NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsSubParent, override) 27 private: 28 IPCResult RecvHello() final override { return IPC_OK(); } 29 30 ~TestManyChildAllocsSubParent() = default; 31 }; 32 33 class TestManyChildAllocsSubChild : public PTestManyChildAllocsSubChild { 34 NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsSubChild, override) 35 private: 36 ~TestManyChildAllocsSubChild() = default; 37 }; 38 39 class TestManyChildAllocsParent : public PTestManyChildAllocsParent { 40 NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsParent, override) 41 private: 42 IPCResult RecvDone() final override { 43 Close(); 44 45 return IPC_OK(); 46 } 47 48 already_AddRefed<PTestManyChildAllocsSubParent> 49 AllocPTestManyChildAllocsSubParent() final override { 50 return MakeAndAddRef<TestManyChildAllocsSubParent>(); 51 } 52 53 ~TestManyChildAllocsParent() = default; 54 }; 55 56 class TestManyChildAllocsChild : public PTestManyChildAllocsChild { 57 NS_INLINE_DECL_REFCOUNTING(TestManyChildAllocsChild, override) 58 private: 59 IPCResult RecvGo() final override { 60 for (int i = 0; i < NALLOCS; ++i) { 61 auto child = MakeRefPtr<TestManyChildAllocsSubChild>(); 62 EXPECT_TRUE(SendPTestManyChildAllocsSubConstructor(child)); 63 EXPECT_TRUE(child->SendHello()) << "can't send Hello()"; 64 } 65 66 size_t len = ManagedPTestManyChildAllocsSubChild().Count(); 67 EXPECT_EQ((size_t)NALLOCS, len) 68 << "expected " << NALLOCS << " kids, got " << len; 69 70 EXPECT_TRUE(SendDone()) << "can't send Done()"; 71 72 return IPC_OK(); 73 } 74 75 ~TestManyChildAllocsChild() = default; 76 }; 77 78 IPDL_TEST(TestManyChildAllocs) { 79 EXPECT_TRUE(mActor->SendGo()) << "can't send Go()"; 80 } 81 82 } // namespace mozilla::_ipdltest