From 9e3c08db40b8916968b9f30096c7be3f00ce9647 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:44:51 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp (limited to 'ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp') diff --git a/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp b/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp new file mode 100644 index 0000000000..7d0e8dd6ca --- /dev/null +++ b/ipc/ipdl/test/cxx/TestUniquePtrIPC.cpp @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "TestUniquePtrIPC.h" + +namespace mozilla { +namespace _ipdltest { + +// --------------------------------------------------------------------------- +// PARENT PROCESS +// --------------------------------------------------------------------------- + +void TestUniquePtrIPCParent::Main() { + UniquePtr a1 = MakeUnique(1); + UniquePtr a2 = MakeUnique(2); + DummyStruct a3(3); + UniquePtr a4; + + if (!SendTestMessage(std::move(a1), std::move(a2), a3, std::move(a4))) { + fail("failed sending UniquePtr items"); + } + + if (a1 || a2) { + fail("did not move TestMessage items in parent"); + } + + if (a4) { + fail("somehow turned null ptr into non-null by sending it"); + } + + // Pass UniquePtr by reference + UniquePtr b = MakeUnique(1); + + if (!SendTestSendReference(std::move(b))) { + fail("failed sending UniquePtr by reference"); + } + if (b) { + fail("did not move UniquePtr sent by reference"); + } +} + +// --------------------------------------------------------------------------- +// CHILD PROCESS +// --------------------------------------------------------------------------- + +mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestMessage( + UniquePtr&& aA1, UniquePtr&& aA2, const DummyStruct& aA3, + UniquePtr&& aA4) { + if ((!aA1) || (!aA2)) { + fail("TestMessage received NULL items in child"); + } + + if (aA4) { + fail("TestMessage received non-NULL when expecting NULL"); + } + + if ((*aA1 != 1) || (aA2->x() != 2) || (aA3.x() != 3)) { + fail("TestMessage received incorrect items in child"); + } + + return IPC_OK(); +} + +mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestSendReference( + UniquePtr&& aA) { + if (!aA) { + fail("TestSendReference received NULL item in child"); + } + + if (*aA != 1) { + fail("TestSendReference received incorrect item in child"); + } + + Close(); + return IPC_OK(); +} + +} // namespace _ipdltest +} // namespace mozilla -- cgit v1.2.3