blob: 8a1b23f01880155289bb3c8a0829caa721f83265 [file] [log] [blame]
Casey Dahlina834dd42015-09-23 11:52:15 -07001/*
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
Elliott Hughes0a620672015-12-04 13:53:18 -080019#include <android-base/stringprintf.h>
Casey Dahlina834dd42015-09-23 11:52:15 -070020#include <gtest/gtest.h>
21
Casey Dahlin2cc93162015-10-02 16:14:17 -070022#include "aidl.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070023#include "aidl_language.h"
24#include "ast_cpp.h"
25#include "code_writer.h"
Christopher Wileyad339272015-10-05 19:11:58 -070026#include "generate_cpp.h"
Christopher Wiley9d6e0b22015-11-13 12:18:16 -080027#include "os.h"
Christopher Wiley4a2884b2015-10-07 11:27:45 -070028#include "tests/fake_io_delegate.h"
Casey Dahlin80ada3d2015-10-20 20:33:56 -070029#include "tests/test_util.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070030
Casey Dahlinb8d9e882015-11-24 10:57:23 -080031using ::android::aidl::test::FakeIoDelegate;
32using ::android::base::StringPrintf;
Casey Dahlina834dd42015-09-23 11:52:15 -070033using std::string;
34using std::unique_ptr;
35
36namespace android {
37namespace aidl {
Christopher Wileyf944e792015-09-29 10:00:46 -070038namespace cpp {
Casey Dahlina834dd42015-09-23 11:52:15 -070039namespace {
40
Jooyung Han43122462020-01-23 13:03:10 +090041// clang-format off
Casey Dahlinb0966612015-10-19 16:35:26 -070042const string kComplexTypeInterfaceAIDL =
43R"(package android.os;
Casey Dahlin389781f2015-10-22 13:13:21 -070044import foo.IFooType;
Casey Dahlinb0966612015-10-19 16:35:26 -070045interface IComplexTypeInterface {
Casey Dahlind40e2fe2015-11-24 14:06:52 -080046 const int MY_CONSTANT = 3;
Casey Dahlincb5317d2015-12-03 15:43:33 -080047 int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
Casey Dahlin0dd08af2015-10-20 18:45:50 -070048 oneway void Piff(int times);
Casey Dahlin389781f2015-10-22 13:13:21 -070049 IFooType TakesABinder(IFooType f);
Casey Dahlinef88bce2016-04-15 11:55:30 -070050 @nullable IFooType NullableBinder();
Christopher Wiley56c9bf32015-10-30 10:41:12 -070051 List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
Casey Dahlin7ecd69f2015-11-03 13:52:38 -080052 List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
Casey Dahlina4ba4b62015-11-02 15:43:30 -080053 FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
54 FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
Casey Dahlinb0966612015-10-19 16:35:26 -070055})";
56
57const char kExpectedComplexTypeClientHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -070058 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -070059
60#include <binder/IBinder.h>
61#include <binder/IInterface.h>
62#include <utils/Errors.h>
63#include <android/os/IComplexTypeInterface.h>
64
65namespace android {
66
67namespace os {
68
Casey Dahlinb8d9e882015-11-24 10:57:23 -080069class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -070070public:
Jiyong Parka755dc72018-06-29 13:52:24 +090071 explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
72 virtual ~BpComplexTypeInterface() = default;
Jooyung Han43122462020-01-23 13:03:10 +090073 ::android::binder::Status Send(const ::std::optional<::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;
Jiyong Parka755dc72018-06-29 13:52:24 +090074 ::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;
Jiyong Park4f3e8c02019-11-22 14:28:47 +090079 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) override;
Jiyong Parka755dc72018-06-29 13:52:24 +090080 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
Casey Dahlinb0966612015-10-19 16:35:26 -070081}; // class BpComplexTypeInterface
82
83} // namespace os
84
85} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -080086)";
Casey Dahlinb0966612015-10-19 16:35:26 -070087
88const char kExpectedComplexTypeClientSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +090089 R"(#include <android/os/BpComplexTypeInterface.h>
Jiyong Park717fc692020-11-25 16:31:32 +090090#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070091#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +090092#include <android-base/macros.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070093
94namespace android {
95
96namespace os {
97
Casey Dahlinb8d9e882015-11-24 10:57:23 -080098BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
99 : BpInterface<IComplexTypeInterface>(_aidl_impl){
Casey Dahlinb0966612015-10-19 16:35:26 -0700100}
101
Jooyung Han43122462020-01-23 13:03:10 +0900102::android::binder::Status BpComplexTypeInterface::Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900103 ::android::Parcel _aidl_data;
104 ::android::Parcel _aidl_reply;
105 ::android::status_t _aidl_ret_status = ::android::OK;
106 ::android::binder::Status _aidl_status;
107 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
108 if (((_aidl_ret_status) != (::android::OK))) {
109 goto _aidl_error;
110 }
111 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
112 if (((_aidl_ret_status) != (::android::OK))) {
113 goto _aidl_error;
114 }
115 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
116 if (((_aidl_ret_status) != (::android::OK))) {
117 goto _aidl_error;
118 }
119 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
120 if (((_aidl_ret_status) != (::android::OK))) {
121 goto _aidl_error;
122 }
Jiyong Park717fc692020-11-25 16:31:32 +0900123 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Send, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900124 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
125 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
126 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900127 if (((_aidl_ret_status) != (::android::OK))) {
128 goto _aidl_error;
129 }
130 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
131 if (((_aidl_ret_status) != (::android::OK))) {
132 goto _aidl_error;
133 }
134 if (!_aidl_status.isOk()) {
135 return _aidl_status;
136 }
137 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
138 if (((_aidl_ret_status) != (::android::OK))) {
139 goto _aidl_error;
140 }
141 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
142 if (((_aidl_ret_status) != (::android::OK))) {
143 goto _aidl_error;
144 }
145 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
146 if (((_aidl_ret_status) != (::android::OK))) {
147 goto _aidl_error;
148 }
149 _aidl_error:
150 _aidl_status.setFromStatusT(_aidl_ret_status);
151 return _aidl_status;
Casey Dahlinb0966612015-10-19 16:35:26 -0700152}
153
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800154::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900155 ::android::Parcel _aidl_data;
156 ::android::Parcel _aidl_reply;
157 ::android::status_t _aidl_ret_status = ::android::OK;
158 ::android::binder::Status _aidl_status;
159 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
160 if (((_aidl_ret_status) != (::android::OK))) {
161 goto _aidl_error;
162 }
163 _aidl_ret_status = _aidl_data.writeInt32(times);
164 if (((_aidl_ret_status) != (::android::OK))) {
165 goto _aidl_error;
166 }
Jiyong Park717fc692020-11-25 16:31:32 +0900167 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Piff, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900168 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
169 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
170 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900171 if (((_aidl_ret_status) != (::android::OK))) {
172 goto _aidl_error;
173 }
174 _aidl_error:
175 _aidl_status.setFromStatusT(_aidl_ret_status);
176 return _aidl_status;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700177}
178
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800179::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900180 ::android::Parcel _aidl_data;
181 ::android::Parcel _aidl_reply;
182 ::android::status_t _aidl_ret_status = ::android::OK;
183 ::android::binder::Status _aidl_status;
184 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
185 if (((_aidl_ret_status) != (::android::OK))) {
186 goto _aidl_error;
187 }
188 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
189 if (((_aidl_ret_status) != (::android::OK))) {
190 goto _aidl_error;
191 }
Jiyong Park717fc692020-11-25 16:31:32 +0900192 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesABinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900193 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
194 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
195 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900196 if (((_aidl_ret_status) != (::android::OK))) {
197 goto _aidl_error;
198 }
199 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
200 if (((_aidl_ret_status) != (::android::OK))) {
201 goto _aidl_error;
202 }
203 if (!_aidl_status.isOk()) {
204 return _aidl_status;
205 }
206 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
207 if (((_aidl_ret_status) != (::android::OK))) {
208 goto _aidl_error;
209 }
210 _aidl_error:
211 _aidl_status.setFromStatusT(_aidl_ret_status);
212 return _aidl_status;
Casey Dahlin389781f2015-10-22 13:13:21 -0700213}
214
Casey Dahlinef88bce2016-04-15 11:55:30 -0700215::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900216 ::android::Parcel _aidl_data;
217 ::android::Parcel _aidl_reply;
218 ::android::status_t _aidl_ret_status = ::android::OK;
219 ::android::binder::Status _aidl_status;
220 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
221 if (((_aidl_ret_status) != (::android::OK))) {
222 goto _aidl_error;
223 }
Jiyong Park717fc692020-11-25 16:31:32 +0900224 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_NullableBinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900225 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
226 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
227 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900228 if (((_aidl_ret_status) != (::android::OK))) {
229 goto _aidl_error;
230 }
231 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
232 if (((_aidl_ret_status) != (::android::OK))) {
233 goto _aidl_error;
234 }
235 if (!_aidl_status.isOk()) {
236 return _aidl_status;
237 }
238 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
239 if (((_aidl_ret_status) != (::android::OK))) {
240 goto _aidl_error;
241 }
242 _aidl_error:
243 _aidl_status.setFromStatusT(_aidl_ret_status);
244 return _aidl_status;
Casey Dahlinef88bce2016-04-15 11:55:30 -0700245}
246
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800247::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900248 ::android::Parcel _aidl_data;
249 ::android::Parcel _aidl_reply;
250 ::android::status_t _aidl_ret_status = ::android::OK;
251 ::android::binder::Status _aidl_status;
252 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
253 if (((_aidl_ret_status) != (::android::OK))) {
254 goto _aidl_error;
255 }
256 _aidl_ret_status = _aidl_data.writeString16Vector(input);
257 if (((_aidl_ret_status) != (::android::OK))) {
258 goto _aidl_error;
259 }
Jiyong Park717fc692020-11-25 16:31:32 +0900260 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_StringListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900261 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
262 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
263 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900264 if (((_aidl_ret_status) != (::android::OK))) {
265 goto _aidl_error;
266 }
267 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
268 if (((_aidl_ret_status) != (::android::OK))) {
269 goto _aidl_error;
270 }
271 if (!_aidl_status.isOk()) {
272 return _aidl_status;
273 }
274 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
275 if (((_aidl_ret_status) != (::android::OK))) {
276 goto _aidl_error;
277 }
278 _aidl_ret_status = _aidl_reply.readString16Vector(output);
279 if (((_aidl_ret_status) != (::android::OK))) {
280 goto _aidl_error;
281 }
282 _aidl_error:
283 _aidl_status.setFromStatusT(_aidl_ret_status);
284 return _aidl_status;
Christopher Wiley56c9bf32015-10-30 10:41:12 -0700285}
286
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800287::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) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900288 ::android::Parcel _aidl_data;
289 ::android::Parcel _aidl_reply;
290 ::android::status_t _aidl_ret_status = ::android::OK;
291 ::android::binder::Status _aidl_status;
292 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
293 if (((_aidl_ret_status) != (::android::OK))) {
294 goto _aidl_error;
295 }
296 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
297 if (((_aidl_ret_status) != (::android::OK))) {
298 goto _aidl_error;
299 }
Jiyong Park717fc692020-11-25 16:31:32 +0900300 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_BinderListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900301 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
302 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
303 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900304 if (((_aidl_ret_status) != (::android::OK))) {
305 goto _aidl_error;
306 }
307 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
308 if (((_aidl_ret_status) != (::android::OK))) {
309 goto _aidl_error;
310 }
311 if (!_aidl_status.isOk()) {
312 return _aidl_status;
313 }
314 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
315 if (((_aidl_ret_status) != (::android::OK))) {
316 goto _aidl_error;
317 }
318 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
319 if (((_aidl_ret_status) != (::android::OK))) {
320 goto _aidl_error;
321 }
322 _aidl_error:
323 _aidl_status.setFromStatusT(_aidl_ret_status);
324 return _aidl_status;
Casey Dahlin7ecd69f2015-11-03 13:52:38 -0800325}
326
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900327::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900328 ::android::Parcel _aidl_data;
329 ::android::Parcel _aidl_reply;
330 ::android::status_t _aidl_ret_status = ::android::OK;
331 ::android::binder::Status _aidl_status;
332 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
333 if (((_aidl_ret_status) != (::android::OK))) {
334 goto _aidl_error;
335 }
336 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
337 if (((_aidl_ret_status) != (::android::OK))) {
338 goto _aidl_error;
339 }
Jiyong Park717fc692020-11-25 16:31:32 +0900340 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900341 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900342 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900343 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900344 if (((_aidl_ret_status) != (::android::OK))) {
345 goto _aidl_error;
346 }
347 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
348 if (((_aidl_ret_status) != (::android::OK))) {
349 goto _aidl_error;
350 }
351 if (!_aidl_status.isOk()) {
352 return _aidl_status;
353 }
354 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
355 if (((_aidl_ret_status) != (::android::OK))) {
356 goto _aidl_error;
357 }
358 _aidl_error:
359 _aidl_status.setFromStatusT(_aidl_ret_status);
360 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800361}
362
Christopher Wiley7cb9c252016-04-11 11:07:33 -0700363::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900364 ::android::Parcel _aidl_data;
365 ::android::Parcel _aidl_reply;
366 ::android::status_t _aidl_ret_status = ::android::OK;
367 ::android::binder::Status _aidl_status;
368 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
369 if (((_aidl_ret_status) != (::android::OK))) {
370 goto _aidl_error;
371 }
372 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
373 if (((_aidl_ret_status) != (::android::OK))) {
374 goto _aidl_error;
375 }
Jiyong Park717fc692020-11-25 16:31:32 +0900376 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900377 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
378 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
379 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900380 if (((_aidl_ret_status) != (::android::OK))) {
381 goto _aidl_error;
382 }
383 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
384 if (((_aidl_ret_status) != (::android::OK))) {
385 goto _aidl_error;
386 }
387 if (!_aidl_status.isOk()) {
388 return _aidl_status;
389 }
390 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
391 if (((_aidl_ret_status) != (::android::OK))) {
392 goto _aidl_error;
393 }
394 _aidl_error:
395 _aidl_status.setFromStatusT(_aidl_ret_status);
396 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800397}
398
Casey Dahlinb0966612015-10-19 16:35:26 -0700399} // namespace os
400
401} // namespace android
402)";
403
Martijn Coenenf1b50782018-02-21 21:06:23 +0100404const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +0900405 R"(#include <android/os/BpComplexTypeInterface.h>
Jiyong Park717fc692020-11-25 16:31:32 +0900406#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100407#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +0900408#include <android-base/macros.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100409
410namespace android {
411
412namespace os {
413
414BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
415 : BpInterface<IComplexTypeInterface>(_aidl_impl){
416}
417
Jooyung Han43122462020-01-23 13:03:10 +0900418::android::binder::Status BpComplexTypeInterface::Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900419 ::android::Parcel _aidl_data;
420 ::android::Parcel _aidl_reply;
421 ::android::status_t _aidl_ret_status = ::android::OK;
422 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700423 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900424 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900440 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Send, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900441 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 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900444 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100469}
470
471::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900472 ::android::Parcel _aidl_data;
473 ::android::Parcel _aidl_reply;
474 ::android::status_t _aidl_ret_status = ::android::OK;
475 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700476 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900477 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900485 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Piff, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900486 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
487 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
488 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900489 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100495}
496
497::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900498 ::android::Parcel _aidl_data;
499 ::android::Parcel _aidl_reply;
500 ::android::status_t _aidl_ret_status = ::android::OK;
501 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700502 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900503 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900511 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesABinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900512 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
513 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
514 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900515 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100532}
533
534::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900535 ::android::Parcel _aidl_data;
536 ::android::Parcel _aidl_reply;
537 ::android::status_t _aidl_ret_status = ::android::OK;
538 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700539 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900540 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
541 if (((_aidl_ret_status) != (::android::OK))) {
542 goto _aidl_error;
543 }
Jiyong Park717fc692020-11-25 16:31:32 +0900544 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_NullableBinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900545 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
546 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
547 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900548 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100565}
566
567::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900568 ::android::Parcel _aidl_data;
569 ::android::Parcel _aidl_reply;
570 ::android::status_t _aidl_ret_status = ::android::OK;
571 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700572 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900573 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900581 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_StringListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900582 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
583 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
584 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900585 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100606}
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) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900609 ::android::Parcel _aidl_data;
610 ::android::Parcel _aidl_reply;
611 ::android::status_t _aidl_ret_status = ::android::OK;
612 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700613 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900614 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900622 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_BinderListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900623 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
624 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
625 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900626 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100647}
648
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900649::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900650 ::android::Parcel _aidl_data;
651 ::android::Parcel _aidl_reply;
652 ::android::status_t _aidl_ret_status = ::android::OK;
653 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700654 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900655 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900663 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900664 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900665 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900666 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900667 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100684}
685
686::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900687 ::android::Parcel _aidl_data;
688 ::android::Parcel _aidl_reply;
689 ::android::status_t _aidl_ret_status = ::android::OK;
690 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700691 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900692 _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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900700 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900701 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
702 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
703 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900704 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;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100721}
722
723} // namespace os
724
725} // namespace android
726)";
727
Casey Dahlinb0966612015-10-19 16:35:26 -0700728const char kExpectedComplexTypeServerHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -0700729 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -0700730
731#include <binder/IInterface.h>
732#include <android/os/IComplexTypeInterface.h>
733
734namespace android {
735
736namespace os {
737
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800738class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -0700739public:
Jiyong Park717fc692020-11-25 16:31:32 +0900740 static constexpr uint32_t TRANSACTION_Send = ::android::IBinder::FIRST_CALL_TRANSACTION + 0;
741 static constexpr uint32_t TRANSACTION_Piff = ::android::IBinder::FIRST_CALL_TRANSACTION + 1;
742 static constexpr uint32_t TRANSACTION_TakesABinder = ::android::IBinder::FIRST_CALL_TRANSACTION + 2;
743 static constexpr uint32_t TRANSACTION_NullableBinder = ::android::IBinder::FIRST_CALL_TRANSACTION + 3;
744 static constexpr uint32_t TRANSACTION_StringListMethod = ::android::IBinder::FIRST_CALL_TRANSACTION + 4;
745 static constexpr uint32_t TRANSACTION_BinderListMethod = ::android::IBinder::FIRST_CALL_TRANSACTION + 5;
746 static constexpr uint32_t TRANSACTION_TakesAFileDescriptor = ::android::IBinder::FIRST_CALL_TRANSACTION + 6;
747 static constexpr uint32_t TRANSACTION_TakesAFileDescriptorArray = ::android::IBinder::FIRST_CALL_TRANSACTION + 7;
Steven Moreland800508d2019-07-30 10:45:31 -0700748 explicit BnComplexTypeInterface();
Jiyong Park8533bd02018-10-29 21:31:18 +0900749 ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override;
Casey Dahlinb0966612015-10-19 16:35:26 -0700750}; // class BnComplexTypeInterface
751
752} // namespace os
753
754} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -0800755)";
Casey Dahlinb0966612015-10-19 16:35:26 -0700756
757const char kExpectedComplexTypeServerSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +0900758 R"(#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700759#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -0700760#include <binder/Stability.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700761
762namespace android {
763
764namespace os {
765
Steven Moreland800508d2019-07-30 10:45:31 -0700766BnComplexTypeInterface::BnComplexTypeInterface()
767{
Steven Morelanda57d0a62019-07-30 09:41:14 -0700768 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -0700769}
770
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800771::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900772 ::android::status_t _aidl_ret_status = ::android::OK;
773 switch (_aidl_code) {
Jiyong Park717fc692020-11-25 16:31:32 +0900774 case BnComplexTypeInterface::TRANSACTION_Send:
Jiyong Parka755dc72018-06-29 13:52:24 +0900775 {
Jooyung Han43122462020-01-23 13:03:10 +0900776 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +0900777 ::std::vector<double> in_goes_in_and_out;
778 ::std::vector<bool> out_goes_out;
779 ::std::vector<int32_t> _aidl_return;
780 if (!(_aidl_data.checkInterface(this))) {
781 _aidl_ret_status = ::android::BAD_TYPE;
782 break;
783 }
784 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
785 if (((_aidl_ret_status) != (::android::OK))) {
786 break;
787 }
788 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
789 if (((_aidl_ret_status) != (::android::OK))) {
790 break;
791 }
792 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
793 if (((_aidl_ret_status) != (::android::OK))) {
794 break;
795 }
796 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
797 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
798 if (((_aidl_ret_status) != (::android::OK))) {
799 break;
800 }
801 if (!_aidl_status.isOk()) {
802 break;
803 }
804 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
805 if (((_aidl_ret_status) != (::android::OK))) {
806 break;
807 }
808 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
809 if (((_aidl_ret_status) != (::android::OK))) {
810 break;
811 }
812 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
813 if (((_aidl_ret_status) != (::android::OK))) {
814 break;
815 }
816 }
817 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900818 case BnComplexTypeInterface::TRANSACTION_Piff:
Jiyong Parka755dc72018-06-29 13:52:24 +0900819 {
820 int32_t in_times;
821 if (!(_aidl_data.checkInterface(this))) {
822 _aidl_ret_status = ::android::BAD_TYPE;
823 break;
824 }
825 _aidl_ret_status = _aidl_data.readInt32(&in_times);
826 if (((_aidl_ret_status) != (::android::OK))) {
827 break;
828 }
829 ::android::binder::Status _aidl_status(Piff(in_times));
830 }
831 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900832 case BnComplexTypeInterface::TRANSACTION_TakesABinder:
Jiyong Parka755dc72018-06-29 13:52:24 +0900833 {
834 ::android::sp<::foo::IFooType> in_f;
835 ::android::sp<::foo::IFooType> _aidl_return;
836 if (!(_aidl_data.checkInterface(this))) {
837 _aidl_ret_status = ::android::BAD_TYPE;
838 break;
839 }
840 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
841 if (((_aidl_ret_status) != (::android::OK))) {
842 break;
843 }
844 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
845 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
846 if (((_aidl_ret_status) != (::android::OK))) {
847 break;
848 }
849 if (!_aidl_status.isOk()) {
850 break;
851 }
852 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
853 if (((_aidl_ret_status) != (::android::OK))) {
854 break;
855 }
856 }
857 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900858 case BnComplexTypeInterface::TRANSACTION_NullableBinder:
Jiyong Parka755dc72018-06-29 13:52:24 +0900859 {
860 ::android::sp<::foo::IFooType> _aidl_return;
861 if (!(_aidl_data.checkInterface(this))) {
862 _aidl_ret_status = ::android::BAD_TYPE;
863 break;
864 }
865 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
866 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
867 if (((_aidl_ret_status) != (::android::OK))) {
868 break;
869 }
870 if (!_aidl_status.isOk()) {
871 break;
872 }
873 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
874 if (((_aidl_ret_status) != (::android::OK))) {
875 break;
876 }
877 }
878 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900879 case BnComplexTypeInterface::TRANSACTION_StringListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +0900880 {
881 ::std::vector<::android::String16> in_input;
882 ::std::vector<::android::String16> out_output;
883 ::std::vector<::android::String16> _aidl_return;
884 if (!(_aidl_data.checkInterface(this))) {
885 _aidl_ret_status = ::android::BAD_TYPE;
886 break;
887 }
888 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
889 if (((_aidl_ret_status) != (::android::OK))) {
890 break;
891 }
892 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_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->writeString16Vector(_aidl_return);
901 if (((_aidl_ret_status) != (::android::OK))) {
902 break;
903 }
904 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
905 if (((_aidl_ret_status) != (::android::OK))) {
906 break;
907 }
908 }
909 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900910 case BnComplexTypeInterface::TRANSACTION_BinderListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +0900911 {
912 ::std::vector<::android::sp<::android::IBinder>> in_input;
913 ::std::vector<::android::sp<::android::IBinder>> out_output;
914 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
915 if (!(_aidl_data.checkInterface(this))) {
916 _aidl_ret_status = ::android::BAD_TYPE;
917 break;
918 }
919 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
920 if (((_aidl_ret_status) != (::android::OK))) {
921 break;
922 }
923 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
924 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
925 if (((_aidl_ret_status) != (::android::OK))) {
926 break;
927 }
928 if (!_aidl_status.isOk()) {
929 break;
930 }
931 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
932 if (((_aidl_ret_status) != (::android::OK))) {
933 break;
934 }
935 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
936 if (((_aidl_ret_status) != (::android::OK))) {
937 break;
938 }
939 }
940 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900941 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor:
Jiyong Parka755dc72018-06-29 13:52:24 +0900942 {
943 ::android::base::unique_fd in_f;
944 ::android::base::unique_fd _aidl_return;
945 if (!(_aidl_data.checkInterface(this))) {
946 _aidl_ret_status = ::android::BAD_TYPE;
947 break;
948 }
949 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
950 if (((_aidl_ret_status) != (::android::OK))) {
951 break;
952 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900953 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +0900954 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
955 if (((_aidl_ret_status) != (::android::OK))) {
956 break;
957 }
958 if (!_aidl_status.isOk()) {
959 break;
960 }
961 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
962 if (((_aidl_ret_status) != (::android::OK))) {
963 break;
964 }
965 }
966 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900967 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray:
Jiyong Parka755dc72018-06-29 13:52:24 +0900968 {
969 ::std::vector<::android::base::unique_fd> in_f;
970 ::std::vector<::android::base::unique_fd> _aidl_return;
971 if (!(_aidl_data.checkInterface(this))) {
972 _aidl_ret_status = ::android::BAD_TYPE;
973 break;
974 }
975 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
976 if (((_aidl_ret_status) != (::android::OK))) {
977 break;
978 }
979 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
980 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
981 if (((_aidl_ret_status) != (::android::OK))) {
982 break;
983 }
984 if (!_aidl_status.isOk()) {
985 break;
986 }
987 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
988 if (((_aidl_ret_status) != (::android::OK))) {
989 break;
990 }
991 }
992 break;
993 default:
994 {
995 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
996 }
997 break;
998 }
999 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1000 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1001 }
1002 return _aidl_ret_status;
Casey Dahlinb0966612015-10-19 16:35:26 -07001003}
1004
1005} // namespace os
1006
1007} // namespace android
1008)";
1009
Martijn Coenenf1b50782018-02-21 21:06:23 +01001010const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +09001011 R"(#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001012#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -07001013#include <binder/Stability.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001014
1015namespace android {
1016
1017namespace os {
1018
Steven Moreland800508d2019-07-30 10:45:31 -07001019BnComplexTypeInterface::BnComplexTypeInterface()
1020{
Steven Morelanda57d0a62019-07-30 09:41:14 -07001021 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -07001022}
1023
Martijn Coenenf1b50782018-02-21 21:06:23 +01001024::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
Jiyong Parka755dc72018-06-29 13:52:24 +09001025 ::android::status_t _aidl_ret_status = ::android::OK;
1026 switch (_aidl_code) {
Jiyong Park717fc692020-11-25 16:31:32 +09001027 case BnComplexTypeInterface::TRANSACTION_Send:
Jiyong Parka755dc72018-06-29 13:52:24 +09001028 {
Jooyung Han43122462020-01-23 13:03:10 +09001029 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +09001030 ::std::vector<double> in_goes_in_and_out;
1031 ::std::vector<bool> out_goes_out;
1032 ::std::vector<int32_t> _aidl_return;
1033 if (!(_aidl_data.checkInterface(this))) {
1034 _aidl_ret_status = ::android::BAD_TYPE;
1035 break;
1036 }
Devin Mooref7600872020-05-13 15:47:50 -07001037 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001038 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
1039 if (((_aidl_ret_status) != (::android::OK))) {
1040 break;
1041 }
1042 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
1043 if (((_aidl_ret_status) != (::android::OK))) {
1044 break;
1045 }
1046 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
1047 if (((_aidl_ret_status) != (::android::OK))) {
1048 break;
1049 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001050 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001051 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1052 if (((_aidl_ret_status) != (::android::OK))) {
1053 break;
1054 }
1055 if (!_aidl_status.isOk()) {
1056 break;
1057 }
1058 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
1059 if (((_aidl_ret_status) != (::android::OK))) {
1060 break;
1061 }
1062 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
1063 if (((_aidl_ret_status) != (::android::OK))) {
1064 break;
1065 }
1066 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1067 if (((_aidl_ret_status) != (::android::OK))) {
1068 break;
1069 }
1070 }
1071 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001072 case BnComplexTypeInterface::TRANSACTION_Piff:
Jiyong Parka755dc72018-06-29 13:52:24 +09001073 {
1074 int32_t in_times;
1075 if (!(_aidl_data.checkInterface(this))) {
1076 _aidl_ret_status = ::android::BAD_TYPE;
1077 break;
1078 }
Devin Mooref7600872020-05-13 15:47:50 -07001079 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001080 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1081 if (((_aidl_ret_status) != (::android::OK))) {
1082 break;
1083 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001084 ::android::binder::Status _aidl_status(Piff(in_times));
Jiyong Parka755dc72018-06-29 13:52:24 +09001085 }
1086 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001087 case BnComplexTypeInterface::TRANSACTION_TakesABinder:
Jiyong Parka755dc72018-06-29 13:52:24 +09001088 {
1089 ::android::sp<::foo::IFooType> in_f;
1090 ::android::sp<::foo::IFooType> _aidl_return;
1091 if (!(_aidl_data.checkInterface(this))) {
1092 _aidl_ret_status = ::android::BAD_TYPE;
1093 break;
1094 }
Devin Mooref7600872020-05-13 15:47:50 -07001095 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001096 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1097 if (((_aidl_ret_status) != (::android::OK))) {
1098 break;
1099 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001100 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001101 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1102 if (((_aidl_ret_status) != (::android::OK))) {
1103 break;
1104 }
1105 if (!_aidl_status.isOk()) {
1106 break;
1107 }
1108 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1109 if (((_aidl_ret_status) != (::android::OK))) {
1110 break;
1111 }
1112 }
1113 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001114 case BnComplexTypeInterface::TRANSACTION_NullableBinder:
Jiyong Parka755dc72018-06-29 13:52:24 +09001115 {
1116 ::android::sp<::foo::IFooType> _aidl_return;
1117 if (!(_aidl_data.checkInterface(this))) {
1118 _aidl_ret_status = ::android::BAD_TYPE;
1119 break;
1120 }
Devin Mooref7600872020-05-13 15:47:50 -07001121 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001122 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001123 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1124 if (((_aidl_ret_status) != (::android::OK))) {
1125 break;
1126 }
1127 if (!_aidl_status.isOk()) {
1128 break;
1129 }
1130 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1131 if (((_aidl_ret_status) != (::android::OK))) {
1132 break;
1133 }
1134 }
1135 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001136 case BnComplexTypeInterface::TRANSACTION_StringListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +09001137 {
1138 ::std::vector<::android::String16> in_input;
1139 ::std::vector<::android::String16> out_output;
1140 ::std::vector<::android::String16> _aidl_return;
1141 if (!(_aidl_data.checkInterface(this))) {
1142 _aidl_ret_status = ::android::BAD_TYPE;
1143 break;
1144 }
Devin Mooref7600872020-05-13 15:47:50 -07001145 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001146 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1147 if (((_aidl_ret_status) != (::android::OK))) {
1148 break;
1149 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001150 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001151 _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;
Jiyong Park717fc692020-11-25 16:31:32 +09001168 case BnComplexTypeInterface::TRANSACTION_BinderListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +09001169 {
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 }
Devin Mooref7600872020-05-13 15:47:50 -07001177 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001178 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1179 if (((_aidl_ret_status) != (::android::OK))) {
1180 break;
1181 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001182 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001183 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1184 if (((_aidl_ret_status) != (::android::OK))) {
1185 break;
1186 }
1187 if (!_aidl_status.isOk()) {
1188 break;
1189 }
1190 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1191 if (((_aidl_ret_status) != (::android::OK))) {
1192 break;
1193 }
1194 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1195 if (((_aidl_ret_status) != (::android::OK))) {
1196 break;
1197 }
1198 }
1199 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001200 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor:
Jiyong Parka755dc72018-06-29 13:52:24 +09001201 {
1202 ::android::base::unique_fd in_f;
1203 ::android::base::unique_fd _aidl_return;
1204 if (!(_aidl_data.checkInterface(this))) {
1205 _aidl_ret_status = ::android::BAD_TYPE;
1206 break;
1207 }
Devin Mooref7600872020-05-13 15:47:50 -07001208 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001209 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1210 if (((_aidl_ret_status) != (::android::OK))) {
1211 break;
1212 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001213 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001214 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1215 if (((_aidl_ret_status) != (::android::OK))) {
1216 break;
1217 }
1218 if (!_aidl_status.isOk()) {
1219 break;
1220 }
1221 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1222 if (((_aidl_ret_status) != (::android::OK))) {
1223 break;
1224 }
1225 }
1226 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001227 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray:
Jiyong Parka755dc72018-06-29 13:52:24 +09001228 {
1229 ::std::vector<::android::base::unique_fd> in_f;
1230 ::std::vector<::android::base::unique_fd> _aidl_return;
1231 if (!(_aidl_data.checkInterface(this))) {
1232 _aidl_ret_status = ::android::BAD_TYPE;
1233 break;
1234 }
Devin Mooref7600872020-05-13 15:47:50 -07001235 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001236 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1237 if (((_aidl_ret_status) != (::android::OK))) {
1238 break;
1239 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001240 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001241 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1242 if (((_aidl_ret_status) != (::android::OK))) {
1243 break;
1244 }
1245 if (!_aidl_status.isOk()) {
1246 break;
1247 }
1248 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1249 if (((_aidl_ret_status) != (::android::OK))) {
1250 break;
1251 }
1252 }
1253 break;
1254 default:
1255 {
1256 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1257 }
1258 break;
1259 }
1260 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1261 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1262 }
1263 return _aidl_ret_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +01001264}
1265
1266} // namespace os
1267
1268} // namespace android
1269)";
1270
Casey Dahlinb0966612015-10-19 16:35:26 -07001271const char kExpectedComplexTypeInterfaceHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001272 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -07001273
Christopher Wiley7cb9c252016-04-11 11:07:33 -07001274#include <android-base/unique_fd.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001275#include <binder/IBinder.h>
1276#include <binder/IInterface.h>
Christopher Wiley433c8bb2015-11-12 14:20:46 -08001277#include <binder/Status.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001278#include <cstdint>
Casey Dahlin389781f2015-10-22 13:13:21 -07001279#include <foo/IFooType.h>
Jooyung Han43122462020-01-23 13:03:10 +09001280#include <optional>
Christopher Wiley56c9bf32015-10-30 10:41:12 -07001281#include <utils/String16.h>
Casey Dahlin389781f2015-10-22 13:13:21 -07001282#include <utils/StrongPointer.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001283#include <vector>
1284
1285namespace android {
1286
1287namespace os {
1288
Casey Dahlinb8d9e882015-11-24 10:57:23 -08001289class IComplexTypeInterface : public ::android::IInterface {
Casey Dahlinb0966612015-10-19 16:35:26 -07001290public:
Jiyong Parka755dc72018-06-29 13:52:24 +09001291 DECLARE_META_INTERFACE(ComplexTypeInterface)
1292 enum : int32_t {
1293 MY_CONSTANT = 3,
1294 };
Jooyung Han43122462020-01-23 13:03:10 +09001295 virtual ::android::binder::Status Send(const ::std::optional<::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;
Jiyong Parka755dc72018-06-29 13:52:24 +09001296 virtual ::android::binder::Status Piff(int32_t times) = 0;
1297 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1298 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1299 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1300 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;
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001301 virtual ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) = 0;
Jiyong Parka755dc72018-06-29 13:52:24 +09001302 virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
Casey Dahlinb0966612015-10-19 16:35:26 -07001303}; // class IComplexTypeInterface
1304
Jiyong Park75e1a742018-07-04 12:31:23 +09001305class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1306public:
Jooyung Han7bee8e32020-01-30 17:25:21 +09001307 ::android::IBinder* onAsBinder() override {
1308 return nullptr;
1309 }
Jooyung Han43122462020-01-23 13:03:10 +09001310 ::android::binder::Status Send(const ::std::optional<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001311 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1312 }
1313 ::android::binder::Status Piff(int32_t) override {
1314 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1315 }
Jooyung Han6991d922020-01-30 18:13:55 +09001316 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001317 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1318 }
Jooyung Han6991d922020-01-30 18:13:55 +09001319 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001320 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1321 }
Jooyung Han6991d922020-01-30 18:13:55 +09001322 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>&, ::std::vector<::android::String16>*, ::std::vector<::android::String16>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001323 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1324 }
Jooyung Han6991d922020-01-30 18:13:55 +09001325 ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>&, ::std::vector<::android::sp<::android::IBinder>>*, ::std::vector<::android::sp<::android::IBinder>>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001326 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1327 }
Jooyung Han6991d922020-01-30 18:13:55 +09001328 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd, ::android::base::unique_fd*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001329 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1330 }
Jooyung Han6991d922020-01-30 18:13:55 +09001331 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>&, ::std::vector<::android::base::unique_fd>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001332 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1333 }
1334}; // class IComplexTypeInterfaceDefault
Jiyong Park75e1a742018-07-04 12:31:23 +09001335
Casey Dahlinb0966612015-10-19 16:35:26 -07001336} // namespace os
1337
1338} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -08001339)";
Casey Dahlinb0966612015-10-19 16:35:26 -07001340
1341const char kExpectedComplexTypeInterfaceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001342 R"(#include <android/os/IComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001343#include <android/os/BpComplexTypeInterface.h>
1344
1345namespace android {
1346
1347namespace os {
1348
Ivan Lozanob3f4d622019-11-25 09:30:02 -08001349DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
Casey Dahlinb0966612015-10-19 16:35:26 -07001350
1351} // namespace os
1352
1353} // namespace android
1354)";
1355
Daniel Norman85aed542019-08-21 12:01:14 -07001356const string kEnumAIDL = R"(package android.os;
1357enum TestEnum {
Daniel Normanb28684e2019-10-17 15:31:39 -07001358 ZERO,
1359 ONE,
1360 THREE = 3,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001361 FOUR = 3 + 1,
Daniel Normanb28684e2019-10-17 15:31:39 -07001362 FIVE,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001363 SIX,
1364 SEVEN,
1365 EIGHT = 16 / 2,
1366 NINE,
1367 TEN,
Daniel Norman85aed542019-08-21 12:01:14 -07001368})";
1369
1370const char kExpectedEnumHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001371 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001372
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001373#include <array>
1374#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001375#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001376#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001377
1378namespace android {
1379
1380namespace os {
1381
1382enum class TestEnum : int8_t {
Daniel Normanb28684e2019-10-17 15:31:39 -07001383 ZERO = 0,
1384 ONE = 1,
1385 THREE = 3,
1386 FOUR = 4,
1387 FIVE = 5,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001388 SIX = 6,
1389 SEVEN = 7,
1390 EIGHT = 8,
1391 NINE = 9,
1392 TEN = 10,
Daniel Norman85aed542019-08-21 12:01:14 -07001393};
1394
Daniel Norman0c1bd362019-11-12 23:05:31 -08001395static inline std::string toString(TestEnum val) {
1396 switch(val) {
1397 case TestEnum::ZERO:
1398 return "ZERO";
1399 case TestEnum::ONE:
1400 return "ONE";
1401 case TestEnum::THREE:
1402 return "THREE";
1403 case TestEnum::FOUR:
1404 return "FOUR";
1405 case TestEnum::FIVE:
1406 return "FIVE";
1407 case TestEnum::SIX:
1408 return "SIX";
1409 case TestEnum::SEVEN:
1410 return "SEVEN";
1411 case TestEnum::EIGHT:
1412 return "EIGHT";
1413 case TestEnum::NINE:
1414 return "NINE";
1415 case TestEnum::TEN:
1416 return "TEN";
1417 default:
1418 return std::to_string(static_cast<int8_t>(val));
1419 }
1420}
1421
Daniel Norman85aed542019-08-21 12:01:14 -07001422} // namespace os
1423
1424} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001425namespace android {
1426
1427namespace internal {
1428
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001429#pragma clang diagnostic push
1430#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001431template <>
1432constexpr inline std::array<::android::os::TestEnum, 10> enum_values<::android::os::TestEnum> = {
1433 ::android::os::TestEnum::ZERO,
1434 ::android::os::TestEnum::ONE,
1435 ::android::os::TestEnum::THREE,
1436 ::android::os::TestEnum::FOUR,
1437 ::android::os::TestEnum::FIVE,
1438 ::android::os::TestEnum::SIX,
1439 ::android::os::TestEnum::SEVEN,
1440 ::android::os::TestEnum::EIGHT,
1441 ::android::os::TestEnum::NINE,
1442 ::android::os::TestEnum::TEN,
1443};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001444#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001445
1446} // namespace internal
1447
1448} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001449)";
1450
1451const string kEnumWithBackingTypeAIDL = R"(package android.os;
1452@Backing(type="long")
1453enum TestEnum {
1454 FOO = 1,
1455 BAR = 2,
1456})";
1457
1458const char kExpectedEnumWithBackingTypeHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001459 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001460
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001461#include <array>
1462#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001463#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001464#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001465
1466namespace android {
1467
1468namespace os {
1469
1470enum class TestEnum : int64_t {
Daniel Norman716d3112019-09-10 13:11:56 -07001471 FOO = 1L,
1472 BAR = 2L,
Daniel Norman85aed542019-08-21 12:01:14 -07001473};
1474
Daniel Norman0c1bd362019-11-12 23:05:31 -08001475static inline std::string toString(TestEnum val) {
1476 switch(val) {
1477 case TestEnum::FOO:
1478 return "FOO";
1479 case TestEnum::BAR:
1480 return "BAR";
1481 default:
1482 return std::to_string(static_cast<int64_t>(val));
1483 }
1484}
1485
Daniel Norman85aed542019-08-21 12:01:14 -07001486} // namespace os
1487
1488} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001489namespace android {
1490
1491namespace internal {
1492
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001493#pragma clang diagnostic push
1494#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001495template <>
1496constexpr inline std::array<::android::os::TestEnum, 2> enum_values<::android::os::TestEnum> = {
1497 ::android::os::TestEnum::FOO,
1498 ::android::os::TestEnum::BAR,
1499};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001500#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001501
1502} // namespace internal
1503
1504} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001505)";
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001506// clang-format on
Daniel Norman85aed542019-08-21 12:01:14 -07001507
Casey Dahlina834dd42015-09-23 11:52:15 -07001508} // namespace
1509
Casey Dahlinb0966612015-10-19 16:35:26 -07001510class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -07001511 protected:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001512 ASTTest(const string& cmdline, const string& file_contents)
1513 : options_(Options::From(cmdline)), file_contents_(file_contents) {
Christopher Wiley56799522015-10-31 10:17:04 -07001514 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001515
Jiyong Parkb034bf02018-07-30 17:44:33 +09001516 AidlInterface* ParseSingleInterface() {
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001517 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
Casey Dahlina834dd42015-09-23 11:52:15 -07001518
Jiyong Parkb034bf02018-07-30 17:44:33 +09001519 vector<string> imported_files;
Jiyong Park8c380532018-08-30 14:55:26 +09001520 ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001521 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001522 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Christopher Wiley4a2884b2015-10-07 11:27:45 -07001523
Steven Moreland5557f1c2018-07-02 13:50:23 -07001524 if (err != AidlError::OK) {
Casey Dahlin2cc93162015-10-02 16:14:17 -07001525 return nullptr;
Steven Moreland5557f1c2018-07-02 13:50:23 -07001526 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001527
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001528 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Jiyong Parkb034bf02018-07-30 17:44:33 +09001529 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001530 EXPECT_NE(nullptr, defined_types.front().get()->AsInterface());
Steven Moreland5557f1c2018-07-02 13:50:23 -07001531
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001532 return defined_types.front().get()->AsInterface();
Christopher Wiley90be4e32015-10-20 14:55:25 -07001533 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001534
Daniel Norman85aed542019-08-21 12:01:14 -07001535 AidlEnumDeclaration* ParseSingleEnumDeclaration() {
1536 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1537
Daniel Norman85aed542019-08-21 12:01:14 -07001538 vector<string> imported_files;
1539 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001540 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Daniel Norman85aed542019-08-21 12:01:14 -07001541
1542 if (err != AidlError::OK) {
1543 return nullptr;
1544 }
1545
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001546 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Daniel Norman85aed542019-08-21 12:01:14 -07001547 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001548 EXPECT_NE(nullptr, defined_types.front().get()->AsEnumDeclaration());
Daniel Norman85aed542019-08-21 12:01:14 -07001549
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001550 return defined_types.front().get()->AsEnumDeclaration();
Daniel Norman85aed542019-08-21 12:01:14 -07001551 }
1552
Christopher Wiley0c732db2015-09-29 14:36:44 -07001553 void Compare(Document* doc, const char* expected) {
1554 string output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +09001555 doc->Write(CodeWriter::ForString(&output).get());
Christopher Wiley0c732db2015-09-29 14:36:44 -07001556
Casey Dahlin80ada3d2015-10-20 20:33:56 -07001557 if (expected == output) {
1558 return; // Success
1559 }
1560
1561 test::PrintDiff(expected, output);
1562 FAIL() << "Document contents did not match expected contents";
Christopher Wiley0c732db2015-09-29 14:36:44 -07001563 }
Casey Dahlin389781f2015-10-22 13:13:21 -07001564
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001565 const Options options_;
Casey Dahlin389781f2015-10-22 13:13:21 -07001566 const string file_contents_;
1567 FakeIoDelegate io_delegate_;
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001568 AidlTypenames typenames_;
Christopher Wiley0c732db2015-09-29 14:36:44 -07001569};
1570
Casey Dahlinb0966612015-10-19 16:35:26 -07001571class ComplexTypeInterfaceASTTest : public ASTTest {
Casey Dahlin389781f2015-10-22 13:13:21 -07001572 public:
1573 ComplexTypeInterfaceASTTest()
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001574 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
Casey Dahlin389781f2015-10-22 13:13:21 -07001575 kComplexTypeInterfaceAIDL) {
1576 io_delegate_.SetFileContents("foo/IFooType.aidl",
1577 "package foo; interface IFooType {}");
1578 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001579};
1580
1581TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001582 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001583 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001584 unique_ptr<Document> doc = internals::BuildClientHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001585 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1586}
1587
1588TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001589 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001590 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001591 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001592 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1593}
1594
1595TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001596 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001597 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001598 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001599 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1600}
1601
1602TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001603 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001604 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001605 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001606 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1607}
1608
1609TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001610 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001611 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001612 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001613 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1614}
1615
1616TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001617 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001618 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001619 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001620 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -07001621}
1622
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001623class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1624 public:
1625 ComplexTypeInterfaceASTTestWithTrace()
1626 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1627 kComplexTypeInterfaceAIDL) {
1628 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1629 }
1630};
1631
1632TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001633 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001634 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001635 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001636 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1637}
1638
1639TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001640 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001641 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001642 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001643 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1644}
1645
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001646namespace test_io_handling {
1647
1648const char kInputPath[] = "a/IFoo.aidl";
1649const char kOutputPath[] = "output.cpp";
1650const char kHeaderDir[] = "headers";
1651const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1652
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001653const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1654
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001655} // namespace test_io_handling
1656
1657class IoErrorHandlingTest : public ASTTest {
1658 public:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001659 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001660};
1661
1662TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1663 // Confirm that this is working correctly without I/O problems.
Jiyong Parkb034bf02018-07-30 17:44:33 +09001664 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001665 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001666 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001667}
1668
1669TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1670 using namespace test_io_handling;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001671 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001672 ASSERT_NE(interface, nullptr);
1673
1674 // Simulate issues closing the interface header.
1675 const string header_path =
1676 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1677 kInterfaceHeaderRelPath);
1678 io_delegate_.AddBrokenFilePath(header_path);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001679 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001680 // We should never attempt to write the C++ file if we fail writing headers.
1681 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1682 // We should remove partial results.
1683 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1684}
1685
1686TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1687 using test_io_handling::kOutputPath;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001688 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001689 ASSERT_NE(interface, nullptr);
1690
1691 // Simulate issues closing the cpp file.
1692 io_delegate_.AddBrokenFilePath(kOutputPath);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001693 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001694 // We should remove partial results.
1695 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1696}
1697
Daniel Norman85aed542019-08-21 12:01:14 -07001698class EnumASTTest : public ASTTest {
1699 public:
1700 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1701};
1702
1703TEST_F(EnumASTTest, GeneratesEnumHeader) {
1704 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1705 ASSERT_NE(enum_decl, nullptr);
1706 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1707 Compare(doc.get(), kExpectedEnumHeaderOutput);
1708}
1709
1710class EnumWithBackingTypeASTTest : public ASTTest {
1711 public:
1712 EnumWithBackingTypeASTTest()
1713 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1714};
1715
1716TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1717 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1718 ASSERT_NE(enum_decl, nullptr);
1719 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1720 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1721}
1722
Christopher Wileyf944e792015-09-29 10:00:46 -07001723} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -07001724} // namespace aidl
1725} // namespace android