1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "TestUniquePtrIPC.h"
7
8 namespace mozilla {
9 namespace _ipdltest {
10
11 // ---------------------------------------------------------------------------
12 // PARENT PROCESS
13 // ---------------------------------------------------------------------------
14
Main()15 void TestUniquePtrIPCParent::Main() {
16 UniquePtr<int> a1 = MakeUnique<int>(1);
17 UniquePtr<DummyStruct> a2 = MakeUnique<DummyStruct>(2);
18 DummyStruct a3(3);
19 UniquePtr<int> a4;
20
21 if (!SendTestMessage(std::move(a1), std::move(a2), a3, std::move(a4))) {
22 fail("failed sending UniquePtr items");
23 }
24
25 if (a1 || a2) {
26 fail("did not move TestMessage items in parent");
27 }
28
29 if (a4) {
30 fail("somehow turned null ptr into non-null by sending it");
31 }
32
33 // Pass UniquePtr by reference
34 UniquePtr<DummyStruct> b = MakeUnique<DummyStruct>(1);
35
36 if (!SendTestSendReference(std::move(b))) {
37 fail("failed sending UniquePtr by reference");
38 }
39 if (b) {
40 fail("did not move UniquePtr sent by reference");
41 }
42 }
43
44 // ---------------------------------------------------------------------------
45 // CHILD PROCESS
46 // ---------------------------------------------------------------------------
47
RecvTestMessage(UniquePtr<int> && aA1,UniquePtr<DummyStruct> && aA2,const DummyStruct & aA3,UniquePtr<int> && aA4)48 mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestMessage(
49 UniquePtr<int>&& aA1, UniquePtr<DummyStruct>&& aA2, const DummyStruct& aA3,
50 UniquePtr<int>&& aA4) {
51 if ((!aA1) || (!aA2)) {
52 fail("TestMessage received NULL items in child");
53 }
54
55 if (aA4) {
56 fail("TestMessage received non-NULL when expecting NULL");
57 }
58
59 if ((*aA1 != 1) || (aA2->x() != 2) || (aA3.x() != 3)) {
60 fail("TestMessage received incorrect items in child");
61 }
62
63 return IPC_OK();
64 }
65
RecvTestSendReference(UniquePtr<DummyStruct> && aA)66 mozilla::ipc::IPCResult TestUniquePtrIPCChild::RecvTestSendReference(
67 UniquePtr<DummyStruct>&& aA) {
68 if (!aA) {
69 fail("TestSendReference received NULL item in child");
70 }
71
72 if (*aA != 1) {
73 fail("TestSendReference received incorrect item in child");
74 }
75
76 Close();
77 return IPC_OK();
78 }
79
80 } // namespace _ipdltest
81 } // namespace mozilla
82