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
32 using ::android::aidl::test::FakeIoDelegate;
33 using ::android::base::StringPrintf;
34 using std::string;
35 using std::unique_ptr;
36
37 namespace android {
38 namespace aidl {
39 namespace cpp {
40 namespace {
41
42 const string kComplexTypeInterfaceAIDL =
43 R"(package android.os;
44 import foo.IFooType;
45 interface 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
57 const char kExpectedComplexTypeClientHeaderOutput[] =
58 R"(#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
66 namespace android {
67
68 namespace os {
69
70 class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
71 public:
72 explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
73 virtual ~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
91 const char kExpectedComplexTypeClientSourceOutput[] =
92 R"(#include <android/os/BpComplexTypeInterface.h>
93 #include <binder/Parcel.h>
94
95 namespace android {
96
97 namespace os {
98
99 BpComplexTypeInterface::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());
109 if (((_aidl_ret_status) != (::android::OK))) {
110 goto _aidl_error;
111 }
112 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
113 if (((_aidl_ret_status) != (::android::OK))) {
114 goto _aidl_error;
115 }
116 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
117 if (((_aidl_ret_status) != (::android::OK))) {
118 goto _aidl_error;
119 }
120 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
121 if (((_aidl_ret_status) != (::android::OK))) {
122 goto _aidl_error;
123 }
124 _aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply);
125 if (((_aidl_ret_status) != (::android::OK))) {
126 goto _aidl_error;
127 }
128 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
129 if (((_aidl_ret_status) != (::android::OK))) {
130 goto _aidl_error;
131 }
132 if (!_aidl_status.isOk()) {
133 return _aidl_status;
134 }
135 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
136 if (((_aidl_ret_status) != (::android::OK))) {
137 goto _aidl_error;
138 }
139 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
140 if (((_aidl_ret_status) != (::android::OK))) {
141 goto _aidl_error;
142 }
143 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
144 if (((_aidl_ret_status) != (::android::OK))) {
145 goto _aidl_error;
146 }
147 _aidl_error:
148 _aidl_status.setFromStatusT(_aidl_ret_status);
149 return _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());
158 if (((_aidl_ret_status) != (::android::OK))) {
159 goto _aidl_error;
160 }
161 _aidl_ret_status = _aidl_data.writeInt32(times);
162 if (((_aidl_ret_status) != (::android::OK))) {
163 goto _aidl_error;
164 }
165 _aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
166 if (((_aidl_ret_status) != (::android::OK))) {
167 goto _aidl_error;
168 }
169 _aidl_error:
170 _aidl_status.setFromStatusT(_aidl_ret_status);
171 return _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());
180 if (((_aidl_ret_status) != (::android::OK))) {
181 goto _aidl_error;
182 }
183 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
184 if (((_aidl_ret_status) != (::android::OK))) {
185 goto _aidl_error;
186 }
187 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply);
188 if (((_aidl_ret_status) != (::android::OK))) {
189 goto _aidl_error;
190 }
191 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
192 if (((_aidl_ret_status) != (::android::OK))) {
193 goto _aidl_error;
194 }
195 if (!_aidl_status.isOk()) {
196 return _aidl_status;
197 }
198 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
199 if (((_aidl_ret_status) != (::android::OK))) {
200 goto _aidl_error;
201 }
202 _aidl_error:
203 _aidl_status.setFromStatusT(_aidl_ret_status);
204 return _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());
213 if (((_aidl_ret_status) != (::android::OK))) {
214 goto _aidl_error;
215 }
216 _aidl_ret_status = remote()->transact(IComplexTypeInterface::NULLABLEBINDER, _aidl_data, &_aidl_reply);
217 if (((_aidl_ret_status) != (::android::OK))) {
218 goto _aidl_error;
219 }
220 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
221 if (((_aidl_ret_status) != (::android::OK))) {
222 goto _aidl_error;
223 }
224 if (!_aidl_status.isOk()) {
225 return _aidl_status;
226 }
227 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
228 if (((_aidl_ret_status) != (::android::OK))) {
229 goto _aidl_error;
230 }
231 _aidl_error:
232 _aidl_status.setFromStatusT(_aidl_ret_status);
233 return _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());
242 if (((_aidl_ret_status) != (::android::OK))) {
243 goto _aidl_error;
244 }
245 _aidl_ret_status = _aidl_data.writeString16Vector(input);
246 if (((_aidl_ret_status) != (::android::OK))) {
247 goto _aidl_error;
248 }
249 _aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply);
250 if (((_aidl_ret_status) != (::android::OK))) {
251 goto _aidl_error;
252 }
253 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
254 if (((_aidl_ret_status) != (::android::OK))) {
255 goto _aidl_error;
256 }
257 if (!_aidl_status.isOk()) {
258 return _aidl_status;
259 }
260 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
261 if (((_aidl_ret_status) != (::android::OK))) {
262 goto _aidl_error;
263 }
264 _aidl_ret_status = _aidl_reply.readString16Vector(output);
265 if (((_aidl_ret_status) != (::android::OK))) {
266 goto _aidl_error;
267 }
268 _aidl_error:
269 _aidl_status.setFromStatusT(_aidl_ret_status);
270 return _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());
279 if (((_aidl_ret_status) != (::android::OK))) {
280 goto _aidl_error;
281 }
282 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
283 if (((_aidl_ret_status) != (::android::OK))) {
284 goto _aidl_error;
285 }
286 _aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply);
287 if (((_aidl_ret_status) != (::android::OK))) {
288 goto _aidl_error;
289 }
290 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
291 if (((_aidl_ret_status) != (::android::OK))) {
292 goto _aidl_error;
293 }
294 if (!_aidl_status.isOk()) {
295 return _aidl_status;
296 }
297 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
298 if (((_aidl_ret_status) != (::android::OK))) {
299 goto _aidl_error;
300 }
301 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
302 if (((_aidl_ret_status) != (::android::OK))) {
303 goto _aidl_error;
304 }
305 _aidl_error:
306 _aidl_status.setFromStatusT(_aidl_ret_status);
307 return _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());
316 if (((_aidl_ret_status) != (::android::OK))) {
317 goto _aidl_error;
318 }
319 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
320 if (((_aidl_ret_status) != (::android::OK))) {
321 goto _aidl_error;
322 }
323 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply);
324 if (((_aidl_ret_status) != (::android::OK))) {
325 goto _aidl_error;
326 }
327 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
328 if (((_aidl_ret_status) != (::android::OK))) {
329 goto _aidl_error;
330 }
331 if (!_aidl_status.isOk()) {
332 return _aidl_status;
333 }
334 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
335 if (((_aidl_ret_status) != (::android::OK))) {
336 goto _aidl_error;
337 }
338 _aidl_error:
339 _aidl_status.setFromStatusT(_aidl_ret_status);
340 return _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());
349 if (((_aidl_ret_status) != (::android::OK))) {
350 goto _aidl_error;
351 }
352 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
353 if (((_aidl_ret_status) != (::android::OK))) {
354 goto _aidl_error;
355 }
356 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply);
357 if (((_aidl_ret_status) != (::android::OK))) {
358 goto _aidl_error;
359 }
360 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
361 if (((_aidl_ret_status) != (::android::OK))) {
362 goto _aidl_error;
363 }
364 if (!_aidl_status.isOk()) {
365 return _aidl_status;
366 }
367 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
368 if (((_aidl_ret_status) != (::android::OK))) {
369 goto _aidl_error;
370 }
371 _aidl_error:
372 _aidl_status.setFromStatusT(_aidl_ret_status);
373 return _aidl_status;
374 }
375
376 } // namespace os
377
378 } // namespace android
379 )";
380
381 const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
382 R"(#include <android/os/BpComplexTypeInterface.h>
383 #include <binder/Parcel.h>
384
385 namespace android {
386
387 namespace os {
388
389 BpComplexTypeInterface::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;
398 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppClient");
399 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
400 if (((_aidl_ret_status) != (::android::OK))) {
401 goto _aidl_error;
402 }
403 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
404 if (((_aidl_ret_status) != (::android::OK))) {
405 goto _aidl_error;
406 }
407 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
408 if (((_aidl_ret_status) != (::android::OK))) {
409 goto _aidl_error;
410 }
411 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
412 if (((_aidl_ret_status) != (::android::OK))) {
413 goto _aidl_error;
414 }
415 _aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply);
416 if (((_aidl_ret_status) != (::android::OK))) {
417 goto _aidl_error;
418 }
419 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
420 if (((_aidl_ret_status) != (::android::OK))) {
421 goto _aidl_error;
422 }
423 if (!_aidl_status.isOk()) {
424 return _aidl_status;
425 }
426 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
427 if (((_aidl_ret_status) != (::android::OK))) {
428 goto _aidl_error;
429 }
430 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
431 if (((_aidl_ret_status) != (::android::OK))) {
432 goto _aidl_error;
433 }
434 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
435 if (((_aidl_ret_status) != (::android::OK))) {
436 goto _aidl_error;
437 }
438 _aidl_error:
439 _aidl_status.setFromStatusT(_aidl_ret_status);
440 return _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;
448 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppClient");
449 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
450 if (((_aidl_ret_status) != (::android::OK))) {
451 goto _aidl_error;
452 }
453 _aidl_ret_status = _aidl_data.writeInt32(times);
454 if (((_aidl_ret_status) != (::android::OK))) {
455 goto _aidl_error;
456 }
457 _aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
458 if (((_aidl_ret_status) != (::android::OK))) {
459 goto _aidl_error;
460 }
461 _aidl_error:
462 _aidl_status.setFromStatusT(_aidl_ret_status);
463 return _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;
471 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppClient");
472 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
473 if (((_aidl_ret_status) != (::android::OK))) {
474 goto _aidl_error;
475 }
476 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
477 if (((_aidl_ret_status) != (::android::OK))) {
478 goto _aidl_error;
479 }
480 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply);
481 if (((_aidl_ret_status) != (::android::OK))) {
482 goto _aidl_error;
483 }
484 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
485 if (((_aidl_ret_status) != (::android::OK))) {
486 goto _aidl_error;
487 }
488 if (!_aidl_status.isOk()) {
489 return _aidl_status;
490 }
491 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
492 if (((_aidl_ret_status) != (::android::OK))) {
493 goto _aidl_error;
494 }
495 _aidl_error:
496 _aidl_status.setFromStatusT(_aidl_ret_status);
497 return _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;
505 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppClient");
506 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
507 if (((_aidl_ret_status) != (::android::OK))) {
508 goto _aidl_error;
509 }
510 _aidl_ret_status = remote()->transact(IComplexTypeInterface::NULLABLEBINDER, _aidl_data, &_aidl_reply);
511 if (((_aidl_ret_status) != (::android::OK))) {
512 goto _aidl_error;
513 }
514 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
515 if (((_aidl_ret_status) != (::android::OK))) {
516 goto _aidl_error;
517 }
518 if (!_aidl_status.isOk()) {
519 return _aidl_status;
520 }
521 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
522 if (((_aidl_ret_status) != (::android::OK))) {
523 goto _aidl_error;
524 }
525 _aidl_error:
526 _aidl_status.setFromStatusT(_aidl_ret_status);
527 return _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;
535 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppClient");
536 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
537 if (((_aidl_ret_status) != (::android::OK))) {
538 goto _aidl_error;
539 }
540 _aidl_ret_status = _aidl_data.writeString16Vector(input);
541 if (((_aidl_ret_status) != (::android::OK))) {
542 goto _aidl_error;
543 }
544 _aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply);
545 if (((_aidl_ret_status) != (::android::OK))) {
546 goto _aidl_error;
547 }
548 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
549 if (((_aidl_ret_status) != (::android::OK))) {
550 goto _aidl_error;
551 }
552 if (!_aidl_status.isOk()) {
553 return _aidl_status;
554 }
555 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
556 if (((_aidl_ret_status) != (::android::OK))) {
557 goto _aidl_error;
558 }
559 _aidl_ret_status = _aidl_reply.readString16Vector(output);
560 if (((_aidl_ret_status) != (::android::OK))) {
561 goto _aidl_error;
562 }
563 _aidl_error:
564 _aidl_status.setFromStatusT(_aidl_ret_status);
565 return _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;
573 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppClient");
574 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
575 if (((_aidl_ret_status) != (::android::OK))) {
576 goto _aidl_error;
577 }
578 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
579 if (((_aidl_ret_status) != (::android::OK))) {
580 goto _aidl_error;
581 }
582 _aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply);
583 if (((_aidl_ret_status) != (::android::OK))) {
584 goto _aidl_error;
585 }
586 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
587 if (((_aidl_ret_status) != (::android::OK))) {
588 goto _aidl_error;
589 }
590 if (!_aidl_status.isOk()) {
591 return _aidl_status;
592 }
593 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
594 if (((_aidl_ret_status) != (::android::OK))) {
595 goto _aidl_error;
596 }
597 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
598 if (((_aidl_ret_status) != (::android::OK))) {
599 goto _aidl_error;
600 }
601 _aidl_error:
602 _aidl_status.setFromStatusT(_aidl_ret_status);
603 return _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;
611 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppClient");
612 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
613 if (((_aidl_ret_status) != (::android::OK))) {
614 goto _aidl_error;
615 }
616 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
617 if (((_aidl_ret_status) != (::android::OK))) {
618 goto _aidl_error;
619 }
620 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply);
621 if (((_aidl_ret_status) != (::android::OK))) {
622 goto _aidl_error;
623 }
624 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
625 if (((_aidl_ret_status) != (::android::OK))) {
626 goto _aidl_error;
627 }
628 if (!_aidl_status.isOk()) {
629 return _aidl_status;
630 }
631 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
632 if (((_aidl_ret_status) != (::android::OK))) {
633 goto _aidl_error;
634 }
635 _aidl_error:
636 _aidl_status.setFromStatusT(_aidl_ret_status);
637 return _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;
645 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
646 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
647 if (((_aidl_ret_status) != (::android::OK))) {
648 goto _aidl_error;
649 }
650 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
651 if (((_aidl_ret_status) != (::android::OK))) {
652 goto _aidl_error;
653 }
654 _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply);
655 if (((_aidl_ret_status) != (::android::OK))) {
656 goto _aidl_error;
657 }
658 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
659 if (((_aidl_ret_status) != (::android::OK))) {
660 goto _aidl_error;
661 }
662 if (!_aidl_status.isOk()) {
663 return _aidl_status;
664 }
665 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
666 if (((_aidl_ret_status) != (::android::OK))) {
667 goto _aidl_error;
668 }
669 _aidl_error:
670 _aidl_status.setFromStatusT(_aidl_ret_status);
671 return _aidl_status;
672 }
673
674 } // namespace os
675
676 } // namespace android
677 )";
678
679 const char kExpectedComplexTypeServerHeaderOutput[] =
680 R"(#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
686 namespace android {
687
688 namespace os {
689
690 class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
691 public:
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
702 const char kExpectedComplexTypeServerSourceOutput[] =
703 R"(#include <android/os/BnComplexTypeInterface.h>
704 #include <binder/Parcel.h>
705
706 namespace android {
707
708 namespace 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;
712 switch (_aidl_code) {
713 case 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;
719 if (!(_aidl_data.checkInterface(this))) {
720 _aidl_ret_status = ::android::BAD_TYPE;
721 break;
722 }
723 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
724 if (((_aidl_ret_status) != (::android::OK))) {
725 break;
726 }
727 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
728 if (((_aidl_ret_status) != (::android::OK))) {
729 break;
730 }
731 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
732 if (((_aidl_ret_status) != (::android::OK))) {
733 break;
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);
737 if (((_aidl_ret_status) != (::android::OK))) {
738 break;
739 }
740 if (!_aidl_status.isOk()) {
741 break;
742 }
743 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
744 if (((_aidl_ret_status) != (::android::OK))) {
745 break;
746 }
747 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
748 if (((_aidl_ret_status) != (::android::OK))) {
749 break;
750 }
751 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
752 if (((_aidl_ret_status) != (::android::OK))) {
753 break;
754 }
755 }
756 break;
757 case Call::PIFF:
758 {
759 int32_t in_times;
760 if (!(_aidl_data.checkInterface(this))) {
761 _aidl_ret_status = ::android::BAD_TYPE;
762 break;
763 }
764 _aidl_ret_status = _aidl_data.readInt32(&in_times);
765 if (((_aidl_ret_status) != (::android::OK))) {
766 break;
767 }
768 ::android::binder::Status _aidl_status(Piff(in_times));
769 }
770 break;
771 case Call::TAKESABINDER:
772 {
773 ::android::sp<::foo::IFooType> in_f;
774 ::android::sp<::foo::IFooType> _aidl_return;
775 if (!(_aidl_data.checkInterface(this))) {
776 _aidl_ret_status = ::android::BAD_TYPE;
777 break;
778 }
779 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
780 if (((_aidl_ret_status) != (::android::OK))) {
781 break;
782 }
783 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
784 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
785 if (((_aidl_ret_status) != (::android::OK))) {
786 break;
787 }
788 if (!_aidl_status.isOk()) {
789 break;
790 }
791 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
792 if (((_aidl_ret_status) != (::android::OK))) {
793 break;
794 }
795 }
796 break;
797 case Call::NULLABLEBINDER:
798 {
799 ::android::sp<::foo::IFooType> _aidl_return;
800 if (!(_aidl_data.checkInterface(this))) {
801 _aidl_ret_status = ::android::BAD_TYPE;
802 break;
803 }
804 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
805 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
806 if (((_aidl_ret_status) != (::android::OK))) {
807 break;
808 }
809 if (!_aidl_status.isOk()) {
810 break;
811 }
812 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
813 if (((_aidl_ret_status) != (::android::OK))) {
814 break;
815 }
816 }
817 break;
818 case Call::STRINGLISTMETHOD:
819 {
820 ::std::vector<::android::String16> in_input;
821 ::std::vector<::android::String16> out_output;
822 ::std::vector<::android::String16> _aidl_return;
823 if (!(_aidl_data.checkInterface(this))) {
824 _aidl_ret_status = ::android::BAD_TYPE;
825 break;
826 }
827 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
828 if (((_aidl_ret_status) != (::android::OK))) {
829 break;
830 }
831 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
832 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
833 if (((_aidl_ret_status) != (::android::OK))) {
834 break;
835 }
836 if (!_aidl_status.isOk()) {
837 break;
838 }
839 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
840 if (((_aidl_ret_status) != (::android::OK))) {
841 break;
842 }
843 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
844 if (((_aidl_ret_status) != (::android::OK))) {
845 break;
846 }
847 }
848 break;
849 case 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;
854 if (!(_aidl_data.checkInterface(this))) {
855 _aidl_ret_status = ::android::BAD_TYPE;
856 break;
857 }
858 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
859 if (((_aidl_ret_status) != (::android::OK))) {
860 break;
861 }
862 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
863 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
864 if (((_aidl_ret_status) != (::android::OK))) {
865 break;
866 }
867 if (!_aidl_status.isOk()) {
868 break;
869 }
870 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
871 if (((_aidl_ret_status) != (::android::OK))) {
872 break;
873 }
874 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
875 if (((_aidl_ret_status) != (::android::OK))) {
876 break;
877 }
878 }
879 break;
880 case Call::TAKESAFILEDESCRIPTOR:
881 {
882 ::android::base::unique_fd in_f;
883 ::android::base::unique_fd _aidl_return;
884 if (!(_aidl_data.checkInterface(this))) {
885 _aidl_ret_status = ::android::BAD_TYPE;
886 break;
887 }
888 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
889 if (((_aidl_ret_status) != (::android::OK))) {
890 break;
891 }
892 ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
893 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
894 if (((_aidl_ret_status) != (::android::OK))) {
895 break;
896 }
897 if (!_aidl_status.isOk()) {
898 break;
899 }
900 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
901 if (((_aidl_ret_status) != (::android::OK))) {
902 break;
903 }
904 }
905 break;
906 case Call::TAKESAFILEDESCRIPTORARRAY:
907 {
908 ::std::vector<::android::base::unique_fd> in_f;
909 ::std::vector<::android::base::unique_fd> _aidl_return;
910 if (!(_aidl_data.checkInterface(this))) {
911 _aidl_ret_status = ::android::BAD_TYPE;
912 break;
913 }
914 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
915 if (((_aidl_ret_status) != (::android::OK))) {
916 break;
917 }
918 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
919 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
920 if (((_aidl_ret_status) != (::android::OK))) {
921 break;
922 }
923 if (!_aidl_status.isOk()) {
924 break;
925 }
926 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
927 if (((_aidl_ret_status) != (::android::OK))) {
928 break;
929 }
930 }
931 break;
932 default:
933 {
934 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
935 }
936 break;
937 }
938 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
939 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
940 }
941 return _aidl_ret_status;
942 }
943
944 } // namespace os
945
946 } // namespace android
947 )";
948
949 const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
950 R"(#include <android/os/BnComplexTypeInterface.h>
951 #include <binder/Parcel.h>
952
953 namespace android {
954
955 namespace 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;
959 switch (_aidl_code) {
960 case 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;
966 if (!(_aidl_data.checkInterface(this))) {
967 _aidl_ret_status = ::android::BAD_TYPE;
968 break;
969 }
970 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
971 if (((_aidl_ret_status) != (::android::OK))) {
972 break;
973 }
974 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
975 if (((_aidl_ret_status) != (::android::OK))) {
976 break;
977 }
978 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
979 if (((_aidl_ret_status) != (::android::OK))) {
980 break;
981 }
982 atrace_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));
984 atrace_end(ATRACE_TAG_AIDL);
985 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
986 if (((_aidl_ret_status) != (::android::OK))) {
987 break;
988 }
989 if (!_aidl_status.isOk()) {
990 break;
991 }
992 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
993 if (((_aidl_ret_status) != (::android::OK))) {
994 break;
995 }
996 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
997 if (((_aidl_ret_status) != (::android::OK))) {
998 break;
999 }
1000 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1001 if (((_aidl_ret_status) != (::android::OK))) {
1002 break;
1003 }
1004 }
1005 break;
1006 case Call::PIFF:
1007 {
1008 int32_t in_times;
1009 if (!(_aidl_data.checkInterface(this))) {
1010 _aidl_ret_status = ::android::BAD_TYPE;
1011 break;
1012 }
1013 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1014 if (((_aidl_ret_status) != (::android::OK))) {
1015 break;
1016 }
1017 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppServer");
1018 ::android::binder::Status _aidl_status(Piff(in_times));
1019 atrace_end(ATRACE_TAG_AIDL);
1020 }
1021 break;
1022 case Call::TAKESABINDER:
1023 {
1024 ::android::sp<::foo::IFooType> in_f;
1025 ::android::sp<::foo::IFooType> _aidl_return;
1026 if (!(_aidl_data.checkInterface(this))) {
1027 _aidl_ret_status = ::android::BAD_TYPE;
1028 break;
1029 }
1030 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1031 if (((_aidl_ret_status) != (::android::OK))) {
1032 break;
1033 }
1034 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppServer");
1035 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
1036 atrace_end(ATRACE_TAG_AIDL);
1037 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1038 if (((_aidl_ret_status) != (::android::OK))) {
1039 break;
1040 }
1041 if (!_aidl_status.isOk()) {
1042 break;
1043 }
1044 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1045 if (((_aidl_ret_status) != (::android::OK))) {
1046 break;
1047 }
1048 }
1049 break;
1050 case Call::NULLABLEBINDER:
1051 {
1052 ::android::sp<::foo::IFooType> _aidl_return;
1053 if (!(_aidl_data.checkInterface(this))) {
1054 _aidl_ret_status = ::android::BAD_TYPE;
1055 break;
1056 }
1057 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppServer");
1058 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
1059 atrace_end(ATRACE_TAG_AIDL);
1060 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1061 if (((_aidl_ret_status) != (::android::OK))) {
1062 break;
1063 }
1064 if (!_aidl_status.isOk()) {
1065 break;
1066 }
1067 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1068 if (((_aidl_ret_status) != (::android::OK))) {
1069 break;
1070 }
1071 }
1072 break;
1073 case Call::STRINGLISTMETHOD:
1074 {
1075 ::std::vector<::android::String16> in_input;
1076 ::std::vector<::android::String16> out_output;
1077 ::std::vector<::android::String16> _aidl_return;
1078 if (!(_aidl_data.checkInterface(this))) {
1079 _aidl_ret_status = ::android::BAD_TYPE;
1080 break;
1081 }
1082 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1083 if (((_aidl_ret_status) != (::android::OK))) {
1084 break;
1085 }
1086 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppServer");
1087 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
1088 atrace_end(ATRACE_TAG_AIDL);
1089 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1090 if (((_aidl_ret_status) != (::android::OK))) {
1091 break;
1092 }
1093 if (!_aidl_status.isOk()) {
1094 break;
1095 }
1096 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1097 if (((_aidl_ret_status) != (::android::OK))) {
1098 break;
1099 }
1100 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1101 if (((_aidl_ret_status) != (::android::OK))) {
1102 break;
1103 }
1104 }
1105 break;
1106 case 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;
1111 if (!(_aidl_data.checkInterface(this))) {
1112 _aidl_ret_status = ::android::BAD_TYPE;
1113 break;
1114 }
1115 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1116 if (((_aidl_ret_status) != (::android::OK))) {
1117 break;
1118 }
1119 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppServer");
1120 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
1121 atrace_end(ATRACE_TAG_AIDL);
1122 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1123 if (((_aidl_ret_status) != (::android::OK))) {
1124 break;
1125 }
1126 if (!_aidl_status.isOk()) {
1127 break;
1128 }
1129 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1130 if (((_aidl_ret_status) != (::android::OK))) {
1131 break;
1132 }
1133 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1134 if (((_aidl_ret_status) != (::android::OK))) {
1135 break;
1136 }
1137 }
1138 break;
1139 case Call::TAKESAFILEDESCRIPTOR:
1140 {
1141 ::android::base::unique_fd in_f;
1142 ::android::base::unique_fd _aidl_return;
1143 if (!(_aidl_data.checkInterface(this))) {
1144 _aidl_ret_status = ::android::BAD_TYPE;
1145 break;
1146 }
1147 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1148 if (((_aidl_ret_status) != (::android::OK))) {
1149 break;
1150 }
1151 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppServer");
1152 ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
1153 atrace_end(ATRACE_TAG_AIDL);
1154 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1155 if (((_aidl_ret_status) != (::android::OK))) {
1156 break;
1157 }
1158 if (!_aidl_status.isOk()) {
1159 break;
1160 }
1161 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1162 if (((_aidl_ret_status) != (::android::OK))) {
1163 break;
1164 }
1165 }
1166 break;
1167 case Call::TAKESAFILEDESCRIPTORARRAY:
1168 {
1169 ::std::vector<::android::base::unique_fd> in_f;
1170 ::std::vector<::android::base::unique_fd> _aidl_return;
1171 if (!(_aidl_data.checkInterface(this))) {
1172 _aidl_ret_status = ::android::BAD_TYPE;
1173 break;
1174 }
1175 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1176 if (((_aidl_ret_status) != (::android::OK))) {
1177 break;
1178 }
1179 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
1180 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
1181 atrace_end(ATRACE_TAG_AIDL);
1182 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1183 if (((_aidl_ret_status) != (::android::OK))) {
1184 break;
1185 }
1186 if (!_aidl_status.isOk()) {
1187 break;
1188 }
1189 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1190 if (((_aidl_ret_status) != (::android::OK))) {
1191 break;
1192 }
1193 }
1194 break;
1195 default:
1196 {
1197 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1198 }
1199 break;
1200 }
1201 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1202 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1203 }
1204 return _aidl_ret_status;
1205 }
1206
1207 } // namespace os
1208
1209 } // namespace android
1210 )";
1211
1212 const char kExpectedComplexTypeInterfaceHeaderOutput[] =
1213 R"(#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
1227 namespace android {
1228
1229 namespace os {
1230
1231 class IComplexTypeInterface : public ::android::IInterface {
1232 public:
1233 DECLARE_META_INTERFACE(ComplexTypeInterface)
1234 enum : int32_t {
1235 MY_CONSTANT = 3,
1236 };
1237 virtual ::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;
1238 virtual ::android::binder::Status Piff(int32_t times) = 0;
1239 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1240 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1241 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1242 virtual ::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;
1243 virtual ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) = 0;
1244 virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
1245 enum 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
1264 const char kExpectedComplexTypeInterfaceSourceOutput[] =
1265 R"(#include <android/os/IComplexTypeInterface.h>
1266 #include <android/os/BpComplexTypeInterface.h>
1267
1268 namespace android {
1269
1270 namespace os {
1271
1272 IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
1273
1274 } // namespace os
1275
1276 } // namespace android
1277 )";
1278
1279 } // namespace
1280
1281 class ASTTest : public ::testing::Test {
1282 protected:
ASTTest(string file_path,string file_contents)1283 ASTTest(string file_path, string file_contents)
1284 : file_path_(file_path),
1285 file_contents_(file_contents) {
1286 types_.Init();
1287 }
1288
Parse()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
Compare(Document * doc,const char * expected)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
1330 class ComplexTypeInterfaceASTTest : public ASTTest {
1331 public:
ComplexTypeInterfaceASTTest()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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesClientHeader)1340 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesClientSource)1347 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesClientSourceWithTrace)1354 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesServerHeader)1362 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesServerSource)1369 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesServerSourceWithTrace)1376 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesInterfaceHeader)1384 TEST_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
TEST_F(ComplexTypeInterfaceASTTest,GeneratesInterfaceSource)1391 TEST_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
1398 namespace test_io_handling {
1399
1400 const char kInputPath[] = "a/IFoo.aidl";
1401 const char kOutputPath[] = "output.cpp";
1402 const char kHeaderDir[] = "headers";
1403 const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1404
1405 } // namespace test_io_handling
1406
1407 class IoErrorHandlingTest : public ASTTest {
1408 public:
IoErrorHandlingTest()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:
GetOptions()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
TEST_F(IoErrorHandlingTest,GenerateCorrectlyAbsentErrors)1428 TEST_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
TEST_F(IoErrorHandlingTest,HandlesBadHeaderWrite)1435 TEST_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
TEST_F(IoErrorHandlingTest,HandlesBadCppWrite)1452 TEST_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