blob: d1ad5042b45957708d798a9b96b31eba2363eacc [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>
Casey Dahlinb0966612015-10-19 16:35:26 -070090#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +090091#include <android-base/macros.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070092
93namespace android {
94
95namespace os {
96
Casey Dahlinb8d9e882015-11-24 10:57:23 -080097BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
98 : BpInterface<IComplexTypeInterface>(_aidl_impl){
Casey Dahlinb0966612015-10-19 16:35:26 -070099}
100
Jooyung Han43122462020-01-23 13:03:10 +0900101::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 +0900102 ::android::Parcel _aidl_data;
103 ::android::Parcel _aidl_reply;
104 ::android::status_t _aidl_ret_status = ::android::OK;
105 ::android::binder::Status _aidl_status;
106 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
107 if (((_aidl_ret_status) != (::android::OK))) {
108 goto _aidl_error;
109 }
110 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
111 if (((_aidl_ret_status) != (::android::OK))) {
112 goto _aidl_error;
113 }
114 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
115 if (((_aidl_ret_status) != (::android::OK))) {
116 goto _aidl_error;
117 }
118 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
119 if (((_aidl_ret_status) != (::android::OK))) {
120 goto _aidl_error;
121 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900122 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900123 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
124 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
125 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900126 if (((_aidl_ret_status) != (::android::OK))) {
127 goto _aidl_error;
128 }
129 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
130 if (((_aidl_ret_status) != (::android::OK))) {
131 goto _aidl_error;
132 }
133 if (!_aidl_status.isOk()) {
134 return _aidl_status;
135 }
136 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
137 if (((_aidl_ret_status) != (::android::OK))) {
138 goto _aidl_error;
139 }
140 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
141 if (((_aidl_ret_status) != (::android::OK))) {
142 goto _aidl_error;
143 }
144 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
145 if (((_aidl_ret_status) != (::android::OK))) {
146 goto _aidl_error;
147 }
148 _aidl_error:
149 _aidl_status.setFromStatusT(_aidl_ret_status);
150 return _aidl_status;
Casey Dahlinb0966612015-10-19 16:35:26 -0700151}
152
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800153::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900154 ::android::Parcel _aidl_data;
155 ::android::Parcel _aidl_reply;
156 ::android::status_t _aidl_ret_status = ::android::OK;
157 ::android::binder::Status _aidl_status;
158 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
159 if (((_aidl_ret_status) != (::android::OK))) {
160 goto _aidl_error;
161 }
162 _aidl_ret_status = _aidl_data.writeInt32(times);
163 if (((_aidl_ret_status) != (::android::OK))) {
164 goto _aidl_error;
165 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900166 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900167 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
168 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
169 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900170 if (((_aidl_ret_status) != (::android::OK))) {
171 goto _aidl_error;
172 }
173 _aidl_error:
174 _aidl_status.setFromStatusT(_aidl_ret_status);
175 return _aidl_status;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700176}
177
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800178::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900179 ::android::Parcel _aidl_data;
180 ::android::Parcel _aidl_reply;
181 ::android::status_t _aidl_ret_status = ::android::OK;
182 ::android::binder::Status _aidl_status;
183 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
184 if (((_aidl_ret_status) != (::android::OK))) {
185 goto _aidl_error;
186 }
187 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
188 if (((_aidl_ret_status) != (::android::OK))) {
189 goto _aidl_error;
190 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900191 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900192 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
193 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
194 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900195 if (((_aidl_ret_status) != (::android::OK))) {
196 goto _aidl_error;
197 }
198 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
199 if (((_aidl_ret_status) != (::android::OK))) {
200 goto _aidl_error;
201 }
202 if (!_aidl_status.isOk()) {
203 return _aidl_status;
204 }
205 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
206 if (((_aidl_ret_status) != (::android::OK))) {
207 goto _aidl_error;
208 }
209 _aidl_error:
210 _aidl_status.setFromStatusT(_aidl_ret_status);
211 return _aidl_status;
Casey Dahlin389781f2015-10-22 13:13:21 -0700212}
213
Casey Dahlinef88bce2016-04-15 11:55:30 -0700214::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900215 ::android::Parcel _aidl_data;
216 ::android::Parcel _aidl_reply;
217 ::android::status_t _aidl_ret_status = ::android::OK;
218 ::android::binder::Status _aidl_status;
219 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
220 if (((_aidl_ret_status) != (::android::OK))) {
221 goto _aidl_error;
222 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900223 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900224 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
225 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
226 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900227 if (((_aidl_ret_status) != (::android::OK))) {
228 goto _aidl_error;
229 }
230 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
231 if (((_aidl_ret_status) != (::android::OK))) {
232 goto _aidl_error;
233 }
234 if (!_aidl_status.isOk()) {
235 return _aidl_status;
236 }
237 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
238 if (((_aidl_ret_status) != (::android::OK))) {
239 goto _aidl_error;
240 }
241 _aidl_error:
242 _aidl_status.setFromStatusT(_aidl_ret_status);
243 return _aidl_status;
Casey Dahlinef88bce2016-04-15 11:55:30 -0700244}
245
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800246::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 +0900247 ::android::Parcel _aidl_data;
248 ::android::Parcel _aidl_reply;
249 ::android::status_t _aidl_ret_status = ::android::OK;
250 ::android::binder::Status _aidl_status;
251 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
252 if (((_aidl_ret_status) != (::android::OK))) {
253 goto _aidl_error;
254 }
255 _aidl_ret_status = _aidl_data.writeString16Vector(input);
256 if (((_aidl_ret_status) != (::android::OK))) {
257 goto _aidl_error;
258 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900259 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900260 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
261 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
262 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900263 if (((_aidl_ret_status) != (::android::OK))) {
264 goto _aidl_error;
265 }
266 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
267 if (((_aidl_ret_status) != (::android::OK))) {
268 goto _aidl_error;
269 }
270 if (!_aidl_status.isOk()) {
271 return _aidl_status;
272 }
273 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
274 if (((_aidl_ret_status) != (::android::OK))) {
275 goto _aidl_error;
276 }
277 _aidl_ret_status = _aidl_reply.readString16Vector(output);
278 if (((_aidl_ret_status) != (::android::OK))) {
279 goto _aidl_error;
280 }
281 _aidl_error:
282 _aidl_status.setFromStatusT(_aidl_ret_status);
283 return _aidl_status;
Christopher Wiley56c9bf32015-10-30 10:41:12 -0700284}
285
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800286::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 +0900287 ::android::Parcel _aidl_data;
288 ::android::Parcel _aidl_reply;
289 ::android::status_t _aidl_ret_status = ::android::OK;
290 ::android::binder::Status _aidl_status;
291 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
292 if (((_aidl_ret_status) != (::android::OK))) {
293 goto _aidl_error;
294 }
295 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
296 if (((_aidl_ret_status) != (::android::OK))) {
297 goto _aidl_error;
298 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900299 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900300 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
301 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
302 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900303 if (((_aidl_ret_status) != (::android::OK))) {
304 goto _aidl_error;
305 }
306 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
307 if (((_aidl_ret_status) != (::android::OK))) {
308 goto _aidl_error;
309 }
310 if (!_aidl_status.isOk()) {
311 return _aidl_status;
312 }
313 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
314 if (((_aidl_ret_status) != (::android::OK))) {
315 goto _aidl_error;
316 }
317 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
318 if (((_aidl_ret_status) != (::android::OK))) {
319 goto _aidl_error;
320 }
321 _aidl_error:
322 _aidl_status.setFromStatusT(_aidl_ret_status);
323 return _aidl_status;
Casey Dahlin7ecd69f2015-11-03 13:52:38 -0800324}
325
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900326::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900327 ::android::Parcel _aidl_data;
328 ::android::Parcel _aidl_reply;
329 ::android::status_t _aidl_ret_status = ::android::OK;
330 ::android::binder::Status _aidl_status;
331 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
332 if (((_aidl_ret_status) != (::android::OK))) {
333 goto _aidl_error;
334 }
335 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
336 if (((_aidl_ret_status) != (::android::OK))) {
337 goto _aidl_error;
338 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900339 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900340 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900341 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900342 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900343 if (((_aidl_ret_status) != (::android::OK))) {
344 goto _aidl_error;
345 }
346 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
347 if (((_aidl_ret_status) != (::android::OK))) {
348 goto _aidl_error;
349 }
350 if (!_aidl_status.isOk()) {
351 return _aidl_status;
352 }
353 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
354 if (((_aidl_ret_status) != (::android::OK))) {
355 goto _aidl_error;
356 }
357 _aidl_error:
358 _aidl_status.setFromStatusT(_aidl_ret_status);
359 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800360}
361
Christopher Wiley7cb9c252016-04-11 11:07:33 -0700362::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 +0900363 ::android::Parcel _aidl_data;
364 ::android::Parcel _aidl_reply;
365 ::android::status_t _aidl_ret_status = ::android::OK;
366 ::android::binder::Status _aidl_status;
367 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
368 if (((_aidl_ret_status) != (::android::OK))) {
369 goto _aidl_error;
370 }
371 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
372 if (((_aidl_ret_status) != (::android::OK))) {
373 goto _aidl_error;
374 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900375 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900376 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
377 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
378 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900379 if (((_aidl_ret_status) != (::android::OK))) {
380 goto _aidl_error;
381 }
382 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
383 if (((_aidl_ret_status) != (::android::OK))) {
384 goto _aidl_error;
385 }
386 if (!_aidl_status.isOk()) {
387 return _aidl_status;
388 }
389 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
390 if (((_aidl_ret_status) != (::android::OK))) {
391 goto _aidl_error;
392 }
393 _aidl_error:
394 _aidl_status.setFromStatusT(_aidl_ret_status);
395 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800396}
397
Casey Dahlinb0966612015-10-19 16:35:26 -0700398} // namespace os
399
400} // namespace android
401)";
402
Martijn Coenenf1b50782018-02-21 21:06:23 +0100403const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +0900404 R"(#include <android/os/BpComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100405#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +0900406#include <android-base/macros.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100407
408namespace android {
409
410namespace os {
411
412BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
413 : BpInterface<IComplexTypeInterface>(_aidl_impl){
414}
415
Jooyung Han43122462020-01-23 13:03:10 +0900416::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 +0900417 ::android::Parcel _aidl_data;
418 ::android::Parcel _aidl_reply;
419 ::android::status_t _aidl_ret_status = ::android::OK;
420 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700421 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900422 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
423 if (((_aidl_ret_status) != (::android::OK))) {
424 goto _aidl_error;
425 }
426 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
427 if (((_aidl_ret_status) != (::android::OK))) {
428 goto _aidl_error;
429 }
430 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
431 if (((_aidl_ret_status) != (::android::OK))) {
432 goto _aidl_error;
433 }
434 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
435 if (((_aidl_ret_status) != (::android::OK))) {
436 goto _aidl_error;
437 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900438 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900439 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
440 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
441 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900442 if (((_aidl_ret_status) != (::android::OK))) {
443 goto _aidl_error;
444 }
445 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
446 if (((_aidl_ret_status) != (::android::OK))) {
447 goto _aidl_error;
448 }
449 if (!_aidl_status.isOk()) {
450 return _aidl_status;
451 }
452 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
453 if (((_aidl_ret_status) != (::android::OK))) {
454 goto _aidl_error;
455 }
456 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
457 if (((_aidl_ret_status) != (::android::OK))) {
458 goto _aidl_error;
459 }
460 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
461 if (((_aidl_ret_status) != (::android::OK))) {
462 goto _aidl_error;
463 }
464 _aidl_error:
465 _aidl_status.setFromStatusT(_aidl_ret_status);
466 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100467}
468
469::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900470 ::android::Parcel _aidl_data;
471 ::android::Parcel _aidl_reply;
472 ::android::status_t _aidl_ret_status = ::android::OK;
473 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700474 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900475 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
476 if (((_aidl_ret_status) != (::android::OK))) {
477 goto _aidl_error;
478 }
479 _aidl_ret_status = _aidl_data.writeInt32(times);
480 if (((_aidl_ret_status) != (::android::OK))) {
481 goto _aidl_error;
482 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900483 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900484 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
485 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
486 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900487 if (((_aidl_ret_status) != (::android::OK))) {
488 goto _aidl_error;
489 }
490 _aidl_error:
491 _aidl_status.setFromStatusT(_aidl_ret_status);
492 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100493}
494
495::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900496 ::android::Parcel _aidl_data;
497 ::android::Parcel _aidl_reply;
498 ::android::status_t _aidl_ret_status = ::android::OK;
499 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700500 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900501 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
502 if (((_aidl_ret_status) != (::android::OK))) {
503 goto _aidl_error;
504 }
505 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
506 if (((_aidl_ret_status) != (::android::OK))) {
507 goto _aidl_error;
508 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900509 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900510 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
511 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
512 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900513 if (((_aidl_ret_status) != (::android::OK))) {
514 goto _aidl_error;
515 }
516 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
517 if (((_aidl_ret_status) != (::android::OK))) {
518 goto _aidl_error;
519 }
520 if (!_aidl_status.isOk()) {
521 return _aidl_status;
522 }
523 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
524 if (((_aidl_ret_status) != (::android::OK))) {
525 goto _aidl_error;
526 }
527 _aidl_error:
528 _aidl_status.setFromStatusT(_aidl_ret_status);
529 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100530}
531
532::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900533 ::android::Parcel _aidl_data;
534 ::android::Parcel _aidl_reply;
535 ::android::status_t _aidl_ret_status = ::android::OK;
536 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700537 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900538 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
539 if (((_aidl_ret_status) != (::android::OK))) {
540 goto _aidl_error;
541 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900542 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900543 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
544 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
545 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900546 if (((_aidl_ret_status) != (::android::OK))) {
547 goto _aidl_error;
548 }
549 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
550 if (((_aidl_ret_status) != (::android::OK))) {
551 goto _aidl_error;
552 }
553 if (!_aidl_status.isOk()) {
554 return _aidl_status;
555 }
556 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
557 if (((_aidl_ret_status) != (::android::OK))) {
558 goto _aidl_error;
559 }
560 _aidl_error:
561 _aidl_status.setFromStatusT(_aidl_ret_status);
562 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100563}
564
565::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 +0900566 ::android::Parcel _aidl_data;
567 ::android::Parcel _aidl_reply;
568 ::android::status_t _aidl_ret_status = ::android::OK;
569 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700570 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900571 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
572 if (((_aidl_ret_status) != (::android::OK))) {
573 goto _aidl_error;
574 }
575 _aidl_ret_status = _aidl_data.writeString16Vector(input);
576 if (((_aidl_ret_status) != (::android::OK))) {
577 goto _aidl_error;
578 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900579 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900580 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
581 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
582 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900583 if (((_aidl_ret_status) != (::android::OK))) {
584 goto _aidl_error;
585 }
586 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
587 if (((_aidl_ret_status) != (::android::OK))) {
588 goto _aidl_error;
589 }
590 if (!_aidl_status.isOk()) {
591 return _aidl_status;
592 }
593 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
594 if (((_aidl_ret_status) != (::android::OK))) {
595 goto _aidl_error;
596 }
597 _aidl_ret_status = _aidl_reply.readString16Vector(output);
598 if (((_aidl_ret_status) != (::android::OK))) {
599 goto _aidl_error;
600 }
601 _aidl_error:
602 _aidl_status.setFromStatusT(_aidl_ret_status);
603 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100604}
605
606::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 +0900607 ::android::Parcel _aidl_data;
608 ::android::Parcel _aidl_reply;
609 ::android::status_t _aidl_ret_status = ::android::OK;
610 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700611 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900612 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
613 if (((_aidl_ret_status) != (::android::OK))) {
614 goto _aidl_error;
615 }
616 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
617 if (((_aidl_ret_status) != (::android::OK))) {
618 goto _aidl_error;
619 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900620 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900621 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
622 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
623 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900624 if (((_aidl_ret_status) != (::android::OK))) {
625 goto _aidl_error;
626 }
627 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
628 if (((_aidl_ret_status) != (::android::OK))) {
629 goto _aidl_error;
630 }
631 if (!_aidl_status.isOk()) {
632 return _aidl_status;
633 }
634 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
635 if (((_aidl_ret_status) != (::android::OK))) {
636 goto _aidl_error;
637 }
638 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
639 if (((_aidl_ret_status) != (::android::OK))) {
640 goto _aidl_error;
641 }
642 _aidl_error:
643 _aidl_status.setFromStatusT(_aidl_ret_status);
644 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100645}
646
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900647::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900648 ::android::Parcel _aidl_data;
649 ::android::Parcel _aidl_reply;
650 ::android::status_t _aidl_ret_status = ::android::OK;
651 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700652 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900653 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
654 if (((_aidl_ret_status) != (::android::OK))) {
655 goto _aidl_error;
656 }
657 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
658 if (((_aidl_ret_status) != (::android::OK))) {
659 goto _aidl_error;
660 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900661 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900662 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900663 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900664 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900665 if (((_aidl_ret_status) != (::android::OK))) {
666 goto _aidl_error;
667 }
668 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
669 if (((_aidl_ret_status) != (::android::OK))) {
670 goto _aidl_error;
671 }
672 if (!_aidl_status.isOk()) {
673 return _aidl_status;
674 }
675 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
676 if (((_aidl_ret_status) != (::android::OK))) {
677 goto _aidl_error;
678 }
679 _aidl_error:
680 _aidl_status.setFromStatusT(_aidl_ret_status);
681 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100682}
683
684::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 +0900685 ::android::Parcel _aidl_data;
686 ::android::Parcel _aidl_reply;
687 ::android::status_t _aidl_ret_status = ::android::OK;
688 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700689 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900690 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
691 if (((_aidl_ret_status) != (::android::OK))) {
692 goto _aidl_error;
693 }
694 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
695 if (((_aidl_ret_status) != (::android::OK))) {
696 goto _aidl_error;
697 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900698 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900699 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
700 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
701 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900702 if (((_aidl_ret_status) != (::android::OK))) {
703 goto _aidl_error;
704 }
705 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
706 if (((_aidl_ret_status) != (::android::OK))) {
707 goto _aidl_error;
708 }
709 if (!_aidl_status.isOk()) {
710 return _aidl_status;
711 }
712 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
713 if (((_aidl_ret_status) != (::android::OK))) {
714 goto _aidl_error;
715 }
716 _aidl_error:
717 _aidl_status.setFromStatusT(_aidl_ret_status);
718 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100719}
720
721} // namespace os
722
723} // namespace android
724)";
725
Casey Dahlinb0966612015-10-19 16:35:26 -0700726const char kExpectedComplexTypeServerHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -0700727 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -0700728
729#include <binder/IInterface.h>
730#include <android/os/IComplexTypeInterface.h>
731
732namespace android {
733
734namespace os {
735
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800736class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -0700737public:
Steven Moreland800508d2019-07-30 10:45:31 -0700738 explicit BnComplexTypeInterface();
Jiyong Park8533bd02018-10-29 21:31:18 +0900739 ::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 -0700740}; // class BnComplexTypeInterface
741
742} // namespace os
743
744} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -0800745)";
Casey Dahlinb0966612015-10-19 16:35:26 -0700746
747const char kExpectedComplexTypeServerSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +0900748 R"(#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700749#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -0700750#include <binder/Stability.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700751
752namespace android {
753
754namespace os {
755
Steven Moreland800508d2019-07-30 10:45:31 -0700756BnComplexTypeInterface::BnComplexTypeInterface()
757{
Steven Morelanda57d0a62019-07-30 09:41:14 -0700758 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -0700759}
760
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800761::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 +0900762 ::android::status_t _aidl_ret_status = ::android::OK;
763 switch (_aidl_code) {
Jeongik Chab5d962f2018-11-17 09:12:28 +0900764 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900765 {
Jooyung Han43122462020-01-23 13:03:10 +0900766 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +0900767 ::std::vector<double> in_goes_in_and_out;
768 ::std::vector<bool> out_goes_out;
769 ::std::vector<int32_t> _aidl_return;
770 if (!(_aidl_data.checkInterface(this))) {
771 _aidl_ret_status = ::android::BAD_TYPE;
772 break;
773 }
774 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
775 if (((_aidl_ret_status) != (::android::OK))) {
776 break;
777 }
778 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
779 if (((_aidl_ret_status) != (::android::OK))) {
780 break;
781 }
782 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
783 if (((_aidl_ret_status) != (::android::OK))) {
784 break;
785 }
786 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
787 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
788 if (((_aidl_ret_status) != (::android::OK))) {
789 break;
790 }
791 if (!_aidl_status.isOk()) {
792 break;
793 }
794 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
795 if (((_aidl_ret_status) != (::android::OK))) {
796 break;
797 }
798 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
799 if (((_aidl_ret_status) != (::android::OK))) {
800 break;
801 }
802 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
803 if (((_aidl_ret_status) != (::android::OK))) {
804 break;
805 }
806 }
807 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900808 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900809 {
810 int32_t in_times;
811 if (!(_aidl_data.checkInterface(this))) {
812 _aidl_ret_status = ::android::BAD_TYPE;
813 break;
814 }
815 _aidl_ret_status = _aidl_data.readInt32(&in_times);
816 if (((_aidl_ret_status) != (::android::OK))) {
817 break;
818 }
819 ::android::binder::Status _aidl_status(Piff(in_times));
820 }
821 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900822 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900823 {
824 ::android::sp<::foo::IFooType> in_f;
825 ::android::sp<::foo::IFooType> _aidl_return;
826 if (!(_aidl_data.checkInterface(this))) {
827 _aidl_ret_status = ::android::BAD_TYPE;
828 break;
829 }
830 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
831 if (((_aidl_ret_status) != (::android::OK))) {
832 break;
833 }
834 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
835 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
836 if (((_aidl_ret_status) != (::android::OK))) {
837 break;
838 }
839 if (!_aidl_status.isOk()) {
840 break;
841 }
842 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
843 if (((_aidl_ret_status) != (::android::OK))) {
844 break;
845 }
846 }
847 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900848 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900849 {
850 ::android::sp<::foo::IFooType> _aidl_return;
851 if (!(_aidl_data.checkInterface(this))) {
852 _aidl_ret_status = ::android::BAD_TYPE;
853 break;
854 }
855 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
856 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
857 if (((_aidl_ret_status) != (::android::OK))) {
858 break;
859 }
860 if (!_aidl_status.isOk()) {
861 break;
862 }
863 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
864 if (((_aidl_ret_status) != (::android::OK))) {
865 break;
866 }
867 }
868 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900869 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900870 {
871 ::std::vector<::android::String16> in_input;
872 ::std::vector<::android::String16> out_output;
873 ::std::vector<::android::String16> _aidl_return;
874 if (!(_aidl_data.checkInterface(this))) {
875 _aidl_ret_status = ::android::BAD_TYPE;
876 break;
877 }
878 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
879 if (((_aidl_ret_status) != (::android::OK))) {
880 break;
881 }
882 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
883 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
884 if (((_aidl_ret_status) != (::android::OK))) {
885 break;
886 }
887 if (!_aidl_status.isOk()) {
888 break;
889 }
890 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
891 if (((_aidl_ret_status) != (::android::OK))) {
892 break;
893 }
894 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
895 if (((_aidl_ret_status) != (::android::OK))) {
896 break;
897 }
898 }
899 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900900 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900901 {
902 ::std::vector<::android::sp<::android::IBinder>> in_input;
903 ::std::vector<::android::sp<::android::IBinder>> out_output;
904 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
905 if (!(_aidl_data.checkInterface(this))) {
906 _aidl_ret_status = ::android::BAD_TYPE;
907 break;
908 }
909 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
910 if (((_aidl_ret_status) != (::android::OK))) {
911 break;
912 }
913 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
914 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
915 if (((_aidl_ret_status) != (::android::OK))) {
916 break;
917 }
918 if (!_aidl_status.isOk()) {
919 break;
920 }
921 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
922 if (((_aidl_ret_status) != (::android::OK))) {
923 break;
924 }
925 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
926 if (((_aidl_ret_status) != (::android::OK))) {
927 break;
928 }
929 }
930 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900931 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900932 {
933 ::android::base::unique_fd in_f;
934 ::android::base::unique_fd _aidl_return;
935 if (!(_aidl_data.checkInterface(this))) {
936 _aidl_ret_status = ::android::BAD_TYPE;
937 break;
938 }
939 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
940 if (((_aidl_ret_status) != (::android::OK))) {
941 break;
942 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900943 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +0900944 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
945 if (((_aidl_ret_status) != (::android::OK))) {
946 break;
947 }
948 if (!_aidl_status.isOk()) {
949 break;
950 }
951 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
952 if (((_aidl_ret_status) != (::android::OK))) {
953 break;
954 }
955 }
956 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900957 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900958 {
959 ::std::vector<::android::base::unique_fd> in_f;
960 ::std::vector<::android::base::unique_fd> _aidl_return;
961 if (!(_aidl_data.checkInterface(this))) {
962 _aidl_ret_status = ::android::BAD_TYPE;
963 break;
964 }
965 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
966 if (((_aidl_ret_status) != (::android::OK))) {
967 break;
968 }
969 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
970 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
971 if (((_aidl_ret_status) != (::android::OK))) {
972 break;
973 }
974 if (!_aidl_status.isOk()) {
975 break;
976 }
977 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
978 if (((_aidl_ret_status) != (::android::OK))) {
979 break;
980 }
981 }
982 break;
983 default:
984 {
985 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
986 }
987 break;
988 }
989 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
990 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
991 }
992 return _aidl_ret_status;
Casey Dahlinb0966612015-10-19 16:35:26 -0700993}
994
995} // namespace os
996
997} // namespace android
998)";
999
Martijn Coenenf1b50782018-02-21 21:06:23 +01001000const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +09001001 R"(#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001002#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -07001003#include <binder/Stability.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001004
1005namespace android {
1006
1007namespace os {
1008
Steven Moreland800508d2019-07-30 10:45:31 -07001009BnComplexTypeInterface::BnComplexTypeInterface()
1010{
Steven Morelanda57d0a62019-07-30 09:41:14 -07001011 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -07001012}
1013
Martijn Coenenf1b50782018-02-21 21:06:23 +01001014::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 +09001015 ::android::status_t _aidl_ret_status = ::android::OK;
1016 switch (_aidl_code) {
Jeongik Chab5d962f2018-11-17 09:12:28 +09001017 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001018 {
Jooyung Han43122462020-01-23 13:03:10 +09001019 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +09001020 ::std::vector<double> in_goes_in_and_out;
1021 ::std::vector<bool> out_goes_out;
1022 ::std::vector<int32_t> _aidl_return;
1023 if (!(_aidl_data.checkInterface(this))) {
1024 _aidl_ret_status = ::android::BAD_TYPE;
1025 break;
1026 }
Devin Mooref7600872020-05-13 15:47:50 -07001027 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001028 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
1029 if (((_aidl_ret_status) != (::android::OK))) {
1030 break;
1031 }
1032 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
1033 if (((_aidl_ret_status) != (::android::OK))) {
1034 break;
1035 }
1036 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
1037 if (((_aidl_ret_status) != (::android::OK))) {
1038 break;
1039 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001040 ::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 +09001041 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1042 if (((_aidl_ret_status) != (::android::OK))) {
1043 break;
1044 }
1045 if (!_aidl_status.isOk()) {
1046 break;
1047 }
1048 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
1049 if (((_aidl_ret_status) != (::android::OK))) {
1050 break;
1051 }
1052 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
1053 if (((_aidl_ret_status) != (::android::OK))) {
1054 break;
1055 }
1056 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1057 if (((_aidl_ret_status) != (::android::OK))) {
1058 break;
1059 }
1060 }
1061 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001062 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001063 {
1064 int32_t in_times;
1065 if (!(_aidl_data.checkInterface(this))) {
1066 _aidl_ret_status = ::android::BAD_TYPE;
1067 break;
1068 }
Devin Mooref7600872020-05-13 15:47:50 -07001069 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001070 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1071 if (((_aidl_ret_status) != (::android::OK))) {
1072 break;
1073 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001074 ::android::binder::Status _aidl_status(Piff(in_times));
Jiyong Parka755dc72018-06-29 13:52:24 +09001075 }
1076 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001077 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001078 {
1079 ::android::sp<::foo::IFooType> in_f;
1080 ::android::sp<::foo::IFooType> _aidl_return;
1081 if (!(_aidl_data.checkInterface(this))) {
1082 _aidl_ret_status = ::android::BAD_TYPE;
1083 break;
1084 }
Devin Mooref7600872020-05-13 15:47:50 -07001085 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001086 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1087 if (((_aidl_ret_status) != (::android::OK))) {
1088 break;
1089 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001090 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001091 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1092 if (((_aidl_ret_status) != (::android::OK))) {
1093 break;
1094 }
1095 if (!_aidl_status.isOk()) {
1096 break;
1097 }
1098 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1099 if (((_aidl_ret_status) != (::android::OK))) {
1100 break;
1101 }
1102 }
1103 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001104 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001105 {
1106 ::android::sp<::foo::IFooType> _aidl_return;
1107 if (!(_aidl_data.checkInterface(this))) {
1108 _aidl_ret_status = ::android::BAD_TYPE;
1109 break;
1110 }
Devin Mooref7600872020-05-13 15:47:50 -07001111 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001112 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001113 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1114 if (((_aidl_ret_status) != (::android::OK))) {
1115 break;
1116 }
1117 if (!_aidl_status.isOk()) {
1118 break;
1119 }
1120 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1121 if (((_aidl_ret_status) != (::android::OK))) {
1122 break;
1123 }
1124 }
1125 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001126 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001127 {
1128 ::std::vector<::android::String16> in_input;
1129 ::std::vector<::android::String16> out_output;
1130 ::std::vector<::android::String16> _aidl_return;
1131 if (!(_aidl_data.checkInterface(this))) {
1132 _aidl_ret_status = ::android::BAD_TYPE;
1133 break;
1134 }
Devin Mooref7600872020-05-13 15:47:50 -07001135 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001136 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1137 if (((_aidl_ret_status) != (::android::OK))) {
1138 break;
1139 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001140 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001141 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1142 if (((_aidl_ret_status) != (::android::OK))) {
1143 break;
1144 }
1145 if (!_aidl_status.isOk()) {
1146 break;
1147 }
1148 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1149 if (((_aidl_ret_status) != (::android::OK))) {
1150 break;
1151 }
1152 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1153 if (((_aidl_ret_status) != (::android::OK))) {
1154 break;
1155 }
1156 }
1157 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001158 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001159 {
1160 ::std::vector<::android::sp<::android::IBinder>> in_input;
1161 ::std::vector<::android::sp<::android::IBinder>> out_output;
1162 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
1163 if (!(_aidl_data.checkInterface(this))) {
1164 _aidl_ret_status = ::android::BAD_TYPE;
1165 break;
1166 }
Devin Mooref7600872020-05-13 15:47:50 -07001167 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001168 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1169 if (((_aidl_ret_status) != (::android::OK))) {
1170 break;
1171 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001172 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001173 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1174 if (((_aidl_ret_status) != (::android::OK))) {
1175 break;
1176 }
1177 if (!_aidl_status.isOk()) {
1178 break;
1179 }
1180 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1181 if (((_aidl_ret_status) != (::android::OK))) {
1182 break;
1183 }
1184 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1185 if (((_aidl_ret_status) != (::android::OK))) {
1186 break;
1187 }
1188 }
1189 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001190 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001191 {
1192 ::android::base::unique_fd in_f;
1193 ::android::base::unique_fd _aidl_return;
1194 if (!(_aidl_data.checkInterface(this))) {
1195 _aidl_ret_status = ::android::BAD_TYPE;
1196 break;
1197 }
Devin Mooref7600872020-05-13 15:47:50 -07001198 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001199 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1200 if (((_aidl_ret_status) != (::android::OK))) {
1201 break;
1202 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001203 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001204 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1205 if (((_aidl_ret_status) != (::android::OK))) {
1206 break;
1207 }
1208 if (!_aidl_status.isOk()) {
1209 break;
1210 }
1211 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1212 if (((_aidl_ret_status) != (::android::OK))) {
1213 break;
1214 }
1215 }
1216 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001217 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001218 {
1219 ::std::vector<::android::base::unique_fd> in_f;
1220 ::std::vector<::android::base::unique_fd> _aidl_return;
1221 if (!(_aidl_data.checkInterface(this))) {
1222 _aidl_ret_status = ::android::BAD_TYPE;
1223 break;
1224 }
Devin Mooref7600872020-05-13 15:47:50 -07001225 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001226 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1227 if (((_aidl_ret_status) != (::android::OK))) {
1228 break;
1229 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001230 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001231 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1232 if (((_aidl_ret_status) != (::android::OK))) {
1233 break;
1234 }
1235 if (!_aidl_status.isOk()) {
1236 break;
1237 }
1238 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1239 if (((_aidl_ret_status) != (::android::OK))) {
1240 break;
1241 }
1242 }
1243 break;
1244 default:
1245 {
1246 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1247 }
1248 break;
1249 }
1250 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1251 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1252 }
1253 return _aidl_ret_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +01001254}
1255
1256} // namespace os
1257
1258} // namespace android
1259)";
1260
Casey Dahlinb0966612015-10-19 16:35:26 -07001261const char kExpectedComplexTypeInterfaceHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001262 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -07001263
Christopher Wiley7cb9c252016-04-11 11:07:33 -07001264#include <android-base/unique_fd.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001265#include <binder/IBinder.h>
1266#include <binder/IInterface.h>
Christopher Wiley433c8bb2015-11-12 14:20:46 -08001267#include <binder/Status.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001268#include <cstdint>
Casey Dahlin389781f2015-10-22 13:13:21 -07001269#include <foo/IFooType.h>
Jooyung Han43122462020-01-23 13:03:10 +09001270#include <optional>
Christopher Wiley56c9bf32015-10-30 10:41:12 -07001271#include <utils/String16.h>
Casey Dahlin389781f2015-10-22 13:13:21 -07001272#include <utils/StrongPointer.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001273#include <vector>
1274
1275namespace android {
1276
1277namespace os {
1278
Casey Dahlinb8d9e882015-11-24 10:57:23 -08001279class IComplexTypeInterface : public ::android::IInterface {
Casey Dahlinb0966612015-10-19 16:35:26 -07001280public:
Jiyong Parka755dc72018-06-29 13:52:24 +09001281 DECLARE_META_INTERFACE(ComplexTypeInterface)
1282 enum : int32_t {
1283 MY_CONSTANT = 3,
1284 };
Jooyung Han43122462020-01-23 13:03:10 +09001285 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 +09001286 virtual ::android::binder::Status Piff(int32_t times) = 0;
1287 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1288 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1289 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1290 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 +09001291 virtual ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) = 0;
Jiyong Parka755dc72018-06-29 13:52:24 +09001292 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 -07001293}; // class IComplexTypeInterface
1294
Jiyong Park75e1a742018-07-04 12:31:23 +09001295class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1296public:
Jooyung Han7bee8e32020-01-30 17:25:21 +09001297 ::android::IBinder* onAsBinder() override {
1298 return nullptr;
1299 }
Jooyung Han43122462020-01-23 13:03:10 +09001300 ::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 +09001301 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1302 }
1303 ::android::binder::Status Piff(int32_t) override {
1304 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1305 }
Jooyung Han6991d922020-01-30 18:13:55 +09001306 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001307 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1308 }
Jooyung Han6991d922020-01-30 18:13:55 +09001309 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001310 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1311 }
Jooyung Han6991d922020-01-30 18:13:55 +09001312 ::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 +09001313 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1314 }
Jooyung Han6991d922020-01-30 18:13:55 +09001315 ::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 +09001316 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1317 }
Jooyung Han6991d922020-01-30 18:13:55 +09001318 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd, ::android::base::unique_fd*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001319 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1320 }
Jooyung Han6991d922020-01-30 18:13:55 +09001321 ::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 +09001322 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1323 }
1324}; // class IComplexTypeInterfaceDefault
Jiyong Park75e1a742018-07-04 12:31:23 +09001325
Casey Dahlinb0966612015-10-19 16:35:26 -07001326} // namespace os
1327
1328} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -08001329)";
Casey Dahlinb0966612015-10-19 16:35:26 -07001330
1331const char kExpectedComplexTypeInterfaceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001332 R"(#include <android/os/IComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001333#include <android/os/BpComplexTypeInterface.h>
1334
1335namespace android {
1336
1337namespace os {
1338
Ivan Lozanob3f4d622019-11-25 09:30:02 -08001339DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
Casey Dahlinb0966612015-10-19 16:35:26 -07001340
1341} // namespace os
1342
1343} // namespace android
1344)";
1345
Daniel Norman85aed542019-08-21 12:01:14 -07001346const string kEnumAIDL = R"(package android.os;
1347enum TestEnum {
Daniel Normanb28684e2019-10-17 15:31:39 -07001348 ZERO,
1349 ONE,
1350 THREE = 3,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001351 FOUR = 3 + 1,
Daniel Normanb28684e2019-10-17 15:31:39 -07001352 FIVE,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001353 SIX,
1354 SEVEN,
1355 EIGHT = 16 / 2,
1356 NINE,
1357 TEN,
Daniel Norman85aed542019-08-21 12:01:14 -07001358})";
1359
1360const char kExpectedEnumHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001361 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001362
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001363#include <array>
1364#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001365#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001366#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001367
1368namespace android {
1369
1370namespace os {
1371
1372enum class TestEnum : int8_t {
Daniel Normanb28684e2019-10-17 15:31:39 -07001373 ZERO = 0,
1374 ONE = 1,
1375 THREE = 3,
1376 FOUR = 4,
1377 FIVE = 5,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001378 SIX = 6,
1379 SEVEN = 7,
1380 EIGHT = 8,
1381 NINE = 9,
1382 TEN = 10,
Daniel Norman85aed542019-08-21 12:01:14 -07001383};
1384
Daniel Norman0c1bd362019-11-12 23:05:31 -08001385static inline std::string toString(TestEnum val) {
1386 switch(val) {
1387 case TestEnum::ZERO:
1388 return "ZERO";
1389 case TestEnum::ONE:
1390 return "ONE";
1391 case TestEnum::THREE:
1392 return "THREE";
1393 case TestEnum::FOUR:
1394 return "FOUR";
1395 case TestEnum::FIVE:
1396 return "FIVE";
1397 case TestEnum::SIX:
1398 return "SIX";
1399 case TestEnum::SEVEN:
1400 return "SEVEN";
1401 case TestEnum::EIGHT:
1402 return "EIGHT";
1403 case TestEnum::NINE:
1404 return "NINE";
1405 case TestEnum::TEN:
1406 return "TEN";
1407 default:
1408 return std::to_string(static_cast<int8_t>(val));
1409 }
1410}
1411
Daniel Norman85aed542019-08-21 12:01:14 -07001412} // namespace os
1413
1414} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001415namespace android {
1416
1417namespace internal {
1418
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001419#pragma clang diagnostic push
1420#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001421template <>
1422constexpr inline std::array<::android::os::TestEnum, 10> enum_values<::android::os::TestEnum> = {
1423 ::android::os::TestEnum::ZERO,
1424 ::android::os::TestEnum::ONE,
1425 ::android::os::TestEnum::THREE,
1426 ::android::os::TestEnum::FOUR,
1427 ::android::os::TestEnum::FIVE,
1428 ::android::os::TestEnum::SIX,
1429 ::android::os::TestEnum::SEVEN,
1430 ::android::os::TestEnum::EIGHT,
1431 ::android::os::TestEnum::NINE,
1432 ::android::os::TestEnum::TEN,
1433};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001434#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001435
1436} // namespace internal
1437
1438} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001439)";
1440
1441const string kEnumWithBackingTypeAIDL = R"(package android.os;
1442@Backing(type="long")
1443enum TestEnum {
1444 FOO = 1,
1445 BAR = 2,
1446})";
1447
1448const char kExpectedEnumWithBackingTypeHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001449 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001450
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001451#include <array>
1452#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001453#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001454#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001455
1456namespace android {
1457
1458namespace os {
1459
1460enum class TestEnum : int64_t {
Daniel Norman716d3112019-09-10 13:11:56 -07001461 FOO = 1L,
1462 BAR = 2L,
Daniel Norman85aed542019-08-21 12:01:14 -07001463};
1464
Daniel Norman0c1bd362019-11-12 23:05:31 -08001465static inline std::string toString(TestEnum val) {
1466 switch(val) {
1467 case TestEnum::FOO:
1468 return "FOO";
1469 case TestEnum::BAR:
1470 return "BAR";
1471 default:
1472 return std::to_string(static_cast<int64_t>(val));
1473 }
1474}
1475
Daniel Norman85aed542019-08-21 12:01:14 -07001476} // namespace os
1477
1478} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001479namespace android {
1480
1481namespace internal {
1482
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001483#pragma clang diagnostic push
1484#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001485template <>
1486constexpr inline std::array<::android::os::TestEnum, 2> enum_values<::android::os::TestEnum> = {
1487 ::android::os::TestEnum::FOO,
1488 ::android::os::TestEnum::BAR,
1489};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001490#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001491
1492} // namespace internal
1493
1494} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001495)";
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001496// clang-format on
Daniel Norman85aed542019-08-21 12:01:14 -07001497
Casey Dahlina834dd42015-09-23 11:52:15 -07001498} // namespace
1499
Casey Dahlinb0966612015-10-19 16:35:26 -07001500class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -07001501 protected:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001502 ASTTest(const string& cmdline, const string& file_contents)
1503 : options_(Options::From(cmdline)), file_contents_(file_contents) {
Christopher Wiley56799522015-10-31 10:17:04 -07001504 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001505
Jiyong Parkb034bf02018-07-30 17:44:33 +09001506 AidlInterface* ParseSingleInterface() {
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001507 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
Casey Dahlina834dd42015-09-23 11:52:15 -07001508
Jiyong Parkb034bf02018-07-30 17:44:33 +09001509 vector<string> imported_files;
Jiyong Park8c380532018-08-30 14:55:26 +09001510 ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001511 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001512 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Christopher Wiley4a2884b2015-10-07 11:27:45 -07001513
Steven Moreland5557f1c2018-07-02 13:50:23 -07001514 if (err != AidlError::OK) {
Casey Dahlin2cc93162015-10-02 16:14:17 -07001515 return nullptr;
Steven Moreland5557f1c2018-07-02 13:50:23 -07001516 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001517
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001518 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Jiyong Parkb034bf02018-07-30 17:44:33 +09001519 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001520 EXPECT_NE(nullptr, defined_types.front().get()->AsInterface());
Steven Moreland5557f1c2018-07-02 13:50:23 -07001521
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001522 return defined_types.front().get()->AsInterface();
Christopher Wiley90be4e32015-10-20 14:55:25 -07001523 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001524
Daniel Norman85aed542019-08-21 12:01:14 -07001525 AidlEnumDeclaration* ParseSingleEnumDeclaration() {
1526 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1527
Daniel Norman85aed542019-08-21 12:01:14 -07001528 vector<string> imported_files;
1529 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001530 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Daniel Norman85aed542019-08-21 12:01:14 -07001531
1532 if (err != AidlError::OK) {
1533 return nullptr;
1534 }
1535
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001536 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Daniel Norman85aed542019-08-21 12:01:14 -07001537 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001538 EXPECT_NE(nullptr, defined_types.front().get()->AsEnumDeclaration());
Daniel Norman85aed542019-08-21 12:01:14 -07001539
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001540 return defined_types.front().get()->AsEnumDeclaration();
Daniel Norman85aed542019-08-21 12:01:14 -07001541 }
1542
Christopher Wiley0c732db2015-09-29 14:36:44 -07001543 void Compare(Document* doc, const char* expected) {
1544 string output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +09001545 doc->Write(CodeWriter::ForString(&output).get());
Christopher Wiley0c732db2015-09-29 14:36:44 -07001546
Casey Dahlin80ada3d2015-10-20 20:33:56 -07001547 if (expected == output) {
1548 return; // Success
1549 }
1550
1551 test::PrintDiff(expected, output);
1552 FAIL() << "Document contents did not match expected contents";
Christopher Wiley0c732db2015-09-29 14:36:44 -07001553 }
Casey Dahlin389781f2015-10-22 13:13:21 -07001554
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001555 const Options options_;
Casey Dahlin389781f2015-10-22 13:13:21 -07001556 const string file_contents_;
1557 FakeIoDelegate io_delegate_;
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001558 AidlTypenames typenames_;
Christopher Wiley0c732db2015-09-29 14:36:44 -07001559};
1560
Casey Dahlinb0966612015-10-19 16:35:26 -07001561class ComplexTypeInterfaceASTTest : public ASTTest {
Casey Dahlin389781f2015-10-22 13:13:21 -07001562 public:
1563 ComplexTypeInterfaceASTTest()
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001564 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
Casey Dahlin389781f2015-10-22 13:13:21 -07001565 kComplexTypeInterfaceAIDL) {
1566 io_delegate_.SetFileContents("foo/IFooType.aidl",
1567 "package foo; interface IFooType {}");
1568 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001569};
1570
1571TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001572 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001573 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001574 unique_ptr<Document> doc = internals::BuildClientHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001575 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1576}
1577
1578TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001579 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001580 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001581 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001582 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1583}
1584
1585TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001586 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001587 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001588 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001589 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1590}
1591
1592TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001593 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001594 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001595 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001596 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1597}
1598
1599TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001600 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001601 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001602 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001603 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1604}
1605
1606TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001607 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001608 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001609 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001610 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -07001611}
1612
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001613class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1614 public:
1615 ComplexTypeInterfaceASTTestWithTrace()
1616 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1617 kComplexTypeInterfaceAIDL) {
1618 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1619 }
1620};
1621
1622TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001623 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001624 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001625 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001626 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1627}
1628
1629TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001630 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001631 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001632 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001633 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1634}
1635
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001636namespace test_io_handling {
1637
1638const char kInputPath[] = "a/IFoo.aidl";
1639const char kOutputPath[] = "output.cpp";
1640const char kHeaderDir[] = "headers";
1641const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1642
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001643const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1644
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001645} // namespace test_io_handling
1646
1647class IoErrorHandlingTest : public ASTTest {
1648 public:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001649 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001650};
1651
1652TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1653 // Confirm that this is working correctly without I/O problems.
Jiyong Parkb034bf02018-07-30 17:44:33 +09001654 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001655 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001656 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001657}
1658
1659TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1660 using namespace test_io_handling;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001661 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001662 ASSERT_NE(interface, nullptr);
1663
1664 // Simulate issues closing the interface header.
1665 const string header_path =
1666 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1667 kInterfaceHeaderRelPath);
1668 io_delegate_.AddBrokenFilePath(header_path);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001669 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001670 // We should never attempt to write the C++ file if we fail writing headers.
1671 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1672 // We should remove partial results.
1673 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1674}
1675
1676TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1677 using test_io_handling::kOutputPath;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001678 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001679 ASSERT_NE(interface, nullptr);
1680
1681 // Simulate issues closing the cpp file.
1682 io_delegate_.AddBrokenFilePath(kOutputPath);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001683 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001684 // We should remove partial results.
1685 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1686}
1687
Daniel Norman85aed542019-08-21 12:01:14 -07001688class EnumASTTest : public ASTTest {
1689 public:
1690 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1691};
1692
1693TEST_F(EnumASTTest, GeneratesEnumHeader) {
1694 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1695 ASSERT_NE(enum_decl, nullptr);
1696 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1697 Compare(doc.get(), kExpectedEnumHeaderOutput);
1698}
1699
1700class EnumWithBackingTypeASTTest : public ASTTest {
1701 public:
1702 EnumWithBackingTypeASTTest()
1703 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1704};
1705
1706TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1707 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1708 ASSERT_NE(enum_decl, nullptr);
1709 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1710 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1711}
1712
Christopher Wileyf944e792015-09-29 10:00:46 -07001713} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -07001714} // namespace aidl
1715} // namespace android