blob: f0a549dde8cace3fd33657b573bdd9fc5771bf6f [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;
79 ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) override;
80 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
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
Christopher Wiley7cb9c252016-04-11 11:07:33 -0700328::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::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())) {
343 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(f, _aidl_return);
344 }
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;
423 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppClient");
424 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
425 if (((_aidl_ret_status) != (::android::OK))) {
426 goto _aidl_error;
427 }
428 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
429 if (((_aidl_ret_status) != (::android::OK))) {
430 goto _aidl_error;
431 }
432 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
433 if (((_aidl_ret_status) != (::android::OK))) {
434 goto _aidl_error;
435 }
436 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
437 if (((_aidl_ret_status) != (::android::OK))) {
438 goto _aidl_error;
439 }
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;
476 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppClient");
477 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
478 if (((_aidl_ret_status) != (::android::OK))) {
479 goto _aidl_error;
480 }
481 _aidl_ret_status = _aidl_data.writeInt32(times);
482 if (((_aidl_ret_status) != (::android::OK))) {
483 goto _aidl_error;
484 }
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;
502 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppClient");
503 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
504 if (((_aidl_ret_status) != (::android::OK))) {
505 goto _aidl_error;
506 }
507 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
508 if (((_aidl_ret_status) != (::android::OK))) {
509 goto _aidl_error;
510 }
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;
539 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppClient");
540 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
541 if (((_aidl_ret_status) != (::android::OK))) {
542 goto _aidl_error;
543 }
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;
572 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppClient");
573 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
574 if (((_aidl_ret_status) != (::android::OK))) {
575 goto _aidl_error;
576 }
577 _aidl_ret_status = _aidl_data.writeString16Vector(input);
578 if (((_aidl_ret_status) != (::android::OK))) {
579 goto _aidl_error;
580 }
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;
613 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppClient");
614 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
615 if (((_aidl_ret_status) != (::android::OK))) {
616 goto _aidl_error;
617 }
618 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
619 if (((_aidl_ret_status) != (::android::OK))) {
620 goto _aidl_error;
621 }
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
649::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::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;
654 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppClient");
655 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
656 if (((_aidl_ret_status) != (::android::OK))) {
657 goto _aidl_error;
658 }
659 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
660 if (((_aidl_ret_status) != (::android::OK))) {
661 goto _aidl_error;
662 }
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())) {
665 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(f, _aidl_return);
666 }
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;
691 ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
692 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
693 if (((_aidl_ret_status) != (::android::OK))) {
694 goto _aidl_error;
695 }
696 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
697 if (((_aidl_ret_status) != (::android::OK))) {
698 goto _aidl_error;
699 }
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 }
948 ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
949 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
950 if (((_aidl_ret_status) != (::android::OK))) {
951 break;
952 }
953 if (!_aidl_status.isOk()) {
954 break;
955 }
956 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
957 if (((_aidl_ret_status) != (::android::OK))) {
958 break;
959 }
960 }
961 break;
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");
1214 ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
1215 atrace_end(ATRACE_TAG_AIDL);
1216 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1217 if (((_aidl_ret_status) != (::android::OK))) {
1218 break;
1219 }
1220 if (!_aidl_status.isOk()) {
1221 break;
1222 }
1223 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1224 if (((_aidl_ret_status) != (::android::OK))) {
1225 break;
1226 }
1227 }
1228 break;
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;
1305 virtual ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) = 0;
1306 virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
Casey Dahlinb0966612015-10-19 16:35:26 -07001307}; // class IComplexTypeInterface
1308
Jiyong Park75e1a742018-07-04 12:31:23 +09001309class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1310public:
1311 ::android::IBinder* onAsBinder() override;
1312 ::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;
1313 ::android::binder::Status Piff(int32_t times) override;
1314 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
1315 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
1316 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
1317 ::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;
1318 ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) override;
1319 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
1320
1321};
1322
Casey Dahlinb0966612015-10-19 16:35:26 -07001323} // namespace os
1324
1325} // namespace android
1326
Christopher Wiley11a9d792016-02-24 17:20:33 -08001327#endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
1328)";
Casey Dahlinb0966612015-10-19 16:35:26 -07001329
1330const char kExpectedComplexTypeInterfaceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001331 R"(#include <android/os/IComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001332#include <android/os/BpComplexTypeInterface.h>
1333
1334namespace android {
1335
1336namespace os {
1337
Christopher Wiley11a9d792016-02-24 17:20:33 -08001338IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
Casey Dahlinb0966612015-10-19 16:35:26 -07001339
Jiyong Park75e1a742018-07-04 12:31:23 +09001340::android::IBinder* IComplexTypeInterfaceDefault::onAsBinder() {
1341 return nullptr;
1342}
1343
1344::android::binder::Status IComplexTypeInterfaceDefault::Send(const ::std::unique_ptr<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>* ) {
1345 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1346}
1347
1348::android::binder::Status IComplexTypeInterfaceDefault::Piff(int32_t) {
1349 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1350}
1351
1352::android::binder::Status IComplexTypeInterfaceDefault::TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>* ) {
1353 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1354}
1355
1356::android::binder::Status IComplexTypeInterfaceDefault::NullableBinder(::android::sp<::foo::IFooType>* ) {
1357 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1358}
1359
1360::android::binder::Status IComplexTypeInterfaceDefault::StringListMethod(const ::std::vector<::android::String16>&, ::std::vector<::android::String16>*, ::std::vector<::android::String16>* ) {
1361 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1362}
1363
1364::android::binder::Status IComplexTypeInterfaceDefault::BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>&, ::std::vector<::android::sp<::android::IBinder>>*, ::std::vector<::android::sp<::android::IBinder>>* ) {
1365 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1366}
1367
1368::android::binder::Status IComplexTypeInterfaceDefault::TakesAFileDescriptor(const ::android::base::unique_fd&, ::android::base::unique_fd* ) {
1369 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1370}
1371
1372::android::binder::Status IComplexTypeInterfaceDefault::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>&, ::std::vector<::android::base::unique_fd>* ) {
1373 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1374}
1375
Casey Dahlinb0966612015-10-19 16:35:26 -07001376} // namespace os
1377
1378} // namespace android
1379)";
1380
Daniel Norman85aed542019-08-21 12:01:14 -07001381const string kEnumAIDL = R"(package android.os;
1382enum TestEnum {
Daniel Normanb28684e2019-10-17 15:31:39 -07001383 ZERO,
1384 ONE,
1385 THREE = 3,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001386 FOUR = 3 + 1,
Daniel Normanb28684e2019-10-17 15:31:39 -07001387 FIVE,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001388 SIX,
1389 SEVEN,
1390 EIGHT = 16 / 2,
1391 NINE,
1392 TEN,
Daniel Norman85aed542019-08-21 12:01:14 -07001393})";
1394
1395const char kExpectedEnumHeaderOutput[] =
1396 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1397#define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1398
1399#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001400#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001401
1402namespace android {
1403
1404namespace os {
1405
1406enum class TestEnum : int8_t {
Daniel Normanb28684e2019-10-17 15:31:39 -07001407 ZERO = 0,
1408 ONE = 1,
1409 THREE = 3,
1410 FOUR = 4,
1411 FIVE = 5,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001412 SIX = 6,
1413 SEVEN = 7,
1414 EIGHT = 8,
1415 NINE = 9,
1416 TEN = 10,
Daniel Norman85aed542019-08-21 12:01:14 -07001417};
1418
Daniel Norman0c1bd362019-11-12 23:05:31 -08001419static inline std::string toString(TestEnum val) {
1420 switch(val) {
1421 case TestEnum::ZERO:
1422 return "ZERO";
1423 case TestEnum::ONE:
1424 return "ONE";
1425 case TestEnum::THREE:
1426 return "THREE";
1427 case TestEnum::FOUR:
1428 return "FOUR";
1429 case TestEnum::FIVE:
1430 return "FIVE";
1431 case TestEnum::SIX:
1432 return "SIX";
1433 case TestEnum::SEVEN:
1434 return "SEVEN";
1435 case TestEnum::EIGHT:
1436 return "EIGHT";
1437 case TestEnum::NINE:
1438 return "NINE";
1439 case TestEnum::TEN:
1440 return "TEN";
1441 default:
1442 return std::to_string(static_cast<int8_t>(val));
1443 }
1444}
1445
Daniel Norman85aed542019-08-21 12:01:14 -07001446} // namespace os
1447
1448} // namespace android
1449
1450#endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1451)";
1452
1453const string kEnumWithBackingTypeAIDL = R"(package android.os;
1454@Backing(type="long")
1455enum TestEnum {
1456 FOO = 1,
1457 BAR = 2,
1458})";
1459
1460const char kExpectedEnumWithBackingTypeHeaderOutput[] =
1461 R"(#ifndef AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1462#define AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1463
1464#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001465#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001466
1467namespace android {
1468
1469namespace os {
1470
1471enum class TestEnum : int64_t {
Daniel Norman716d3112019-09-10 13:11:56 -07001472 FOO = 1L,
1473 BAR = 2L,
Daniel Norman85aed542019-08-21 12:01:14 -07001474};
1475
Daniel Norman0c1bd362019-11-12 23:05:31 -08001476static inline std::string toString(TestEnum val) {
1477 switch(val) {
1478 case TestEnum::FOO:
1479 return "FOO";
1480 case TestEnum::BAR:
1481 return "BAR";
1482 default:
1483 return std::to_string(static_cast<int64_t>(val));
1484 }
1485}
1486
Daniel Norman85aed542019-08-21 12:01:14 -07001487} // namespace os
1488
1489} // namespace android
1490
1491#endif // AIDL_GENERATED_ANDROID_OS_TEST_ENUM_H_
1492)";
1493
Casey Dahlina834dd42015-09-23 11:52:15 -07001494} // namespace
1495
Casey Dahlinb0966612015-10-19 16:35:26 -07001496class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -07001497 protected:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001498 ASTTest(const string& cmdline, const string& file_contents)
1499 : options_(Options::From(cmdline)), file_contents_(file_contents) {
Christopher Wiley56799522015-10-31 10:17:04 -07001500 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001501
Jiyong Parkb034bf02018-07-30 17:44:33 +09001502 AidlInterface* ParseSingleInterface() {
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001503 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
Casey Dahlina834dd42015-09-23 11:52:15 -07001504
Jiyong Parkb034bf02018-07-30 17:44:33 +09001505 vector<AidlDefinedType*> defined_types;
1506 vector<string> imported_files;
Jiyong Park8c380532018-08-30 14:55:26 +09001507 ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001508 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001509 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
Jiyong Parkb034bf02018-07-30 17:44:33 +09001510 &imported_files);
Christopher Wiley4a2884b2015-10-07 11:27:45 -07001511
Steven Moreland5557f1c2018-07-02 13:50:23 -07001512 if (err != AidlError::OK) {
Casey Dahlin2cc93162015-10-02 16:14:17 -07001513 return nullptr;
Steven Moreland5557f1c2018-07-02 13:50:23 -07001514 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001515
Jiyong Parkb034bf02018-07-30 17:44:33 +09001516 EXPECT_EQ(1ul, defined_types.size());
1517 EXPECT_NE(nullptr, defined_types.front()->AsInterface());
Steven Moreland5557f1c2018-07-02 13:50:23 -07001518
Jiyong Parkb034bf02018-07-30 17:44:33 +09001519 return defined_types.front()->AsInterface();
Christopher Wiley90be4e32015-10-20 14:55:25 -07001520 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001521
Daniel Norman85aed542019-08-21 12:01:14 -07001522 AidlEnumDeclaration* ParseSingleEnumDeclaration() {
1523 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
1524
1525 vector<AidlDefinedType*> defined_types;
1526 vector<string> imported_files;
1527 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
1528 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &defined_types,
1529 &imported_files);
1530
1531 if (err != AidlError::OK) {
1532 return nullptr;
1533 }
1534
1535 EXPECT_EQ(1ul, defined_types.size());
1536 EXPECT_NE(nullptr, defined_types.front()->AsEnumDeclaration());
1537
1538 return defined_types.front()->AsEnumDeclaration();
1539 }
1540
Christopher Wiley0c732db2015-09-29 14:36:44 -07001541 void Compare(Document* doc, const char* expected) {
1542 string output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +09001543 doc->Write(CodeWriter::ForString(&output).get());
Christopher Wiley0c732db2015-09-29 14:36:44 -07001544
Casey Dahlin80ada3d2015-10-20 20:33:56 -07001545 if (expected == output) {
1546 return; // Success
1547 }
1548
1549 test::PrintDiff(expected, output);
1550 FAIL() << "Document contents did not match expected contents";
Christopher Wiley0c732db2015-09-29 14:36:44 -07001551 }
Casey Dahlin389781f2015-10-22 13:13:21 -07001552
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001553 const Options options_;
Casey Dahlin389781f2015-10-22 13:13:21 -07001554 const string file_contents_;
1555 FakeIoDelegate io_delegate_;
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001556 AidlTypenames typenames_;
Christopher Wiley0c732db2015-09-29 14:36:44 -07001557};
1558
Casey Dahlinb0966612015-10-19 16:35:26 -07001559class ComplexTypeInterfaceASTTest : public ASTTest {
Casey Dahlin389781f2015-10-22 13:13:21 -07001560 public:
1561 ComplexTypeInterfaceASTTest()
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001562 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
Casey Dahlin389781f2015-10-22 13:13:21 -07001563 kComplexTypeInterfaceAIDL) {
1564 io_delegate_.SetFileContents("foo/IFooType.aidl",
1565 "package foo; interface IFooType {}");
1566 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001567};
1568
1569TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001570 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001571 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001572 unique_ptr<Document> doc = internals::BuildClientHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001573 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1574}
1575
1576TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001577 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001578 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001579 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001580 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1581}
1582
1583TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001584 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001585 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001586 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001587 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1588}
1589
1590TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001591 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001592 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001593 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001594 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1595}
1596
1597TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001598 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001599 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001600 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001601 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1602}
1603
1604TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001605 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001606 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001607 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001608 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -07001609}
1610
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001611class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1612 public:
1613 ComplexTypeInterfaceASTTestWithTrace()
1614 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1615 kComplexTypeInterfaceAIDL) {
1616 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1617 }
1618};
1619
1620TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001621 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001622 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001623 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001624 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1625}
1626
1627TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001628 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001629 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001630 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001631 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1632}
1633
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001634namespace test_io_handling {
1635
1636const char kInputPath[] = "a/IFoo.aidl";
1637const char kOutputPath[] = "output.cpp";
1638const char kHeaderDir[] = "headers";
1639const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1640
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001641const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1642
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001643} // namespace test_io_handling
1644
1645class IoErrorHandlingTest : public ASTTest {
1646 public:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001647 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001648};
1649
1650TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1651 // Confirm that this is working correctly without I/O problems.
Jiyong Parkb034bf02018-07-30 17:44:33 +09001652 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001653 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001654 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001655}
1656
1657TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1658 using namespace test_io_handling;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001659 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001660 ASSERT_NE(interface, nullptr);
1661
1662 // Simulate issues closing the interface header.
1663 const string header_path =
1664 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1665 kInterfaceHeaderRelPath);
1666 io_delegate_.AddBrokenFilePath(header_path);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001667 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001668 // We should never attempt to write the C++ file if we fail writing headers.
1669 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1670 // We should remove partial results.
1671 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1672}
1673
1674TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1675 using test_io_handling::kOutputPath;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001676 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001677 ASSERT_NE(interface, nullptr);
1678
1679 // Simulate issues closing the cpp file.
1680 io_delegate_.AddBrokenFilePath(kOutputPath);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001681 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001682 // We should remove partial results.
1683 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1684}
1685
Daniel Norman85aed542019-08-21 12:01:14 -07001686class EnumASTTest : public ASTTest {
1687 public:
1688 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1689};
1690
1691TEST_F(EnumASTTest, GeneratesEnumHeader) {
1692 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1693 ASSERT_NE(enum_decl, nullptr);
1694 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1695 Compare(doc.get(), kExpectedEnumHeaderOutput);
1696}
1697
1698class EnumWithBackingTypeASTTest : public ASTTest {
1699 public:
1700 EnumWithBackingTypeASTTest()
1701 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1702};
1703
1704TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1705 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1706 ASSERT_NE(enum_decl, nullptr);
1707 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1708 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1709}
1710
Christopher Wileyf944e792015-09-29 10:00:46 -07001711} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -07001712} // namespace aidl
1713} // namespace android