blob: a88ae9e2c0fc1690955cb2f74a303545a5d09740 [file] [log] [blame]
Casey Dahlina834dd42015-09-23 11:52:15 -07001/*
2 * Copyright (C) 2015, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <string>
18
Elliott Hughes0a620672015-12-04 13:53:18 -080019#include <android-base/stringprintf.h>
Casey Dahlina834dd42015-09-23 11:52:15 -070020#include <gtest/gtest.h>
21
Casey Dahlin2cc93162015-10-02 16:14:17 -070022#include "aidl.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070023#include "aidl_language.h"
24#include "ast_cpp.h"
25#include "code_writer.h"
Christopher Wileyad339272015-10-05 19:11:58 -070026#include "generate_cpp.h"
Christopher Wiley9d6e0b22015-11-13 12:18:16 -080027#include "os.h"
Christopher Wiley4a2884b2015-10-07 11:27:45 -070028#include "tests/fake_io_delegate.h"
Casey Dahlin80ada3d2015-10-20 20:33:56 -070029#include "tests/test_util.h"
Casey Dahlina834dd42015-09-23 11:52:15 -070030
Casey Dahlinb8d9e882015-11-24 10:57:23 -080031using ::android::aidl::test::FakeIoDelegate;
32using ::android::base::StringPrintf;
Casey Dahlina834dd42015-09-23 11:52:15 -070033using std::string;
34using std::unique_ptr;
35
36namespace android {
37namespace aidl {
Christopher Wileyf944e792015-09-29 10:00:46 -070038namespace cpp {
Casey Dahlina834dd42015-09-23 11:52:15 -070039namespace {
40
Jooyung Han43122462020-01-23 13:03:10 +090041// clang-format off
Casey Dahlinb0966612015-10-19 16:35:26 -070042const string kComplexTypeInterfaceAIDL =
43R"(package android.os;
Casey Dahlin389781f2015-10-22 13:13:21 -070044import foo.IFooType;
Casey Dahlinb0966612015-10-19 16:35:26 -070045interface IComplexTypeInterface {
Casey Dahlind40e2fe2015-11-24 14:06:52 -080046 const int MY_CONSTANT = 3;
Casey Dahlincb5317d2015-12-03 15:43:33 -080047 int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
Casey Dahlin0dd08af2015-10-20 18:45:50 -070048 oneway void Piff(int times);
Casey Dahlin389781f2015-10-22 13:13:21 -070049 IFooType TakesABinder(IFooType f);
Casey Dahlinef88bce2016-04-15 11:55:30 -070050 @nullable IFooType NullableBinder();
Christopher Wiley56c9bf32015-10-30 10:41:12 -070051 List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
Casey Dahlin7ecd69f2015-11-03 13:52:38 -080052 List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
Casey Dahlina4ba4b62015-11-02 15:43:30 -080053 FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
54 FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
Casey Dahlinb0966612015-10-19 16:35:26 -070055})";
56
57const char kExpectedComplexTypeClientHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -070058 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -070059
60#include <binder/IBinder.h>
61#include <binder/IInterface.h>
62#include <utils/Errors.h>
63#include <android/os/IComplexTypeInterface.h>
64
65namespace android {
66
67namespace os {
68
Casey Dahlinb8d9e882015-11-24 10:57:23 -080069class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -070070public:
Jiyong Parka755dc72018-06-29 13:52:24 +090071 explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
72 virtual ~BpComplexTypeInterface() = default;
Jooyung Han43122462020-01-23 13:03:10 +090073 ::android::binder::Status Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) override;
Jiyong Parka755dc72018-06-29 13:52:24 +090074 ::android::binder::Status Piff(int32_t times) override;
75 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
76 ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
77 ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
78 ::android::binder::Status BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>& input, ::std::vector<::android::sp<::android::IBinder>>* output, ::std::vector<::android::sp<::android::IBinder>>* _aidl_return) override;
Jiyong Park4f3e8c02019-11-22 14:28:47 +090079 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) override;
Jiyong Parka755dc72018-06-29 13:52:24 +090080 ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
Casey Dahlinb0966612015-10-19 16:35:26 -070081}; // class BpComplexTypeInterface
82
83} // namespace os
84
85} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -080086)";
Casey Dahlinb0966612015-10-19 16:35:26 -070087
88const char kExpectedComplexTypeClientSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +090089 R"(#include <android/os/BpComplexTypeInterface.h>
Jiyong Park717fc692020-11-25 16:31:32 +090090#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070091#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +090092#include <android-base/macros.h>
Casey Dahlinb0966612015-10-19 16:35:26 -070093
94namespace android {
95
96namespace os {
97
Casey Dahlinb8d9e882015-11-24 10:57:23 -080098BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
99 : BpInterface<IComplexTypeInterface>(_aidl_impl){
Casey Dahlinb0966612015-10-19 16:35:26 -0700100}
101
Jooyung Han43122462020-01-23 13:03:10 +0900102::android::binder::Status BpComplexTypeInterface::Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900103 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000104 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900105 ::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 }
Jiyong Park717fc692020-11-25 16:31:32 +0900124 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Send, _aidl_data, &_aidl_reply, 0);
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;
Steven Moreland7a935a82020-11-21 00:44:35 +0000157 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900158 ::android::Parcel _aidl_reply;
159 ::android::status_t _aidl_ret_status = ::android::OK;
160 ::android::binder::Status _aidl_status;
161 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
162 if (((_aidl_ret_status) != (::android::OK))) {
163 goto _aidl_error;
164 }
165 _aidl_ret_status = _aidl_data.writeInt32(times);
166 if (((_aidl_ret_status) != (::android::OK))) {
167 goto _aidl_error;
168 }
Jiyong Park717fc692020-11-25 16:31:32 +0900169 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Piff, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900170 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
171 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
172 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900173 if (((_aidl_ret_status) != (::android::OK))) {
174 goto _aidl_error;
175 }
176 _aidl_error:
177 _aidl_status.setFromStatusT(_aidl_ret_status);
178 return _aidl_status;
Casey Dahlin0dd08af2015-10-20 18:45:50 -0700179}
180
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800181::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900182 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000183 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900184 ::android::Parcel _aidl_reply;
185 ::android::status_t _aidl_ret_status = ::android::OK;
186 ::android::binder::Status _aidl_status;
187 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
188 if (((_aidl_ret_status) != (::android::OK))) {
189 goto _aidl_error;
190 }
191 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
192 if (((_aidl_ret_status) != (::android::OK))) {
193 goto _aidl_error;
194 }
Jiyong Park717fc692020-11-25 16:31:32 +0900195 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesABinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900196 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
197 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
198 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900199 if (((_aidl_ret_status) != (::android::OK))) {
200 goto _aidl_error;
201 }
202 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
203 if (((_aidl_ret_status) != (::android::OK))) {
204 goto _aidl_error;
205 }
206 if (!_aidl_status.isOk()) {
207 return _aidl_status;
208 }
209 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
210 if (((_aidl_ret_status) != (::android::OK))) {
211 goto _aidl_error;
212 }
213 _aidl_error:
214 _aidl_status.setFromStatusT(_aidl_ret_status);
215 return _aidl_status;
Casey Dahlin389781f2015-10-22 13:13:21 -0700216}
217
Casey Dahlinef88bce2016-04-15 11:55:30 -0700218::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900219 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000220 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900221 ::android::Parcel _aidl_reply;
222 ::android::status_t _aidl_ret_status = ::android::OK;
223 ::android::binder::Status _aidl_status;
224 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
225 if (((_aidl_ret_status) != (::android::OK))) {
226 goto _aidl_error;
227 }
Jiyong Park717fc692020-11-25 16:31:32 +0900228 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_NullableBinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900229 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
230 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
231 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900232 if (((_aidl_ret_status) != (::android::OK))) {
233 goto _aidl_error;
234 }
235 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
236 if (((_aidl_ret_status) != (::android::OK))) {
237 goto _aidl_error;
238 }
239 if (!_aidl_status.isOk()) {
240 return _aidl_status;
241 }
242 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
243 if (((_aidl_ret_status) != (::android::OK))) {
244 goto _aidl_error;
245 }
246 _aidl_error:
247 _aidl_status.setFromStatusT(_aidl_ret_status);
248 return _aidl_status;
Casey Dahlinef88bce2016-04-15 11:55:30 -0700249}
250
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800251::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 +0900252 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000253 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900254 ::android::Parcel _aidl_reply;
255 ::android::status_t _aidl_ret_status = ::android::OK;
256 ::android::binder::Status _aidl_status;
257 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
258 if (((_aidl_ret_status) != (::android::OK))) {
259 goto _aidl_error;
260 }
261 _aidl_ret_status = _aidl_data.writeString16Vector(input);
262 if (((_aidl_ret_status) != (::android::OK))) {
263 goto _aidl_error;
264 }
Jiyong Park717fc692020-11-25 16:31:32 +0900265 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_StringListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900266 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
267 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
268 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900269 if (((_aidl_ret_status) != (::android::OK))) {
270 goto _aidl_error;
271 }
272 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
273 if (((_aidl_ret_status) != (::android::OK))) {
274 goto _aidl_error;
275 }
276 if (!_aidl_status.isOk()) {
277 return _aidl_status;
278 }
279 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
280 if (((_aidl_ret_status) != (::android::OK))) {
281 goto _aidl_error;
282 }
283 _aidl_ret_status = _aidl_reply.readString16Vector(output);
284 if (((_aidl_ret_status) != (::android::OK))) {
285 goto _aidl_error;
286 }
287 _aidl_error:
288 _aidl_status.setFromStatusT(_aidl_ret_status);
289 return _aidl_status;
Christopher Wiley56c9bf32015-10-30 10:41:12 -0700290}
291
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800292::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 +0900293 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000294 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900295 ::android::Parcel _aidl_reply;
296 ::android::status_t _aidl_ret_status = ::android::OK;
297 ::android::binder::Status _aidl_status;
298 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
299 if (((_aidl_ret_status) != (::android::OK))) {
300 goto _aidl_error;
301 }
302 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
303 if (((_aidl_ret_status) != (::android::OK))) {
304 goto _aidl_error;
305 }
Jiyong Park717fc692020-11-25 16:31:32 +0900306 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_BinderListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900307 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
308 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
309 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900310 if (((_aidl_ret_status) != (::android::OK))) {
311 goto _aidl_error;
312 }
313 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
314 if (((_aidl_ret_status) != (::android::OK))) {
315 goto _aidl_error;
316 }
317 if (!_aidl_status.isOk()) {
318 return _aidl_status;
319 }
320 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
321 if (((_aidl_ret_status) != (::android::OK))) {
322 goto _aidl_error;
323 }
324 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
325 if (((_aidl_ret_status) != (::android::OK))) {
326 goto _aidl_error;
327 }
328 _aidl_error:
329 _aidl_status.setFromStatusT(_aidl_ret_status);
330 return _aidl_status;
Casey Dahlin7ecd69f2015-11-03 13:52:38 -0800331}
332
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900333::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900334 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000335 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900336 ::android::Parcel _aidl_reply;
337 ::android::status_t _aidl_ret_status = ::android::OK;
338 ::android::binder::Status _aidl_status;
339 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
340 if (((_aidl_ret_status) != (::android::OK))) {
341 goto _aidl_error;
342 }
343 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
344 if (((_aidl_ret_status) != (::android::OK))) {
345 goto _aidl_error;
346 }
Jiyong Park717fc692020-11-25 16:31:32 +0900347 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900348 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900349 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900350 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900351 if (((_aidl_ret_status) != (::android::OK))) {
352 goto _aidl_error;
353 }
354 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
355 if (((_aidl_ret_status) != (::android::OK))) {
356 goto _aidl_error;
357 }
358 if (!_aidl_status.isOk()) {
359 return _aidl_status;
360 }
361 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
362 if (((_aidl_ret_status) != (::android::OK))) {
363 goto _aidl_error;
364 }
365 _aidl_error:
366 _aidl_status.setFromStatusT(_aidl_ret_status);
367 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800368}
369
Christopher Wiley7cb9c252016-04-11 11:07:33 -0700370::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 +0900371 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000372 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900373 ::android::Parcel _aidl_reply;
374 ::android::status_t _aidl_ret_status = ::android::OK;
375 ::android::binder::Status _aidl_status;
376 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
377 if (((_aidl_ret_status) != (::android::OK))) {
378 goto _aidl_error;
379 }
380 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
381 if (((_aidl_ret_status) != (::android::OK))) {
382 goto _aidl_error;
383 }
Jiyong Park717fc692020-11-25 16:31:32 +0900384 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900385 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
386 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
387 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900388 if (((_aidl_ret_status) != (::android::OK))) {
389 goto _aidl_error;
390 }
391 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
392 if (((_aidl_ret_status) != (::android::OK))) {
393 goto _aidl_error;
394 }
395 if (!_aidl_status.isOk()) {
396 return _aidl_status;
397 }
398 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
399 if (((_aidl_ret_status) != (::android::OK))) {
400 goto _aidl_error;
401 }
402 _aidl_error:
403 _aidl_status.setFromStatusT(_aidl_ret_status);
404 return _aidl_status;
Casey Dahlina4ba4b62015-11-02 15:43:30 -0800405}
406
Casey Dahlinb0966612015-10-19 16:35:26 -0700407} // namespace os
408
409} // namespace android
410)";
411
Martijn Coenenf1b50782018-02-21 21:06:23 +0100412const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +0900413 R"(#include <android/os/BpComplexTypeInterface.h>
Jiyong Park717fc692020-11-25 16:31:32 +0900414#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100415#include <binder/Parcel.h>
Jiyong Park75e1a742018-07-04 12:31:23 +0900416#include <android-base/macros.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +0100417
418namespace android {
419
420namespace os {
421
422BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
423 : BpInterface<IComplexTypeInterface>(_aidl_impl){
424}
425
Jooyung Han43122462020-01-23 13:03:10 +0900426::android::binder::Status BpComplexTypeInterface::Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900427 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000428 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900429 ::android::Parcel _aidl_reply;
430 ::android::status_t _aidl_ret_status = ::android::OK;
431 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700432 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900433 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
434 if (((_aidl_ret_status) != (::android::OK))) {
435 goto _aidl_error;
436 }
437 _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
438 if (((_aidl_ret_status) != (::android::OK))) {
439 goto _aidl_error;
440 }
441 _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
442 if (((_aidl_ret_status) != (::android::OK))) {
443 goto _aidl_error;
444 }
445 _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
446 if (((_aidl_ret_status) != (::android::OK))) {
447 goto _aidl_error;
448 }
Jiyong Park717fc692020-11-25 16:31:32 +0900449 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Send, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900450 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
451 return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
452 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900453 if (((_aidl_ret_status) != (::android::OK))) {
454 goto _aidl_error;
455 }
456 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
457 if (((_aidl_ret_status) != (::android::OK))) {
458 goto _aidl_error;
459 }
460 if (!_aidl_status.isOk()) {
461 return _aidl_status;
462 }
463 _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
464 if (((_aidl_ret_status) != (::android::OK))) {
465 goto _aidl_error;
466 }
467 _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
468 if (((_aidl_ret_status) != (::android::OK))) {
469 goto _aidl_error;
470 }
471 _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
472 if (((_aidl_ret_status) != (::android::OK))) {
473 goto _aidl_error;
474 }
475 _aidl_error:
476 _aidl_status.setFromStatusT(_aidl_ret_status);
477 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100478}
479
480::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900481 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000482 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900483 ::android::Parcel _aidl_reply;
484 ::android::status_t _aidl_ret_status = ::android::OK;
485 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700486 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900487 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
488 if (((_aidl_ret_status) != (::android::OK))) {
489 goto _aidl_error;
490 }
491 _aidl_ret_status = _aidl_data.writeInt32(times);
492 if (((_aidl_ret_status) != (::android::OK))) {
493 goto _aidl_error;
494 }
Jiyong Park717fc692020-11-25 16:31:32 +0900495 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_Piff, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
Jiyong Park75e1a742018-07-04 12:31:23 +0900496 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
497 return IComplexTypeInterface::getDefaultImpl()->Piff(times);
498 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900499 if (((_aidl_ret_status) != (::android::OK))) {
500 goto _aidl_error;
501 }
502 _aidl_error:
503 _aidl_status.setFromStatusT(_aidl_ret_status);
504 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100505}
506
507::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900508 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000509 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900510 ::android::Parcel _aidl_reply;
511 ::android::status_t _aidl_ret_status = ::android::OK;
512 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700513 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900514 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
515 if (((_aidl_ret_status) != (::android::OK))) {
516 goto _aidl_error;
517 }
518 _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
519 if (((_aidl_ret_status) != (::android::OK))) {
520 goto _aidl_error;
521 }
Jiyong Park717fc692020-11-25 16:31:32 +0900522 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesABinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900523 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
524 return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
525 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900526 if (((_aidl_ret_status) != (::android::OK))) {
527 goto _aidl_error;
528 }
529 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
530 if (((_aidl_ret_status) != (::android::OK))) {
531 goto _aidl_error;
532 }
533 if (!_aidl_status.isOk()) {
534 return _aidl_status;
535 }
536 _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
537 if (((_aidl_ret_status) != (::android::OK))) {
538 goto _aidl_error;
539 }
540 _aidl_error:
541 _aidl_status.setFromStatusT(_aidl_ret_status);
542 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100543}
544
545::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900546 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000547 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900548 ::android::Parcel _aidl_reply;
549 ::android::status_t _aidl_ret_status = ::android::OK;
550 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700551 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900552 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
553 if (((_aidl_ret_status) != (::android::OK))) {
554 goto _aidl_error;
555 }
Jiyong Park717fc692020-11-25 16:31:32 +0900556 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_NullableBinder, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900557 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
558 return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
559 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900560 if (((_aidl_ret_status) != (::android::OK))) {
561 goto _aidl_error;
562 }
563 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
564 if (((_aidl_ret_status) != (::android::OK))) {
565 goto _aidl_error;
566 }
567 if (!_aidl_status.isOk()) {
568 return _aidl_status;
569 }
570 _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
571 if (((_aidl_ret_status) != (::android::OK))) {
572 goto _aidl_error;
573 }
574 _aidl_error:
575 _aidl_status.setFromStatusT(_aidl_ret_status);
576 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100577}
578
579::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 +0900580 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000581 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900582 ::android::Parcel _aidl_reply;
583 ::android::status_t _aidl_ret_status = ::android::OK;
584 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700585 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900586 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
587 if (((_aidl_ret_status) != (::android::OK))) {
588 goto _aidl_error;
589 }
590 _aidl_ret_status = _aidl_data.writeString16Vector(input);
591 if (((_aidl_ret_status) != (::android::OK))) {
592 goto _aidl_error;
593 }
Jiyong Park717fc692020-11-25 16:31:32 +0900594 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_StringListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900595 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
596 return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
597 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900598 if (((_aidl_ret_status) != (::android::OK))) {
599 goto _aidl_error;
600 }
601 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
602 if (((_aidl_ret_status) != (::android::OK))) {
603 goto _aidl_error;
604 }
605 if (!_aidl_status.isOk()) {
606 return _aidl_status;
607 }
608 _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
609 if (((_aidl_ret_status) != (::android::OK))) {
610 goto _aidl_error;
611 }
612 _aidl_ret_status = _aidl_reply.readString16Vector(output);
613 if (((_aidl_ret_status) != (::android::OK))) {
614 goto _aidl_error;
615 }
616 _aidl_error:
617 _aidl_status.setFromStatusT(_aidl_ret_status);
618 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100619}
620
621::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 +0900622 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000623 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900624 ::android::Parcel _aidl_reply;
625 ::android::status_t _aidl_ret_status = ::android::OK;
626 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700627 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900628 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
629 if (((_aidl_ret_status) != (::android::OK))) {
630 goto _aidl_error;
631 }
632 _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
633 if (((_aidl_ret_status) != (::android::OK))) {
634 goto _aidl_error;
635 }
Jiyong Park717fc692020-11-25 16:31:32 +0900636 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_BinderListMethod, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900637 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
638 return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
639 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900640 if (((_aidl_ret_status) != (::android::OK))) {
641 goto _aidl_error;
642 }
643 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
644 if (((_aidl_ret_status) != (::android::OK))) {
645 goto _aidl_error;
646 }
647 if (!_aidl_status.isOk()) {
648 return _aidl_status;
649 }
650 _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
651 if (((_aidl_ret_status) != (::android::OK))) {
652 goto _aidl_error;
653 }
654 _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
655 if (((_aidl_ret_status) != (::android::OK))) {
656 goto _aidl_error;
657 }
658 _aidl_error:
659 _aidl_status.setFromStatusT(_aidl_ret_status);
660 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100661}
662
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900663::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) {
Jiyong Parka755dc72018-06-29 13:52:24 +0900664 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000665 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900666 ::android::Parcel _aidl_reply;
667 ::android::status_t _aidl_ret_status = ::android::OK;
668 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700669 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900670 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
671 if (((_aidl_ret_status) != (::android::OK))) {
672 goto _aidl_error;
673 }
674 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
675 if (((_aidl_ret_status) != (::android::OK))) {
676 goto _aidl_error;
677 }
Jiyong Park717fc692020-11-25 16:31:32 +0900678 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900679 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900680 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(std::move(f), _aidl_return);
Jiyong Park75e1a742018-07-04 12:31:23 +0900681 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900682 if (((_aidl_ret_status) != (::android::OK))) {
683 goto _aidl_error;
684 }
685 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
686 if (((_aidl_ret_status) != (::android::OK))) {
687 goto _aidl_error;
688 }
689 if (!_aidl_status.isOk()) {
690 return _aidl_status;
691 }
692 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
693 if (((_aidl_ret_status) != (::android::OK))) {
694 goto _aidl_error;
695 }
696 _aidl_error:
697 _aidl_status.setFromStatusT(_aidl_ret_status);
698 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100699}
700
701::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 +0900702 ::android::Parcel _aidl_data;
Steven Moreland7a935a82020-11-21 00:44:35 +0000703 _aidl_data.markForBinder(remote());
Jiyong Parka755dc72018-06-29 13:52:24 +0900704 ::android::Parcel _aidl_reply;
705 ::android::status_t _aidl_ret_status = ::android::OK;
706 ::android::binder::Status _aidl_status;
Devin Mooref7600872020-05-13 15:47:50 -0700707 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
Jiyong Parka755dc72018-06-29 13:52:24 +0900708 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
709 if (((_aidl_ret_status) != (::android::OK))) {
710 goto _aidl_error;
711 }
712 _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
713 if (((_aidl_ret_status) != (::android::OK))) {
714 goto _aidl_error;
715 }
Jiyong Park717fc692020-11-25 16:31:32 +0900716 _aidl_ret_status = remote()->transact(BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray, _aidl_data, &_aidl_reply, 0);
Jiyong Park75e1a742018-07-04 12:31:23 +0900717 if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
718 return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
719 }
Jiyong Parka755dc72018-06-29 13:52:24 +0900720 if (((_aidl_ret_status) != (::android::OK))) {
721 goto _aidl_error;
722 }
723 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
724 if (((_aidl_ret_status) != (::android::OK))) {
725 goto _aidl_error;
726 }
727 if (!_aidl_status.isOk()) {
728 return _aidl_status;
729 }
730 _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
731 if (((_aidl_ret_status) != (::android::OK))) {
732 goto _aidl_error;
733 }
734 _aidl_error:
735 _aidl_status.setFromStatusT(_aidl_ret_status);
736 return _aidl_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +0100737}
738
739} // namespace os
740
741} // namespace android
742)";
743
Casey Dahlinb0966612015-10-19 16:35:26 -0700744const char kExpectedComplexTypeServerHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -0700745 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -0700746
747#include <binder/IInterface.h>
748#include <android/os/IComplexTypeInterface.h>
749
750namespace android {
751
752namespace os {
753
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800754class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
Casey Dahlinb0966612015-10-19 16:35:26 -0700755public:
Jiyong Park717fc692020-11-25 16:31:32 +0900756 static constexpr uint32_t TRANSACTION_Send = ::android::IBinder::FIRST_CALL_TRANSACTION + 0;
757 static constexpr uint32_t TRANSACTION_Piff = ::android::IBinder::FIRST_CALL_TRANSACTION + 1;
758 static constexpr uint32_t TRANSACTION_TakesABinder = ::android::IBinder::FIRST_CALL_TRANSACTION + 2;
759 static constexpr uint32_t TRANSACTION_NullableBinder = ::android::IBinder::FIRST_CALL_TRANSACTION + 3;
760 static constexpr uint32_t TRANSACTION_StringListMethod = ::android::IBinder::FIRST_CALL_TRANSACTION + 4;
761 static constexpr uint32_t TRANSACTION_BinderListMethod = ::android::IBinder::FIRST_CALL_TRANSACTION + 5;
762 static constexpr uint32_t TRANSACTION_TakesAFileDescriptor = ::android::IBinder::FIRST_CALL_TRANSACTION + 6;
763 static constexpr uint32_t TRANSACTION_TakesAFileDescriptorArray = ::android::IBinder::FIRST_CALL_TRANSACTION + 7;
Steven Moreland800508d2019-07-30 10:45:31 -0700764 explicit BnComplexTypeInterface();
Jiyong Park8533bd02018-10-29 21:31:18 +0900765 ::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 -0700766}; // class BnComplexTypeInterface
767
768} // namespace os
769
770} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -0800771)";
Casey Dahlinb0966612015-10-19 16:35:26 -0700772
773const char kExpectedComplexTypeServerSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +0900774 R"(#include <android/os/BnComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700775#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -0700776#include <binder/Stability.h>
Casey Dahlinb0966612015-10-19 16:35:26 -0700777
778namespace android {
779
780namespace os {
781
Steven Moreland800508d2019-07-30 10:45:31 -0700782BnComplexTypeInterface::BnComplexTypeInterface()
783{
Steven Morelanda57d0a62019-07-30 09:41:14 -0700784 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -0700785}
786
Casey Dahlinb8d9e882015-11-24 10:57:23 -0800787::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 +0900788 ::android::status_t _aidl_ret_status = ::android::OK;
789 switch (_aidl_code) {
Jiyong Park717fc692020-11-25 16:31:32 +0900790 case BnComplexTypeInterface::TRANSACTION_Send:
Jiyong Parka755dc72018-06-29 13:52:24 +0900791 {
Jooyung Han43122462020-01-23 13:03:10 +0900792 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +0900793 ::std::vector<double> in_goes_in_and_out;
794 ::std::vector<bool> out_goes_out;
795 ::std::vector<int32_t> _aidl_return;
796 if (!(_aidl_data.checkInterface(this))) {
797 _aidl_ret_status = ::android::BAD_TYPE;
798 break;
799 }
800 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
801 if (((_aidl_ret_status) != (::android::OK))) {
802 break;
803 }
804 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
805 if (((_aidl_ret_status) != (::android::OK))) {
806 break;
807 }
808 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
809 if (((_aidl_ret_status) != (::android::OK))) {
810 break;
811 }
812 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
813 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
814 if (((_aidl_ret_status) != (::android::OK))) {
815 break;
816 }
817 if (!_aidl_status.isOk()) {
818 break;
819 }
820 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
821 if (((_aidl_ret_status) != (::android::OK))) {
822 break;
823 }
824 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
825 if (((_aidl_ret_status) != (::android::OK))) {
826 break;
827 }
828 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
829 if (((_aidl_ret_status) != (::android::OK))) {
830 break;
831 }
832 }
833 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900834 case BnComplexTypeInterface::TRANSACTION_Piff:
Jiyong Parka755dc72018-06-29 13:52:24 +0900835 {
836 int32_t in_times;
837 if (!(_aidl_data.checkInterface(this))) {
838 _aidl_ret_status = ::android::BAD_TYPE;
839 break;
840 }
841 _aidl_ret_status = _aidl_data.readInt32(&in_times);
842 if (((_aidl_ret_status) != (::android::OK))) {
843 break;
844 }
845 ::android::binder::Status _aidl_status(Piff(in_times));
846 }
847 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900848 case BnComplexTypeInterface::TRANSACTION_TakesABinder:
Jiyong Parka755dc72018-06-29 13:52:24 +0900849 {
850 ::android::sp<::foo::IFooType> in_f;
851 ::android::sp<::foo::IFooType> _aidl_return;
852 if (!(_aidl_data.checkInterface(this))) {
853 _aidl_ret_status = ::android::BAD_TYPE;
854 break;
855 }
856 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
857 if (((_aidl_ret_status) != (::android::OK))) {
858 break;
859 }
860 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_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;
Jiyong Park717fc692020-11-25 16:31:32 +0900874 case BnComplexTypeInterface::TRANSACTION_NullableBinder:
Jiyong Parka755dc72018-06-29 13:52:24 +0900875 {
876 ::android::sp<::foo::IFooType> _aidl_return;
877 if (!(_aidl_data.checkInterface(this))) {
878 _aidl_ret_status = ::android::BAD_TYPE;
879 break;
880 }
881 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
882 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
883 if (((_aidl_ret_status) != (::android::OK))) {
884 break;
885 }
886 if (!_aidl_status.isOk()) {
887 break;
888 }
889 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
890 if (((_aidl_ret_status) != (::android::OK))) {
891 break;
892 }
893 }
894 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900895 case BnComplexTypeInterface::TRANSACTION_StringListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +0900896 {
897 ::std::vector<::android::String16> in_input;
898 ::std::vector<::android::String16> out_output;
899 ::std::vector<::android::String16> _aidl_return;
900 if (!(_aidl_data.checkInterface(this))) {
901 _aidl_ret_status = ::android::BAD_TYPE;
902 break;
903 }
904 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
905 if (((_aidl_ret_status) != (::android::OK))) {
906 break;
907 }
908 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
909 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
910 if (((_aidl_ret_status) != (::android::OK))) {
911 break;
912 }
913 if (!_aidl_status.isOk()) {
914 break;
915 }
916 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
917 if (((_aidl_ret_status) != (::android::OK))) {
918 break;
919 }
920 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
921 if (((_aidl_ret_status) != (::android::OK))) {
922 break;
923 }
924 }
925 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900926 case BnComplexTypeInterface::TRANSACTION_BinderListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +0900927 {
928 ::std::vector<::android::sp<::android::IBinder>> in_input;
929 ::std::vector<::android::sp<::android::IBinder>> out_output;
930 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
931 if (!(_aidl_data.checkInterface(this))) {
932 _aidl_ret_status = ::android::BAD_TYPE;
933 break;
934 }
935 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
936 if (((_aidl_ret_status) != (::android::OK))) {
937 break;
938 }
939 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
940 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
941 if (((_aidl_ret_status) != (::android::OK))) {
942 break;
943 }
944 if (!_aidl_status.isOk()) {
945 break;
946 }
947 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
948 if (((_aidl_ret_status) != (::android::OK))) {
949 break;
950 }
951 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
952 if (((_aidl_ret_status) != (::android::OK))) {
953 break;
954 }
955 }
956 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900957 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor:
Jiyong Parka755dc72018-06-29 13:52:24 +0900958 {
959 ::android::base::unique_fd in_f;
960 ::android::base::unique_fd _aidl_return;
961 if (!(_aidl_data.checkInterface(this))) {
962 _aidl_ret_status = ::android::BAD_TYPE;
963 break;
964 }
965 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
966 if (((_aidl_ret_status) != (::android::OK))) {
967 break;
968 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +0900969 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +0900970 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
971 if (((_aidl_ret_status) != (::android::OK))) {
972 break;
973 }
974 if (!_aidl_status.isOk()) {
975 break;
976 }
977 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
978 if (((_aidl_ret_status) != (::android::OK))) {
979 break;
980 }
981 }
982 break;
Jiyong Park717fc692020-11-25 16:31:32 +0900983 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray:
Jiyong Parka755dc72018-06-29 13:52:24 +0900984 {
985 ::std::vector<::android::base::unique_fd> in_f;
986 ::std::vector<::android::base::unique_fd> _aidl_return;
987 if (!(_aidl_data.checkInterface(this))) {
988 _aidl_ret_status = ::android::BAD_TYPE;
989 break;
990 }
991 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
992 if (((_aidl_ret_status) != (::android::OK))) {
993 break;
994 }
995 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
996 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
997 if (((_aidl_ret_status) != (::android::OK))) {
998 break;
999 }
1000 if (!_aidl_status.isOk()) {
1001 break;
1002 }
1003 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1004 if (((_aidl_ret_status) != (::android::OK))) {
1005 break;
1006 }
1007 }
1008 break;
1009 default:
1010 {
1011 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1012 }
1013 break;
1014 }
1015 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1016 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1017 }
1018 return _aidl_ret_status;
Casey Dahlinb0966612015-10-19 16:35:26 -07001019}
1020
1021} // namespace os
1022
1023} // namespace android
1024)";
1025
Martijn Coenenf1b50782018-02-21 21:06:23 +01001026const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
Jeongik Chab5d962f2018-11-17 09:12:28 +09001027 R"(#include <android/os/BnComplexTypeInterface.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001028#include <binder/Parcel.h>
Steven Morelanda57d0a62019-07-30 09:41:14 -07001029#include <binder/Stability.h>
Martijn Coenenf1b50782018-02-21 21:06:23 +01001030
1031namespace android {
1032
1033namespace os {
1034
Steven Moreland800508d2019-07-30 10:45:31 -07001035BnComplexTypeInterface::BnComplexTypeInterface()
1036{
Steven Morelanda57d0a62019-07-30 09:41:14 -07001037 ::android::internal::Stability::markCompilationUnit(this);
Steven Moreland800508d2019-07-30 10:45:31 -07001038}
1039
Martijn Coenenf1b50782018-02-21 21:06:23 +01001040::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 +09001041 ::android::status_t _aidl_ret_status = ::android::OK;
1042 switch (_aidl_code) {
Jiyong Park717fc692020-11-25 16:31:32 +09001043 case BnComplexTypeInterface::TRANSACTION_Send:
Jiyong Parka755dc72018-06-29 13:52:24 +09001044 {
Jooyung Han43122462020-01-23 13:03:10 +09001045 ::std::optional<::std::vector<int32_t>> in_goes_in;
Jiyong Parka755dc72018-06-29 13:52:24 +09001046 ::std::vector<double> in_goes_in_and_out;
1047 ::std::vector<bool> out_goes_out;
1048 ::std::vector<int32_t> _aidl_return;
1049 if (!(_aidl_data.checkInterface(this))) {
1050 _aidl_ret_status = ::android::BAD_TYPE;
1051 break;
1052 }
Devin Mooref7600872020-05-13 15:47:50 -07001053 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Send::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001054 _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
1055 if (((_aidl_ret_status) != (::android::OK))) {
1056 break;
1057 }
1058 _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
1059 if (((_aidl_ret_status) != (::android::OK))) {
1060 break;
1061 }
1062 _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
1063 if (((_aidl_ret_status) != (::android::OK))) {
1064 break;
1065 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001066 ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001067 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1068 if (((_aidl_ret_status) != (::android::OK))) {
1069 break;
1070 }
1071 if (!_aidl_status.isOk()) {
1072 break;
1073 }
1074 _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
1075 if (((_aidl_ret_status) != (::android::OK))) {
1076 break;
1077 }
1078 _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
1079 if (((_aidl_ret_status) != (::android::OK))) {
1080 break;
1081 }
1082 _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
1083 if (((_aidl_ret_status) != (::android::OK))) {
1084 break;
1085 }
1086 }
1087 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001088 case BnComplexTypeInterface::TRANSACTION_Piff:
Jiyong Parka755dc72018-06-29 13:52:24 +09001089 {
1090 int32_t in_times;
1091 if (!(_aidl_data.checkInterface(this))) {
1092 _aidl_ret_status = ::android::BAD_TYPE;
1093 break;
1094 }
Devin Mooref7600872020-05-13 15:47:50 -07001095 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::Piff::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001096 _aidl_ret_status = _aidl_data.readInt32(&in_times);
1097 if (((_aidl_ret_status) != (::android::OK))) {
1098 break;
1099 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001100 ::android::binder::Status _aidl_status(Piff(in_times));
Jiyong Parka755dc72018-06-29 13:52:24 +09001101 }
1102 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001103 case BnComplexTypeInterface::TRANSACTION_TakesABinder:
Jiyong Parka755dc72018-06-29 13:52:24 +09001104 {
1105 ::android::sp<::foo::IFooType> in_f;
1106 ::android::sp<::foo::IFooType> _aidl_return;
1107 if (!(_aidl_data.checkInterface(this))) {
1108 _aidl_ret_status = ::android::BAD_TYPE;
1109 break;
1110 }
Devin Mooref7600872020-05-13 15:47:50 -07001111 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesABinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001112 _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
1113 if (((_aidl_ret_status) != (::android::OK))) {
1114 break;
1115 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001116 ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001117 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1118 if (((_aidl_ret_status) != (::android::OK))) {
1119 break;
1120 }
1121 if (!_aidl_status.isOk()) {
1122 break;
1123 }
1124 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1125 if (((_aidl_ret_status) != (::android::OK))) {
1126 break;
1127 }
1128 }
1129 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001130 case BnComplexTypeInterface::TRANSACTION_NullableBinder:
Jiyong Parka755dc72018-06-29 13:52:24 +09001131 {
1132 ::android::sp<::foo::IFooType> _aidl_return;
1133 if (!(_aidl_data.checkInterface(this))) {
1134 _aidl_ret_status = ::android::BAD_TYPE;
1135 break;
1136 }
Devin Mooref7600872020-05-13 15:47:50 -07001137 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::NullableBinder::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001138 ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001139 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1140 if (((_aidl_ret_status) != (::android::OK))) {
1141 break;
1142 }
1143 if (!_aidl_status.isOk()) {
1144 break;
1145 }
1146 _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
1147 if (((_aidl_ret_status) != (::android::OK))) {
1148 break;
1149 }
1150 }
1151 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001152 case BnComplexTypeInterface::TRANSACTION_StringListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +09001153 {
1154 ::std::vector<::android::String16> in_input;
1155 ::std::vector<::android::String16> out_output;
1156 ::std::vector<::android::String16> _aidl_return;
1157 if (!(_aidl_data.checkInterface(this))) {
1158 _aidl_ret_status = ::android::BAD_TYPE;
1159 break;
1160 }
Devin Mooref7600872020-05-13 15:47:50 -07001161 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::StringListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001162 _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
1163 if (((_aidl_ret_status) != (::android::OK))) {
1164 break;
1165 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001166 ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001167 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1168 if (((_aidl_ret_status) != (::android::OK))) {
1169 break;
1170 }
1171 if (!_aidl_status.isOk()) {
1172 break;
1173 }
1174 _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
1175 if (((_aidl_ret_status) != (::android::OK))) {
1176 break;
1177 }
1178 _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
1179 if (((_aidl_ret_status) != (::android::OK))) {
1180 break;
1181 }
1182 }
1183 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001184 case BnComplexTypeInterface::TRANSACTION_BinderListMethod:
Jiyong Parka755dc72018-06-29 13:52:24 +09001185 {
1186 ::std::vector<::android::sp<::android::IBinder>> in_input;
1187 ::std::vector<::android::sp<::android::IBinder>> out_output;
1188 ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
1189 if (!(_aidl_data.checkInterface(this))) {
1190 _aidl_ret_status = ::android::BAD_TYPE;
1191 break;
1192 }
Devin Mooref7600872020-05-13 15:47:50 -07001193 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::BinderListMethod::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001194 _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
1195 if (((_aidl_ret_status) != (::android::OK))) {
1196 break;
1197 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001198 ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001199 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1200 if (((_aidl_ret_status) != (::android::OK))) {
1201 break;
1202 }
1203 if (!_aidl_status.isOk()) {
1204 break;
1205 }
1206 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
1207 if (((_aidl_ret_status) != (::android::OK))) {
1208 break;
1209 }
1210 _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
1211 if (((_aidl_ret_status) != (::android::OK))) {
1212 break;
1213 }
1214 }
1215 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001216 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptor:
Jiyong Parka755dc72018-06-29 13:52:24 +09001217 {
1218 ::android::base::unique_fd in_f;
1219 ::android::base::unique_fd _aidl_return;
1220 if (!(_aidl_data.checkInterface(this))) {
1221 _aidl_ret_status = ::android::BAD_TYPE;
1222 break;
1223 }
Devin Mooref7600872020-05-13 15:47:50 -07001224 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptor::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001225 _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
1226 if (((_aidl_ret_status) != (::android::OK))) {
1227 break;
1228 }
Jiyong Park4f3e8c02019-11-22 14:28:47 +09001229 ::android::binder::Status _aidl_status(TakesAFileDescriptor(std::move(in_f), &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001230 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1231 if (((_aidl_ret_status) != (::android::OK))) {
1232 break;
1233 }
1234 if (!_aidl_status.isOk()) {
1235 break;
1236 }
1237 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
1238 if (((_aidl_ret_status) != (::android::OK))) {
1239 break;
1240 }
1241 }
1242 break;
Jiyong Park717fc692020-11-25 16:31:32 +09001243 case BnComplexTypeInterface::TRANSACTION_TakesAFileDescriptorArray:
Jiyong Parka755dc72018-06-29 13:52:24 +09001244 {
1245 ::std::vector<::android::base::unique_fd> in_f;
1246 ::std::vector<::android::base::unique_fd> _aidl_return;
1247 if (!(_aidl_data.checkInterface(this))) {
1248 _aidl_ret_status = ::android::BAD_TYPE;
1249 break;
1250 }
Devin Mooref7600872020-05-13 15:47:50 -07001251 ::android::ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "AIDL::cpp::IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
Jiyong Parka755dc72018-06-29 13:52:24 +09001252 _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
1253 if (((_aidl_ret_status) != (::android::OK))) {
1254 break;
1255 }
Jiyong Parka755dc72018-06-29 13:52:24 +09001256 ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
Jiyong Parka755dc72018-06-29 13:52:24 +09001257 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
1258 if (((_aidl_ret_status) != (::android::OK))) {
1259 break;
1260 }
1261 if (!_aidl_status.isOk()) {
1262 break;
1263 }
1264 _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
1265 if (((_aidl_ret_status) != (::android::OK))) {
1266 break;
1267 }
1268 }
1269 break;
1270 default:
1271 {
1272 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
1273 }
1274 break;
1275 }
1276 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
1277 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
1278 }
1279 return _aidl_ret_status;
Martijn Coenenf1b50782018-02-21 21:06:23 +01001280}
1281
1282} // namespace os
1283
1284} // namespace android
1285)";
1286
Casey Dahlinb0966612015-10-19 16:35:26 -07001287const char kExpectedComplexTypeInterfaceHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001288 R"(#pragma once
Casey Dahlinb0966612015-10-19 16:35:26 -07001289
Christopher Wiley7cb9c252016-04-11 11:07:33 -07001290#include <android-base/unique_fd.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001291#include <binder/IBinder.h>
1292#include <binder/IInterface.h>
Christopher Wiley433c8bb2015-11-12 14:20:46 -08001293#include <binder/Status.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001294#include <cstdint>
Casey Dahlin389781f2015-10-22 13:13:21 -07001295#include <foo/IFooType.h>
Jooyung Han43122462020-01-23 13:03:10 +09001296#include <optional>
Christopher Wiley56c9bf32015-10-30 10:41:12 -07001297#include <utils/String16.h>
Casey Dahlin389781f2015-10-22 13:13:21 -07001298#include <utils/StrongPointer.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001299#include <vector>
1300
1301namespace android {
1302
1303namespace os {
1304
Casey Dahlinb8d9e882015-11-24 10:57:23 -08001305class IComplexTypeInterface : public ::android::IInterface {
Casey Dahlinb0966612015-10-19 16:35:26 -07001306public:
Jiyong Parka755dc72018-06-29 13:52:24 +09001307 DECLARE_META_INTERFACE(ComplexTypeInterface)
1308 enum : int32_t {
1309 MY_CONSTANT = 3,
1310 };
Jooyung Han43122462020-01-23 13:03:10 +09001311 virtual ::android::binder::Status Send(const ::std::optional<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) = 0;
Jiyong Parka755dc72018-06-29 13:52:24 +09001312 virtual ::android::binder::Status Piff(int32_t times) = 0;
1313 virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
1314 virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
1315 virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
1316 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 +09001317 virtual ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd f, ::android::base::unique_fd* _aidl_return) = 0;
Jiyong Parka755dc72018-06-29 13:52:24 +09001318 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 -07001319}; // class IComplexTypeInterface
1320
Jiyong Park75e1a742018-07-04 12:31:23 +09001321class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
1322public:
Jooyung Han7bee8e32020-01-30 17:25:21 +09001323 ::android::IBinder* onAsBinder() override {
1324 return nullptr;
1325 }
Jooyung Han43122462020-01-23 13:03:10 +09001326 ::android::binder::Status Send(const ::std::optional<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001327 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1328 }
1329 ::android::binder::Status Piff(int32_t) override {
1330 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1331 }
Jooyung Han6991d922020-01-30 18:13:55 +09001332 ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>*) 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 NullableBinder(::android::sp<::foo::IFooType>*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001336 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1337 }
Jooyung Han6991d922020-01-30 18:13:55 +09001338 ::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 +09001339 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1340 }
Jooyung Han6991d922020-01-30 18:13:55 +09001341 ::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 +09001342 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1343 }
Jooyung Han6991d922020-01-30 18:13:55 +09001344 ::android::binder::Status TakesAFileDescriptor(::android::base::unique_fd, ::android::base::unique_fd*) override {
Jooyung Han7bee8e32020-01-30 17:25:21 +09001345 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1346 }
Jooyung Han6991d922020-01-30 18:13:55 +09001347 ::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 +09001348 return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
1349 }
1350}; // class IComplexTypeInterfaceDefault
Jiyong Park75e1a742018-07-04 12:31:23 +09001351
Casey Dahlinb0966612015-10-19 16:35:26 -07001352} // namespace os
1353
1354} // namespace android
Christopher Wiley11a9d792016-02-24 17:20:33 -08001355)";
Casey Dahlinb0966612015-10-19 16:35:26 -07001356
1357const char kExpectedComplexTypeInterfaceSourceOutput[] =
Jiyong Park75e1a742018-07-04 12:31:23 +09001358 R"(#include <android/os/IComplexTypeInterface.h>
Casey Dahlinb0966612015-10-19 16:35:26 -07001359#include <android/os/BpComplexTypeInterface.h>
1360
1361namespace android {
1362
1363namespace os {
1364
Ivan Lozanob3f4d622019-11-25 09:30:02 -08001365DO_NOT_DIRECTLY_USE_ME_IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
Casey Dahlinb0966612015-10-19 16:35:26 -07001366
1367} // namespace os
1368
1369} // namespace android
1370)";
1371
Daniel Norman85aed542019-08-21 12:01:14 -07001372const string kEnumAIDL = R"(package android.os;
1373enum TestEnum {
Daniel Normanb28684e2019-10-17 15:31:39 -07001374 ZERO,
1375 ONE,
1376 THREE = 3,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001377 FOUR = 3 + 1,
Daniel Normanb28684e2019-10-17 15:31:39 -07001378 FIVE,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001379 SIX,
1380 SEVEN,
1381 EIGHT = 16 / 2,
1382 NINE,
1383 TEN,
Daniel Norman85aed542019-08-21 12:01:14 -07001384})";
1385
1386const char kExpectedEnumHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001387 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001388
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001389#include <array>
1390#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001391#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001392#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001393
1394namespace android {
1395
1396namespace os {
1397
1398enum class TestEnum : int8_t {
Daniel Normanb28684e2019-10-17 15:31:39 -07001399 ZERO = 0,
1400 ONE = 1,
1401 THREE = 3,
1402 FOUR = 4,
1403 FIVE = 5,
Daniel Normanf0ca44f2019-10-25 09:59:44 -07001404 SIX = 6,
1405 SEVEN = 7,
1406 EIGHT = 8,
1407 NINE = 9,
1408 TEN = 10,
Daniel Norman85aed542019-08-21 12:01:14 -07001409};
1410
Daniel Norman0c1bd362019-11-12 23:05:31 -08001411static inline std::string toString(TestEnum val) {
1412 switch(val) {
1413 case TestEnum::ZERO:
1414 return "ZERO";
1415 case TestEnum::ONE:
1416 return "ONE";
1417 case TestEnum::THREE:
1418 return "THREE";
1419 case TestEnum::FOUR:
1420 return "FOUR";
1421 case TestEnum::FIVE:
1422 return "FIVE";
1423 case TestEnum::SIX:
1424 return "SIX";
1425 case TestEnum::SEVEN:
1426 return "SEVEN";
1427 case TestEnum::EIGHT:
1428 return "EIGHT";
1429 case TestEnum::NINE:
1430 return "NINE";
1431 case TestEnum::TEN:
1432 return "TEN";
1433 default:
1434 return std::to_string(static_cast<int8_t>(val));
1435 }
1436}
1437
Daniel Norman85aed542019-08-21 12:01:14 -07001438} // namespace os
1439
1440} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001441namespace android {
1442
1443namespace internal {
1444
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001445#pragma clang diagnostic push
1446#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001447template <>
1448constexpr inline std::array<::android::os::TestEnum, 10> enum_values<::android::os::TestEnum> = {
1449 ::android::os::TestEnum::ZERO,
1450 ::android::os::TestEnum::ONE,
1451 ::android::os::TestEnum::THREE,
1452 ::android::os::TestEnum::FOUR,
1453 ::android::os::TestEnum::FIVE,
1454 ::android::os::TestEnum::SIX,
1455 ::android::os::TestEnum::SEVEN,
1456 ::android::os::TestEnum::EIGHT,
1457 ::android::os::TestEnum::NINE,
1458 ::android::os::TestEnum::TEN,
1459};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001460#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001461
1462} // namespace internal
1463
1464} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001465)";
1466
1467const string kEnumWithBackingTypeAIDL = R"(package android.os;
1468@Backing(type="long")
1469enum TestEnum {
1470 FOO = 1,
1471 BAR = 2,
1472})";
1473
1474const char kExpectedEnumWithBackingTypeHeaderOutput[] =
Devin Moore7aaa9cb2020-08-13 14:53:01 -07001475 R"(#pragma once
Daniel Norman85aed542019-08-21 12:01:14 -07001476
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001477#include <array>
1478#include <binder/Enums.h>
Daniel Norman85aed542019-08-21 12:01:14 -07001479#include <cstdint>
Daniel Norman0c1bd362019-11-12 23:05:31 -08001480#include <string>
Daniel Norman85aed542019-08-21 12:01:14 -07001481
1482namespace android {
1483
1484namespace os {
1485
1486enum class TestEnum : int64_t {
Daniel Norman716d3112019-09-10 13:11:56 -07001487 FOO = 1L,
1488 BAR = 2L,
Daniel Norman85aed542019-08-21 12:01:14 -07001489};
1490
Daniel Norman0c1bd362019-11-12 23:05:31 -08001491static inline std::string toString(TestEnum val) {
1492 switch(val) {
1493 case TestEnum::FOO:
1494 return "FOO";
1495 case TestEnum::BAR:
1496 return "BAR";
1497 default:
1498 return std::to_string(static_cast<int64_t>(val));
1499 }
1500}
1501
Daniel Norman85aed542019-08-21 12:01:14 -07001502} // namespace os
1503
1504} // namespace android
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001505namespace android {
1506
1507namespace internal {
1508
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001509#pragma clang diagnostic push
1510#pragma clang diagnostic ignored "-Wc++17-extensions"
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001511template <>
1512constexpr inline std::array<::android::os::TestEnum, 2> enum_values<::android::os::TestEnum> = {
1513 ::android::os::TestEnum::FOO,
1514 ::android::os::TestEnum::BAR,
1515};
Jooyung Han0e2a03c2019-12-17 23:25:39 +09001516#pragma clang diagnostic pop
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001517
1518} // namespace internal
1519
1520} // namespace android
Daniel Norman85aed542019-08-21 12:01:14 -07001521)";
Jooyung Han7a9aceb2019-12-17 14:18:15 +00001522// clang-format on
Daniel Norman85aed542019-08-21 12:01:14 -07001523
Casey Dahlina834dd42015-09-23 11:52:15 -07001524} // namespace
1525
Casey Dahlinb0966612015-10-19 16:35:26 -07001526class ASTTest : public ::testing::Test {
Christopher Wiley0c732db2015-09-29 14:36:44 -07001527 protected:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001528 ASTTest(const string& cmdline, const string& file_contents)
1529 : options_(Options::From(cmdline)), file_contents_(file_contents) {
Christopher Wiley56799522015-10-31 10:17:04 -07001530 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001531
Jiyong Parkb034bf02018-07-30 17:44:33 +09001532 AidlInterface* ParseSingleInterface() {
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001533 io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
Casey Dahlina834dd42015-09-23 11:52:15 -07001534
Jiyong Parkb034bf02018-07-30 17:44:33 +09001535 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(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001538 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Christopher Wiley4a2884b2015-10-07 11:27:45 -07001539
Steven Moreland5557f1c2018-07-02 13:50:23 -07001540 if (err != AidlError::OK) {
Casey Dahlin2cc93162015-10-02 16:14:17 -07001541 return nullptr;
Steven Moreland5557f1c2018-07-02 13:50:23 -07001542 }
Casey Dahlina834dd42015-09-23 11:52:15 -07001543
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001544 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Jiyong Parkb034bf02018-07-30 17:44:33 +09001545 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001546 EXPECT_NE(nullptr, defined_types.front().get()->AsInterface());
Steven Moreland5557f1c2018-07-02 13:50:23 -07001547
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001548 return defined_types.front().get()->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
Daniel Norman85aed542019-08-21 12:01:14 -07001554 vector<string> imported_files;
1555 AidlError err = ::android::aidl::internals::load_and_validate_aidl(
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001556 options_.InputFiles().front(), options_, io_delegate_, &typenames_, &imported_files);
Daniel Norman85aed542019-08-21 12:01:14 -07001557
1558 if (err != AidlError::OK) {
1559 return nullptr;
1560 }
1561
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001562 const auto& defined_types = typenames_.MainDocument().DefinedTypes();
Daniel Norman85aed542019-08-21 12:01:14 -07001563 EXPECT_EQ(1ul, defined_types.size());
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001564 EXPECT_NE(nullptr, defined_types.front().get()->AsEnumDeclaration());
Daniel Norman85aed542019-08-21 12:01:14 -07001565
Jiyong Park8e79b7f2020-07-20 20:52:38 +09001566 return defined_types.front().get()->AsEnumDeclaration();
Daniel Norman85aed542019-08-21 12:01:14 -07001567 }
1568
Christopher Wiley0c732db2015-09-29 14:36:44 -07001569 void Compare(Document* doc, const char* expected) {
1570 string output;
Jiyong Parkb78e15b2018-07-04 20:31:03 +09001571 doc->Write(CodeWriter::ForString(&output).get());
Christopher Wiley0c732db2015-09-29 14:36:44 -07001572
Casey Dahlin80ada3d2015-10-20 20:33:56 -07001573 if (expected == output) {
1574 return; // Success
1575 }
1576
1577 test::PrintDiff(expected, output);
1578 FAIL() << "Document contents did not match expected contents";
Christopher Wiley0c732db2015-09-29 14:36:44 -07001579 }
Casey Dahlin389781f2015-10-22 13:13:21 -07001580
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001581 const Options options_;
Casey Dahlin389781f2015-10-22 13:13:21 -07001582 const string file_contents_;
1583 FakeIoDelegate io_delegate_;
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001584 AidlTypenames typenames_;
Christopher Wiley0c732db2015-09-29 14:36:44 -07001585};
1586
Casey Dahlinb0966612015-10-19 16:35:26 -07001587class ComplexTypeInterfaceASTTest : public ASTTest {
Casey Dahlin389781f2015-10-22 13:13:21 -07001588 public:
1589 ComplexTypeInterfaceASTTest()
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001590 : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
Casey Dahlin389781f2015-10-22 13:13:21 -07001591 kComplexTypeInterfaceAIDL) {
1592 io_delegate_.SetFileContents("foo/IFooType.aidl",
1593 "package foo; interface IFooType {}");
1594 }
Casey Dahlinb0966612015-10-19 16:35:26 -07001595};
1596
1597TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
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::BuildClientHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001601 Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
1602}
1603
1604TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
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::BuildClientSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001608 Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
1609}
1610
1611TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001612 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001613 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001614 unique_ptr<Document> doc = internals::BuildServerHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001615 Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
1616}
1617
1618TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001619 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001620 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001621 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001622 Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
1623}
1624
1625TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001626 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001627 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001628 unique_ptr<Document> doc = internals::BuildInterfaceHeader(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001629 Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
1630}
1631
1632TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001633 AidlInterface* interface = ParseSingleInterface();
Casey Dahlinb0966612015-10-19 16:35:26 -07001634 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001635 unique_ptr<Document> doc = internals::BuildInterfaceSource(typenames_, *interface, options_);
Casey Dahlinb0966612015-10-19 16:35:26 -07001636 Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
Christopher Wiley1dd458d2015-09-30 11:05:52 -07001637}
1638
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001639class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
1640 public:
1641 ComplexTypeInterfaceASTTestWithTrace()
1642 : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
1643 kComplexTypeInterfaceAIDL) {
1644 io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
1645 }
1646};
1647
1648TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001649 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001650 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001651 unique_ptr<Document> doc = internals::BuildClientSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001652 Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
1653}
1654
1655TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
Jiyong Parkb034bf02018-07-30 17:44:33 +09001656 AidlInterface* interface = ParseSingleInterface();
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001657 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001658 unique_ptr<Document> doc = internals::BuildServerSource(typenames_, *interface, options_);
Jiyong Parkfbbfa932018-07-30 21:44:10 +09001659 Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
1660}
1661
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001662namespace test_io_handling {
1663
1664const char kInputPath[] = "a/IFoo.aidl";
1665const char kOutputPath[] = "output.cpp";
1666const char kHeaderDir[] = "headers";
1667const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
1668
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001669const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
1670
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001671} // namespace test_io_handling
1672
1673class IoErrorHandlingTest : public ASTTest {
1674 public:
Jiyong Park6f77e0c2018-07-28 16:55:44 +09001675 IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001676};
1677
1678TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
1679 // Confirm that this is working correctly without I/O problems.
Jiyong Parkb034bf02018-07-30 17:44:33 +09001680 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001681 ASSERT_NE(interface, nullptr);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001682 ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001683}
1684
1685TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
1686 using namespace test_io_handling;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001687 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001688 ASSERT_NE(interface, nullptr);
1689
1690 // Simulate issues closing the interface header.
1691 const string header_path =
1692 StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
1693 kInterfaceHeaderRelPath);
1694 io_delegate_.AddBrokenFilePath(header_path);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001695 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001696 // We should never attempt to write the C++ file if we fail writing headers.
1697 ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
1698 // We should remove partial results.
1699 ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
1700}
1701
1702TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
1703 using test_io_handling::kOutputPath;
Jiyong Parkb034bf02018-07-30 17:44:33 +09001704 AidlInterface* interface = ParseSingleInterface();
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001705 ASSERT_NE(interface, nullptr);
1706
1707 // Simulate issues closing the cpp file.
1708 io_delegate_.AddBrokenFilePath(kOutputPath);
Jeongik Cha047c5ee2019-08-07 23:16:49 +09001709 ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, typenames_, *interface, io_delegate_));
Christopher Wiley9d6e0b22015-11-13 12:18:16 -08001710 // We should remove partial results.
1711 ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
1712}
1713
Daniel Norman85aed542019-08-21 12:01:14 -07001714class EnumASTTest : public ASTTest {
1715 public:
1716 EnumASTTest() : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumAIDL) {}
1717};
1718
1719TEST_F(EnumASTTest, GeneratesEnumHeader) {
1720 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1721 ASSERT_NE(enum_decl, nullptr);
1722 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1723 Compare(doc.get(), kExpectedEnumHeaderOutput);
1724}
1725
1726class EnumWithBackingTypeASTTest : public ASTTest {
1727 public:
1728 EnumWithBackingTypeASTTest()
1729 : ASTTest("aidl --lang=cpp -I . -o out android/os/TestEnum.aidl", kEnumWithBackingTypeAIDL) {}
1730};
1731
1732TEST_F(EnumWithBackingTypeASTTest, GeneratesEnumHeader) {
1733 AidlEnumDeclaration* enum_decl = ParseSingleEnumDeclaration();
1734 ASSERT_NE(enum_decl, nullptr);
1735 unique_ptr<Document> doc = internals::BuildEnumHeader(typenames_, *enum_decl);
1736 Compare(doc.get(), kExpectedEnumWithBackingTypeHeaderOutput);
1737}
1738
Christopher Wileyf944e792015-09-29 10:00:46 -07001739} // namespace cpp
Casey Dahlina834dd42015-09-23 11:52:15 -07001740} // namespace aidl
1741} // namespace android