1/*
2 * Copyright (C) 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <string>
18
19#include <android-base/stringprintf.h>
20#include <gtest/gtest.h>
21
22#include "aidl.h"
23#include "aidl_language.h"
24#include "ast_cpp.h"
25#include "code_writer.h"
26#include "generate_cpp.h"
27#include "os.h"
28#include "tests/fake_io_delegate.h"
29#include "tests/test_util.h"
30#include "type_cpp.h"
31
32using ::android::aidl::test::FakeIoDelegate;
33using ::android::base::StringPrintf;
34using std::string;
35using std::unique_ptr;
36
37namespace android {
38namespace aidl {
39namespace cpp {
40namespace {
41
42const string kComplexTypeInterfaceAIDL =
43R"(package android.os;
44import foo.IFooType;
45interface IComplexTypeInterface {
46  const int MY_CONSTANT = 3;
47  int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
48  oneway void Piff(int times);
49  IFooType TakesABinder(IFooType f);
50  @nullable IFooType NullableBinder();
51  List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
52  List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
53  FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
54  FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
55})";
56
57const char kExpectedComplexTypeClientHeaderOutput[] =
58R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
59#define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
60
61#include <binder/IBinder.h>
62#include <binder/IInterface.h>
63#include <utils/Errors.h>
64#include <android/os/IComplexTypeInterface.h>
65
66namespace android {
67
68namespace os {
69
70class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
71public:
72explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
73virtual ~BpComplexTypeInterface() = default;
74::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) override;
75::android::binder::Status Piff(int32_t times) override;
76::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
77::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
78::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
79::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) override;
80::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) override;
81::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
82};  // class BpComplexTypeInterface
83
84}  // namespace os
85
86}  // namespace android
87
88#endif  // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
89)";
90
91const char kExpectedComplexTypeClientSourceOutput[] =
92R"(#include <android/os/BpComplexTypeInterface.h>
93#include <binder/Parcel.h>
94
95namespace android {
96
97namespace os {
98
99BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
100    : BpInterface<IComplexTypeInterface>(_aidl_impl){
101}
102
103::android::binder::Status BpComplexTypeInterface::Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
104::android::Parcel _aidl_data;
105::android::Parcel _aidl_reply;
106::android::status_t _aidl_ret_status = ::android::OK;
107::android::binder::Status _aidl_status;
108_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
109if (((_aidl_ret_status) != (::android::OK))) {
110goto _aidl_error;
111}
112_aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
113if (((_aidl_ret_status) != (::android::OK))) {
114goto _aidl_error;
115}
116_aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
117if (((_aidl_ret_status) != (::android::OK))) {
118goto _aidl_error;
119}
120_aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
121if (((_aidl_ret_status) != (::android::OK))) {
122goto _aidl_error;
123}
124_aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply);
125if (((_aidl_ret_status) != (::android::OK))) {
126goto _aidl_error;
127}
128_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
129if (((_aidl_ret_status) != (::android::OK))) {
130goto _aidl_error;
131}
132if (!_aidl_status.isOk()) {
133return _aidl_status;
134}
135_aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
136if (((_aidl_ret_status) != (::android::OK))) {
137goto _aidl_error;
138}
139_aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
140if (((_aidl_ret_status) != (::android::OK))) {
141goto _aidl_error;
142}
143_aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
144if (((_aidl_ret_status) != (::android::OK))) {
145goto _aidl_error;
146}
147_aidl_error:
148_aidl_status.setFromStatusT(_aidl_ret_status);
149return _aidl_status;
150}
151
152::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
153::android::Parcel _aidl_data;
154::android::Parcel _aidl_reply;
155::android::status_t _aidl_ret_status = ::android::OK;
156::android::binder::Status _aidl_status;
157_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
158if (((_aidl_ret_status) != (::android::OK))) {
159goto _aidl_error;
160}
161_aidl_ret_status = _aidl_data.writeInt32(times);
162if (((_aidl_ret_status) != (::android::OK))) {
163goto _aidl_error;
164}
165_aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
166if (((_aidl_ret_status) != (::android::OK))) {
167goto _aidl_error;
168}
169_aidl_error:
170_aidl_status.setFromStatusT(_aidl_ret_status);
171return _aidl_status;
172}
173
174::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
175::android::Parcel _aidl_data;
176::android::Parcel _aidl_reply;
177::android::status_t _aidl_ret_status = ::android::OK;
178::android::binder::Status _aidl_status;
179_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
180if (((_aidl_ret_status) != (::android::OK))) {
181goto _aidl_error;
182}
183_aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
184if (((_aidl_ret_status) != (::android::OK))) {
185goto _aidl_error;
186}
187_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply);
188if (((_aidl_ret_status) != (::android::OK))) {
189goto _aidl_error;
190}
191_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
192if (((_aidl_ret_status) != (::android::OK))) {
193goto _aidl_error;
194}
195if (!_aidl_status.isOk()) {
196return _aidl_status;
197}
198_aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
199if (((_aidl_ret_status) != (::android::OK))) {
200goto _aidl_error;
201}
202_aidl_error:
203_aidl_status.setFromStatusT(_aidl_ret_status);
204return _aidl_status;
205}
206
207::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
208::android::Parcel _aidl_data;
209::android::Parcel _aidl_reply;
210::android::status_t _aidl_ret_status = ::android::OK;
211::android::binder::Status _aidl_status;
212_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
213if (((_aidl_ret_status) != (::android::OK))) {
214goto _aidl_error;
215}
216_aidl_ret_status = remote()->transact(IComplexTypeInterface::NULLABLEBINDER, _aidl_data, &_aidl_reply);
217if (((_aidl_ret_status) != (::android::OK))) {
218goto _aidl_error;
219}
220_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
221if (((_aidl_ret_status) != (::android::OK))) {
222goto _aidl_error;
223}
224if (!_aidl_status.isOk()) {
225return _aidl_status;
226}
227_aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
228if (((_aidl_ret_status) != (::android::OK))) {
229goto _aidl_error;
230}
231_aidl_error:
232_aidl_status.setFromStatusT(_aidl_ret_status);
233return _aidl_status;
234}
235
236::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
237::android::Parcel _aidl_data;
238::android::Parcel _aidl_reply;
239::android::status_t _aidl_ret_status = ::android::OK;
240::android::binder::Status _aidl_status;
241_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
242if (((_aidl_ret_status) != (::android::OK))) {
243goto _aidl_error;
244}
245_aidl_ret_status = _aidl_data.writeString16Vector(input);
246if (((_aidl_ret_status) != (::android::OK))) {
247goto _aidl_error;
248}
249_aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply);
250if (((_aidl_ret_status) != (::android::OK))) {
251goto _aidl_error;
252}
253_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
254if (((_aidl_ret_status) != (::android::OK))) {
255goto _aidl_error;
256}
257if (!_aidl_status.isOk()) {
258return _aidl_status;
259}
260_aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
261if (((_aidl_ret_status) != (::android::OK))) {
262goto _aidl_error;
263}
264_aidl_ret_status = _aidl_reply.readString16Vector(output);
265if (((_aidl_ret_status) != (::android::OK))) {
266goto _aidl_error;
267}
268_aidl_error:
269_aidl_status.setFromStatusT(_aidl_ret_status);
270return _aidl_status;
271}
272
273::android::binder::Status BpComplexTypeInterface::BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) {
274::android::Parcel _aidl_data;
275::android::Parcel _aidl_reply;
276::android::status_t _aidl_ret_status = ::android::OK;
277::android::binder::Status _aidl_status;
278_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
279if (((_aidl_ret_status) != (::android::OK))) {
280goto _aidl_error;
281}
282_aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
283if (((_aidl_ret_status) != (::android::OK))) {
284goto _aidl_error;
285}
286_aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply);
287if (((_aidl_ret_status) != (::android::OK))) {
288goto _aidl_error;
289}
290_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
291if (((_aidl_ret_status) != (::android::OK))) {
292goto _aidl_error;
293}
294if (!_aidl_status.isOk()) {
295return _aidl_status;
296}
297_aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
298if (((_aidl_ret_status) != (::android::OK))) {
299goto _aidl_error;
300}
301_aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
302if (((_aidl_ret_status) != (::android::OK))) {
303goto _aidl_error;
304}
305_aidl_error:
306_aidl_status.setFromStatusT(_aidl_ret_status);
307return _aidl_status;
308}
309
310::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) {
311::android::Parcel _aidl_data;
312::android::Parcel _aidl_reply;
313::android::status_t _aidl_ret_status = ::android::OK;
314::android::binder::Status _aidl_status;
315_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
316if (((_aidl_ret_status) != (::android::OK))) {
317goto _aidl_error;
318}
319_aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
320if (((_aidl_ret_status) != (::android::OK))) {
321goto _aidl_error;
322}
323_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply);
324if (((_aidl_ret_status) != (::android::OK))) {
325goto _aidl_error;
326}
327_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
328if (((_aidl_ret_status) != (::android::OK))) {
329goto _aidl_error;
330}
331if (!_aidl_status.isOk()) {
332return _aidl_status;
333}
334_aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
335if (((_aidl_ret_status) != (::android::OK))) {
336goto _aidl_error;
337}
338_aidl_error:
339_aidl_status.setFromStatusT(_aidl_ret_status);
340return _aidl_status;
341}
342
343::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
344::android::Parcel _aidl_data;
345::android::Parcel _aidl_reply;
346::android::status_t _aidl_ret_status = ::android::OK;
347::android::binder::Status _aidl_status;
348_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
349if (((_aidl_ret_status) != (::android::OK))) {
350goto _aidl_error;
351}
352_aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
353if (((_aidl_ret_status) != (::android::OK))) {
354goto _aidl_error;
355}
356_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply);
357if (((_aidl_ret_status) != (::android::OK))) {
358goto _aidl_error;
359}
360_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
361if (((_aidl_ret_status) != (::android::OK))) {
362goto _aidl_error;
363}
364if (!_aidl_status.isOk()) {
365return _aidl_status;
366}
367_aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
368if (((_aidl_ret_status) != (::android::OK))) {
369goto _aidl_error;
370}
371_aidl_error:
372_aidl_status.setFromStatusT(_aidl_ret_status);
373return _aidl_status;
374}
375
376}  // namespace os
377
378}  // namespace android
379)";
380
381const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
382R"(#include <android/os/BpComplexTypeInterface.h>
383#include <binder/Parcel.h>
384
385namespace android {
386
387namespace os {
388
389BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
390    : BpInterface<IComplexTypeInterface>(_aidl_impl){
391}
392
393::android::binder::Status BpComplexTypeInterface::Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
394::android::Parcel _aidl_data;
395::android::Parcel _aidl_reply;
396::android::status_t _aidl_ret_status = ::android::OK;
397::android::binder::Status _aidl_status;
398ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppClient");
399_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
400if (((_aidl_ret_status) != (::android::OK))) {
401goto _aidl_error;
402}
403_aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
404if (((_aidl_ret_status) != (::android::OK))) {
405goto _aidl_error;
406}
407_aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
408if (((_aidl_ret_status) != (::android::OK))) {
409goto _aidl_error;
410}
411_aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
412if (((_aidl_ret_status) != (::android::OK))) {
413goto _aidl_error;
414}
415_aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply);
416if (((_aidl_ret_status) != (::android::OK))) {
417goto _aidl_error;
418}
419_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
420if (((_aidl_ret_status) != (::android::OK))) {
421goto _aidl_error;
422}
423if (!_aidl_status.isOk()) {
424return _aidl_status;
425}
426_aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
427if (((_aidl_ret_status) != (::android::OK))) {
428goto _aidl_error;
429}
430_aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
431if (((_aidl_ret_status) != (::android::OK))) {
432goto _aidl_error;
433}
434_aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
435if (((_aidl_ret_status) != (::android::OK))) {
436goto _aidl_error;
437}
438_aidl_error:
439_aidl_status.setFromStatusT(_aidl_ret_status);
440return _aidl_status;
441}
442
443::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
444::android::Parcel _aidl_data;
445::android::Parcel _aidl_reply;
446::android::status_t _aidl_ret_status = ::android::OK;
447::android::binder::Status _aidl_status;
448ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppClient");
449_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
450if (((_aidl_ret_status) != (::android::OK))) {
451goto _aidl_error;
452}
453_aidl_ret_status = _aidl_data.writeInt32(times);
454if (((_aidl_ret_status) != (::android::OK))) {
455goto _aidl_error;
456}
457_aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
458if (((_aidl_ret_status) != (::android::OK))) {
459goto _aidl_error;
460}
461_aidl_error:
462_aidl_status.setFromStatusT(_aidl_ret_status);
463return _aidl_status;
464}
465
466::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
467::android::Parcel _aidl_data;
468::android::Parcel _aidl_reply;
469::android::status_t _aidl_ret_status = ::android::OK;
470::android::binder::Status _aidl_status;
471ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppClient");
472_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
473if (((_aidl_ret_status) != (::android::OK))) {
474goto _aidl_error;
475}
476_aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
477if (((_aidl_ret_status) != (::android::OK))) {
478goto _aidl_error;
479}
480_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply);
481if (((_aidl_ret_status) != (::android::OK))) {
482goto _aidl_error;
483}
484_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
485if (((_aidl_ret_status) != (::android::OK))) {
486goto _aidl_error;
487}
488if (!_aidl_status.isOk()) {
489return _aidl_status;
490}
491_aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
492if (((_aidl_ret_status) != (::android::OK))) {
493goto _aidl_error;
494}
495_aidl_error:
496_aidl_status.setFromStatusT(_aidl_ret_status);
497return _aidl_status;
498}
499
500::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
501::android::Parcel _aidl_data;
502::android::Parcel _aidl_reply;
503::android::status_t _aidl_ret_status = ::android::OK;
504::android::binder::Status _aidl_status;
505ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppClient");
506_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
507if (((_aidl_ret_status) != (::android::OK))) {
508goto _aidl_error;
509}
510_aidl_ret_status = remote()->transact(IComplexTypeInterface::NULLABLEBINDER, _aidl_data, &_aidl_reply);
511if (((_aidl_ret_status) != (::android::OK))) {
512goto _aidl_error;
513}
514_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
515if (((_aidl_ret_status) != (::android::OK))) {
516goto _aidl_error;
517}
518if (!_aidl_status.isOk()) {
519return _aidl_status;
520}
521_aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
522if (((_aidl_ret_status) != (::android::OK))) {
523goto _aidl_error;
524}
525_aidl_error:
526_aidl_status.setFromStatusT(_aidl_ret_status);
527return _aidl_status;
528}
529
530::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
531::android::Parcel _aidl_data;
532::android::Parcel _aidl_reply;
533::android::status_t _aidl_ret_status = ::android::OK;
534::android::binder::Status _aidl_status;
535ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppClient");
536_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
537if (((_aidl_ret_status) != (::android::OK))) {
538goto _aidl_error;
539}
540_aidl_ret_status = _aidl_data.writeString16Vector(input);
541if (((_aidl_ret_status) != (::android::OK))) {
542goto _aidl_error;
543}
544_aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply);
545if (((_aidl_ret_status) != (::android::OK))) {
546goto _aidl_error;
547}
548_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
549if (((_aidl_ret_status) != (::android::OK))) {
550goto _aidl_error;
551}
552if (!_aidl_status.isOk()) {
553return _aidl_status;
554}
555_aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
556if (((_aidl_ret_status) != (::android::OK))) {
557goto _aidl_error;
558}
559_aidl_ret_status = _aidl_reply.readString16Vector(output);
560if (((_aidl_ret_status) != (::android::OK))) {
561goto _aidl_error;
562}
563_aidl_error:
564_aidl_status.setFromStatusT(_aidl_ret_status);
565return _aidl_status;
566}
567
568::android::binder::Status BpComplexTypeInterface::BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) {
569::android::Parcel _aidl_data;
570::android::Parcel _aidl_reply;
571::android::status_t _aidl_ret_status = ::android::OK;
572::android::binder::Status _aidl_status;
573ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppClient");
574_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
575if (((_aidl_ret_status) != (::android::OK))) {
576goto _aidl_error;
577}
578_aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
579if (((_aidl_ret_status) != (::android::OK))) {
580goto _aidl_error;
581}
582_aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply);
583if (((_aidl_ret_status) != (::android::OK))) {
584goto _aidl_error;
585}
586_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
587if (((_aidl_ret_status) != (::android::OK))) {
588goto _aidl_error;
589}
590if (!_aidl_status.isOk()) {
591return _aidl_status;
592}
593_aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
594if (((_aidl_ret_status) != (::android::OK))) {
595goto _aidl_error;
596}
597_aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
598if (((_aidl_ret_status) != (::android::OK))) {
599goto _aidl_error;
600}
601_aidl_error:
602_aidl_status.setFromStatusT(_aidl_ret_status);
603return _aidl_status;
604}
605
606::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) {
607::android::Parcel _aidl_data;
608::android::Parcel _aidl_reply;
609::android::status_t _aidl_ret_status = ::android::OK;
610::android::binder::Status _aidl_status;
611ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppClient");
612_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
613if (((_aidl_ret_status) != (::android::OK))) {
614goto _aidl_error;
615}
616_aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
617if (((_aidl_ret_status) != (::android::OK))) {
618goto _aidl_error;
619}
620_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply);
621if (((_aidl_ret_status) != (::android::OK))) {
622goto _aidl_error;
623}
624_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
625if (((_aidl_ret_status) != (::android::OK))) {
626goto _aidl_error;
627}
628if (!_aidl_status.isOk()) {
629return _aidl_status;
630}
631_aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
632if (((_aidl_ret_status) != (::android::OK))) {
633goto _aidl_error;
634}
635_aidl_error:
636_aidl_status.setFromStatusT(_aidl_ret_status);
637return _aidl_status;
638}
639
640::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
641::android::Parcel _aidl_data;
642::android::Parcel _aidl_reply;
643::android::status_t _aidl_ret_status = ::android::OK;
644::android::binder::Status _aidl_status;
645ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
646_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
647if (((_aidl_ret_status) != (::android::OK))) {
648goto _aidl_error;
649}
650_aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
651if (((_aidl_ret_status) != (::android::OK))) {
652goto _aidl_error;
653}
654_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply);
655if (((_aidl_ret_status) != (::android::OK))) {
656goto _aidl_error;
657}
658_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
659if (((_aidl_ret_status) != (::android::OK))) {
660goto _aidl_error;
661}
662if (!_aidl_status.isOk()) {
663return _aidl_status;
664}
665_aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
666if (((_aidl_ret_status) != (::android::OK))) {
667goto _aidl_error;
668}
669_aidl_error:
670_aidl_status.setFromStatusT(_aidl_ret_status);
671return _aidl_status;
672}
673
674}  // namespace os
675
676}  // namespace android
677)";
678
679const char kExpectedComplexTypeServerHeaderOutput[] =
680R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
681#define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
682
683#include <binder/IInterface.h>
684#include <android/os/IComplexTypeInterface.h>
685
686namespace android {
687
688namespace os {
689
690class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
691public:
692::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags = 0) override;
693};  // class BnComplexTypeInterface
694
695}  // namespace os
696
697}  // namespace android
698
699#endif  // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
700)";
701
702const char kExpectedComplexTypeServerSourceOutput[] =
703R"(#include <android/os/BnComplexTypeInterface.h>
704#include <binder/Parcel.h>
705
706namespace android {
707
708namespace os {
709
710::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
711::android::status_t _aidl_ret_status = ::android::OK;
712switch (_aidl_code) {
713case Call::SEND:
714{
715::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
716::std::vector<double> in_goes_in_and_out;
717::std::vector<bool> out_goes_out;
718::std::vector<int32_t> _aidl_return;
719if (!(_aidl_data.checkInterface(this))) {
720_aidl_ret_status = ::android::BAD_TYPE;
721break;
722}
723_aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
724if (((_aidl_ret_status) != (::android::OK))) {
725break;
726}
727_aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
728if (((_aidl_ret_status) != (::android::OK))) {
729break;
730}
731_aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
732if (((_aidl_ret_status) != (::android::OK))) {
733break;
734}
735::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
736_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
737if (((_aidl_ret_status) != (::android::OK))) {
738break;
739}
740if (!_aidl_status.isOk()) {
741break;
742}
743_aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
744if (((_aidl_ret_status) != (::android::OK))) {
745break;
746}
747_aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
748if (((_aidl_ret_status) != (::android::OK))) {
749break;
750}
751_aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
752if (((_aidl_ret_status) != (::android::OK))) {
753break;
754}
755}
756break;
757case Call::PIFF:
758{
759int32_t in_times;
760if (!(_aidl_data.checkInterface(this))) {
761_aidl_ret_status = ::android::BAD_TYPE;
762break;
763}
764_aidl_ret_status = _aidl_data.readInt32(&in_times);
765if (((_aidl_ret_status) != (::android::OK))) {
766break;
767}
768::android::binder::Status _aidl_status(Piff(in_times));
769}
770break;
771case Call::TAKESABINDER:
772{
773::android::sp<::foo::IFooType> in_f;
774::android::sp<::foo::IFooType> _aidl_return;
775if (!(_aidl_data.checkInterface(this))) {
776_aidl_ret_status = ::android::BAD_TYPE;
777break;
778}
779_aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
780if (((_aidl_ret_status) != (::android::OK))) {
781break;
782}
783::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
784_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
785if (((_aidl_ret_status) != (::android::OK))) {
786break;
787}
788if (!_aidl_status.isOk()) {
789break;
790}
791_aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
792if (((_aidl_ret_status) != (::android::OK))) {
793break;
794}
795}
796break;
797case Call::NULLABLEBINDER:
798{
799::android::sp<::foo::IFooType> _aidl_return;
800if (!(_aidl_data.checkInterface(this))) {
801_aidl_ret_status = ::android::BAD_TYPE;
802break;
803}
804::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
805_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
806if (((_aidl_ret_status) != (::android::OK))) {
807break;
808}
809if (!_aidl_status.isOk()) {
810break;
811}
812_aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
813if (((_aidl_ret_status) != (::android::OK))) {
814break;
815}
816}
817break;
818case Call::STRINGLISTMETHOD:
819{
820::std::vector<::android::String16> in_input;
821::std::vector<::android::String16> out_output;
822::std::vector<::android::String16> _aidl_return;
823if (!(_aidl_data.checkInterface(this))) {
824_aidl_ret_status = ::android::BAD_TYPE;
825break;
826}
827_aidl_ret_status = _aidl_data.readString16Vector(&in_input);
828if (((_aidl_ret_status) != (::android::OK))) {
829break;
830}
831::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
832_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
833if (((_aidl_ret_status) != (::android::OK))) {
834break;
835}
836if (!_aidl_status.isOk()) {
837break;
838}
839_aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
840if (((_aidl_ret_status) != (::android::OK))) {
841break;
842}
843_aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
844if (((_aidl_ret_status) != (::android::OK))) {
845break;
846}
847}
848break;
849case Call::BINDERLISTMETHOD:
850{
851::std::vector<::android::sp<::android::IBinder>> in_input;
852::std::vector<::android::sp<::android::IBinder>> out_output;
853::std::vector<::android::sp<::android::IBinder>> _aidl_return;
854if (!(_aidl_data.checkInterface(this))) {
855_aidl_ret_status = ::android::BAD_TYPE;
856break;
857}
858_aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
859if (((_aidl_ret_status) != (::android::OK))) {
860break;
861}
862::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
863_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
864if (((_aidl_ret_status) != (::android::OK))) {
865break;
866}
867if (!_aidl_status.isOk()) {
868break;
869}
870_aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
871if (((_aidl_ret_status) != (::android::OK))) {
872break;
873}
874_aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
875if (((_aidl_ret_status) != (::android::OK))) {
876break;
877}
878}
879break;
880case Call::TAKESAFILEDESCRIPTOR:
881{
882::android::base::unique_fd in_f;
883::android::base::unique_fd _aidl_return;
884if (!(_aidl_data.checkInterface(this))) {
885_aidl_ret_status = ::android::BAD_TYPE;
886break;
887}
888_aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
889if (((_aidl_ret_status) != (::android::OK))) {
890break;
891}
892::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
893_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
894if (((_aidl_ret_status) != (::android::OK))) {
895break;
896}
897if (!_aidl_status.isOk()) {
898break;
899}
900_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
901if (((_aidl_ret_status) != (::android::OK))) {
902break;
903}
904}
905break;
906case Call::TAKESAFILEDESCRIPTORARRAY:
907{
908::std::vector<::android::base::unique_fd> in_f;
909::std::vector<::android::base::unique_fd> _aidl_return;
910if (!(_aidl_data.checkInterface(this))) {
911_aidl_ret_status = ::android::BAD_TYPE;
912break;
913}
914_aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
915if (((_aidl_ret_status) != (::android::OK))) {
916break;
917}
918::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
919_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
920if (((_aidl_ret_status) != (::android::OK))) {
921break;
922}
923if (!_aidl_status.isOk()) {
924break;
925}
926_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
927if (((_aidl_ret_status) != (::android::OK))) {
928break;
929}
930}
931break;
932default:
933{
934_aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
935}
936break;
937}
938if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
939_aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
940}
941return _aidl_ret_status;
942}
943
944}  // namespace os
945
946}  // namespace android
947)";
948
949const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
950R"(#include <android/os/BnComplexTypeInterface.h>
951#include <binder/Parcel.h>
952
953namespace android {
954
955namespace os {
956
957::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
958::android::status_t _aidl_ret_status = ::android::OK;
959switch (_aidl_code) {
960case Call::SEND:
961{
962::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
963::std::vector<double> in_goes_in_and_out;
964::std::vector<bool> out_goes_out;
965::std::vector<int32_t> _aidl_return;
966if (!(_aidl_data.checkInterface(this))) {
967_aidl_ret_status = ::android::BAD_TYPE;
968break;
969}
970_aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
971if (((_aidl_ret_status) != (::android::OK))) {
972break;
973}
974_aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
975if (((_aidl_ret_status) != (::android::OK))) {
976break;
977}
978_aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
979if (((_aidl_ret_status) != (::android::OK))) {
980break;
981}
982atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppServer");
983::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
984atrace_end(ATRACE_TAG_AIDL);
985_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
986if (((_aidl_ret_status) != (::android::OK))) {
987break;
988}
989if (!_aidl_status.isOk()) {
990break;
991}
992_aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
993if (((_aidl_ret_status) != (::android::OK))) {
994break;
995}
996_aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
997if (((_aidl_ret_status) != (::android::OK))) {
998break;
999}
1000_aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1001if (((_aidl_ret_status) != (::android::OK))) {
1002break;
1003}
1004}
1005break;
1006case Call::PIFF:
1007{
1008int32_t in_times;
1009if (!(_aidl_data.checkInterface(this))) {
1010_aidl_ret_status = ::android::BAD_TYPE;
1011break;
1012}
1013_aidl_ret_status = _aidl_data.readInt32(&in_times);
1014if (((_aidl_ret_status) != (::android::OK))) {
1015break;
1016}
1017atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppServer");
1018::android::binder::Status _aidl_status(Piff(in_times));
1019atrace_end(ATRACE_TAG_AIDL);
1020}
1021break;
1022case Call::TAKESABINDER:
1023{
1024::android::sp<::foo::IFooType> in_f;
1025::android::sp<::foo::IFooType> _aidl_return;
1026if (!(_aidl_data.checkInterface(this))) {
1027_aidl_ret_status = ::android::BAD_TYPE;
1028break;
1029}
1030_aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1031if (((_aidl_ret_status) != (::android::OK))) {
1032break;
1033}
1034atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppServer");
1035::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
1036atrace_end(ATRACE_TAG_AIDL);
1037_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1038if (((_aidl_ret_status) != (::android::OK))) {
1039break;
1040}
1041if (!_aidl_status.isOk()) {
1042break;
1043}
1044_aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1045if (((_aidl_ret_status) != (::android::OK))) {
1046break;
1047}
1048}
1049break;
1050case Call::NULLABLEBINDER:
1051{
1052::android::sp<::foo::IFooType> _aidl_return;
1053if (!(_aidl_data.checkInterface(this))) {
1054_aidl_ret_status = ::android::BAD_TYPE;
1055break;
1056}
1057atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppServer");
1058::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
1059atrace_end(ATRACE_TAG_AIDL);
1060_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1061if (((_aidl_ret_status) != (::android::OK))) {
1062break;
1063}
1064if (!_aidl_status.isOk()) {
1065break;
1066}
1067_aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1068if (((_aidl_ret_status) != (::android::OK))) {
1069break;
1070}
1071}
1072break;
1073case Call::STRINGLISTMETHOD:
1074{
1075::std::vector<::android::String16> in_input;
1076::std::vector<::android::String16> out_output;
1077::std::vector<::android::String16> _aidl_return;
1078if (!(_aidl_data.checkInterface(this))) {
1079_aidl_ret_status = ::android::BAD_TYPE;
1080break;
1081}
1082_aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1083if (((_aidl_ret_status) != (::android::OK))) {
1084break;
1085}
1086atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppServer");
1087::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
1088atrace_end(ATRACE_TAG_AIDL);
1089_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1090if (((_aidl_ret_status) != (::android::OK))) {
1091break;
1092}
1093if (!_aidl_status.isOk()) {
1094break;
1095}
1096_aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1097if (((_aidl_ret_status) != (::android::OK))) {
1098break;
1099}
1100_aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1101if (((_aidl_ret_status) != (::android::OK))) {
1102break;
1103}
1104}
1105break;
1106case Call::BINDERLISTMETHOD:
1107{
1108::std::vector<::android::sp<::android::IBinder>> in_input;
1109::std::vector<::android::sp<::android::IBinder>> out_output;
1110::std::vector<::android::sp<::android::IBinder>> _aidl_return;
1111if (!(_aidl_data.checkInterface(this))) {
1112_aidl_ret_status = ::android::BAD_TYPE;
1113break;
1114}
1115_aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1116if (((_aidl_ret_status) != (::android::OK))) {
1117break;
1118}
1119atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppServer");
1120::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
1121atrace_end(ATRACE_TAG_AIDL);
1122_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1123if (((_aidl_ret_status) != (::android::OK))) {
1124break;
1125}
1126if (!_aidl_status.isOk()) {
1127break;
1128}
1129_aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1130if (((_aidl_ret_status) != (::android::OK))) {
1131break;
1132}
1133_aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1134if (((_aidl_ret_status) != (::android::OK))) {
1135break;
1136}
1137}
1138break;
1139case Call::TAKESAFILEDESCRIPTOR:
1140{
1141::android::base::unique_fd in_f;
1142::android::base::unique_fd _aidl_return;
1143if (!(_aidl_data.checkInterface(this))) {
1144_aidl_ret_status = ::android::BAD_TYPE;
1145break;
1146}
1147_aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1148if (((_aidl_ret_status) != (::android::OK))) {
1149break;
1150}
1151atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppServer");
1152::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
1153atrace_end(ATRACE_TAG_AIDL);
1154_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1155if (((_aidl_ret_status) != (::android::OK))) {
1156break;
1157}
1158if (!_aidl_status.isOk()) {
1159break;
1160}
1161_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1162if (((_aidl_ret_status) != (::android::OK))) {
1163break;
1164}
1165}
1166break;
1167case Call::TAKESAFILEDESCRIPTORARRAY:
1168{
1169::std::vector<::android::base::unique_fd> in_f;
1170::std::vector<::android::base::unique_fd> _aidl_return;
1171if (!(_aidl_data.checkInterface(this))) {
1172_aidl_ret_status = ::android::BAD_TYPE;
1173break;
1174}
1175_aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1176if (((_aidl_ret_status) != (::android::OK))) {
1177break;
1178}
1179atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
1180::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
1181atrace_end(ATRACE_TAG_AIDL);
1182_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1183if (((_aidl_ret_status) != (::android::OK))) {
1184break;
1185}
1186if (!_aidl_status.isOk()) {
1187break;
1188}
1189_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1190if (((_aidl_ret_status) != (::android::OK))) {
1191break;
1192}
1193}
1194break;
1195default:
1196{
1197_aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1198}
1199break;
1200}
1201if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1202_aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1203}
1204return _aidl_ret_status;
1205}
1206
1207}  // namespace os
1208
1209}  // namespace android
1210)";
1211
1212const char kExpectedComplexTypeInterfaceHeaderOutput[] =
1213R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1214#define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1215
1216#include <android-base/unique_fd.h>
1217#include <binder/IBinder.h>
1218#include <binder/IInterface.h>
1219#include <binder/Status.h>
1220#include <cstdint>
1221#include <foo/IFooType.h>
1222#include <memory>
1223#include <utils/String16.h>
1224#include <utils/StrongPointer.h>
1225#include <vector>
1226
1227namespace android {
1228
1229namespace os {
1230
1231class IComplexTypeInterface : public ::android::IInterface {
1232public:
1233DECLARE_META_INTERFACE(ComplexTypeInterface)
1234enum  : int32_t {
1235  MY_CONSTANT = 3,
1236};
1237virtual ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) = 0;
1238virtual ::android::binder::Status Piff(int32_t times) = 0;
1239virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1240virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1241virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1242virtual ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) = 0;
1243virtual ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) = 0;
1244virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
1245enum Call {
1246  SEND = ::android::IBinder::FIRST_CALL_TRANSACTION + 0,
1247  PIFF = ::android::IBinder::FIRST_CALL_TRANSACTION + 1,
1248  TAKESABINDER = ::android::IBinder::FIRST_CALL_TRANSACTION + 2,
1249  NULLABLEBINDER = ::android::IBinder::FIRST_CALL_TRANSACTION + 3,
1250  STRINGLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 4,
1251  BINDERLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 5,
1252  TAKESAFILEDESCRIPTOR = ::android::IBinder::FIRST_CALL_TRANSACTION + 6,
1253  TAKESAFILEDESCRIPTORARRAY = ::android::IBinder::FIRST_CALL_TRANSACTION + 7,
1254};
1255};  // class IComplexTypeInterface
1256
1257}  // namespace os
1258
1259}  // namespace android
1260
1261#endif  // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1262)";
1263
1264const char kExpectedComplexTypeInterfaceSourceOutput[] =
1265R"(#include <android/os/IComplexTypeInterface.h>
1266#include <android/os/BpComplexTypeInterface.h>
1267
1268namespace android {
1269
1270namespace os {
1271
1272IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
1273
1274}  // namespace os
1275
1276}  // namespace android
1277)";
1278
1279}  // namespace
1280
1281class ASTTest : public ::testing::Test {
1282 protected:
1283  ASTTest(string file_path, string file_contents)
1284      : file_path_(file_path),
1285        file_contents_(file_contents) {
1286    types_.Init();
1287  }
1288
1289  unique_ptr<AidlInterface> Parse() {
1290    io_delegate_.SetFileContents(file_path_, file_contents_);
1291
1292    unique_ptr<AidlInterface> ret;
1293    std::vector<std::unique_ptr<AidlImport>> imports;
1294    AidlError err = ::android::aidl::internals::load_and_validate_aidl(
1295        {},  // no preprocessed files
1296        {"."},
1297        file_path_,
1298        false, // generate_traces
1299        io_delegate_,
1300        &types_,
1301        &ret,
1302        &imports);
1303
1304    if (err != AidlError::OK)
1305      return nullptr;
1306
1307    return ret;
1308  }
1309
1310  void Compare(Document* doc, const char* expected) {
1311    string output;
1312    unique_ptr<CodeWriter> cw = GetStringWriter(&output);
1313
1314    doc->Write(cw.get());
1315
1316    if (expected == output) {
1317      return; // Success
1318    }
1319
1320    test::PrintDiff(expected, output);
1321    FAIL() << "Document contents did not match expected contents";
1322  }
1323
1324  const string file_path_;
1325  const string file_contents_;
1326  FakeIoDelegate io_delegate_;
1327  TypeNamespace types_;
1328};
1329
1330class ComplexTypeInterfaceASTTest : public ASTTest {
1331 public:
1332  ComplexTypeInterfaceASTTest()
1333      : ASTTest("android/os/IComplexTypeInterface.aidl",
1334                kComplexTypeInterfaceAIDL) {
1335    io_delegate_.SetFileContents("foo/IFooType.aidl",
1336                                 "package foo; interface IFooType {}");
1337  }
1338};
1339
1340TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
1341  unique_ptr<AidlInterface> interface = Parse();
1342  ASSERT_NE(interface, nullptr);
1343  unique_ptr<Document> doc = internals::BuildClientHeader(types_, *interface);
1344  Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1345}
1346
1347TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
1348  unique_ptr<AidlInterface> interface = Parse();
1349  ASSERT_NE(interface, nullptr);
1350  unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface);
1351  Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1352}
1353
1354TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSourceWithTrace) {
1355  unique_ptr<AidlInterface> interface = Parse();
1356  ASSERT_NE(interface, nullptr);
1357  interface->SetGenerateTraces(true);
1358  unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface);
1359  Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1360}
1361
1362TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
1363  unique_ptr<AidlInterface> interface = Parse();
1364  ASSERT_NE(interface, nullptr);
1365  unique_ptr<Document> doc = internals::BuildServerHeader(types_, *interface);
1366  Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1367}
1368
1369TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
1370  unique_ptr<AidlInterface> interface = Parse();
1371  ASSERT_NE(interface, nullptr);
1372  unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface);
1373  Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1374}
1375
1376TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSourceWithTrace) {
1377  unique_ptr<AidlInterface> interface = Parse();
1378  ASSERT_NE(interface, nullptr);
1379  interface->SetGenerateTraces(true);
1380  unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface);
1381  Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1382}
1383
1384TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
1385  unique_ptr<AidlInterface> interface = Parse();
1386  ASSERT_NE(interface, nullptr);
1387  unique_ptr<Document> doc = internals::BuildInterfaceHeader(types_, *interface);
1388  Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1389}
1390
1391TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
1392  unique_ptr<AidlInterface> interface = Parse();
1393  ASSERT_NE(interface, nullptr);
1394  unique_ptr<Document> doc = internals::BuildInterfaceSource(types_, *interface);
1395  Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
1396}
1397
1398namespace test_io_handling {
1399
1400const char kInputPath[] = "a/IFoo.aidl";
1401const char kOutputPath[] = "output.cpp";
1402const char kHeaderDir[] = "headers";
1403const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1404
1405}  // namespace test_io_handling
1406
1407class IoErrorHandlingTest : public ASTTest {
1408 public:
1409  IoErrorHandlingTest ()
1410      : ASTTest(test_io_handling::kInputPath,
1411                "package a; interface IFoo {}"),
1412        options_(GetOptions()) {}
1413
1414  const unique_ptr<CppOptions> options_;
1415
1416 private:
1417  static unique_ptr<CppOptions> GetOptions() {
1418    using namespace test_io_handling;
1419
1420    const int argc = 4;
1421    const char* cmdline[argc] = {
1422      "aidl-cpp", kInputPath, kHeaderDir, kOutputPath
1423    };
1424    return CppOptions::Parse(argc, cmdline);
1425  }
1426};
1427
1428TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1429  // Confirm that this is working correctly without I/O problems.
1430  const unique_ptr<AidlInterface> interface = Parse();
1431  ASSERT_NE(interface, nullptr);
1432  ASSERT_TRUE(GenerateCpp(*options_, types_, *interface, io_delegate_));
1433}
1434
1435TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1436  using namespace test_io_handling;
1437  const unique_ptr<AidlInterface> interface = Parse();
1438  ASSERT_NE(interface, nullptr);
1439
1440  // Simulate issues closing the interface header.
1441  const string header_path =
1442      StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1443                   kInterfaceHeaderRelPath);
1444  io_delegate_.AddBrokenFilePath(header_path);
1445  ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_));
1446  // We should never attempt to write the C++ file if we fail writing headers.
1447  ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1448  // We should remove partial results.
1449  ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1450}
1451
1452TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1453  using test_io_handling::kOutputPath;
1454  const unique_ptr<AidlInterface> interface = Parse();
1455  ASSERT_NE(interface, nullptr);
1456
1457  // Simulate issues closing the cpp file.
1458  io_delegate_.AddBrokenFilePath(kOutputPath);
1459  ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_));
1460  // We should remove partial results.
1461  ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1462}
1463
1464}  // namespace cpp
1465}  // namespace aidl
1466}  // namespace android
1467