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
31 using ::android::aidl::test::FakeIoDelegate;
32 using ::android::base::StringPrintf;
33 using std::string;
34 using std::unique_ptr;
35
36 namespace android {
37 namespace aidl {
38 namespace cpp {
39 namespace {
40
41 const string kComplexTypeInterfaceAIDL =
42 R"(package android.os;
43 import foo.IFooType;
44 interface IComplexTypeInterface {
45 const int MY_CONSTANT = 3;
46 int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
47 oneway void Piff(int times);
48 IFooType TakesABinder(IFooType f);
49 @nullable IFooType NullableBinder();
50 List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
51 List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
52 FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
53 FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
54 })";
55
56 const char kExpectedComplexTypeClientHeaderOutput[] =
57 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
58 #define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
59
60 #include <binder/IBinder.h>
61 #include <binder/IInterface.h>
62 #include <utils/Errors.h>
63 #include <android/os/IComplexTypeInterface.h>
64
65 namespace android {
66
67 namespace os {
68
69 class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
70 public:
71 explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
72 virtual ~BpComplexTypeInterface() = default;
73 ::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;
74 ::android::binder::Status Piff(int32_t times) override;
75 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
76 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
77 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
78 ::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;
79 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) override;
80 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
81 }; // class BpComplexTypeInterface
82
83 } // namespace os
84
85 } // namespace android
86
87 #endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
88 )";
89
90 const char kExpectedComplexTypeClientSourceOutput[] =
91 R"(#include <android/os/BpComplexTypeInterface.h>
92 #include <binder/Parcel.h>
93 #include <android-base/macros.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(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
125 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
126 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
127 }
128 if (((_aidl_ret_status) != (::android::OK))) {
129 goto _aidl_error;
130 }
131 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
132 if (((_aidl_ret_status) != (::android::OK))) {
133 goto _aidl_error;
134 }
135 if (!_aidl_status.isOk()) {
136 return _aidl_status;
137 }
138 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
139 if (((_aidl_ret_status) != (::android::OK))) {
140 goto _aidl_error;
141 }
142 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
143 if (((_aidl_ret_status) != (::android::OK))) {
144 goto _aidl_error;
145 }
146 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
147 if (((_aidl_ret_status) != (::android::OK))) {
148 goto _aidl_error;
149 }
150 _aidl_error:
151 _aidl_status.setFromStatusT(_aidl_ret_status);
152 return _aidl_status;
153 }
154
155 ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
156 ::android::Parcel _aidl_data;
157 ::android::Parcel _aidl_reply;
158 ::android::status_t _aidl_ret_status = ::android::OK;
159 ::android::binder::Status _aidl_status;
160 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
161 if (((_aidl_ret_status) != (::android::OK))) {
162 goto _aidl_error;
163 }
164 _aidl_ret_status = _aidl_data.writeInt32(times);
165 if (((_aidl_ret_status) != (::android::OK))) {
166 goto _aidl_error;
167 }
168 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
169 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
170 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
171 }
172 if (((_aidl_ret_status) != (::android::OK))) {
173 goto _aidl_error;
174 }
175 _aidl_error:
176 _aidl_status.setFromStatusT(_aidl_ret_status);
177 return _aidl_status;
178 }
179
180 ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
181 ::android::Parcel _aidl_data;
182 ::android::Parcel _aidl_reply;
183 ::android::status_t _aidl_ret_status = ::android::OK;
184 ::android::binder::Status _aidl_status;
185 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
186 if (((_aidl_ret_status) != (::android::OK))) {
187 goto _aidl_error;
188 }
189 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
190 if (((_aidl_ret_status) != (::android::OK))) {
191 goto _aidl_error;
192 }
193 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
194 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
195 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
196 }
197 if (((_aidl_ret_status) != (::android::OK))) {
198 goto _aidl_error;
199 }
200 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
201 if (((_aidl_ret_status) != (::android::OK))) {
202 goto _aidl_error;
203 }
204 if (!_aidl_status.isOk()) {
205 return _aidl_status;
206 }
207 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
208 if (((_aidl_ret_status) != (::android::OK))) {
209 goto _aidl_error;
210 }
211 _aidl_error:
212 _aidl_status.setFromStatusT(_aidl_ret_status);
213 return _aidl_status;
214 }
215
216 ::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
217 ::android::Parcel _aidl_data;
218 ::android::Parcel _aidl_reply;
219 ::android::status_t _aidl_ret_status = ::android::OK;
220 ::android::binder::Status _aidl_status;
221 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
222 if (((_aidl_ret_status) != (::android::OK))) {
223 goto _aidl_error;
224 }
225 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
226 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
227 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
228 }
229 if (((_aidl_ret_status) != (::android::OK))) {
230 goto _aidl_error;
231 }
232 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
233 if (((_aidl_ret_status) != (::android::OK))) {
234 goto _aidl_error;
235 }
236 if (!_aidl_status.isOk()) {
237 return _aidl_status;
238 }
239 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
240 if (((_aidl_ret_status) != (::android::OK))) {
241 goto _aidl_error;
242 }
243 _aidl_error:
244 _aidl_status.setFromStatusT(_aidl_ret_status);
245 return _aidl_status;
246 }
247
248 ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
249 ::android::Parcel _aidl_data;
250 ::android::Parcel _aidl_reply;
251 ::android::status_t _aidl_ret_status = ::android::OK;
252 ::android::binder::Status _aidl_status;
253 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
254 if (((_aidl_ret_status) != (::android::OK))) {
255 goto _aidl_error;
256 }
257 _aidl_ret_status = _aidl_data.writeString16Vector(input);
258 if (((_aidl_ret_status) != (::android::OK))) {
259 goto _aidl_error;
260 }
261 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
262 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
263 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
264 }
265 if (((_aidl_ret_status) != (::android::OK))) {
266 goto _aidl_error;
267 }
268 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
269 if (((_aidl_ret_status) != (::android::OK))) {
270 goto _aidl_error;
271 }
272 if (!_aidl_status.isOk()) {
273 return _aidl_status;
274 }
275 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
276 if (((_aidl_ret_status) != (::android::OK))) {
277 goto _aidl_error;
278 }
279 _aidl_ret_status = _aidl_reply.readString16Vector(output);
280 if (((_aidl_ret_status) != (::android::OK))) {
281 goto _aidl_error;
282 }
283 _aidl_error:
284 _aidl_status.setFromStatusT(_aidl_ret_status);
285 return _aidl_status;
286 }
287
288 ::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) {
289 ::android::Parcel _aidl_data;
290 ::android::Parcel _aidl_reply;
291 ::android::status_t _aidl_ret_status = ::android::OK;
292 ::android::binder::Status _aidl_status;
293 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
294 if (((_aidl_ret_status) != (::android::OK))) {
295 goto _aidl_error;
296 }
297 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
298 if (((_aidl_ret_status) != (::android::OK))) {
299 goto _aidl_error;
300 }
301 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
302 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
303 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
304 }
305 if (((_aidl_ret_status) != (::android::OK))) {
306 goto _aidl_error;
307 }
308 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
309 if (((_aidl_ret_status) != (::android::OK))) {
310 goto _aidl_error;
311 }
312 if (!_aidl_status.isOk()) {
313 return _aidl_status;
314 }
315 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
316 if (((_aidl_ret_status) != (::android::OK))) {
317 goto _aidl_error;
318 }
319 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
320 if (((_aidl_ret_status) != (::android::OK))) {
321 goto _aidl_error;
322 }
323 _aidl_error:
324 _aidl_status.setFromStatusT(_aidl_ret_status);
325 return _aidl_status;
326 }
327
328 ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
329 ::android::Parcel _aidl_data;
330 ::android::Parcel _aidl_reply;
331 ::android::status_t _aidl_ret_status = ::android::OK;
332 ::android::binder::Status _aidl_status;
333 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
334 if (((_aidl_ret_status) != (::android::OK))) {
335 goto _aidl_error;
336 }
337 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
338 if (((_aidl_ret_status) != (::android::OK))) {
339 goto _aidl_error;
340 }
341 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
342 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
343 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
344 }
345 if (((_aidl_ret_status) != (::android::OK))) {
346 goto _aidl_error;
347 }
348 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
349 if (((_aidl_ret_status) != (::android::OK))) {
350 goto _aidl_error;
351 }
352 if (!_aidl_status.isOk()) {
353 return _aidl_status;
354 }
355 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
356 if (((_aidl_ret_status) != (::android::OK))) {
357 goto _aidl_error;
358 }
359 _aidl_error:
360 _aidl_status.setFromStatusT(_aidl_ret_status);
361 return _aidl_status;
362 }
363
364 ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
365 ::android::Parcel _aidl_data;
366 ::android::Parcel _aidl_reply;
367 ::android::status_t _aidl_ret_status = ::android::OK;
368 ::android::binder::Status _aidl_status;
369 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
370 if (((_aidl_ret_status) != (::android::OK))) {
371 goto _aidl_error;
372 }
373 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
374 if (((_aidl_ret_status) != (::android::OK))) {
375 goto _aidl_error;
376 }
377 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
378 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
379 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
380 }
381 if (((_aidl_ret_status) != (::android::OK))) {
382 goto _aidl_error;
383 }
384 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
385 if (((_aidl_ret_status) != (::android::OK))) {
386 goto _aidl_error;
387 }
388 if (!_aidl_status.isOk()) {
389 return _aidl_status;
390 }
391 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
392 if (((_aidl_ret_status) != (::android::OK))) {
393 goto _aidl_error;
394 }
395 _aidl_error:
396 _aidl_status.setFromStatusT(_aidl_ret_status);
397 return _aidl_status;
398 }
399
400 } // namespace os
401
402 } // namespace android
403 )";
404
405 const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
406 R"(#include <android/os/BpComplexTypeInterface.h>
407 #include <binder/Parcel.h>
408 #include <android-base/macros.h>
409
410 namespace android {
411
412 namespace os {
413
414 BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
415 : BpInterface<IComplexTypeInterface>(_aidl_impl){
416 }
417
418 ::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) {
419 ::android::Parcel _aidl_data;
420 ::android::Parcel _aidl_reply;
421 ::android::status_t _aidl_ret_status = ::android::OK;
422 ::android::binder::Status _aidl_status;
423 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppClient");
424 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
425 if (((_aidl_ret_status) != (::android::OK))) {
426 goto _aidl_error;
427 }
428 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
429 if (((_aidl_ret_status) != (::android::OK))) {
430 goto _aidl_error;
431 }
432 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
433 if (((_aidl_ret_status) != (::android::OK))) {
434 goto _aidl_error;
435 }
436 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
437 if (((_aidl_ret_status) != (::android::OK))) {
438 goto _aidl_error;
439 }
440 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
441 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
442 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
443 }
444 if (((_aidl_ret_status) != (::android::OK))) {
445 goto _aidl_error;
446 }
447 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
448 if (((_aidl_ret_status) != (::android::OK))) {
449 goto _aidl_error;
450 }
451 if (!_aidl_status.isOk()) {
452 return _aidl_status;
453 }
454 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
455 if (((_aidl_ret_status) != (::android::OK))) {
456 goto _aidl_error;
457 }
458 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
459 if (((_aidl_ret_status) != (::android::OK))) {
460 goto _aidl_error;
461 }
462 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
463 if (((_aidl_ret_status) != (::android::OK))) {
464 goto _aidl_error;
465 }
466 _aidl_error:
467 _aidl_status.setFromStatusT(_aidl_ret_status);
468 return _aidl_status;
469 }
470
471 ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
472 ::android::Parcel _aidl_data;
473 ::android::Parcel _aidl_reply;
474 ::android::status_t _aidl_ret_status = ::android::OK;
475 ::android::binder::Status _aidl_status;
476 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppClient");
477 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
478 if (((_aidl_ret_status) != (::android::OK))) {
479 goto _aidl_error;
480 }
481 _aidl_ret_status = _aidl_data.writeInt32(times);
482 if (((_aidl_ret_status) != (::android::OK))) {
483 goto _aidl_error;
484 }
485 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
486 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
487 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
488 }
489 if (((_aidl_ret_status) != (::android::OK))) {
490 goto _aidl_error;
491 }
492 _aidl_error:
493 _aidl_status.setFromStatusT(_aidl_ret_status);
494 return _aidl_status;
495 }
496
497 ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
498 ::android::Parcel _aidl_data;
499 ::android::Parcel _aidl_reply;
500 ::android::status_t _aidl_ret_status = ::android::OK;
501 ::android::binder::Status _aidl_status;
502 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppClient");
503 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
504 if (((_aidl_ret_status) != (::android::OK))) {
505 goto _aidl_error;
506 }
507 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
508 if (((_aidl_ret_status) != (::android::OK))) {
509 goto _aidl_error;
510 }
511 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
512 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
513 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
514 }
515 if (((_aidl_ret_status) != (::android::OK))) {
516 goto _aidl_error;
517 }
518 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
519 if (((_aidl_ret_status) != (::android::OK))) {
520 goto _aidl_error;
521 }
522 if (!_aidl_status.isOk()) {
523 return _aidl_status;
524 }
525 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
526 if (((_aidl_ret_status) != (::android::OK))) {
527 goto _aidl_error;
528 }
529 _aidl_error:
530 _aidl_status.setFromStatusT(_aidl_ret_status);
531 return _aidl_status;
532 }
533
534 ::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
535 ::android::Parcel _aidl_data;
536 ::android::Parcel _aidl_reply;
537 ::android::status_t _aidl_ret_status = ::android::OK;
538 ::android::binder::Status _aidl_status;
539 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppClient");
540 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
541 if (((_aidl_ret_status) != (::android::OK))) {
542 goto _aidl_error;
543 }
544 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
545 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
546 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
547 }
548 if (((_aidl_ret_status) != (::android::OK))) {
549 goto _aidl_error;
550 }
551 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
552 if (((_aidl_ret_status) != (::android::OK))) {
553 goto _aidl_error;
554 }
555 if (!_aidl_status.isOk()) {
556 return _aidl_status;
557 }
558 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
559 if (((_aidl_ret_status) != (::android::OK))) {
560 goto _aidl_error;
561 }
562 _aidl_error:
563 _aidl_status.setFromStatusT(_aidl_ret_status);
564 return _aidl_status;
565 }
566
567 ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
568 ::android::Parcel _aidl_data;
569 ::android::Parcel _aidl_reply;
570 ::android::status_t _aidl_ret_status = ::android::OK;
571 ::android::binder::Status _aidl_status;
572 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppClient");
573 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
574 if (((_aidl_ret_status) != (::android::OK))) {
575 goto _aidl_error;
576 }
577 _aidl_ret_status = _aidl_data.writeString16Vector(input);
578 if (((_aidl_ret_status) != (::android::OK))) {
579 goto _aidl_error;
580 }
581 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
582 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
583 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
584 }
585 if (((_aidl_ret_status) != (::android::OK))) {
586 goto _aidl_error;
587 }
588 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
589 if (((_aidl_ret_status) != (::android::OK))) {
590 goto _aidl_error;
591 }
592 if (!_aidl_status.isOk()) {
593 return _aidl_status;
594 }
595 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
596 if (((_aidl_ret_status) != (::android::OK))) {
597 goto _aidl_error;
598 }
599 _aidl_ret_status = _aidl_reply.readString16Vector(output);
600 if (((_aidl_ret_status) != (::android::OK))) {
601 goto _aidl_error;
602 }
603 _aidl_error:
604 _aidl_status.setFromStatusT(_aidl_ret_status);
605 return _aidl_status;
606 }
607
608 ::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) {
609 ::android::Parcel _aidl_data;
610 ::android::Parcel _aidl_reply;
611 ::android::status_t _aidl_ret_status = ::android::OK;
612 ::android::binder::Status _aidl_status;
613 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppClient");
614 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
615 if (((_aidl_ret_status) != (::android::OK))) {
616 goto _aidl_error;
617 }
618 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
619 if (((_aidl_ret_status) != (::android::OK))) {
620 goto _aidl_error;
621 }
622 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
623 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
624 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
625 }
626 if (((_aidl_ret_status) != (::android::OK))) {
627 goto _aidl_error;
628 }
629 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
630 if (((_aidl_ret_status) != (::android::OK))) {
631 goto _aidl_error;
632 }
633 if (!_aidl_status.isOk()) {
634 return _aidl_status;
635 }
636 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
637 if (((_aidl_ret_status) != (::android::OK))) {
638 goto _aidl_error;
639 }
640 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
641 if (((_aidl_ret_status) != (::android::OK))) {
642 goto _aidl_error;
643 }
644 _aidl_error:
645 _aidl_status.setFromStatusT(_aidl_ret_status);
646 return _aidl_status;
647 }
648
649 ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
650 ::android::Parcel _aidl_data;
651 ::android::Parcel _aidl_reply;
652 ::android::status_t _aidl_ret_status = ::android::OK;
653 ::android::binder::Status _aidl_status;
654 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppClient");
655 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
656 if (((_aidl_ret_status) != (::android::OK))) {
657 goto _aidl_error;
658 }
659 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
660 if (((_aidl_ret_status) != (::android::OK))) {
661 goto _aidl_error;
662 }
663 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
664 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
665 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
666 }
667 if (((_aidl_ret_status) != (::android::OK))) {
668 goto _aidl_error;
669 }
670 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
671 if (((_aidl_ret_status) != (::android::OK))) {
672 goto _aidl_error;
673 }
674 if (!_aidl_status.isOk()) {
675 return _aidl_status;
676 }
677 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
678 if (((_aidl_ret_status) != (::android::OK))) {
679 goto _aidl_error;
680 }
681 _aidl_error:
682 _aidl_status.setFromStatusT(_aidl_ret_status);
683 return _aidl_status;
684 }
685
686 ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
687 ::android::Parcel _aidl_data;
688 ::android::Parcel _aidl_reply;
689 ::android::status_t _aidl_ret_status = ::android::OK;
690 ::android::binder::Status _aidl_status;
691 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
692 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
693 if (((_aidl_ret_status) != (::android::OK))) {
694 goto _aidl_error;
695 }
696 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
697 if (((_aidl_ret_status) != (::android::OK))) {
698 goto _aidl_error;
699 }
700 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
701 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
702 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
703 }
704 if (((_aidl_ret_status) != (::android::OK))) {
705 goto _aidl_error;
706 }
707 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
708 if (((_aidl_ret_status) != (::android::OK))) {
709 goto _aidl_error;
710 }
711 if (!_aidl_status.isOk()) {
712 return _aidl_status;
713 }
714 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
715 if (((_aidl_ret_status) != (::android::OK))) {
716 goto _aidl_error;
717 }
718 _aidl_error:
719 _aidl_status.setFromStatusT(_aidl_ret_status);
720 return _aidl_status;
721 }
722
723 } // namespace os
724
725 } // namespace android
726 )";
727
728 const char kExpectedComplexTypeServerHeaderOutput[] =
729 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
730 #define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
731
732 #include <binder/IInterface.h>
733 #include <android/os/IComplexTypeInterface.h>
734
735 namespace android {
736
737 namespace os {
738
739 class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
740 public:
741 explicit BnComplexTypeInterface();
742 ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override;
743 }; // class BnComplexTypeInterface
744
745 } // namespace os
746
747 } // namespace android
748
749 #endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
750 )";
751
752 const char kExpectedComplexTypeServerSourceOutput[] =
753 R"(#include <android/os/BnComplexTypeInterface.h>
754 #include <binder/Parcel.h>
755 #include <binder/Stability.h>
756
757 namespace android {
758
759 namespace os {
760
761 BnComplexTypeInterface::BnComplexTypeInterface()
762 {
763 ::android::internal::Stability::markCompilationUnit(this);
764 }
765
766 ::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
767 ::android::status_t _aidl_ret_status = ::android::OK;
768 switch (_aidl_code) {
769 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
770 {
771 ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
772 ::std::vector<double> in_goes_in_and_out;
773 ::std::vector<bool> out_goes_out;
774 ::std::vector<int32_t> _aidl_return;
775 if (!(_aidl_data.checkInterface(this))) {
776 _aidl_ret_status = ::android::BAD_TYPE;
777 break;
778 }
779 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
780 if (((_aidl_ret_status) != (::android::OK))) {
781 break;
782 }
783 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
784 if (((_aidl_ret_status) != (::android::OK))) {
785 break;
786 }
787 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
788 if (((_aidl_ret_status) != (::android::OK))) {
789 break;
790 }
791 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
792 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
793 if (((_aidl_ret_status) != (::android::OK))) {
794 break;
795 }
796 if (!_aidl_status.isOk()) {
797 break;
798 }
799 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
800 if (((_aidl_ret_status) != (::android::OK))) {
801 break;
802 }
803 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
804 if (((_aidl_ret_status) != (::android::OK))) {
805 break;
806 }
807 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
808 if (((_aidl_ret_status) != (::android::OK))) {
809 break;
810 }
811 }
812 break;
813 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
814 {
815 int32_t in_times;
816 if (!(_aidl_data.checkInterface(this))) {
817 _aidl_ret_status = ::android::BAD_TYPE;
818 break;
819 }
820 _aidl_ret_status = _aidl_data.readInt32(&in_times);
821 if (((_aidl_ret_status) != (::android::OK))) {
822 break;
823 }
824 ::android::binder::Status _aidl_status(Piff(in_times));
825 }
826 break;
827 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
828 {
829 ::android::sp<::foo::IFooType> in_f;
830 ::android::sp<::foo::IFooType> _aidl_return;
831 if (!(_aidl_data.checkInterface(this))) {
832 _aidl_ret_status = ::android::BAD_TYPE;
833 break;
834 }
835 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
836 if (((_aidl_ret_status) != (::android::OK))) {
837 break;
838 }
839 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
840 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
841 if (((_aidl_ret_status) != (::android::OK))) {
842 break;
843 }
844 if (!_aidl_status.isOk()) {
845 break;
846 }
847 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
848 if (((_aidl_ret_status) != (::android::OK))) {
849 break;
850 }
851 }
852 break;
853 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
854 {
855 ::android::sp<::foo::IFooType> _aidl_return;
856 if (!(_aidl_data.checkInterface(this))) {
857 _aidl_ret_status = ::android::BAD_TYPE;
858 break;
859 }
860 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
861 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
862 if (((_aidl_ret_status) != (::android::OK))) {
863 break;
864 }
865 if (!_aidl_status.isOk()) {
866 break;
867 }
868 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
869 if (((_aidl_ret_status) != (::android::OK))) {
870 break;
871 }
872 }
873 break;
874 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
875 {
876 ::std::vector<::android::String16> in_input;
877 ::std::vector<::android::String16> out_output;
878 ::std::vector<::android::String16> _aidl_return;
879 if (!(_aidl_data.checkInterface(this))) {
880 _aidl_ret_status = ::android::BAD_TYPE;
881 break;
882 }
883 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
884 if (((_aidl_ret_status) != (::android::OK))) {
885 break;
886 }
887 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
888 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
889 if (((_aidl_ret_status) != (::android::OK))) {
890 break;
891 }
892 if (!_aidl_status.isOk()) {
893 break;
894 }
895 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
896 if (((_aidl_ret_status) != (::android::OK))) {
897 break;
898 }
899 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
900 if (((_aidl_ret_status) != (::android::OK))) {
901 break;
902 }
903 }
904 break;
905 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
906 {
907 ::std::vector<::android::sp<::android::IBinder>> in_input;
908 ::std::vector<::android::sp<::android::IBinder>> out_output;
909 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
910 if (!(_aidl_data.checkInterface(this))) {
911 _aidl_ret_status = ::android::BAD_TYPE;
912 break;
913 }
914 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
915 if (((_aidl_ret_status) != (::android::OK))) {
916 break;
917 }
918 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_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->writeStrongBinderVector(_aidl_return);
927 if (((_aidl_ret_status) != (::android::OK))) {
928 break;
929 }
930 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
931 if (((_aidl_ret_status) != (::android::OK))) {
932 break;
933 }
934 }
935 break;
936 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
937 {
938 ::android::base::unique_fd in_f;
939 ::android::base::unique_fd _aidl_return;
940 if (!(_aidl_data.checkInterface(this))) {
941 _aidl_ret_status = ::android::BAD_TYPE;
942 break;
943 }
944 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
945 if (((_aidl_ret_status) != (::android::OK))) {
946 break;
947 }
948 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
949 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
950 if (((_aidl_ret_status) != (::android::OK))) {
951 break;
952 }
953 if (!_aidl_status.isOk()) {
954 break;
955 }
956 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
957 if (((_aidl_ret_status) != (::android::OK))) {
958 break;
959 }
960 }
961 break;
962 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
963 {
964 ::std::vector<::android::base::unique_fd> in_f;
965 ::std::vector<::android::base::unique_fd> _aidl_return;
966 if (!(_aidl_data.checkInterface(this))) {
967 _aidl_ret_status = ::android::BAD_TYPE;
968 break;
969 }
970 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
971 if (((_aidl_ret_status) != (::android::OK))) {
972 break;
973 }
974 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
975 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
976 if (((_aidl_ret_status) != (::android::OK))) {
977 break;
978 }
979 if (!_aidl_status.isOk()) {
980 break;
981 }
982 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
983 if (((_aidl_ret_status) != (::android::OK))) {
984 break;
985 }
986 }
987 break;
988 default:
989 {
990 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
991 }
992 break;
993 }
994 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
995 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
996 }
997 return _aidl_ret_status;
998 }
999
1000 } // namespace os
1001
1002 } // namespace android
1003 )";
1004
1005 const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
1006 R"(#include <android/os/BnComplexTypeInterface.h>
1007 #include <binder/Parcel.h>
1008 #include <binder/Stability.h>
1009
1010 namespace android {
1011
1012 namespace os {
1013
1014 BnComplexTypeInterface::BnComplexTypeInterface()
1015 {
1016 ::android::internal::Stability::markCompilationUnit(this);
1017 }
1018
1019 ::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
1020 ::android::status_t _aidl_ret_status = ::android::OK;
1021 switch (_aidl_code) {
1022 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
1023 {
1024 ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
1025 ::std::vector<double> in_goes_in_and_out;
1026 ::std::vector<bool> out_goes_out;
1027 ::std::vector<int32_t> _aidl_return;
1028 if (!(_aidl_data.checkInterface(this))) {
1029 _aidl_ret_status = ::android::BAD_TYPE;
1030 break;
1031 }
1032 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
1033 if (((_aidl_ret_status) != (::android::OK))) {
1034 break;
1035 }
1036 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
1037 if (((_aidl_ret_status) != (::android::OK))) {
1038 break;
1039 }
1040 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
1041 if (((_aidl_ret_status) != (::android::OK))) {
1042 break;
1043 }
1044 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppServer");
1045 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
1046 atrace_end(ATRACE_TAG_AIDL);
1047 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1048 if (((_aidl_ret_status) != (::android::OK))) {
1049 break;
1050 }
1051 if (!_aidl_status.isOk()) {
1052 break;
1053 }
1054 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
1055 if (((_aidl_ret_status) != (::android::OK))) {
1056 break;
1057 }
1058 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
1059 if (((_aidl_ret_status) != (::android::OK))) {
1060 break;
1061 }
1062 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1063 if (((_aidl_ret_status) != (::android::OK))) {
1064 break;
1065 }
1066 }
1067 break;
1068 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
1069 {
1070 int32_t in_times;
1071 if (!(_aidl_data.checkInterface(this))) {
1072 _aidl_ret_status = ::android::BAD_TYPE;
1073 break;
1074 }
1075 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1076 if (((_aidl_ret_status) != (::android::OK))) {
1077 break;
1078 }
1079 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppServer");
1080 ::android::binder::Status _aidl_status(Piff(in_times));
1081 atrace_end(ATRACE_TAG_AIDL);
1082 }
1083 break;
1084 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
1085 {
1086 ::android::sp<::foo::IFooType> in_f;
1087 ::android::sp<::foo::IFooType> _aidl_return;
1088 if (!(_aidl_data.checkInterface(this))) {
1089 _aidl_ret_status = ::android::BAD_TYPE;
1090 break;
1091 }
1092 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1093 if (((_aidl_ret_status) != (::android::OK))) {
1094 break;
1095 }
1096 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppServer");
1097 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
1098 atrace_end(ATRACE_TAG_AIDL);
1099 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1100 if (((_aidl_ret_status) != (::android::OK))) {
1101 break;
1102 }
1103 if (!_aidl_status.isOk()) {
1104 break;
1105 }
1106 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1107 if (((_aidl_ret_status) != (::android::OK))) {
1108 break;
1109 }
1110 }
1111 break;
1112 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
1113 {
1114 ::android::sp<::foo::IFooType> _aidl_return;
1115 if (!(_aidl_data.checkInterface(this))) {
1116 _aidl_ret_status = ::android::BAD_TYPE;
1117 break;
1118 }
1119 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppServer");
1120 ::android::binder::Status _aidl_status(NullableBinder(&_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->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1130 if (((_aidl_ret_status) != (::android::OK))) {
1131 break;
1132 }
1133 }
1134 break;
1135 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
1136 {
1137 ::std::vector<::android::String16> in_input;
1138 ::std::vector<::android::String16> out_output;
1139 ::std::vector<::android::String16> _aidl_return;
1140 if (!(_aidl_data.checkInterface(this))) {
1141 _aidl_ret_status = ::android::BAD_TYPE;
1142 break;
1143 }
1144 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1145 if (((_aidl_ret_status) != (::android::OK))) {
1146 break;
1147 }
1148 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppServer");
1149 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
1150 atrace_end(ATRACE_TAG_AIDL);
1151 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1152 if (((_aidl_ret_status) != (::android::OK))) {
1153 break;
1154 }
1155 if (!_aidl_status.isOk()) {
1156 break;
1157 }
1158 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1159 if (((_aidl_ret_status) != (::android::OK))) {
1160 break;
1161 }
1162 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1163 if (((_aidl_ret_status) != (::android::OK))) {
1164 break;
1165 }
1166 }
1167 break;
1168 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
1169 {
1170 ::std::vector<::android::sp<::android::IBinder>> in_input;
1171 ::std::vector<::android::sp<::android::IBinder>> out_output;
1172 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
1173 if (!(_aidl_data.checkInterface(this))) {
1174 _aidl_ret_status = ::android::BAD_TYPE;
1175 break;
1176 }
1177 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1178 if (((_aidl_ret_status) != (::android::OK))) {
1179 break;
1180 }
1181 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppServer");
1182 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
1183 atrace_end(ATRACE_TAG_AIDL);
1184 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1185 if (((_aidl_ret_status) != (::android::OK))) {
1186 break;
1187 }
1188 if (!_aidl_status.isOk()) {
1189 break;
1190 }
1191 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1192 if (((_aidl_ret_status) != (::android::OK))) {
1193 break;
1194 }
1195 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1196 if (((_aidl_ret_status) != (::android::OK))) {
1197 break;
1198 }
1199 }
1200 break;
1201 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
1202 {
1203 ::android::base::unique_fd in_f;
1204 ::android::base::unique_fd _aidl_return;
1205 if (!(_aidl_data.checkInterface(this))) {
1206 _aidl_ret_status = ::android::BAD_TYPE;
1207 break;
1208 }
1209 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1210 if (((_aidl_ret_status) != (::android::OK))) {
1211 break;
1212 }
1213 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppServer");
1214 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
1215 atrace_end(ATRACE_TAG_AIDL);
1216 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1217 if (((_aidl_ret_status) != (::android::OK))) {
1218 break;
1219 }
1220 if (!_aidl_status.isOk()) {
1221 break;
1222 }
1223 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1224 if (((_aidl_ret_status) != (::android::OK))) {
1225 break;
1226 }
1227 }
1228 break;
1229 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
1230 {
1231 ::std::vector<::android::base::unique_fd> in_f;
1232 ::std::vector<::android::base::unique_fd> _aidl_return;
1233 if (!(_aidl_data.checkInterface(this))) {
1234 _aidl_ret_status = ::android::BAD_TYPE;
1235 break;
1236 }
1237 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1238 if (((_aidl_ret_status) != (::android::OK))) {
1239 break;
1240 }
1241 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
1242 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
1243 atrace_end(ATRACE_TAG_AIDL);
1244 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1245 if (((_aidl_ret_status) != (::android::OK))) {
1246 break;
1247 }
1248 if (!_aidl_status.isOk()) {
1249 break;
1250 }
1251 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1252 if (((_aidl_ret_status) != (::android::OK))) {
1253 break;
1254 }
1255 }
1256 break;
1257 default:
1258 {
1259 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1260 }
1261 break;
1262 }
1263 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1264 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1265 }
1266 return _aidl_ret_status;
1267 }
1268
1269 } // namespace os
1270
1271 } // namespace android
1272 )";
1273
1274 const char kExpectedComplexTypeInterfaceHeaderOutput[] =
1275 R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1276 #define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1277
1278 #include <android-base/unique_fd.h>
1279 #include <binder/IBinder.h>
1280 #include <binder/IInterface.h>
1281 #include <binder/Status.h>
1282 #include <cstdint>
1283 #include <foo/IFooType.h>
1284 #include <memory>
1285 #include <utils/String16.h>
1286 #include <utils/StrongPointer.h>
1287 #include <vector>
1288
1289 namespace android {
1290
1291 namespace os {
1292
1293 class IComplexTypeInterface : public ::android::IInterface {
1294 public:
1295 DECLARE_META_INTERFACE(ComplexTypeInterface)
1296 enum : int32_t {
1297 MY_CONSTANT = 3,
1298 };
1299 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;
1300 virtual ::android::binder::Status Piff(int32_t times) = 0;
1301 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1302 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1303 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1304 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;
1305 virtual ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) = 0;
1306 virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
1307 }; // class IComplexTypeInterface
1308
1309 class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1310 public:
1311 ::android::IBinder* onAsBinder() override {
1312 return nullptr;
1313 }
1314 ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>*) override {
1315 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1316 }
1317 ::android::binder::Status Piff(int32_t) override {
1318 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1319 }
1320 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>*) override {
1321 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1322 }
1323 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>*) override {
1324 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1325 }
1326 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>&, ::std::vector<::android::String16>*, ::std::vector<::android::String16>*) override {
1327 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1328 }
1329 ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>&, ::std::vector<::android::sp<::android::IBinder>>*, ::std::vector<::android::sp<::android::IBinder>>*) override {
1330 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1331 }
1332 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd, ::android::base::unique_fd*) override {
1333 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1334 }
1335 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>&, ::std::vector<::android::base::unique_fd>*) override {
1336 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1337 }
1338 }; // class IComplexTypeInterfaceDefault
1339
1340 } // namespace os
1341
1342 } // namespace android
1343
1344 #endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1345 )";
1346
1347 const char kExpectedComplexTypeInterfaceSourceOutput[] =
1348 R"(#include <android/os/IComplexTypeInterface.h>
1349 #include <android/os/BpComplexTypeInterface.h>
1350
1351 namespace android {
1352
1353 namespace os {
1354
1355 DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
1356
1357 } // namespace os
1358
1359 } // namespace android
1360 )";
1361
1362 const string kEnumAIDL = R"(package android.os;
1363 enum TestEnum {
1364 ZERO,
1365 ONE,
1366 THREE = 3,
1367 FOUR = 3 + 1,
1368 FIVE,
1369 SIX,
1370 SEVEN,
1371 EIGHT = 16 / 2,
1372 NINE,
1373 TEN,
1374 })";
1375
1376 // clang-format off
1377 const char kExpectedEnumHeaderOutput[] =
1378 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1379 #define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1380
1381 #include <array>
1382 #include <binder/Enums.h>
1383 #include <cstdint>
1384 #include <string>
1385
1386 namespace android {
1387
1388 namespace os {
1389
1390 enum class TestEnum : int8_t {
1391 ZERO = 0,
1392 ONE = 1,
1393 THREE = 3,
1394 FOUR = 4,
1395 FIVE = 5,
1396 SIX = 6,
1397 SEVEN = 7,
1398 EIGHT = 8,
1399 NINE = 9,
1400 TEN = 10,
1401 };
1402
1403 static inline std::string toString(TestEnum val) {
1404 switch(val) {
1405 case TestEnum::ZERO:
1406 return "ZERO";
1407 case TestEnum::ONE:
1408 return "ONE";
1409 case TestEnum::THREE:
1410 return "THREE";
1411 case TestEnum::FOUR:
1412 return "FOUR";
1413 case TestEnum::FIVE:
1414 return "FIVE";
1415 case TestEnum::SIX:
1416 return "SIX";
1417 case TestEnum::SEVEN:
1418 return "SEVEN";
1419 case TestEnum::EIGHT:
1420 return "EIGHT";
1421 case TestEnum::NINE:
1422 return "NINE";
1423 case TestEnum::TEN:
1424 return "TEN";
1425 default:
1426 return std::to_string(static_cast<int8_t>(val));
1427 }
1428 }
1429
1430 } // namespace os
1431
1432 } // namespace android
1433 namespace android {
1434
1435 namespace internal {
1436
1437 #pragma clang diagnostic push
1438 #pragma clang diagnostic ignored "-Wc++17-extensions"
1439 template <>
1440 constexpr inline std::array<::android::os::TestEnum, 10> enum_values<::android::os::TestEnum> = {
1441 ::android::os::TestEnum::ZERO,
1442 ::android::os::TestEnum::ONE,
1443 ::android::os::TestEnum::THREE,
1444 ::android::os::TestEnum::FOUR,
1445 ::android::os::TestEnum::FIVE,
1446 ::android::os::TestEnum::SIX,
1447 ::android::os::TestEnum::SEVEN,
1448 ::android::os::TestEnum::EIGHT,
1449 ::android::os::TestEnum::NINE,
1450 ::android::os::TestEnum::TEN,
1451 };
1452 #pragma clang diagnostic pop
1453
1454 } // namespace internal
1455
1456 } // namespace android
1457
1458 #endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1459 )";
1460 // clang-format on
1461
1462 const string kEnumWithBackingTypeAIDL = R"(package android.os;
1463 @Backing(type="long")
1464 enum TestEnum {
1465 FOO = 1,
1466 BAR = 2,
1467 })";
1468
1469 // clang-format off
1470 const char kExpectedEnumWithBackingTypeHeaderOutput[] =
1471 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1472 #define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1473
1474 #include <array>
1475 #include <binder/Enums.h>
1476 #include <cstdint>
1477 #include <string>
1478
1479 namespace android {
1480
1481 namespace os {
1482
1483 enum class TestEnum : int64_t {
1484 FOO = 1L,
1485 BAR = 2L,
1486 };
1487
1488 static inline std::string toString(TestEnum val) {
1489 switch(val) {
1490 case TestEnum::FOO:
1491 return "FOO";
1492 case TestEnum::BAR:
1493 return "BAR";
1494 default:
1495 return std::to_string(static_cast<int64_t>(val));
1496 }
1497 }
1498
1499 } // namespace os
1500
1501 } // namespace android
1502 namespace android {
1503
1504 namespace internal {
1505
1506 #pragma clang diagnostic push
1507 #pragma clang diagnostic ignored "-Wc++17-extensions"
1508 template <>
1509 constexpr inline std::array<::android::os::TestEnum, 2> enum_values<::android::os::TestEnum> = {
1510 ::android::os::TestEnum::FOO,
1511 ::android::os::TestEnum::BAR,
1512 };
1513 #pragma clang diagnostic pop
1514
1515 } // namespace internal
1516
1517 } // namespace android
1518
1519 #endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1520 )";
1521 // clang-format on
1522
1523 } // namespace
1524
1525 class ASTTest : public ::testing::Test {
1526 protected:
ASTTest(const string & cmdline,const string & file_contents)1527 ASTTest(const string& cmdline, const string& file_contents)
1528 : options_(Options::From(cmdline)), file_contents_(file_contents) {
1529 }
1530
ParseSingleInterface()1531 AidlInterface* ParseSingleInterface() {
1532 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1533
1534 vector<AidlDefinedType*> defined_types;
1535 vector<string> imported_files;
1536 ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
1537 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
1538 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
1539 &imported_files);
1540
1541 if (err != AidlError::OK) {
1542 return nullptr;
1543 }
1544
1545 EXPECT_EQ(1ul, defined_types.size());
1546 EXPECT_NE(nullptr, defined_types.front()->AsInterface());
1547
1548 return defined_types.front()->AsInterface();
1549 }
1550
ParseSingleEnumDeclaration()1551 AidlEnumDeclaration* ParseSingleEnumDeclaration() {
1552 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1553
1554 vector<AidlDefinedType*> defined_types;
1555 vector<string> imported_files;
1556 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
1557 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
1558 &imported_files);
1559
1560 if (err != AidlError::OK) {
1561 return nullptr;
1562 }
1563
1564 EXPECT_EQ(1ul, defined_types.size());
1565 EXPECT_NE(nullptr, defined_types.front()->AsEnumDeclaration());
1566
1567 return defined_types.front()->AsEnumDeclaration();
1568 }
1569
Compare(Document * doc,const char * expected)1570 void Compare(Document* doc, const char* expected) {
1571 string output;
1572 doc->Write(CodeWriter::ForString(&output).get());
1573
1574 if (expected == output) {
1575 return; // Success
1576 }
1577
1578 test::PrintDiff(expected, output);
1579 FAIL() << "Document contents did not match expected contents";
1580 }
1581
1582 const Options options_;
1583 const string file_contents_;
1584 FakeIoDelegate io_delegate_;
1585 AidlTypenames typenames_;
1586 };
1587
1588 class ComplexTypeInterfaceASTTest : public ASTTest {
1589 public:
ComplexTypeInterfaceASTTest()1590 ComplexTypeInterfaceASTTest()
1591 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
1592 kComplexTypeInterfaceAIDL) {
1593 io_delegate_.SetFileContents("foo/IFooType.aidl",
1594 "package foo; interface IFooType {}");
1595 }
1596 };
1597
TEST_F(ComplexTypeInterfaceASTTest,GeneratesClientHeader)1598 TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
1599 AidlInterface* interface = ParseSingleInterface();
1600 ASSERT_NE(interface, nullptr);
1601 unique_ptr<Document> doc = internals::BuildClientHeader(typenames_, *interface, options_);
1602 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1603 }
1604
TEST_F(ComplexTypeInterfaceASTTest,GeneratesClientSource)1605 TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
1606 AidlInterface* interface = ParseSingleInterface();
1607 ASSERT_NE(interface, nullptr);
1608 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
1609 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1610 }
1611
TEST_F(ComplexTypeInterfaceASTTest,GeneratesServerHeader)1612 TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
1613 AidlInterface* interface = ParseSingleInterface();
1614 ASSERT_NE(interface, nullptr);
1615 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
1616 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1617 }
1618
TEST_F(ComplexTypeInterfaceASTTest,GeneratesServerSource)1619 TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
1620 AidlInterface* interface = ParseSingleInterface();
1621 ASSERT_NE(interface, nullptr);
1622 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
1623 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1624 }
1625
TEST_F(ComplexTypeInterfaceASTTest,GeneratesInterfaceHeader)1626 TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
1627 AidlInterface* interface = ParseSingleInterface();
1628 ASSERT_NE(interface, nullptr);
1629 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
1630 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1631 }
1632
TEST_F(ComplexTypeInterfaceASTTest,GeneratesInterfaceSource)1633 TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
1634 AidlInterface* interface = ParseSingleInterface();
1635 ASSERT_NE(interface, nullptr);
1636 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
1637 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
1638 }
1639
1640 class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1641 public:
ComplexTypeInterfaceASTTestWithTrace()1642 ComplexTypeInterfaceASTTestWithTrace()
1643 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1644 kComplexTypeInterfaceAIDL) {
1645 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1646 }
1647 };
1648
TEST_F(ComplexTypeInterfaceASTTestWithTrace,GeneratesClientSource)1649 TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
1650 AidlInterface* interface = ParseSingleInterface();
1651 ASSERT_NE(interface, nullptr);
1652 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
1653 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1654 }
1655
TEST_F(ComplexTypeInterfaceASTTestWithTrace,GeneratesServerSource)1656 TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
1657 AidlInterface* interface = ParseSingleInterface();
1658 ASSERT_NE(interface, nullptr);
1659 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
1660 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1661 }
1662
1663 namespace test_io_handling {
1664
1665 const char kInputPath[] = "a/IFoo.aidl";
1666 const char kOutputPath[] = "output.cpp";
1667 const char kHeaderDir[] = "headers";
1668 const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1669
1670 const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1671
1672 } // namespace test_io_handling
1673
1674 class IoErrorHandlingTest : public ASTTest {
1675 public:
IoErrorHandlingTest()1676 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
1677 };
1678
TEST_F(IoErrorHandlingTest,GenerateCorrectlyAbsentErrors)1679 TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1680 // Confirm that this is working correctly without I/O problems.
1681 AidlInterface* interface = ParseSingleInterface();
1682 ASSERT_NE(interface, nullptr);
1683 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
1684 }
1685
TEST_F(IoErrorHandlingTest,HandlesBadHeaderWrite)1686 TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1687 using namespace test_io_handling;
1688 AidlInterface* interface = ParseSingleInterface();
1689 ASSERT_NE(interface, nullptr);
1690
1691 // Simulate issues closing the interface header.
1692 const string header_path =
1693 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1694 kInterfaceHeaderRelPath);
1695 io_delegate_.AddBrokenFilePath(header_path);
1696 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
1697 // We should never attempt to write the C++ file if we fail writing headers.
1698 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1699 // We should remove partial results.
1700 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1701 }
1702
TEST_F(IoErrorHandlingTest,HandlesBadCppWrite)1703 TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1704 using test_io_handling::kOutputPath;
1705 AidlInterface* interface = ParseSingleInterface();
1706 ASSERT_NE(interface, nullptr);
1707
1708 // Simulate issues closing the cpp file.
1709 io_delegate_.AddBrokenFilePath(kOutputPath);
1710 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
1711 // We should remove partial results.
1712 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1713 }
1714
1715 class EnumASTTest : public ASTTest {
1716 public:
EnumASTTest()1717 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1718 };
1719
TEST_F(EnumASTTest,GeneratesEnumHeader)1720 TEST_F(EnumASTTest, GeneratesEnumHeader) {
1721 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1722 ASSERT_NE(enum_decl, nullptr);
1723 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1724 Compare(doc.get(), kExpectedEnumHeaderOutput);
1725 }
1726
1727 class EnumWithBackingTypeASTTest : public ASTTest {
1728 public:
EnumWithBackingTypeASTTest()1729 EnumWithBackingTypeASTTest()
1730 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1731 };
1732
TEST_F(EnumWithBackingTypeASTTest,GeneratesEnumHeader)1733 TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1734 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1735 ASSERT_NE(enum_decl, nullptr);
1736 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1737 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1738 }
1739
1740 } // namespace cpp
1741 } // namespace aidl
1742 } // namespace android
1743