generate_cpp_unittest.cpp 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  1. /*
  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. #include <string>
  17. #include <android-base/stringprintf.h>
  18. #include <gtest/gtest.h>
  19. #include "aidl.h"
  20. #include "aidl_language.h"
  21. #include "ast_cpp.h"
  22. #include "code_writer.h"
  23. #include "generate_cpp.h"
  24. #include "os.h"
  25. #include "tests/fake_io_delegate.h"
  26. #include "tests/test_util.h"
  27. #include "type_cpp.h"
  28. using ::android::aidl::test::FakeIoDelegate;
  29. using ::android::base::StringPrintf;
  30. using std::string;
  31. using std::unique_ptr;
  32. namespace android {
  33. namespace aidl {
  34. namespace cpp {
  35. namespace {
  36. const string kComplexTypeInterfaceAIDL =
  37. R"(package android.os;
  38. import foo.IFooType;
  39. interface IComplexTypeInterface {
  40. const int MY_CONSTANT = 3;
  41. int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
  42. oneway void Piff(int times);
  43. IFooType TakesABinder(IFooType f);
  44. @nullable IFooType NullableBinder();
  45. List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
  46. List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
  47. FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
  48. FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
  49. })";
  50. const char kExpectedComplexTypeClientHeaderOutput[] =
  51. R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
  52. #define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
  53. #include <binder/IBinder.h>
  54. #include <binder/IInterface.h>
  55. #include <utils/Errors.h>
  56. #include <android/os/IComplexTypeInterface.h>
  57. namespace android {
  58. namespace os {
  59. class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
  60. public:
  61. explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
  62. virtual ~BpComplexTypeInterface() = default;
  63. ::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;
  64. ::android::binder::Status Piff(int32_t times) override;
  65. ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
  66. ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
  67. ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
  68. ::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;
  69. ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) override;
  70. ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
  71. }; // class BpComplexTypeInterface
  72. } // namespace os
  73. } // namespace android
  74. #endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
  75. )";
  76. const char kExpectedComplexTypeClientSourceOutput[] =
  77. R"(#include <android/os/BpComplexTypeInterface.h>
  78. #include <binder/Parcel.h>
  79. #include <android-base/macros.h>
  80. namespace android {
  81. namespace os {
  82. BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
  83. : BpInterface<IComplexTypeInterface>(_aidl_impl){
  84. }
  85. ::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) {
  86. ::android::Parcel _aidl_data;
  87. ::android::Parcel _aidl_reply;
  88. ::android::status_t _aidl_ret_status = ::android::OK;
  89. ::android::binder::Status _aidl_status;
  90. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  91. if (((_aidl_ret_status) != (::android::OK))) {
  92. goto _aidl_error;
  93. }
  94. _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
  95. if (((_aidl_ret_status) != (::android::OK))) {
  96. goto _aidl_error;
  97. }
  98. _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
  99. if (((_aidl_ret_status) != (::android::OK))) {
  100. goto _aidl_error;
  101. }
  102. _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
  103. if (((_aidl_ret_status) != (::android::OK))) {
  104. goto _aidl_error;
  105. }
  106. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
  107. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  108. return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
  109. }
  110. if (((_aidl_ret_status) != (::android::OK))) {
  111. goto _aidl_error;
  112. }
  113. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  114. if (((_aidl_ret_status) != (::android::OK))) {
  115. goto _aidl_error;
  116. }
  117. if (!_aidl_status.isOk()) {
  118. return _aidl_status;
  119. }
  120. _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
  121. if (((_aidl_ret_status) != (::android::OK))) {
  122. goto _aidl_error;
  123. }
  124. _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
  125. if (((_aidl_ret_status) != (::android::OK))) {
  126. goto _aidl_error;
  127. }
  128. _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
  129. if (((_aidl_ret_status) != (::android::OK))) {
  130. goto _aidl_error;
  131. }
  132. _aidl_error:
  133. _aidl_status.setFromStatusT(_aidl_ret_status);
  134. return _aidl_status;
  135. }
  136. ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
  137. ::android::Parcel _aidl_data;
  138. ::android::Parcel _aidl_reply;
  139. ::android::status_t _aidl_ret_status = ::android::OK;
  140. ::android::binder::Status _aidl_status;
  141. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  142. if (((_aidl_ret_status) != (::android::OK))) {
  143. goto _aidl_error;
  144. }
  145. _aidl_ret_status = _aidl_data.writeInt32(times);
  146. if (((_aidl_ret_status) != (::android::OK))) {
  147. goto _aidl_error;
  148. }
  149. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
  150. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  151. return IComplexTypeInterface::getDefaultImpl()->Piff(times);
  152. }
  153. if (((_aidl_ret_status) != (::android::OK))) {
  154. goto _aidl_error;
  155. }
  156. _aidl_error:
  157. _aidl_status.setFromStatusT(_aidl_ret_status);
  158. return _aidl_status;
  159. }
  160. ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
  161. ::android::Parcel _aidl_data;
  162. ::android::Parcel _aidl_reply;
  163. ::android::status_t _aidl_ret_status = ::android::OK;
  164. ::android::binder::Status _aidl_status;
  165. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  166. if (((_aidl_ret_status) != (::android::OK))) {
  167. goto _aidl_error;
  168. }
  169. _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
  170. if (((_aidl_ret_status) != (::android::OK))) {
  171. goto _aidl_error;
  172. }
  173. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
  174. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  175. return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
  176. }
  177. if (((_aidl_ret_status) != (::android::OK))) {
  178. goto _aidl_error;
  179. }
  180. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  181. if (((_aidl_ret_status) != (::android::OK))) {
  182. goto _aidl_error;
  183. }
  184. if (!_aidl_status.isOk()) {
  185. return _aidl_status;
  186. }
  187. _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
  188. if (((_aidl_ret_status) != (::android::OK))) {
  189. goto _aidl_error;
  190. }
  191. _aidl_error:
  192. _aidl_status.setFromStatusT(_aidl_ret_status);
  193. return _aidl_status;
  194. }
  195. ::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
  196. ::android::Parcel _aidl_data;
  197. ::android::Parcel _aidl_reply;
  198. ::android::status_t _aidl_ret_status = ::android::OK;
  199. ::android::binder::Status _aidl_status;
  200. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  201. if (((_aidl_ret_status) != (::android::OK))) {
  202. goto _aidl_error;
  203. }
  204. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
  205. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  206. return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
  207. }
  208. if (((_aidl_ret_status) != (::android::OK))) {
  209. goto _aidl_error;
  210. }
  211. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  212. if (((_aidl_ret_status) != (::android::OK))) {
  213. goto _aidl_error;
  214. }
  215. if (!_aidl_status.isOk()) {
  216. return _aidl_status;
  217. }
  218. _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
  219. if (((_aidl_ret_status) != (::android::OK))) {
  220. goto _aidl_error;
  221. }
  222. _aidl_error:
  223. _aidl_status.setFromStatusT(_aidl_ret_status);
  224. return _aidl_status;
  225. }
  226. ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
  227. ::android::Parcel _aidl_data;
  228. ::android::Parcel _aidl_reply;
  229. ::android::status_t _aidl_ret_status = ::android::OK;
  230. ::android::binder::Status _aidl_status;
  231. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  232. if (((_aidl_ret_status) != (::android::OK))) {
  233. goto _aidl_error;
  234. }
  235. _aidl_ret_status = _aidl_data.writeString16Vector(input);
  236. if (((_aidl_ret_status) != (::android::OK))) {
  237. goto _aidl_error;
  238. }
  239. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
  240. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  241. return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
  242. }
  243. if (((_aidl_ret_status) != (::android::OK))) {
  244. goto _aidl_error;
  245. }
  246. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  247. if (((_aidl_ret_status) != (::android::OK))) {
  248. goto _aidl_error;
  249. }
  250. if (!_aidl_status.isOk()) {
  251. return _aidl_status;
  252. }
  253. _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
  254. if (((_aidl_ret_status) != (::android::OK))) {
  255. goto _aidl_error;
  256. }
  257. _aidl_ret_status = _aidl_reply.readString16Vector(output);
  258. if (((_aidl_ret_status) != (::android::OK))) {
  259. goto _aidl_error;
  260. }
  261. _aidl_error:
  262. _aidl_status.setFromStatusT(_aidl_ret_status);
  263. return _aidl_status;
  264. }
  265. ::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) {
  266. ::android::Parcel _aidl_data;
  267. ::android::Parcel _aidl_reply;
  268. ::android::status_t _aidl_ret_status = ::android::OK;
  269. ::android::binder::Status _aidl_status;
  270. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  271. if (((_aidl_ret_status) != (::android::OK))) {
  272. goto _aidl_error;
  273. }
  274. _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
  275. if (((_aidl_ret_status) != (::android::OK))) {
  276. goto _aidl_error;
  277. }
  278. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
  279. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  280. return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
  281. }
  282. if (((_aidl_ret_status) != (::android::OK))) {
  283. goto _aidl_error;
  284. }
  285. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  286. if (((_aidl_ret_status) != (::android::OK))) {
  287. goto _aidl_error;
  288. }
  289. if (!_aidl_status.isOk()) {
  290. return _aidl_status;
  291. }
  292. _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
  293. if (((_aidl_ret_status) != (::android::OK))) {
  294. goto _aidl_error;
  295. }
  296. _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
  297. if (((_aidl_ret_status) != (::android::OK))) {
  298. goto _aidl_error;
  299. }
  300. _aidl_error:
  301. _aidl_status.setFromStatusT(_aidl_ret_status);
  302. return _aidl_status;
  303. }
  304. ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) {
  305. ::android::Parcel _aidl_data;
  306. ::android::Parcel _aidl_reply;
  307. ::android::status_t _aidl_ret_status = ::android::OK;
  308. ::android::binder::Status _aidl_status;
  309. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  310. if (((_aidl_ret_status) != (::android::OK))) {
  311. goto _aidl_error;
  312. }
  313. _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
  314. if (((_aidl_ret_status) != (::android::OK))) {
  315. goto _aidl_error;
  316. }
  317. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
  318. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  319. return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(f, _aidl_return);
  320. }
  321. if (((_aidl_ret_status) != (::android::OK))) {
  322. goto _aidl_error;
  323. }
  324. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  325. if (((_aidl_ret_status) != (::android::OK))) {
  326. goto _aidl_error;
  327. }
  328. if (!_aidl_status.isOk()) {
  329. return _aidl_status;
  330. }
  331. _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
  332. if (((_aidl_ret_status) != (::android::OK))) {
  333. goto _aidl_error;
  334. }
  335. _aidl_error:
  336. _aidl_status.setFromStatusT(_aidl_ret_status);
  337. return _aidl_status;
  338. }
  339. ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
  340. ::android::Parcel _aidl_data;
  341. ::android::Parcel _aidl_reply;
  342. ::android::status_t _aidl_ret_status = ::android::OK;
  343. ::android::binder::Status _aidl_status;
  344. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  345. if (((_aidl_ret_status) != (::android::OK))) {
  346. goto _aidl_error;
  347. }
  348. _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
  349. if (((_aidl_ret_status) != (::android::OK))) {
  350. goto _aidl_error;
  351. }
  352. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
  353. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  354. return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
  355. }
  356. if (((_aidl_ret_status) != (::android::OK))) {
  357. goto _aidl_error;
  358. }
  359. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  360. if (((_aidl_ret_status) != (::android::OK))) {
  361. goto _aidl_error;
  362. }
  363. if (!_aidl_status.isOk()) {
  364. return _aidl_status;
  365. }
  366. _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
  367. if (((_aidl_ret_status) != (::android::OK))) {
  368. goto _aidl_error;
  369. }
  370. _aidl_error:
  371. _aidl_status.setFromStatusT(_aidl_ret_status);
  372. return _aidl_status;
  373. }
  374. } // namespace os
  375. } // namespace android
  376. )";
  377. const char kExpectedComplexTypeClientWithTraceSourceOutput[] =
  378. R"(#include <android/os/BpComplexTypeInterface.h>
  379. #include <binder/Parcel.h>
  380. #include <android-base/macros.h>
  381. namespace android {
  382. namespace os {
  383. BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
  384. : BpInterface<IComplexTypeInterface>(_aidl_impl){
  385. }
  386. ::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) {
  387. ::android::Parcel _aidl_data;
  388. ::android::Parcel _aidl_reply;
  389. ::android::status_t _aidl_ret_status = ::android::OK;
  390. ::android::binder::Status _aidl_status;
  391. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppClient");
  392. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  393. if (((_aidl_ret_status) != (::android::OK))) {
  394. goto _aidl_error;
  395. }
  396. _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
  397. if (((_aidl_ret_status) != (::android::OK))) {
  398. goto _aidl_error;
  399. }
  400. _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
  401. if (((_aidl_ret_status) != (::android::OK))) {
  402. goto _aidl_error;
  403. }
  404. _aidl_ret_status = _aidl_data.writeVectorSize(*goes_out);
  405. if (((_aidl_ret_status) != (::android::OK))) {
  406. goto _aidl_error;
  407. }
  408. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */, _aidl_data, &_aidl_reply);
  409. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  410. return IComplexTypeInterface::getDefaultImpl()->Send(goes_in, goes_in_and_out, goes_out, _aidl_return);
  411. }
  412. if (((_aidl_ret_status) != (::android::OK))) {
  413. goto _aidl_error;
  414. }
  415. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  416. if (((_aidl_ret_status) != (::android::OK))) {
  417. goto _aidl_error;
  418. }
  419. if (!_aidl_status.isOk()) {
  420. return _aidl_status;
  421. }
  422. _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
  423. if (((_aidl_ret_status) != (::android::OK))) {
  424. goto _aidl_error;
  425. }
  426. _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
  427. if (((_aidl_ret_status) != (::android::OK))) {
  428. goto _aidl_error;
  429. }
  430. _aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
  431. if (((_aidl_ret_status) != (::android::OK))) {
  432. goto _aidl_error;
  433. }
  434. _aidl_error:
  435. _aidl_status.setFromStatusT(_aidl_ret_status);
  436. return _aidl_status;
  437. }
  438. ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
  439. ::android::Parcel _aidl_data;
  440. ::android::Parcel _aidl_reply;
  441. ::android::status_t _aidl_ret_status = ::android::OK;
  442. ::android::binder::Status _aidl_status;
  443. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppClient");
  444. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  445. if (((_aidl_ret_status) != (::android::OK))) {
  446. goto _aidl_error;
  447. }
  448. _aidl_ret_status = _aidl_data.writeInt32(times);
  449. if (((_aidl_ret_status) != (::android::OK))) {
  450. goto _aidl_error;
  451. }
  452. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
  453. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  454. return IComplexTypeInterface::getDefaultImpl()->Piff(times);
  455. }
  456. if (((_aidl_ret_status) != (::android::OK))) {
  457. goto _aidl_error;
  458. }
  459. _aidl_error:
  460. _aidl_status.setFromStatusT(_aidl_ret_status);
  461. return _aidl_status;
  462. }
  463. ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
  464. ::android::Parcel _aidl_data;
  465. ::android::Parcel _aidl_reply;
  466. ::android::status_t _aidl_ret_status = ::android::OK;
  467. ::android::binder::Status _aidl_status;
  468. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppClient");
  469. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  470. if (((_aidl_ret_status) != (::android::OK))) {
  471. goto _aidl_error;
  472. }
  473. _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f));
  474. if (((_aidl_ret_status) != (::android::OK))) {
  475. goto _aidl_error;
  476. }
  477. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */, _aidl_data, &_aidl_reply);
  478. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  479. return IComplexTypeInterface::getDefaultImpl()->TakesABinder(f, _aidl_return);
  480. }
  481. if (((_aidl_ret_status) != (::android::OK))) {
  482. goto _aidl_error;
  483. }
  484. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  485. if (((_aidl_ret_status) != (::android::OK))) {
  486. goto _aidl_error;
  487. }
  488. if (!_aidl_status.isOk()) {
  489. return _aidl_status;
  490. }
  491. _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
  492. if (((_aidl_ret_status) != (::android::OK))) {
  493. goto _aidl_error;
  494. }
  495. _aidl_error:
  496. _aidl_status.setFromStatusT(_aidl_ret_status);
  497. return _aidl_status;
  498. }
  499. ::android::binder::Status BpComplexTypeInterface::NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) {
  500. ::android::Parcel _aidl_data;
  501. ::android::Parcel _aidl_reply;
  502. ::android::status_t _aidl_ret_status = ::android::OK;
  503. ::android::binder::Status _aidl_status;
  504. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppClient");
  505. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  506. if (((_aidl_ret_status) != (::android::OK))) {
  507. goto _aidl_error;
  508. }
  509. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */, _aidl_data, &_aidl_reply);
  510. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  511. return IComplexTypeInterface::getDefaultImpl()->NullableBinder(_aidl_return);
  512. }
  513. if (((_aidl_ret_status) != (::android::OK))) {
  514. goto _aidl_error;
  515. }
  516. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  517. if (((_aidl_ret_status) != (::android::OK))) {
  518. goto _aidl_error;
  519. }
  520. if (!_aidl_status.isOk()) {
  521. return _aidl_status;
  522. }
  523. _aidl_ret_status = _aidl_reply.readNullableStrongBinder(_aidl_return);
  524. if (((_aidl_ret_status) != (::android::OK))) {
  525. goto _aidl_error;
  526. }
  527. _aidl_error:
  528. _aidl_status.setFromStatusT(_aidl_ret_status);
  529. return _aidl_status;
  530. }
  531. ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
  532. ::android::Parcel _aidl_data;
  533. ::android::Parcel _aidl_reply;
  534. ::android::status_t _aidl_ret_status = ::android::OK;
  535. ::android::binder::Status _aidl_status;
  536. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppClient");
  537. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  538. if (((_aidl_ret_status) != (::android::OK))) {
  539. goto _aidl_error;
  540. }
  541. _aidl_ret_status = _aidl_data.writeString16Vector(input);
  542. if (((_aidl_ret_status) != (::android::OK))) {
  543. goto _aidl_error;
  544. }
  545. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */, _aidl_data, &_aidl_reply);
  546. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  547. return IComplexTypeInterface::getDefaultImpl()->StringListMethod(input, output, _aidl_return);
  548. }
  549. if (((_aidl_ret_status) != (::android::OK))) {
  550. goto _aidl_error;
  551. }
  552. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  553. if (((_aidl_ret_status) != (::android::OK))) {
  554. goto _aidl_error;
  555. }
  556. if (!_aidl_status.isOk()) {
  557. return _aidl_status;
  558. }
  559. _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
  560. if (((_aidl_ret_status) != (::android::OK))) {
  561. goto _aidl_error;
  562. }
  563. _aidl_ret_status = _aidl_reply.readString16Vector(output);
  564. if (((_aidl_ret_status) != (::android::OK))) {
  565. goto _aidl_error;
  566. }
  567. _aidl_error:
  568. _aidl_status.setFromStatusT(_aidl_ret_status);
  569. return _aidl_status;
  570. }
  571. ::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) {
  572. ::android::Parcel _aidl_data;
  573. ::android::Parcel _aidl_reply;
  574. ::android::status_t _aidl_ret_status = ::android::OK;
  575. ::android::binder::Status _aidl_status;
  576. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppClient");
  577. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  578. if (((_aidl_ret_status) != (::android::OK))) {
  579. goto _aidl_error;
  580. }
  581. _aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
  582. if (((_aidl_ret_status) != (::android::OK))) {
  583. goto _aidl_error;
  584. }
  585. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */, _aidl_data, &_aidl_reply);
  586. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  587. return IComplexTypeInterface::getDefaultImpl()->BinderListMethod(input, output, _aidl_return);
  588. }
  589. if (((_aidl_ret_status) != (::android::OK))) {
  590. goto _aidl_error;
  591. }
  592. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  593. if (((_aidl_ret_status) != (::android::OK))) {
  594. goto _aidl_error;
  595. }
  596. if (!_aidl_status.isOk()) {
  597. return _aidl_status;
  598. }
  599. _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
  600. if (((_aidl_ret_status) != (::android::OK))) {
  601. goto _aidl_error;
  602. }
  603. _aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
  604. if (((_aidl_ret_status) != (::android::OK))) {
  605. goto _aidl_error;
  606. }
  607. _aidl_error:
  608. _aidl_status.setFromStatusT(_aidl_ret_status);
  609. return _aidl_status;
  610. }
  611. ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) {
  612. ::android::Parcel _aidl_data;
  613. ::android::Parcel _aidl_reply;
  614. ::android::status_t _aidl_ret_status = ::android::OK;
  615. ::android::binder::Status _aidl_status;
  616. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppClient");
  617. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  618. if (((_aidl_ret_status) != (::android::OK))) {
  619. goto _aidl_error;
  620. }
  621. _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
  622. if (((_aidl_ret_status) != (::android::OK))) {
  623. goto _aidl_error;
  624. }
  625. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */, _aidl_data, &_aidl_reply);
  626. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  627. return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptor(f, _aidl_return);
  628. }
  629. if (((_aidl_ret_status) != (::android::OK))) {
  630. goto _aidl_error;
  631. }
  632. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  633. if (((_aidl_ret_status) != (::android::OK))) {
  634. goto _aidl_error;
  635. }
  636. if (!_aidl_status.isOk()) {
  637. return _aidl_status;
  638. }
  639. _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
  640. if (((_aidl_ret_status) != (::android::OK))) {
  641. goto _aidl_error;
  642. }
  643. _aidl_error:
  644. _aidl_status.setFromStatusT(_aidl_ret_status);
  645. return _aidl_status;
  646. }
  647. ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) {
  648. ::android::Parcel _aidl_data;
  649. ::android::Parcel _aidl_reply;
  650. ::android::status_t _aidl_ret_status = ::android::OK;
  651. ::android::binder::Status _aidl_status;
  652. ScopedTrace _aidl_trace(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppClient");
  653. _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
  654. if (((_aidl_ret_status) != (::android::OK))) {
  655. goto _aidl_error;
  656. }
  657. _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
  658. if (((_aidl_ret_status) != (::android::OK))) {
  659. goto _aidl_error;
  660. }
  661. _aidl_ret_status = remote()->transact(::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */, _aidl_data, &_aidl_reply);
  662. if (UNLIKELY(_aidl_ret_status == ::android::UNKNOWN_TRANSACTION && IComplexTypeInterface::getDefaultImpl())) {
  663. return IComplexTypeInterface::getDefaultImpl()->TakesAFileDescriptorArray(f, _aidl_return);
  664. }
  665. if (((_aidl_ret_status) != (::android::OK))) {
  666. goto _aidl_error;
  667. }
  668. _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
  669. if (((_aidl_ret_status) != (::android::OK))) {
  670. goto _aidl_error;
  671. }
  672. if (!_aidl_status.isOk()) {
  673. return _aidl_status;
  674. }
  675. _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
  676. if (((_aidl_ret_status) != (::android::OK))) {
  677. goto _aidl_error;
  678. }
  679. _aidl_error:
  680. _aidl_status.setFromStatusT(_aidl_ret_status);
  681. return _aidl_status;
  682. }
  683. } // namespace os
  684. } // namespace android
  685. )";
  686. const char kExpectedComplexTypeServerHeaderOutput[] =
  687. R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
  688. #define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
  689. #include <binder/IInterface.h>
  690. #include <android/os/IComplexTypeInterface.h>
  691. namespace android {
  692. namespace os {
  693. class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
  694. public:
  695. ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) override;
  696. }; // class BnComplexTypeInterface
  697. } // namespace os
  698. } // namespace android
  699. #endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
  700. )";
  701. const char kExpectedComplexTypeServerSourceOutput[] =
  702. R"(#include <android/os/BnComplexTypeInterface.h>
  703. #include <binder/Parcel.h>
  704. namespace android {
  705. namespace os {
  706. ::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
  707. ::android::status_t _aidl_ret_status = ::android::OK;
  708. switch (_aidl_code) {
  709. case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
  710. {
  711. ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
  712. ::std::vector<double> in_goes_in_and_out;
  713. ::std::vector<bool> out_goes_out;
  714. ::std::vector<int32_t> _aidl_return;
  715. if (!(_aidl_data.checkInterface(this))) {
  716. _aidl_ret_status = ::android::BAD_TYPE;
  717. break;
  718. }
  719. _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
  720. if (((_aidl_ret_status) != (::android::OK))) {
  721. break;
  722. }
  723. _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
  724. if (((_aidl_ret_status) != (::android::OK))) {
  725. break;
  726. }
  727. _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
  728. if (((_aidl_ret_status) != (::android::OK))) {
  729. break;
  730. }
  731. ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
  732. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  733. if (((_aidl_ret_status) != (::android::OK))) {
  734. break;
  735. }
  736. if (!_aidl_status.isOk()) {
  737. break;
  738. }
  739. _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
  740. if (((_aidl_ret_status) != (::android::OK))) {
  741. break;
  742. }
  743. _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
  744. if (((_aidl_ret_status) != (::android::OK))) {
  745. break;
  746. }
  747. _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
  748. if (((_aidl_ret_status) != (::android::OK))) {
  749. break;
  750. }
  751. }
  752. break;
  753. case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
  754. {
  755. int32_t in_times;
  756. if (!(_aidl_data.checkInterface(this))) {
  757. _aidl_ret_status = ::android::BAD_TYPE;
  758. break;
  759. }
  760. _aidl_ret_status = _aidl_data.readInt32(&in_times);
  761. if (((_aidl_ret_status) != (::android::OK))) {
  762. break;
  763. }
  764. ::android::binder::Status _aidl_status(Piff(in_times));
  765. }
  766. break;
  767. case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
  768. {
  769. ::android::sp<::foo::IFooType> in_f;
  770. ::android::sp<::foo::IFooType> _aidl_return;
  771. if (!(_aidl_data.checkInterface(this))) {
  772. _aidl_ret_status = ::android::BAD_TYPE;
  773. break;
  774. }
  775. _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
  776. if (((_aidl_ret_status) != (::android::OK))) {
  777. break;
  778. }
  779. ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
  780. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  781. if (((_aidl_ret_status) != (::android::OK))) {
  782. break;
  783. }
  784. if (!_aidl_status.isOk()) {
  785. break;
  786. }
  787. _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
  788. if (((_aidl_ret_status) != (::android::OK))) {
  789. break;
  790. }
  791. }
  792. break;
  793. case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
  794. {
  795. ::android::sp<::foo::IFooType> _aidl_return;
  796. if (!(_aidl_data.checkInterface(this))) {
  797. _aidl_ret_status = ::android::BAD_TYPE;
  798. break;
  799. }
  800. ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
  801. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  802. if (((_aidl_ret_status) != (::android::OK))) {
  803. break;
  804. }
  805. if (!_aidl_status.isOk()) {
  806. break;
  807. }
  808. _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
  809. if (((_aidl_ret_status) != (::android::OK))) {
  810. break;
  811. }
  812. }
  813. break;
  814. case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
  815. {
  816. ::std::vector<::android::String16> in_input;
  817. ::std::vector<::android::String16> out_output;
  818. ::std::vector<::android::String16> _aidl_return;
  819. if (!(_aidl_data.checkInterface(this))) {
  820. _aidl_ret_status = ::android::BAD_TYPE;
  821. break;
  822. }
  823. _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
  824. if (((_aidl_ret_status) != (::android::OK))) {
  825. break;
  826. }
  827. ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
  828. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  829. if (((_aidl_ret_status) != (::android::OK))) {
  830. break;
  831. }
  832. if (!_aidl_status.isOk()) {
  833. break;
  834. }
  835. _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
  836. if (((_aidl_ret_status) != (::android::OK))) {
  837. break;
  838. }
  839. _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
  840. if (((_aidl_ret_status) != (::android::OK))) {
  841. break;
  842. }
  843. }
  844. break;
  845. case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
  846. {
  847. ::std::vector<::android::sp<::android::IBinder>> in_input;
  848. ::std::vector<::android::sp<::android::IBinder>> out_output;
  849. ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
  850. if (!(_aidl_data.checkInterface(this))) {
  851. _aidl_ret_status = ::android::BAD_TYPE;
  852. break;
  853. }
  854. _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
  855. if (((_aidl_ret_status) != (::android::OK))) {
  856. break;
  857. }
  858. ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
  859. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  860. if (((_aidl_ret_status) != (::android::OK))) {
  861. break;
  862. }
  863. if (!_aidl_status.isOk()) {
  864. break;
  865. }
  866. _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
  867. if (((_aidl_ret_status) != (::android::OK))) {
  868. break;
  869. }
  870. _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
  871. if (((_aidl_ret_status) != (::android::OK))) {
  872. break;
  873. }
  874. }
  875. break;
  876. case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
  877. {
  878. ::android::base::unique_fd in_f;
  879. ::android::base::unique_fd _aidl_return;
  880. if (!(_aidl_data.checkInterface(this))) {
  881. _aidl_ret_status = ::android::BAD_TYPE;
  882. break;
  883. }
  884. _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
  885. if (((_aidl_ret_status) != (::android::OK))) {
  886. break;
  887. }
  888. ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
  889. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  890. if (((_aidl_ret_status) != (::android::OK))) {
  891. break;
  892. }
  893. if (!_aidl_status.isOk()) {
  894. break;
  895. }
  896. _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
  897. if (((_aidl_ret_status) != (::android::OK))) {
  898. break;
  899. }
  900. }
  901. break;
  902. case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
  903. {
  904. ::std::vector<::android::base::unique_fd> in_f;
  905. ::std::vector<::android::base::unique_fd> _aidl_return;
  906. if (!(_aidl_data.checkInterface(this))) {
  907. _aidl_ret_status = ::android::BAD_TYPE;
  908. break;
  909. }
  910. _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
  911. if (((_aidl_ret_status) != (::android::OK))) {
  912. break;
  913. }
  914. ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
  915. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  916. if (((_aidl_ret_status) != (::android::OK))) {
  917. break;
  918. }
  919. if (!_aidl_status.isOk()) {
  920. break;
  921. }
  922. _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
  923. if (((_aidl_ret_status) != (::android::OK))) {
  924. break;
  925. }
  926. }
  927. break;
  928. default:
  929. {
  930. _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
  931. }
  932. break;
  933. }
  934. if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
  935. _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
  936. }
  937. return _aidl_ret_status;
  938. }
  939. } // namespace os
  940. } // namespace android
  941. )";
  942. const char kExpectedComplexTypeServerWithTraceSourceOutput[] =
  943. R"(#include <android/os/BnComplexTypeInterface.h>
  944. #include <binder/Parcel.h>
  945. namespace android {
  946. namespace os {
  947. ::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
  948. ::android::status_t _aidl_ret_status = ::android::OK;
  949. switch (_aidl_code) {
  950. case ::android::IBinder::FIRST_CALL_TRANSACTION + 0 /* Send */:
  951. {
  952. ::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
  953. ::std::vector<double> in_goes_in_and_out;
  954. ::std::vector<bool> out_goes_out;
  955. ::std::vector<int32_t> _aidl_return;
  956. if (!(_aidl_data.checkInterface(this))) {
  957. _aidl_ret_status = ::android::BAD_TYPE;
  958. break;
  959. }
  960. _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
  961. if (((_aidl_ret_status) != (::android::OK))) {
  962. break;
  963. }
  964. _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
  965. if (((_aidl_ret_status) != (::android::OK))) {
  966. break;
  967. }
  968. _aidl_ret_status = _aidl_data.resizeOutVector(&out_goes_out);
  969. if (((_aidl_ret_status) != (::android::OK))) {
  970. break;
  971. }
  972. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Send::cppServer");
  973. ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
  974. atrace_end(ATRACE_TAG_AIDL);
  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->writeInt32Vector(_aidl_return);
  983. if (((_aidl_ret_status) != (::android::OK))) {
  984. break;
  985. }
  986. _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
  987. if (((_aidl_ret_status) != (::android::OK))) {
  988. break;
  989. }
  990. _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
  991. if (((_aidl_ret_status) != (::android::OK))) {
  992. break;
  993. }
  994. }
  995. break;
  996. case ::android::IBinder::FIRST_CALL_TRANSACTION + 1 /* Piff */:
  997. {
  998. int32_t in_times;
  999. if (!(_aidl_data.checkInterface(this))) {
  1000. _aidl_ret_status = ::android::BAD_TYPE;
  1001. break;
  1002. }
  1003. _aidl_ret_status = _aidl_data.readInt32(&in_times);
  1004. if (((_aidl_ret_status) != (::android::OK))) {
  1005. break;
  1006. }
  1007. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::Piff::cppServer");
  1008. ::android::binder::Status _aidl_status(Piff(in_times));
  1009. atrace_end(ATRACE_TAG_AIDL);
  1010. }
  1011. break;
  1012. case ::android::IBinder::FIRST_CALL_TRANSACTION + 2 /* TakesABinder */:
  1013. {
  1014. ::android::sp<::foo::IFooType> in_f;
  1015. ::android::sp<::foo::IFooType> _aidl_return;
  1016. if (!(_aidl_data.checkInterface(this))) {
  1017. _aidl_ret_status = ::android::BAD_TYPE;
  1018. break;
  1019. }
  1020. _aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
  1021. if (((_aidl_ret_status) != (::android::OK))) {
  1022. break;
  1023. }
  1024. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesABinder::cppServer");
  1025. ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
  1026. atrace_end(ATRACE_TAG_AIDL);
  1027. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1028. if (((_aidl_ret_status) != (::android::OK))) {
  1029. break;
  1030. }
  1031. if (!_aidl_status.isOk()) {
  1032. break;
  1033. }
  1034. _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
  1035. if (((_aidl_ret_status) != (::android::OK))) {
  1036. break;
  1037. }
  1038. }
  1039. break;
  1040. case ::android::IBinder::FIRST_CALL_TRANSACTION + 3 /* NullableBinder */:
  1041. {
  1042. ::android::sp<::foo::IFooType> _aidl_return;
  1043. if (!(_aidl_data.checkInterface(this))) {
  1044. _aidl_ret_status = ::android::BAD_TYPE;
  1045. break;
  1046. }
  1047. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::NullableBinder::cppServer");
  1048. ::android::binder::Status _aidl_status(NullableBinder(&_aidl_return));
  1049. atrace_end(ATRACE_TAG_AIDL);
  1050. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1051. if (((_aidl_ret_status) != (::android::OK))) {
  1052. break;
  1053. }
  1054. if (!_aidl_status.isOk()) {
  1055. break;
  1056. }
  1057. _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return));
  1058. if (((_aidl_ret_status) != (::android::OK))) {
  1059. break;
  1060. }
  1061. }
  1062. break;
  1063. case ::android::IBinder::FIRST_CALL_TRANSACTION + 4 /* StringListMethod */:
  1064. {
  1065. ::std::vector<::android::String16> in_input;
  1066. ::std::vector<::android::String16> out_output;
  1067. ::std::vector<::android::String16> _aidl_return;
  1068. if (!(_aidl_data.checkInterface(this))) {
  1069. _aidl_ret_status = ::android::BAD_TYPE;
  1070. break;
  1071. }
  1072. _aidl_ret_status = _aidl_data.readString16Vector(&in_input);
  1073. if (((_aidl_ret_status) != (::android::OK))) {
  1074. break;
  1075. }
  1076. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::StringListMethod::cppServer");
  1077. ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
  1078. atrace_end(ATRACE_TAG_AIDL);
  1079. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1080. if (((_aidl_ret_status) != (::android::OK))) {
  1081. break;
  1082. }
  1083. if (!_aidl_status.isOk()) {
  1084. break;
  1085. }
  1086. _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
  1087. if (((_aidl_ret_status) != (::android::OK))) {
  1088. break;
  1089. }
  1090. _aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
  1091. if (((_aidl_ret_status) != (::android::OK))) {
  1092. break;
  1093. }
  1094. }
  1095. break;
  1096. case ::android::IBinder::FIRST_CALL_TRANSACTION + 5 /* BinderListMethod */:
  1097. {
  1098. ::std::vector<::android::sp<::android::IBinder>> in_input;
  1099. ::std::vector<::android::sp<::android::IBinder>> out_output;
  1100. ::std::vector<::android::sp<::android::IBinder>> _aidl_return;
  1101. if (!(_aidl_data.checkInterface(this))) {
  1102. _aidl_ret_status = ::android::BAD_TYPE;
  1103. break;
  1104. }
  1105. _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
  1106. if (((_aidl_ret_status) != (::android::OK))) {
  1107. break;
  1108. }
  1109. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::BinderListMethod::cppServer");
  1110. ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
  1111. atrace_end(ATRACE_TAG_AIDL);
  1112. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1113. if (((_aidl_ret_status) != (::android::OK))) {
  1114. break;
  1115. }
  1116. if (!_aidl_status.isOk()) {
  1117. break;
  1118. }
  1119. _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
  1120. if (((_aidl_ret_status) != (::android::OK))) {
  1121. break;
  1122. }
  1123. _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
  1124. if (((_aidl_ret_status) != (::android::OK))) {
  1125. break;
  1126. }
  1127. }
  1128. break;
  1129. case ::android::IBinder::FIRST_CALL_TRANSACTION + 6 /* TakesAFileDescriptor */:
  1130. {
  1131. ::android::base::unique_fd in_f;
  1132. ::android::base::unique_fd _aidl_return;
  1133. if (!(_aidl_data.checkInterface(this))) {
  1134. _aidl_ret_status = ::android::BAD_TYPE;
  1135. break;
  1136. }
  1137. _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
  1138. if (((_aidl_ret_status) != (::android::OK))) {
  1139. break;
  1140. }
  1141. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptor::cppServer");
  1142. ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
  1143. atrace_end(ATRACE_TAG_AIDL);
  1144. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1145. if (((_aidl_ret_status) != (::android::OK))) {
  1146. break;
  1147. }
  1148. if (!_aidl_status.isOk()) {
  1149. break;
  1150. }
  1151. _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
  1152. if (((_aidl_ret_status) != (::android::OK))) {
  1153. break;
  1154. }
  1155. }
  1156. break;
  1157. case ::android::IBinder::FIRST_CALL_TRANSACTION + 7 /* TakesAFileDescriptorArray */:
  1158. {
  1159. ::std::vector<::android::base::unique_fd> in_f;
  1160. ::std::vector<::android::base::unique_fd> _aidl_return;
  1161. if (!(_aidl_data.checkInterface(this))) {
  1162. _aidl_ret_status = ::android::BAD_TYPE;
  1163. break;
  1164. }
  1165. _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
  1166. if (((_aidl_ret_status) != (::android::OK))) {
  1167. break;
  1168. }
  1169. atrace_begin(ATRACE_TAG_AIDL, "IComplexTypeInterface::TakesAFileDescriptorArray::cppServer");
  1170. ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
  1171. atrace_end(ATRACE_TAG_AIDL);
  1172. _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
  1173. if (((_aidl_ret_status) != (::android::OK))) {
  1174. break;
  1175. }
  1176. if (!_aidl_status.isOk()) {
  1177. break;
  1178. }
  1179. _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
  1180. if (((_aidl_ret_status) != (::android::OK))) {
  1181. break;
  1182. }
  1183. }
  1184. break;
  1185. default:
  1186. {
  1187. _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
  1188. }
  1189. break;
  1190. }
  1191. if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
  1192. _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
  1193. }
  1194. return _aidl_ret_status;
  1195. }
  1196. } // namespace os
  1197. } // namespace android
  1198. )";
  1199. const char kExpectedComplexTypeInterfaceHeaderOutput[] =
  1200. R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
  1201. #define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
  1202. #include <android-base/unique_fd.h>
  1203. #include <binder/IBinder.h>
  1204. #include <binder/IInterface.h>
  1205. #include <binder/Status.h>
  1206. #include <cstdint>
  1207. #include <foo/IFooType.h>
  1208. #include <memory>
  1209. #include <utils/String16.h>
  1210. #include <utils/StrongPointer.h>
  1211. #include <vector>
  1212. namespace android {
  1213. namespace os {
  1214. class IComplexTypeInterface : public ::android::IInterface {
  1215. public:
  1216. DECLARE_META_INTERFACE(ComplexTypeInterface)
  1217. enum : int32_t {
  1218. MY_CONSTANT = 3,
  1219. };
  1220. 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;
  1221. virtual ::android::binder::Status Piff(int32_t times) = 0;
  1222. virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
  1223. virtual ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) = 0;
  1224. virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
  1225. 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;
  1226. virtual ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) = 0;
  1227. virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) = 0;
  1228. }; // class IComplexTypeInterface
  1229. class IComplexTypeInterfaceDefault : public IComplexTypeInterface {
  1230. public:
  1231. ::android::IBinder* onAsBinder() override;
  1232. ::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;
  1233. ::android::binder::Status Piff(int32_t times) override;
  1234. ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
  1235. ::android::binder::Status NullableBinder(::android::sp<::foo::IFooType>* _aidl_return) override;
  1236. ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
  1237. ::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;
  1238. ::android::binder::Status TakesAFileDescriptor(const ::android::base::unique_fd& f, ::android::base::unique_fd* _aidl_return) override;
  1239. ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>& f, ::std::vector<::android::base::unique_fd>* _aidl_return) override;
  1240. };
  1241. } // namespace os
  1242. } // namespace android
  1243. #endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
  1244. )";
  1245. const char kExpectedComplexTypeInterfaceSourceOutput[] =
  1246. R"(#include <android/os/IComplexTypeInterface.h>
  1247. #include <android/os/BpComplexTypeInterface.h>
  1248. namespace android {
  1249. namespace os {
  1250. IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface")
  1251. ::android::IBinder* IComplexTypeInterfaceDefault::onAsBinder() {
  1252. return nullptr;
  1253. }
  1254. ::android::binder::Status IComplexTypeInterfaceDefault::Send(const ::std::unique_ptr<::std::vector<int32_t>>&, ::std::vector<double>*, ::std::vector<bool>*, ::std::vector<int32_t>* ) {
  1255. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1256. }
  1257. ::android::binder::Status IComplexTypeInterfaceDefault::Piff(int32_t) {
  1258. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1259. }
  1260. ::android::binder::Status IComplexTypeInterfaceDefault::TakesABinder(const ::android::sp<::foo::IFooType>&, ::android::sp<::foo::IFooType>* ) {
  1261. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1262. }
  1263. ::android::binder::Status IComplexTypeInterfaceDefault::NullableBinder(::android::sp<::foo::IFooType>* ) {
  1264. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1265. }
  1266. ::android::binder::Status IComplexTypeInterfaceDefault::StringListMethod(const ::std::vector<::android::String16>&, ::std::vector<::android::String16>*, ::std::vector<::android::String16>* ) {
  1267. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1268. }
  1269. ::android::binder::Status IComplexTypeInterfaceDefault::BinderListMethod(const ::std::vector<::android::sp<::android::IBinder>>&, ::std::vector<::android::sp<::android::IBinder>>*, ::std::vector<::android::sp<::android::IBinder>>* ) {
  1270. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1271. }
  1272. ::android::binder::Status IComplexTypeInterfaceDefault::TakesAFileDescriptor(const ::android::base::unique_fd&, ::android::base::unique_fd* ) {
  1273. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1274. }
  1275. ::android::binder::Status IComplexTypeInterfaceDefault::TakesAFileDescriptorArray(const ::std::vector<::android::base::unique_fd>&, ::std::vector<::android::base::unique_fd>* ) {
  1276. return ::android::binder::Status::fromStatusT(::android::UNKNOWN_TRANSACTION);
  1277. }
  1278. } // namespace os
  1279. } // namespace android
  1280. )";
  1281. } // namespace
  1282. class ASTTest : public ::testing::Test {
  1283. protected:
  1284. ASTTest(const string& cmdline, const string& file_contents)
  1285. : options_(Options::From(cmdline)), file_contents_(file_contents) {
  1286. types_.Init();
  1287. }
  1288. AidlInterface* ParseSingleInterface() {
  1289. io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
  1290. vector<AidlDefinedType*> defined_types;
  1291. vector<string> imported_files;
  1292. ImportResolver import_resolver{io_delegate_, options_.InputFiles().at(0), {"."}, {}};
  1293. AidlError err = ::android::aidl::internals::load_and_validate_aidl(
  1294. options_.InputFiles().front(), options_, io_delegate_, &types_, &defined_types,
  1295. &imported_files);
  1296. if (err != AidlError::OK) {
  1297. return nullptr;
  1298. }
  1299. EXPECT_EQ(1ul, defined_types.size());
  1300. EXPECT_NE(nullptr, defined_types.front()->AsInterface());
  1301. return defined_types.front()->AsInterface();
  1302. }
  1303. void Compare(Document* doc, const char* expected) {
  1304. string output;
  1305. doc->Write(CodeWriter::ForString(&output).get());
  1306. if (expected == output) {
  1307. return; // Success
  1308. }
  1309. test::PrintDiff(expected, output);
  1310. FAIL() << "Document contents did not match expected contents";
  1311. }
  1312. const Options options_;
  1313. const string file_contents_;
  1314. FakeIoDelegate io_delegate_;
  1315. TypeNamespace types_;
  1316. };
  1317. class ComplexTypeInterfaceASTTest : public ASTTest {
  1318. public:
  1319. ComplexTypeInterfaceASTTest()
  1320. : ASTTest("aidl --lang=cpp -I . -o out android/os/IComplexTypeInterface.aidl",
  1321. kComplexTypeInterfaceAIDL) {
  1322. io_delegate_.SetFileContents("foo/IFooType.aidl",
  1323. "package foo; interface IFooType {}");
  1324. }
  1325. };
  1326. TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
  1327. AidlInterface* interface = ParseSingleInterface();
  1328. ASSERT_NE(interface, nullptr);
  1329. unique_ptr<Document> doc = internals::BuildClientHeader(types_, *interface, options_);
  1330. Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
  1331. }
  1332. TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
  1333. AidlInterface* interface = ParseSingleInterface();
  1334. ASSERT_NE(interface, nullptr);
  1335. unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface, options_);
  1336. Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
  1337. }
  1338. TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
  1339. AidlInterface* interface = ParseSingleInterface();
  1340. ASSERT_NE(interface, nullptr);
  1341. unique_ptr<Document> doc = internals::BuildServerHeader(types_, *interface, options_);
  1342. Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
  1343. }
  1344. TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
  1345. AidlInterface* interface = ParseSingleInterface();
  1346. ASSERT_NE(interface, nullptr);
  1347. unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface, options_);
  1348. Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
  1349. }
  1350. TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
  1351. AidlInterface* interface = ParseSingleInterface();
  1352. ASSERT_NE(interface, nullptr);
  1353. unique_ptr<Document> doc = internals::BuildInterfaceHeader(types_, *interface, options_);
  1354. Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
  1355. }
  1356. TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
  1357. AidlInterface* interface = ParseSingleInterface();
  1358. ASSERT_NE(interface, nullptr);
  1359. unique_ptr<Document> doc = internals::BuildInterfaceSource(types_, *interface, options_);
  1360. Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
  1361. }
  1362. class ComplexTypeInterfaceASTTestWithTrace : public ASTTest {
  1363. public:
  1364. ComplexTypeInterfaceASTTestWithTrace()
  1365. : ASTTest("aidl --lang=cpp -t -I . -o out android/os/IComplexTypeInterface.aidl",
  1366. kComplexTypeInterfaceAIDL) {
  1367. io_delegate_.SetFileContents("foo/IFooType.aidl", "package foo; interface IFooType {}");
  1368. }
  1369. };
  1370. TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesClientSource) {
  1371. AidlInterface* interface = ParseSingleInterface();
  1372. ASSERT_NE(interface, nullptr);
  1373. unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface, options_);
  1374. Compare(doc.get(), kExpectedComplexTypeClientWithTraceSourceOutput);
  1375. }
  1376. TEST_F(ComplexTypeInterfaceASTTestWithTrace, GeneratesServerSource) {
  1377. AidlInterface* interface = ParseSingleInterface();
  1378. ASSERT_NE(interface, nullptr);
  1379. unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface, options_);
  1380. Compare(doc.get(), kExpectedComplexTypeServerWithTraceSourceOutput);
  1381. }
  1382. namespace test_io_handling {
  1383. const char kInputPath[] = "a/IFoo.aidl";
  1384. const char kOutputPath[] = "output.cpp";
  1385. const char kHeaderDir[] = "headers";
  1386. const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
  1387. const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
  1388. } // namespace test_io_handling
  1389. class IoErrorHandlingTest : public ASTTest {
  1390. public:
  1391. IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
  1392. };
  1393. TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
  1394. // Confirm that this is working correctly without I/O problems.
  1395. AidlInterface* interface = ParseSingleInterface();
  1396. ASSERT_NE(interface, nullptr);
  1397. ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
  1398. }
  1399. TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
  1400. using namespace test_io_handling;
  1401. AidlInterface* interface = ParseSingleInterface();
  1402. ASSERT_NE(interface, nullptr);
  1403. // Simulate issues closing the interface header.
  1404. const string header_path =
  1405. StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
  1406. kInterfaceHeaderRelPath);
  1407. io_delegate_.AddBrokenFilePath(header_path);
  1408. ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
  1409. // We should never attempt to write the C++ file if we fail writing headers.
  1410. ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
  1411. // We should remove partial results.
  1412. ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
  1413. }
  1414. TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
  1415. using test_io_handling::kOutputPath;
  1416. AidlInterface* interface = ParseSingleInterface();
  1417. ASSERT_NE(interface, nullptr);
  1418. // Simulate issues closing the cpp file.
  1419. io_delegate_.AddBrokenFilePath(kOutputPath);
  1420. ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
  1421. // We should remove partial results.
  1422. ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
  1423. }
  1424. } // namespace cpp
  1425. } // namespace aidl
  1426. } // namespace android