blob: 53574be75e0504cc02a2f91dd32a963bbacae842 [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
Casey Dahlinb0966612015-10-19 16:35:26 -070041const string kComplexTypeInterfaceAIDL =
42R"(package android.os;
Casey Dahlin389781f2015-10-22 13:13:21 -070043import foo.IFooType;
Casey Dahlinb0966612015-10-19 16:35:26 -070044interface IComplexTypeInterface {
Casey Dahlind40e2fe2015-11-24 14:06:52 -080045 const int MY_CONSTANT = 3;
Casey Dahlincb5317d2015-12-03 15:43:33 -080046 int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
Casey Dahlin0dd08af2015-10-20 18:45:50 -070047 oneway void Piff(int times);
Casey Dahlin389781f2015-10-22 13:13:21 -070048 IFooType TakesABinder(IFooType f);
Casey Dahlinef88bce2016-04-15 11:55:30 -070049 @nullable IFooType NullableBinder();
Christopher Wiley56c9bf32015-10-30 10:41:12 -070050 List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
Casey Dahlin7ecd69f2015-11-03 13:52:38 -080051 List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
Casey Dahlina4ba4b62015-11-02 15:43:30 -080052 FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
53 FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
Casey Dahlinb0966612015-10-19 16:35:26 -070054})";
55
56const char kExpectedComplexTypeClientHeaderOutput[] =
57R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
58#define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
59
60#include <binder/IBinder.h>
61#include <binder/IInterface.h>
62#include <utils/Errors.h>
63#include <android/os/IComplexTypeInterface.h>
64
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;
73 ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) override;
74 ::android::binder::Status Piff(int32_t times) override;
75 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
76 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
77 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
78 ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) override;
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
86
Christopher Wiley11a9d792016-02-24 17:20:33 -080087#endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
88)";
Casey Dahlinb0966612015-10-19 16:35:26 -070089
90const char kExpectedComplexTypeClientSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +090091 R"(#include <android/os/BpComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070092#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +090093#include <android-base/macros.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070094
95namespace android {
96
97namespace os {
98
Casey Dahlinb8d9e882015-11-24 10:57:23 -080099BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
100 : BpInterface<IComplexTypeInterface>(_aidl_impl){
Casey Dahlinb0966612015-10-19 16:35:26 -0700101}
102
Casey Dahlin57dbe242015-12-04 11:44:02 -0800103::android::binder::Status BpComplexTypeInterface::Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900104 ::android::Parcel _aidl_data;
105 ::android::Parcel _aidl_reply;
106 ::android::status_t _aidl_ret_status = ::android::OK;
107 ::android::binder::Status _aidl_status;
108 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
109 if (((_aidl_ret_status) != (::android::OK))) {
110 goto _aidl_error;
111 }
112 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
113 if (((_aidl_ret_status) != (::android::OK))) {
114 goto _aidl_error;
115 }
116 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
117 if (((_aidl_ret_status) != (::android::OK))) {
118 goto _aidl_error;
119 }
120 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
121 if (((_aidl_ret_status) != (::android::OK))) {
122 goto _aidl_error;
123 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900124 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900125 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
126 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
127 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900128 if (((_aidl_ret_status) != (::android::OK))) {
129 goto _aidl_error;
130 }
131 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
132 if (((_aidl_ret_status) != (::android::OK))) {
133 goto _aidl_error;
134 }
135 if (!_aidl_status.isOk()) {
136 return _aidl_status;
137 }
138 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
139 if (((_aidl_ret_status) != (::android::OK))) {
140 goto _aidl_error;
141 }
142 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
143 if (((_aidl_ret_status) != (::android::OK))) {
144 goto _aidl_error;
145 }
146 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
147 if (((_aidl_ret_status) != (::android::OK))) {
148 goto _aidl_error;
149 }
150 _aidl_error:
151 _aidl_status.setFromStatusT(_aidl_ret_status);
152 return _aidl_status;
Casey Dahlinb0966612015-10-19 16:35:26 -0700153}
154
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800155::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900156 ::android::Parcel _aidl_data;
157 ::android::Parcel _aidl_reply;
158 ::android::status_t _aidl_ret_status = ::android::OK;
159 ::android::binder::Status _aidl_status;
160 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
161 if (((_aidl_ret_status) != (::android::OK))) {
162 goto _aidl_error;
163 }
164 _aidl_ret_status = _aidl_data.writeInt32(times);
165 if (((_aidl_ret_status) != (::android::OK))) {
166 goto _aidl_error;
167 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900168 _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 +0900169 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
170 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
171 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900172 if (((_aidl_ret_status) != (::android::OK))) {
173 goto _aidl_error;
174 }
175 _aidl_error:
176 _aidl_status.setFromStatusT(_aidl_ret_status);
177 return _aidl_status;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700178}
179
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800180::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900181 ::android::Parcel _aidl_data;
182 ::android::Parcel _aidl_reply;
183 ::android::status_t _aidl_ret_status = ::android::OK;
184 ::android::binder::Status _aidl_status;
185 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
186 if (((_aidl_ret_status) != (::android::OK))) {
187 goto _aidl_error;
188 }
189 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
190 if (((_aidl_ret_status) != (::android::OK))) {
191 goto _aidl_error;
192 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900193 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900194 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
195 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
196 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900197 if (((_aidl_ret_status) != (::android::OK))) {
198 goto _aidl_error;
199 }
200 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
201 if (((_aidl_ret_status) != (::android::OK))) {
202 goto _aidl_error;
203 }
204 if (!_aidl_status.isOk()) {
205 return _aidl_status;
206 }
207 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
208 if (((_aidl_ret_status) != (::android::OK))) {
209 goto _aidl_error;
210 }
211 _aidl_error:
212 _aidl_status.setFromStatusT(_aidl_ret_status);
213 return _aidl_status;
Casey Dahlin389781f2015-10-22 13:13:21 -0700214}
215
Casey Dahlinef88bce2016-04-15 11:55:30 -0700216::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900217 ::android::Parcel _aidl_data;
218 ::android::Parcel _aidl_reply;
219 ::android::status_t _aidl_ret_status = ::android::OK;
220 ::android::binder::Status _aidl_status;
221 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
222 if (((_aidl_ret_status) != (::android::OK))) {
223 goto _aidl_error;
224 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900225 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900226 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
227 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
228 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900229 if (((_aidl_ret_status) != (::android::OK))) {
230 goto _aidl_error;
231 }
232 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
233 if (((_aidl_ret_status) != (::android::OK))) {
234 goto _aidl_error;
235 }
236 if (!_aidl_status.isOk()) {
237 return _aidl_status;
238 }
239 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
240 if (((_aidl_ret_status) != (::android::OK))) {
241 goto _aidl_error;
242 }
243 _aidl_error:
244 _aidl_status.setFromStatusT(_aidl_ret_status);
245 return _aidl_status;
Casey Dahlinef88bce2016-04-15 11:55:30 -0700246}
247
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800248::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 +0900249 ::android::Parcel _aidl_data;
250 ::android::Parcel _aidl_reply;
251 ::android::status_t _aidl_ret_status = ::android::OK;
252 ::android::binder::Status _aidl_status;
253 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
254 if (((_aidl_ret_status) != (::android::OK))) {
255 goto _aidl_error;
256 }
257 _aidl_ret_status = _aidl_data.writeString16Vector(input);
258 if (((_aidl_ret_status) != (::android::OK))) {
259 goto _aidl_error;
260 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900261 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900262 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
263 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
264 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900265 if (((_aidl_ret_status) != (::android::OK))) {
266 goto _aidl_error;
267 }
268 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
269 if (((_aidl_ret_status) != (::android::OK))) {
270 goto _aidl_error;
271 }
272 if (!_aidl_status.isOk()) {
273 return _aidl_status;
274 }
275 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
276 if (((_aidl_ret_status) != (::android::OK))) {
277 goto _aidl_error;
278 }
279 _aidl_ret_status = _aidl_reply.readString16Vector(output);
280 if (((_aidl_ret_status) != (::android::OK))) {
281 goto _aidl_error;
282 }
283 _aidl_error:
284 _aidl_status.setFromStatusT(_aidl_ret_status);
285 return _aidl_status;
Christopher Wiley56c9bf32015-10-30 10:41:12 -0700286}
287
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800288::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 +0900289 ::android::Parcel _aidl_data;
290 ::android::Parcel _aidl_reply;
291 ::android::status_t _aidl_ret_status = ::android::OK;
292 ::android::binder::Status _aidl_status;
293 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
294 if (((_aidl_ret_status) != (::android::OK))) {
295 goto _aidl_error;
296 }
297 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
298 if (((_aidl_ret_status) != (::android::OK))) {
299 goto _aidl_error;
300 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900301 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900302 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
303 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
304 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900305 if (((_aidl_ret_status) != (::android::OK))) {
306 goto _aidl_error;
307 }
308 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
309 if (((_aidl_ret_status) != (::android::OK))) {
310 goto _aidl_error;
311 }
312 if (!_aidl_status.isOk()) {
313 return _aidl_status;
314 }
315 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
316 if (((_aidl_ret_status) != (::android::OK))) {
317 goto _aidl_error;
318 }
319 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
320 if (((_aidl_ret_status) != (::android::OK))) {
321 goto _aidl_error;
322 }
323 _aidl_error:
324 _aidl_status.setFromStatusT(_aidl_ret_status);
325 return _aidl_status;
Casey Dahlin7ecd69f2015-11-03 13:52:38 -0800326}
327
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900328::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900329 ::android::Parcel _aidl_data;
330 ::android::Parcel _aidl_reply;
331 ::android::status_t _aidl_ret_status = ::android::OK;
332 ::android::binder::Status _aidl_status;
333 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
334 if (((_aidl_ret_status) != (::android::OK))) {
335 goto _aidl_error;
336 }
337 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
338 if (((_aidl_ret_status) != (::android::OK))) {
339 goto _aidl_error;
340 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900341 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900342 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900343 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900344 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900345 if (((_aidl_ret_status) != (::android::OK))) {
346 goto _aidl_error;
347 }
348 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
349 if (((_aidl_ret_status) != (::android::OK))) {
350 goto _aidl_error;
351 }
352 if (!_aidl_status.isOk()) {
353 return _aidl_status;
354 }
355 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
356 if (((_aidl_ret_status) != (::android::OK))) {
357 goto _aidl_error;
358 }
359 _aidl_error:
360 _aidl_status.setFromStatusT(_aidl_ret_status);
361 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800362}
363
Christopher Wiley7cb9c252016-04-11 11:07:33 -0700364::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 +0900365 ::android::Parcel _aidl_data;
366 ::android::Parcel _aidl_reply;
367 ::android::status_t _aidl_ret_status = ::android::OK;
368 ::android::binder::Status _aidl_status;
369 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
370 if (((_aidl_ret_status) != (::android::OK))) {
371 goto _aidl_error;
372 }
373 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
374 if (((_aidl_ret_status) != (::android::OK))) {
375 goto _aidl_error;
376 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900377 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
Jiyong Park75e1a742018-07-04 12:31:23 +0900378 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
379 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
380 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900381 if (((_aidl_ret_status) != (::android::OK))) {
382 goto _aidl_error;
383 }
384 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
385 if (((_aidl_ret_status) != (::android::OK))) {
386 goto _aidl_error;
387 }
388 if (!_aidl_status.isOk()) {
389 return _aidl_status;
390 }
391 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
392 if (((_aidl_ret_status) != (::android::OK))) {
393 goto _aidl_error;
394 }
395 _aidl_error:
396 _aidl_status.setFromStatusT(_aidl_ret_status);
397 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800398}
399
Casey Dahlinb0966612015-10-19 16:35:26 -0700400} // namespace os
401
402} // namespace android
403)";
404
Martijn Coenenf1b50782018-02-21 21:06:23 +0100405const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +0900406 R"(#include <android/os/BpComplexTypeInterface.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
418::android::binder::Status BpComplexTypeInterface::Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
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 Mooreff1e4812020-04-16 11:22:55 -0700423 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900440 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700476 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900485 _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 +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 Mooreff1e4812020-04-16 11:22:55 -0700502 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900511 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700539 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900544 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700572 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900581 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700613 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900622 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700654 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900663 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
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 Mooreff1e4812020-04-16 11:22:55 -0700691 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "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 }
Jeongik Chab5d962f2018-11-17 09:12:28 +0900700 _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
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[] =
Steven Moreland800508d2019-07-30 10:45:31 -0700729 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
Casey Dahlinb0966612015-10-19 16:35:26 -0700730#define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
731
732#include <binder/IInterface.h>
733#include <android/os/IComplexTypeInterface.h>
734
735namespace android {
736
737namespace os {
738
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800739class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -0700740public:
Steven Moreland800508d2019-07-30 10:45:31 -0700741 explicit BnComplexTypeInterface();
Jiyong Park8533bd02018-10-29 21:31:18 +0900742 ::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 -0700743}; // class BnComplexTypeInterface
744
745} // namespace os
746
747} // namespace android
748
Christopher Wiley11a9d792016-02-24 17:20:33 -0800749#endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
750)";
Casey Dahlinb0966612015-10-19 16:35:26 -0700751
752const char kExpectedComplexTypeServerSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +0900753 R"(#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700754#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -0700755#include <binder/Stability.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700756
757namespace android {
758
759namespace os {
760
Steven Moreland800508d2019-07-30 10:45:31 -0700761BnComplexTypeInterface::BnComplexTypeInterface()
762{
Steven Morelanda57d0a62019-07-30 09:41:14 -0700763 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -0700764}
765
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800766::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 +0900767 ::android::status_t _aidl_ret_status = ::android::OK;
768 switch (_aidl_code) {
Jeongik Chab5d962f2018-11-17 09:12:28 +0900769 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900770 {
771 ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
772 ::std::vector<double> in_goes_in_and_out;
773 ::std::vector<bool> out_goes_out;
774 ::std::vector<int32_t> _aidl_return;
775 if (!(_aidl_data.checkInterface(this))) {
776 _aidl_ret_status = ::android::BAD_TYPE;
777 break;
778 }
779 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
780 if (((_aidl_ret_status) != (::android::OK))) {
781 break;
782 }
783 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
784 if (((_aidl_ret_status) != (::android::OK))) {
785 break;
786 }
787 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
788 if (((_aidl_ret_status) != (::android::OK))) {
789 break;
790 }
791 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
792 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
793 if (((_aidl_ret_status) != (::android::OK))) {
794 break;
795 }
796 if (!_aidl_status.isOk()) {
797 break;
798 }
799 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
800 if (((_aidl_ret_status) != (::android::OK))) {
801 break;
802 }
803 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
804 if (((_aidl_ret_status) != (::android::OK))) {
805 break;
806 }
807 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
808 if (((_aidl_ret_status) != (::android::OK))) {
809 break;
810 }
811 }
812 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900813 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900814 {
815 int32_t in_times;
816 if (!(_aidl_data.checkInterface(this))) {
817 _aidl_ret_status = ::android::BAD_TYPE;
818 break;
819 }
820 _aidl_ret_status = _aidl_data.readInt32(&in_times);
821 if (((_aidl_ret_status) != (::android::OK))) {
822 break;
823 }
824 ::android::binder::Status _aidl_status(Piff(in_times));
825 }
826 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900827 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900828 {
829 ::android::sp<::foo::IFooType> in_f;
830 ::android::sp<::foo::IFooType> _aidl_return;
831 if (!(_aidl_data.checkInterface(this))) {
832 _aidl_ret_status = ::android::BAD_TYPE;
833 break;
834 }
835 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
836 if (((_aidl_ret_status) != (::android::OK))) {
837 break;
838 }
839 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
840 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
841 if (((_aidl_ret_status) != (::android::OK))) {
842 break;
843 }
844 if (!_aidl_status.isOk()) {
845 break;
846 }
847 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
848 if (((_aidl_ret_status) != (::android::OK))) {
849 break;
850 }
851 }
852 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900853 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900854 {
855 ::android::sp<::foo::IFooType> _aidl_return;
856 if (!(_aidl_data.checkInterface(this))) {
857 _aidl_ret_status = ::android::BAD_TYPE;
858 break;
859 }
860 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
861 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
862 if (((_aidl_ret_status) != (::android::OK))) {
863 break;
864 }
865 if (!_aidl_status.isOk()) {
866 break;
867 }
868 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
869 if (((_aidl_ret_status) != (::android::OK))) {
870 break;
871 }
872 }
873 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900874 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900875 {
876 ::std::vector<::android::String16> in_input;
877 ::std::vector<::android::String16> out_output;
878 ::std::vector<::android::String16> _aidl_return;
879 if (!(_aidl_data.checkInterface(this))) {
880 _aidl_ret_status = ::android::BAD_TYPE;
881 break;
882 }
883 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
884 if (((_aidl_ret_status) != (::android::OK))) {
885 break;
886 }
887 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
888 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
889 if (((_aidl_ret_status) != (::android::OK))) {
890 break;
891 }
892 if (!_aidl_status.isOk()) {
893 break;
894 }
895 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
896 if (((_aidl_ret_status) != (::android::OK))) {
897 break;
898 }
899 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
900 if (((_aidl_ret_status) != (::android::OK))) {
901 break;
902 }
903 }
904 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900905 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900906 {
907 ::std::vector<::android::sp<::android::IBinder>> in_input;
908 ::std::vector<::android::sp<::android::IBinder>> out_output;
909 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
910 if (!(_aidl_data.checkInterface(this))) {
911 _aidl_ret_status = ::android::BAD_TYPE;
912 break;
913 }
914 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
915 if (((_aidl_ret_status) != (::android::OK))) {
916 break;
917 }
918 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
919 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
920 if (((_aidl_ret_status) != (::android::OK))) {
921 break;
922 }
923 if (!_aidl_status.isOk()) {
924 break;
925 }
926 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
927 if (((_aidl_ret_status) != (::android::OK))) {
928 break;
929 }
930 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
931 if (((_aidl_ret_status) != (::android::OK))) {
932 break;
933 }
934 }
935 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900936 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900937 {
938 ::android::base::unique_fd in_f;
939 ::android::base::unique_fd _aidl_return;
940 if (!(_aidl_data.checkInterface(this))) {
941 _aidl_ret_status = ::android::BAD_TYPE;
942 break;
943 }
944 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
945 if (((_aidl_ret_status) != (::android::OK))) {
946 break;
947 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900948 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +0900949 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
950 if (((_aidl_ret_status) != (::android::OK))) {
951 break;
952 }
953 if (!_aidl_status.isOk()) {
954 break;
955 }
956 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
957 if (((_aidl_ret_status) != (::android::OK))) {
958 break;
959 }
960 }
961 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +0900962 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
Jiyong Parka755dc72018-06-29 13:52:24 +0900963 {
964 ::std::vector<::android::base::unique_fd> in_f;
965 ::std::vector<::android::base::unique_fd> _aidl_return;
966 if (!(_aidl_data.checkInterface(this))) {
967 _aidl_ret_status = ::android::BAD_TYPE;
968 break;
969 }
970 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
971 if (((_aidl_ret_status) != (::android::OK))) {
972 break;
973 }
974 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
975 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
976 if (((_aidl_ret_status) != (::android::OK))) {
977 break;
978 }
979 if (!_aidl_status.isOk()) {
980 break;
981 }
982 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
983 if (((_aidl_ret_status) != (::android::OK))) {
984 break;
985 }
986 }
987 break;
988 default:
989 {
990 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
991 }
992 break;
993 }
994 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
995 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
996 }
997 return _aidl_ret_status;
Casey Dahlinb0966612015-10-19 16:35:26 -0700998}
999
1000} // namespace os
1001
1002} // namespace android
1003)";
1004
Martijn Coenenf1b50782018-02-21 21:06:23 +01001005const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +09001006 R"(#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001007#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -07001008#include <binder/Stability.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001009
1010namespace android {
1011
1012namespace os {
1013
Steven Moreland800508d2019-07-30 10:45:31 -07001014BnComplexTypeInterface::BnComplexTypeInterface()
1015{
Steven Morelanda57d0a62019-07-30 09:41:14 -07001016 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -07001017}
1018
Martijn Coenenf1b50782018-02-21 21:06:23 +01001019::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 +09001020 ::android::status_t _aidl_ret_status = ::android::OK;
1021 switch (_aidl_code) {
Jeongik Chab5d962f2018-11-17 09:12:28 +09001022 case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001023 {
1024 ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
1025 ::std::vector<double> in_goes_in_and_out;
1026 ::std::vector<bool> out_goes_out;
1027 ::std::vector<int32_t> _aidl_return;
1028 if (!(_aidl_data.checkInterface(this))) {
1029 _aidl_ret_status = ::android::BAD_TYPE;
1030 break;
1031 }
1032 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
1033 if (((_aidl_ret_status) != (::android::OK))) {
1034 break;
1035 }
1036 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
1037 if (((_aidl_ret_status) != (::android::OK))) {
1038 break;
1039 }
1040 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
1041 if (((_aidl_ret_status) != (::android::OK))) {
1042 break;
1043 }
1044 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppServer");
1045 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
1046 atrace_end(ATRACE_TAG_AIDL);
1047 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1048 if (((_aidl_ret_status) != (::android::OK))) {
1049 break;
1050 }
1051 if (!_aidl_status.isOk()) {
1052 break;
1053 }
1054 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
1055 if (((_aidl_ret_status) != (::android::OK))) {
1056 break;
1057 }
1058 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
1059 if (((_aidl_ret_status) != (::android::OK))) {
1060 break;
1061 }
1062 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1063 if (((_aidl_ret_status) != (::android::OK))) {
1064 break;
1065 }
1066 }
1067 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001068 case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001069 {
1070 int32_t in_times;
1071 if (!(_aidl_data.checkInterface(this))) {
1072 _aidl_ret_status = ::android::BAD_TYPE;
1073 break;
1074 }
1075 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1076 if (((_aidl_ret_status) != (::android::OK))) {
1077 break;
1078 }
1079 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppServer");
1080 ::android::binder::Status _aidl_status(Piff(in_times));
1081 atrace_end(ATRACE_TAG_AIDL);
1082 }
1083 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001084 case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001085 {
1086 ::android::sp<::foo::IFooType> in_f;
1087 ::android::sp<::foo::IFooType> _aidl_return;
1088 if (!(_aidl_data.checkInterface(this))) {
1089 _aidl_ret_status = ::android::BAD_TYPE;
1090 break;
1091 }
1092 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1093 if (((_aidl_ret_status) != (::android::OK))) {
1094 break;
1095 }
1096 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppServer");
1097 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
1098 atrace_end(ATRACE_TAG_AIDL);
1099 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1100 if (((_aidl_ret_status) != (::android::OK))) {
1101 break;
1102 }
1103 if (!_aidl_status.isOk()) {
1104 break;
1105 }
1106 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1107 if (((_aidl_ret_status) != (::android::OK))) {
1108 break;
1109 }
1110 }
1111 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001112 case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001113 {
1114 ::android::sp<::foo::IFooType> _aidl_return;
1115 if (!(_aidl_data.checkInterface(this))) {
1116 _aidl_ret_status = ::android::BAD_TYPE;
1117 break;
1118 }
1119 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppServer");
1120 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
1121 atrace_end(ATRACE_TAG_AIDL);
1122 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1123 if (((_aidl_ret_status) != (::android::OK))) {
1124 break;
1125 }
1126 if (!_aidl_status.isOk()) {
1127 break;
1128 }
1129 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1130 if (((_aidl_ret_status) != (::android::OK))) {
1131 break;
1132 }
1133 }
1134 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001135 case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001136 {
1137 ::std::vector<::android::String16> in_input;
1138 ::std::vector<::android::String16> out_output;
1139 ::std::vector<::android::String16> _aidl_return;
1140 if (!(_aidl_data.checkInterface(this))) {
1141 _aidl_ret_status = ::android::BAD_TYPE;
1142 break;
1143 }
1144 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1145 if (((_aidl_ret_status) != (::android::OK))) {
1146 break;
1147 }
1148 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppServer");
1149 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
1150 atrace_end(ATRACE_TAG_AIDL);
1151 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1152 if (((_aidl_ret_status) != (::android::OK))) {
1153 break;
1154 }
1155 if (!_aidl_status.isOk()) {
1156 break;
1157 }
1158 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1159 if (((_aidl_ret_status) != (::android::OK))) {
1160 break;
1161 }
1162 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1163 if (((_aidl_ret_status) != (::android::OK))) {
1164 break;
1165 }
1166 }
1167 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001168 case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* 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 }
1177 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1178 if (((_aidl_ret_status) != (::android::OK))) {
1179 break;
1180 }
1181 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppServer");
1182 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
1183 atrace_end(ATRACE_TAG_AIDL);
1184 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1185 if (((_aidl_ret_status) != (::android::OK))) {
1186 break;
1187 }
1188 if (!_aidl_status.isOk()) {
1189 break;
1190 }
1191 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1192 if (((_aidl_ret_status) != (::android::OK))) {
1193 break;
1194 }
1195 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1196 if (((_aidl_ret_status) != (::android::OK))) {
1197 break;
1198 }
1199 }
1200 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001201 case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001202 {
1203 ::android::base::unique_fd in_f;
1204 ::android::base::unique_fd _aidl_return;
1205 if (!(_aidl_data.checkInterface(this))) {
1206 _aidl_ret_status = ::android::BAD_TYPE;
1207 break;
1208 }
1209 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1210 if (((_aidl_ret_status) != (::android::OK))) {
1211 break;
1212 }
1213 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppServer");
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001214 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001215 atrace_end(ATRACE_TAG_AIDL);
1216 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1217 if (((_aidl_ret_status) != (::android::OK))) {
1218 break;
1219 }
1220 if (!_aidl_status.isOk()) {
1221 break;
1222 }
1223 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1224 if (((_aidl_ret_status) != (::android::OK))) {
1225 break;
1226 }
1227 }
1228 break;
Jeongik Chab5d962f2018-11-17 09:12:28 +09001229 case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
Jiyong Parka755dc72018-06-29 13:52:24 +09001230 {
1231 ::std::vector<::android::base::unique_fd> in_f;
1232 ::std::vector<::android::base::unique_fd> _aidl_return;
1233 if (!(_aidl_data.checkInterface(this))) {
1234 _aidl_ret_status = ::android::BAD_TYPE;
1235 break;
1236 }
1237 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1238 if (((_aidl_ret_status) != (::android::OK))) {
1239 break;
1240 }
1241 atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
1242 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
1243 atrace_end(ATRACE_TAG_AIDL);
1244 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1245 if (((_aidl_ret_status) != (::android::OK))) {
1246 break;
1247 }
1248 if (!_aidl_status.isOk()) {
1249 break;
1250 }
1251 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1252 if (((_aidl_ret_status) != (::android::OK))) {
1253 break;
1254 }
1255 }
1256 break;
1257 default:
1258 {
1259 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1260 }
1261 break;
1262 }
1263 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1264 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1265 }
1266 return _aidl_ret_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +01001267}
1268
1269} // namespace os
1270
1271} // namespace android
1272)";
1273
Casey Dahlinb0966612015-10-19 16:35:26 -07001274const char kExpectedComplexTypeInterfaceHeaderOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001275 R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
Casey Dahlinb0966612015-10-19 16:35:26 -07001276#define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1277
Christopher Wiley7cb9c252016-04-11 11:07:33 -07001278#include <android-base/unique_fd.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001279#include <binder/IBinder.h>
1280#include <binder/IInterface.h>
Christopher Wiley433c8bb2015-11-12 14:20:46 -08001281#include <binder/Status.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001282#include <cstdint>
Casey Dahlin389781f2015-10-22 13:13:21 -07001283#include <foo/IFooType.h>
Christopher Wiley041c8d72016-08-18 13:52:51 -07001284#include <memory>
Christopher Wiley56c9bf32015-10-30 10:41:12 -07001285#include <utils/String16.h>
Casey Dahlin389781f2015-10-22 13:13:21 -07001286#include <utils/StrongPointer.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001287#include <vector>
1288
1289namespace android {
1290
1291namespace os {
1292
Casey Dahlinb8d9e882015-11-24 10:57:23 -08001293class IComplexTypeInterface : public ::android::IInterface {
Casey Dahlinb0966612015-10-19 16:35:26 -07001294public:
Jiyong Parka755dc72018-06-29 13:52:24 +09001295 DECLARE_META_INTERFACE(ComplexTypeInterface)
1296 enum : int32_t {
1297 MY_CONSTANT = 3,
1298 };
1299 virtual ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) = 0;
1300 virtual ::android::binder::Status Piff(int32_t times) = 0;
1301 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1302 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1303 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1304 virtual ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) = 0;
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001305 virtual ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) = 0;
Jiyong Parka755dc72018-06-29 13:52:24 +09001306 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 -07001307}; // class IComplexTypeInterface
1308
Jiyong Park75e1a742018-07-04 12:31:23 +09001309class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1310public:
Jooyung Han7bee8e32020-01-30 17:25:21 +09001311 ::android::IBinder* onAsBinder() override {
1312 return nullptr;
1313 }
Jooyung Han6991d922020-01-30 18:13:55 +09001314 ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001315 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1316 }
1317 ::android::binder::Status Piff(int32_t) override {
1318 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1319 }
Jooyung Han6991d922020-01-30 18:13:55 +09001320 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001321 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1322 }
Jooyung Han6991d922020-01-30 18:13:55 +09001323 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001324 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1325 }
Jooyung Han6991d922020-01-30 18:13:55 +09001326 ::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 +09001327 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1328 }
Jooyung Han6991d922020-01-30 18:13:55 +09001329 ::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 +09001330 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1331 }
Jooyung Han6991d922020-01-30 18:13:55 +09001332 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd, ::android::base::unique_fd*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001333 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1334 }
Jooyung Han6991d922020-01-30 18:13:55 +09001335 ::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 +09001336 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1337 }
1338}; // class IComplexTypeInterfaceDefault
Jiyong Park75e1a742018-07-04 12:31:23 +09001339
Casey Dahlinb0966612015-10-19 16:35:26 -07001340} // namespace os
1341
1342} // namespace android
1343
Christopher Wiley11a9d792016-02-24 17:20:33 -08001344#endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1345)";
Casey Dahlinb0966612015-10-19 16:35:26 -07001346
1347const char kExpectedComplexTypeInterfaceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001348 R"(#include <android/os/IComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001349#include <android/os/BpComplexTypeInterface.h>
1350
1351namespace android {
1352
1353namespace os {
1354
Ivan Lozanob3f4d622019-11-25 09:30:02 -08001355DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
Casey Dahlinb0966612015-10-19 16:35:26 -07001356
1357} // namespace os
1358
1359} // namespace android
1360)";
1361
Daniel Norman85aed542019-08-21 12:01:14 -07001362const string kEnumAIDL = R"(package android.os;
1363enum TestEnum {
Daniel Normanb28684e2019-10-17 15:31:39 -07001364 ZERO,
1365 ONE,
1366 THREE = 3,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001367 FOUR = 3 + 1,
Daniel Normanb28684e2019-10-17 15:31:39 -07001368 FIVE,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001369 SIX,
1370 SEVEN,
1371 EIGHT = 16 / 2,
1372 NINE,
1373 TEN,
Daniel Norman85aed542019-08-21 12:01:14 -07001374})";
1375
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001376// clang-format off
Daniel Norman85aed542019-08-21 12:01:14 -07001377const char kExpectedEnumHeaderOutput[] =
1378 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1379#define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1380
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001381#include <array>
1382#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001383#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001384#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001385
1386namespace android {
1387
1388namespace os {
1389
1390enum class TestEnum : int8_t {
Daniel Normanb28684e2019-10-17 15:31:39 -07001391 ZERO = 0,
1392 ONE = 1,
1393 THREE = 3,
1394 FOUR = 4,
1395 FIVE = 5,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001396 SIX = 6,
1397 SEVEN = 7,
1398 EIGHT = 8,
1399 NINE = 9,
1400 TEN = 10,
Daniel Norman85aed542019-08-21 12:01:14 -07001401};
1402
Daniel Norman0c1bd362019-11-12 23:05:31 -08001403static inline std::string toString(TestEnum val) {
1404 switch(val) {
1405 case TestEnum::ZERO:
1406 return "ZERO";
1407 case TestEnum::ONE:
1408 return "ONE";
1409 case TestEnum::THREE:
1410 return "THREE";
1411 case TestEnum::FOUR:
1412 return "FOUR";
1413 case TestEnum::FIVE:
1414 return "FIVE";
1415 case TestEnum::SIX:
1416 return "SIX";
1417 case TestEnum::SEVEN:
1418 return "SEVEN";
1419 case TestEnum::EIGHT:
1420 return "EIGHT";
1421 case TestEnum::NINE:
1422 return "NINE";
1423 case TestEnum::TEN:
1424 return "TEN";
1425 default:
1426 return std::to_string(static_cast<int8_t>(val));
1427 }
1428}
1429
Daniel Norman85aed542019-08-21 12:01:14 -07001430} // namespace os
1431
1432} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001433namespace android {
1434
1435namespace internal {
1436
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001437#pragma clang diagnostic push
1438#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001439template <>
1440constexpr inline std::array<::android::os::TestEnum, 10> enum_values<::android::os::TestEnum> = {
1441 ::android::os::TestEnum::ZERO,
1442 ::android::os::TestEnum::ONE,
1443 ::android::os::TestEnum::THREE,
1444 ::android::os::TestEnum::FOUR,
1445 ::android::os::TestEnum::FIVE,
1446 ::android::os::TestEnum::SIX,
1447 ::android::os::TestEnum::SEVEN,
1448 ::android::os::TestEnum::EIGHT,
1449 ::android::os::TestEnum::NINE,
1450 ::android::os::TestEnum::TEN,
1451};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001452#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001453
1454} // namespace internal
1455
1456} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001457
1458#endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1459)";
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001460// clang-format on
Daniel Norman85aed542019-08-21 12:01:14 -07001461
1462const string kEnumWithBackingTypeAIDL = R"(package android.os;
1463@Backing(type="long")
1464enum TestEnum {
1465 FOO = 1,
1466 BAR = 2,
1467})";
1468
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001469// clang-format off
Daniel Norman85aed542019-08-21 12:01:14 -07001470const char kExpectedEnumWithBackingTypeHeaderOutput[] =
1471 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1472#define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1473
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001474#include <array>
1475#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001476#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001477#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001478
1479namespace android {
1480
1481namespace os {
1482
1483enum class TestEnum : int64_t {
Daniel Norman716d3112019-09-10 13:11:56 -07001484 FOO = 1L,
1485 BAR = 2L,
Daniel Norman85aed542019-08-21 12:01:14 -07001486};
1487
Daniel Norman0c1bd362019-11-12 23:05:31 -08001488static inline std::string toString(TestEnum val) {
1489 switch(val) {
1490 case TestEnum::FOO:
1491 return "FOO";
1492 case TestEnum::BAR:
1493 return "BAR";
1494 default:
1495 return std::to_string(static_cast<int64_t>(val));
1496 }
1497}
1498
Daniel Norman85aed542019-08-21 12:01:14 -07001499} // namespace os
1500
1501} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001502namespace android {
1503
1504namespace internal {
1505
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001506#pragma clang diagnostic push
1507#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001508template <>
1509constexpr inline std::array<::android::os::TestEnum, 2> enum_values<::android::os::TestEnum> = {
1510 ::android::os::TestEnum::FOO,
1511 ::android::os::TestEnum::BAR,
1512};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001513#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001514
1515} // namespace internal
1516
1517} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001518
1519#endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1520)";
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001521// clang-format on
Daniel Norman85aed542019-08-21 12:01:14 -07001522
Casey Dahlina834dd42015-09-23 11:52:15 -07001523} // namespace
1524
Casey Dahlinb0966612015-10-19 16:35:26 -07001525class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -07001526 protected:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001527 ASTTest(const string& cmdline, const string& file_contents)
1528 : options_(Options::From(cmdline)), file_contents_(file_contents) {
Christopher Wiley56799522015-10-31 10:17:04 -07001529 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001530
Jiyong Parkb034bf02018-07-30 17:44:33 +09001531 AidlInterface* ParseSingleInterface() {
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001532 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
Casey Dahlina834dd42015-09-23 11:52:15 -07001533
Jiyong Parkb034bf02018-07-30 17:44:33 +09001534 vector<AidlDefinedType*> defined_types;
1535 vector<string> imported_files;
Jiyong Park8c380532018-08-30 14:55:26 +09001536 ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001537 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001538 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
Jiyong Parkb034bf02018-07-30 17:44:33 +09001539 &imported_files);
Christopher Wiley4a2884b2015-10-07 11:27:45 -07001540
Steven Moreland5557f1c2018-07-02 13:50:23 -07001541 if (err != AidlError::OK) {
Casey Dahlin2cc93162015-10-02 16:14:17 -07001542 return nullptr;
Steven Moreland5557f1c2018-07-02 13:50:23 -07001543 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001544
Jiyong Parkb034bf02018-07-30 17:44:33 +09001545 EXPECT_EQ(1ul, defined_types.size());
1546 EXPECT_NE(nullptr, defined_types.front()->AsInterface());
Steven Moreland5557f1c2018-07-02 13:50:23 -07001547
Jiyong Parkb034bf02018-07-30 17:44:33 +09001548 return defined_types.front()->AsInterface();
Christopher Wiley90be4e32015-10-20 14:55:25 -07001549 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001550
Daniel Norman85aed542019-08-21 12:01:14 -07001551 AidlEnumDeclaration* ParseSingleEnumDeclaration() {
1552 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1553
1554 vector<AidlDefinedType*> defined_types;
1555 vector<string> imported_files;
1556 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
1557 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
1558 &imported_files);
1559
1560 if (err != AidlError::OK) {
1561 return nullptr;
1562 }
1563
1564 EXPECT_EQ(1ul, defined_types.size());
1565 EXPECT_NE(nullptr, defined_types.front()->AsEnumDeclaration());
1566
1567 return defined_types.front()->AsEnumDeclaration();
1568 }
1569
Christopher Wiley0c732db2015-09-29 14:36:44 -07001570 void Compare(Document* doc, const char* expected) {
1571 string output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +09001572 doc->Write(CodeWriter::ForString(&output).get());
Christopher Wiley0c732db2015-09-29 14:36:44 -07001573
Casey Dahlin80ada3d2015-10-20 20:33:56 -07001574 if (expected == output) {
1575 return; // Success
1576 }
1577
1578 test::PrintDiff(expected, output);
1579 FAIL() << "Document contents did not match expected contents";
Christopher Wiley0c732db2015-09-29 14:36:44 -07001580 }
Casey Dahlin389781f2015-10-22 13:13:21 -07001581
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001582 const Options options_;
Casey Dahlin389781f2015-10-22 13:13:21 -07001583 const string file_contents_;
1584 FakeIoDelegate io_delegate_;
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001585 AidlTypenames typenames_;
Christopher Wiley0c732db2015-09-29 14:36:44 -07001586};
1587
Casey Dahlinb0966612015-10-19 16:35:26 -07001588class ComplexTypeInterfaceASTTest : public ASTTest {
Casey Dahlin389781f2015-10-22 13:13:21 -07001589 public:
1590 ComplexTypeInterfaceASTTest()
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001591 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
Casey Dahlin389781f2015-10-22 13:13:21 -07001592 kComplexTypeInterfaceAIDL) {
1593 io_delegate_.SetFileContents("foo/IFooType.aidl",
1594 "package foo; interface IFooType {}");
1595 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001596};
1597
1598TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001599 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001600 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001601 unique_ptr<Document> doc = internals::BuildClientHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001602 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1603}
1604
1605TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001606 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001607 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001608 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001609 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1610}
1611
1612TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001613 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001614 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001615 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001616 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1617}
1618
1619TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001620 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001621 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001622 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001623 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1624}
1625
1626TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001627 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001628 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001629 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001630 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1631}
1632
1633TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001634 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001635 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001636 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001637 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -07001638}
1639
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001640class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1641 public:
1642 ComplexTypeInterfaceASTTestWithTrace()
1643 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1644 kComplexTypeInterfaceAIDL) {
1645 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1646 }
1647};
1648
1649TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001650 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001651 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001652 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001653 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1654}
1655
1656TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001657 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001658 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001659 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001660 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1661}
1662
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001663namespace test_io_handling {
1664
1665const char kInputPath[] = "a/IFoo.aidl";
1666const char kOutputPath[] = "output.cpp";
1667const char kHeaderDir[] = "headers";
1668const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1669
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001670const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1671
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001672} // namespace test_io_handling
1673
1674class IoErrorHandlingTest : public ASTTest {
1675 public:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001676 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001677};
1678
1679TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1680 // Confirm that this is working correctly without I/O problems.
Jiyong Parkb034bf02018-07-30 17:44:33 +09001681 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001682 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001683 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001684}
1685
1686TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1687 using namespace test_io_handling;
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 interface header.
1692 const string header_path =
1693 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1694 kInterfaceHeaderRelPath);
1695 io_delegate_.AddBrokenFilePath(header_path);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001696 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001697 // We should never attempt to write the C++ file if we fail writing headers.
1698 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1699 // We should remove partial results.
1700 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1701}
1702
1703TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1704 using test_io_handling::kOutputPath;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001705 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001706 ASSERT_NE(interface, nullptr);
1707
1708 // Simulate issues closing the cpp file.
1709 io_delegate_.AddBrokenFilePath(kOutputPath);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001710 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001711 // We should remove partial results.
1712 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1713}
1714
Daniel Norman85aed542019-08-21 12:01:14 -07001715class EnumASTTest : public ASTTest {
1716 public:
1717 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1718};
1719
1720TEST_F(EnumASTTest, GeneratesEnumHeader) {
1721 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1722 ASSERT_NE(enum_decl, nullptr);
1723 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1724 Compare(doc.get(), kExpectedEnumHeaderOutput);
1725}
1726
1727class EnumWithBackingTypeASTTest : public ASTTest {
1728 public:
1729 EnumWithBackingTypeASTTest()
1730 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1731};
1732
1733TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1734 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1735 ASSERT_NE(enum_decl, nullptr);
1736 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1737 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1738}
1739
Christopher Wileyf944e792015-09-29 10:00:46 -07001740} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -07001741} // namespace aidl
1742} // namespace android