generate_cpp_unittest.cpp revision 57dbe24bcb8f4509a876e8445c78d9504d7e616a
11aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber/*
21aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Copyright (C) 2015, The Android Open Source Project
31aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
41aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
51aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * you may not use this file except in compliance with the License.
61aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * You may obtain a copy of the License at
71aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
81aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *     http://www.apache.org/licenses/LICENSE-2.0
91aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber *
101aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * Unless required by applicable law or agreed to in writing, software
111aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
121aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * See the License for the specific language governing permissions and
141aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber * limitations under the License.
151aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber */
161aec397b1fdea7db4120dbe55b6995bb2a9d9138Andreas Huber
17c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include <string>
18c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
19c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include <android-base/stringprintf.h>
20c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include <gtest/gtest.h>
21c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
22881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber#include "aidl.h"
23881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber#include "aidl_language.h"
247c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber#include "ast_cpp.h"
25979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland#include "code_writer.h"
26c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "generate_cpp.h"
27c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "os.h"
28c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "tests/fake_io_delegate.h"
297c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber#include "tests/test_util.h"
30c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber#include "type_cpp.h"
31737080baf85882c45bb322ee2191ae5fd9e1283aAndreas Huber
32979e099f1163ff75beed5776cd01fb409b90a0cdSteven Morelandusing ::android::aidl::test::FakeIoDelegate;
33c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberusing ::android::base::StringPrintf;
34c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberusing std::string;
35c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberusing std::unique_ptr;
36c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber
37c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubernamespace android {
3899e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coenennamespace aidl {
39295ad30bf6212c16accc5095601b2a71d44b4c8bAndreas Hubernamespace cpp {
40f630bc8736003dcf4aac3dfe47167beb6beb6c6aAndreas Hubernamespace {
4199e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coenen
4299e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coenenconst string kComplexTypeInterfaceAIDL =
4399e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn CoenenR"(package android.os;
4499e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coenenimport foo.IFooType;
4599e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coeneninterface IComplexTypeInterface {
4699e6bebc96d75d1c9b9b8130cd9b880dacb95b01Martijn Coenen  const int MY_CONSTANT = 3;
47709b62dbda6184770bb34470ff550e02c1643e67Andreas Huber  int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out);
488d3ac0c6112e02e3a705fd4f9d82e523f10b4287Andreas Huber  oneway void Piff(int times);
49737080baf85882c45bb322ee2191ae5fd9e1283aAndreas Huber  IFooType TakesABinder(IFooType f);
50c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber  List<String> StringListMethod(in java.util.List<String> input, out List<String> output);
5130bb6a869be0f3f82497b7b11c71ec9d47652ed0Steven Moreland  List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output);
5230bb6a869be0f3f82497b7b11c71ec9d47652ed0Steven Moreland  FileDescriptor TakesAFileDescriptor(in FileDescriptor f);
538d3ac0c6112e02e3a705fd4f9d82e523f10b4287Andreas Huber  FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f);
548d3ac0c6112e02e3a705fd4f9d82e523f10b4287Andreas Huber})";
55881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
56881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberconst char kExpectedComplexTypeClientHeaderOutput[] =
57881227d860c59471eee31d39946e96ce2daa35d6Andreas HuberR"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
58ac5878945afde379e41d9c93de44c32537f868b1Martijn Coenen#define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_
59881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
603b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong#include <binder/IBinder.h>
61881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber#include <binder/IInterface.h>
62979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland#include <utils/Errors.h>
633b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong#include <android/os/IComplexTypeInterface.h>
643b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong
653b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hongnamespace android {
663b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong
673b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hongnamespace os {
68979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland
69979e099f1163ff75beed5776cd01fb409b90a0cdSteven Morelandclass BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> {
70979e099f1163ff75beed5776cd01fb409b90a0cdSteven Morelandpublic:
71979e099f1163ff75beed5776cd01fb409b90a0cdSteven Morelandexplicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl);
72979e099f1163ff75beed5776cd01fb409b90a0cdSteven Morelandvirtual ~BpComplexTypeInterface() = default;
73979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::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;
74979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::android::binder::Status Piff(int32_t times) override;
75979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override;
76979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override;
77979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::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;
78979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::android::binder::Status TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) override;
79979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) override;
80979e099f1163ff75beed5776cd01fb409b90a0cdSteven Moreland};  // class BpComplexTypeInterface
81881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
823b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong}  // namespace os
83881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
843b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong}  // namespace android
854c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber
863b320f8a60e4343bf06319bca3fc949c95eaf326Yifan Hong#endif  // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_)";
874c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber
884ed1347cd29e6e07acad368891bb03078c798abaYifan Hongconst char kExpectedComplexTypeClientSourceOutput[] =
894ed1347cd29e6e07acad368891bb03078c798abaYifan HongR"(#include <android/os/BpComplexTypeInterface.h>
904c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber#include <binder/Parcel.h>
914c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huber
924ed1347cd29e6e07acad368891bb03078c798abaYifan Hongnamespace android {
93881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
9485eabdbe56720dcdcf130e5ca83129d47b143768Andreas Hubernamespace os {
952831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber
962831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas HuberBpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl)
97c5ea9f589cc7cce0b5e97bd4ac6a8561eb313a02Zhuoyao Zhang    : BpInterface<IComplexTypeInterface>(_aidl_impl){
98c5ea9f589cc7cce0b5e97bd4ac6a8561eb313a02Zhuoyao Zhang}
99881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber
100881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber::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) {
101881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber::android::Parcel _aidl_data;
102881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber::android::Parcel _aidl_reply;
103737080baf85882c45bb322ee2191ae5fd9e1283aAndreas Huber::android::status_t _aidl_ret_status = ::android::OK;
104881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber::android::binder::Status _aidl_status;
105881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
106881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
107881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
108881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
109881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_data.writeInt32Vector(goes_in);
110881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
111881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
112881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
113881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out);
114881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
115f9d49f1468bd65595f6f0ae5f4d7300f4e95edf8Andreas Hubergoto _aidl_error;
116881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
117be2a3737675b83dd61b52c11f0d7549fa1276739Yifan Hong_aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply);
118881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
119881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
120881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
121881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
122881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
123881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
124881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
125881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (!_aidl_status.isOk()) {
126bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongreturn _aidl_status;
127bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
128bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return);
129bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
130bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
131bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
132bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out);
133bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
134bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
135bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
136bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_ret_status = _aidl_reply.readBoolVector(goes_out);
137bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
138bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
139bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
140bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_error:
141bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_status.setFromStatusT(_aidl_ret_status);
142bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongreturn _aidl_status;
143bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
144bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong
145bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) {
146bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong::android::Parcel _aidl_data;
147bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong::android::Parcel _aidl_reply;
14800f471711684903fd747e7871edf437ca54ed397Yifan Hong::android::status_t _aidl_ret_status = ::android::OK;
14900f471711684903fd747e7871edf437ca54ed397Yifan Hong::android::binder::Status _aidl_status;
150244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
151244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
1522831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Hubergoto _aidl_error;
1532831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber}
1542831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber_aidl_ret_status = _aidl_data.writeInt32(times);
1552831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huberif (((_aidl_ret_status) != (::android::OK))) {
1562831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Hubergoto _aidl_error;
1572831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber}
15885eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber_aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY);
15985eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
16085eabdbe56720dcdcf130e5ca83129d47b143768Andreas Hubergoto _aidl_error;
16185eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber}
16285eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber_aidl_error:
16385eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber_aidl_status.setFromStatusT(_aidl_ret_status);
1644c865b72b320a46f326a335cfd326b66b0e10f67Andreas Huberreturn _aidl_status;
165709b62dbda6184770bb34470ff550e02c1643e67Andreas Huber}
16685eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber
16785eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) {
16885eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::Parcel _aidl_data;
16985eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::Parcel _aidl_reply;
17085eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::status_t _aidl_ret_status = ::android::OK;
171881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber::android::binder::Status _aidl_status;
172881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
173e3f769aa75dd6be6bb1ba83904def47d9e464769Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
174e3f769aa75dd6be6bb1ba83904def47d9e464769Andreas Hubergoto _aidl_error;
175e3f769aa75dd6be6bb1ba83904def47d9e464769Andreas Huber}
176e3f769aa75dd6be6bb1ba83904def47d9e464769Andreas Huber_aidl_ret_status = _aidl_data.writeStrongBinder(IFooType::asBinder(f));
177244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
178244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Honggoto _aidl_error;
179244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong}
180244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply);
181881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
182881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
183881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
18485eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
18585eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
1862831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Hubergoto _aidl_error;
187881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
188bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (!_aidl_status.isOk()) {
189881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberreturn _aidl_status;
190881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
1915158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhang_aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return);
1925158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhangif (((_aidl_ret_status) != (::android::OK))) {
1935158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhanggoto _aidl_error;
194864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang}
195864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang_aidl_error:
196864c771ca4ec8a01e31c7c243625b7a5f6316768Zhuoyao Zhang_aidl_status.setFromStatusT(_aidl_ret_status);
1975158db484e5ab302368f191d75d5b1334c270e52Zhuoyao Zhangreturn _aidl_status;
19870a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber}
19970a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber
20070a59e1dc3dcf32f791d2dd7966111d4adf32ecaAndreas Huber::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) {
20185eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::Parcel _aidl_data;
20285eabdbe56720dcdcf130e5ca83129d47b143768Andreas Huber::android::Parcel _aidl_reply;
2037c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber::android::status_t _aidl_ret_status = ::android::OK;
2047c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber::android::binder::Status _aidl_status;
2057c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
206019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
207019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Hubergoto _aidl_error;
208019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huber}
2091c507273be6a1beefbe7ef6ec63992a7cf66c4f8Andreas Huber_aidl_ret_status = _aidl_data.writeString16Vector(input);
210019d21db821ee4ae6dd3858174a0a5cee4d33c25Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
211881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
212881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
213881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply);
214881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
215881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
216881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
217881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
218881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
219881227d860c59471eee31d39946e96ce2daa35d6Andreas Hubergoto _aidl_error;
220881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
221881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (!_aidl_status.isOk()) {
222881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberreturn _aidl_status;
223881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber}
224881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return);
225881227d860c59471eee31d39946e96ce2daa35d6Andreas Huberif (((_aidl_ret_status) != (::android::OK))) {
226244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Honggoto _aidl_error;
227244e82d34bf0ef5d8d5b0730a9dea3e3fc4de7c5Yifan Hong}
228881227d860c59471eee31d39946e96ce2daa35d6Andreas Huber_aidl_ret_status = _aidl_reply.readString16Vector(output);
2292831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huberif (((_aidl_ret_status) != (::android::OK))) {
2302831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Hubergoto _aidl_error;
2312831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber}
2322831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber_aidl_error:
2332831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber_aidl_status.setFromStatusT(_aidl_ret_status);
2342831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huberreturn _aidl_status;
2352831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber}
2362831d5145675ead9f2fb767bf5fe4ae56b88349fAndreas Huber
237c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber::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) {
2387c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber::android::Parcel _aidl_data;
2397c5ddfb41a806a7bf71581952d06b637a7670cf7Andreas Huber::android::Parcel _aidl_reply;
240c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber::android::status_t _aidl_ret_status = ::android::OK;
241c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber::android::binder::Status _aidl_status;
242c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
243bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
244bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
245bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
24630bb6a869be0f3f82497b7b11c71ec9d47652ed0Steven Moreland_aidl_ret_status = _aidl_data.writeStrongBinderVector(input);
247bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
248bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
249bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
250bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong_aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply);
251bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hongif (((_aidl_ret_status) != (::android::OK))) {
252bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Honggoto _aidl_error;
253bf459bcedc2ab1a22a9cc290fbcc0a5462e63690Yifan Hong}
254c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
255c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huberif (((_aidl_ret_status) != (::android::OK))) {
256c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Hubergoto _aidl_error;
257c9410c7e62a33fd7599b2f3e025093a2d171577eAndreas Huber}
258if (!_aidl_status.isOk()) {
259return _aidl_status;
260}
261_aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return);
262if (((_aidl_ret_status) != (::android::OK))) {
263goto _aidl_error;
264}
265_aidl_ret_status = _aidl_reply.readStrongBinderVector(output);
266if (((_aidl_ret_status) != (::android::OK))) {
267goto _aidl_error;
268}
269_aidl_error:
270_aidl_status.setFromStatusT(_aidl_ret_status);
271return _aidl_status;
272}
273
274::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) {
275::android::Parcel _aidl_data;
276::android::Parcel _aidl_reply;
277::android::status_t _aidl_ret_status = ::android::OK;
278::android::binder::Status _aidl_status;
279_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
280if (((_aidl_ret_status) != (::android::OK))) {
281goto _aidl_error;
282}
283_aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f);
284if (((_aidl_ret_status) != (::android::OK))) {
285goto _aidl_error;
286}
287_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply);
288if (((_aidl_ret_status) != (::android::OK))) {
289goto _aidl_error;
290}
291_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
292if (((_aidl_ret_status) != (::android::OK))) {
293goto _aidl_error;
294}
295if (!_aidl_status.isOk()) {
296return _aidl_status;
297}
298_aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return);
299if (((_aidl_ret_status) != (::android::OK))) {
300goto _aidl_error;
301}
302_aidl_error:
303_aidl_status.setFromStatusT(_aidl_ret_status);
304return _aidl_status;
305}
306
307::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) {
308::android::Parcel _aidl_data;
309::android::Parcel _aidl_reply;
310::android::status_t _aidl_ret_status = ::android::OK;
311::android::binder::Status _aidl_status;
312_aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
313if (((_aidl_ret_status) != (::android::OK))) {
314goto _aidl_error;
315}
316_aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f);
317if (((_aidl_ret_status) != (::android::OK))) {
318goto _aidl_error;
319}
320_aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply);
321if (((_aidl_ret_status) != (::android::OK))) {
322goto _aidl_error;
323}
324_aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
325if (((_aidl_ret_status) != (::android::OK))) {
326goto _aidl_error;
327}
328if (!_aidl_status.isOk()) {
329return _aidl_status;
330}
331_aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return);
332if (((_aidl_ret_status) != (::android::OK))) {
333goto _aidl_error;
334}
335_aidl_error:
336_aidl_status.setFromStatusT(_aidl_ret_status);
337return _aidl_status;
338}
339
340}  // namespace os
341
342}  // namespace android
343)";
344
345const char kExpectedComplexTypeServerHeaderOutput[] =
346R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
347#define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_
348
349#include <binder/IInterface.h>
350#include <android/os/IComplexTypeInterface.h>
351
352namespace android {
353
354namespace os {
355
356class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> {
357public:
358::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags = 0) override;
359};  // class BnComplexTypeInterface
360
361}  // namespace os
362
363}  // namespace android
364
365#endif  // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_)";
366
367const char kExpectedComplexTypeServerSourceOutput[] =
368R"(#include <android/os/BnComplexTypeInterface.h>
369#include <binder/Parcel.h>
370
371namespace android {
372
373namespace os {
374
375::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
376::android::status_t _aidl_ret_status = ::android::OK;
377switch (_aidl_code) {
378case Call::SEND:
379{
380::std::unique_ptr<::std::vector<int32_t>> in_goes_in;
381::std::vector<double> in_goes_in_and_out;
382::std::vector<bool> out_goes_out;
383::std::vector<int32_t> _aidl_return;
384if (!(_aidl_data.checkInterface(this))) {
385_aidl_ret_status = ::android::BAD_TYPE;
386break;
387}
388_aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in);
389if (((_aidl_ret_status) != (::android::OK))) {
390break;
391}
392_aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out);
393if (((_aidl_ret_status) != (::android::OK))) {
394break;
395}
396::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return));
397_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
398if (((_aidl_ret_status) != (::android::OK))) {
399break;
400}
401if (!_aidl_status.isOk()) {
402break;
403}
404_aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return);
405if (((_aidl_ret_status) != (::android::OK))) {
406break;
407}
408_aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out);
409if (((_aidl_ret_status) != (::android::OK))) {
410break;
411}
412_aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out);
413if (((_aidl_ret_status) != (::android::OK))) {
414break;
415}
416}
417break;
418case Call::PIFF:
419{
420int32_t in_times;
421if (!(_aidl_data.checkInterface(this))) {
422_aidl_ret_status = ::android::BAD_TYPE;
423break;
424}
425_aidl_ret_status = _aidl_data.readInt32(&in_times);
426if (((_aidl_ret_status) != (::android::OK))) {
427break;
428}
429::android::binder::Status _aidl_status(Piff(in_times));
430}
431break;
432case Call::TAKESABINDER:
433{
434::android::sp<::foo::IFooType> in_f;
435::android::sp<::foo::IFooType> _aidl_return;
436if (!(_aidl_data.checkInterface(this))) {
437_aidl_ret_status = ::android::BAD_TYPE;
438break;
439}
440_aidl_ret_status = _aidl_data.readStrongBinder(&in_f);
441if (((_aidl_ret_status) != (::android::OK))) {
442break;
443}
444::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return));
445_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
446if (((_aidl_ret_status) != (::android::OK))) {
447break;
448}
449if (!_aidl_status.isOk()) {
450break;
451}
452_aidl_ret_status = _aidl_reply->writeStrongBinder(IFooType::asBinder(_aidl_return));
453if (((_aidl_ret_status) != (::android::OK))) {
454break;
455}
456}
457break;
458case Call::STRINGLISTMETHOD:
459{
460::std::vector<::android::String16> in_input;
461::std::vector<::android::String16> out_output;
462::std::vector<::android::String16> _aidl_return;
463if (!(_aidl_data.checkInterface(this))) {
464_aidl_ret_status = ::android::BAD_TYPE;
465break;
466}
467_aidl_ret_status = _aidl_data.readString16Vector(&in_input);
468if (((_aidl_ret_status) != (::android::OK))) {
469break;
470}
471::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return));
472_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
473if (((_aidl_ret_status) != (::android::OK))) {
474break;
475}
476if (!_aidl_status.isOk()) {
477break;
478}
479_aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return);
480if (((_aidl_ret_status) != (::android::OK))) {
481break;
482}
483_aidl_ret_status = _aidl_reply->writeString16Vector(out_output);
484if (((_aidl_ret_status) != (::android::OK))) {
485break;
486}
487}
488break;
489case Call::BINDERLISTMETHOD:
490{
491::std::vector<::android::sp<::android::IBinder>> in_input;
492::std::vector<::android::sp<::android::IBinder>> out_output;
493::std::vector<::android::sp<::android::IBinder>> _aidl_return;
494if (!(_aidl_data.checkInterface(this))) {
495_aidl_ret_status = ::android::BAD_TYPE;
496break;
497}
498_aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input);
499if (((_aidl_ret_status) != (::android::OK))) {
500break;
501}
502::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return));
503_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
504if (((_aidl_ret_status) != (::android::OK))) {
505break;
506}
507if (!_aidl_status.isOk()) {
508break;
509}
510_aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return);
511if (((_aidl_ret_status) != (::android::OK))) {
512break;
513}
514_aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output);
515if (((_aidl_ret_status) != (::android::OK))) {
516break;
517}
518}
519break;
520case Call::TAKESAFILEDESCRIPTOR:
521{
522::ScopedFd in_f;
523::ScopedFd _aidl_return;
524if (!(_aidl_data.checkInterface(this))) {
525_aidl_ret_status = ::android::BAD_TYPE;
526break;
527}
528_aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f);
529if (((_aidl_ret_status) != (::android::OK))) {
530break;
531}
532::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return));
533_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
534if (((_aidl_ret_status) != (::android::OK))) {
535break;
536}
537if (!_aidl_status.isOk()) {
538break;
539}
540_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return);
541if (((_aidl_ret_status) != (::android::OK))) {
542break;
543}
544}
545break;
546case Call::TAKESAFILEDESCRIPTORARRAY:
547{
548::std::vector<::ScopedFd> in_f;
549::std::vector<::ScopedFd> _aidl_return;
550if (!(_aidl_data.checkInterface(this))) {
551_aidl_ret_status = ::android::BAD_TYPE;
552break;
553}
554_aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f);
555if (((_aidl_ret_status) != (::android::OK))) {
556break;
557}
558::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return));
559_aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
560if (((_aidl_ret_status) != (::android::OK))) {
561break;
562}
563if (!_aidl_status.isOk()) {
564break;
565}
566_aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return);
567if (((_aidl_ret_status) != (::android::OK))) {
568break;
569}
570}
571break;
572default:
573{
574_aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
575}
576break;
577}
578if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
579_aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
580}
581return _aidl_ret_status;
582}
583
584}  // namespace os
585
586}  // namespace android
587)";
588
589const char kExpectedComplexTypeInterfaceHeaderOutput[] =
590R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
591#define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_
592
593#include <binder/IBinder.h>
594#include <binder/IInterface.h>
595#include <binder/Status.h>
596#include <cstdint>
597#include <foo/IFooType.h>
598#include <nativehelper/ScopedFd.h>
599#include <utils/String16.h>
600#include <utils/StrongPointer.h>
601#include <vector>
602
603namespace android {
604
605namespace os {
606
607class IComplexTypeInterface : public ::android::IInterface {
608public:
609DECLARE_META_INTERFACE(ComplexTypeInterface);
610static constexpr int32_t MY_CONSTANT = 3;
611virtual ::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;
612virtual ::android::binder::Status Piff(int32_t times) = 0;
613virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0;
614virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0;
615virtual ::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;
616virtual ::android::binder::Status TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) = 0;
617virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) = 0;
618enum Call {
619  SEND = ::android::IBinder::FIRST_CALL_TRANSACTION + 0,
620  PIFF = ::android::IBinder::FIRST_CALL_TRANSACTION + 1,
621  TAKESABINDER = ::android::IBinder::FIRST_CALL_TRANSACTION + 2,
622  STRINGLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 3,
623  BINDERLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 4,
624  TAKESAFILEDESCRIPTOR = ::android::IBinder::FIRST_CALL_TRANSACTION + 5,
625  TAKESAFILEDESCRIPTORARRAY = ::android::IBinder::FIRST_CALL_TRANSACTION + 6,
626};
627};  // class IComplexTypeInterface
628
629}  // namespace os
630
631}  // namespace android
632
633#endif  // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_)";
634
635const char kExpectedComplexTypeInterfaceSourceOutput[] =
636R"(#include <android/os/IComplexTypeInterface.h>
637#include <android/os/BpComplexTypeInterface.h>
638
639namespace android {
640
641namespace os {
642
643IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface");
644
645}  // namespace os
646
647}  // namespace android
648)";
649
650}  // namespace
651
652class ASTTest : public ::testing::Test {
653 protected:
654  ASTTest(string file_path, string file_contents)
655      : file_path_(file_path),
656        file_contents_(file_contents) {
657    types_.Init();
658  }
659
660  unique_ptr<AidlInterface> Parse() {
661    io_delegate_.SetFileContents(file_path_, file_contents_);
662
663    unique_ptr<AidlInterface> ret;
664    std::vector<std::unique_ptr<AidlImport>> imports;
665    AidlError err = ::android::aidl::internals::load_and_validate_aidl(
666        {},  // no preprocessed files
667        {"."},
668        file_path_,
669        io_delegate_,
670        &types_,
671        &ret,
672        &imports);
673
674    if (err != AidlError::OK)
675      return nullptr;
676
677    return ret;
678  }
679
680  void Compare(Document* doc, const char* expected) {
681    string output;
682    unique_ptr<CodeWriter> cw = GetStringWriter(&output);
683
684    doc->Write(cw.get());
685
686    if (expected == output) {
687      return; // Success
688    }
689
690    test::PrintDiff(expected, output);
691    FAIL() << "Document contents did not match expected contents";
692  }
693
694  const string file_path_;
695  const string file_contents_;
696  FakeIoDelegate io_delegate_;
697  TypeNamespace types_;
698};
699
700class ComplexTypeInterfaceASTTest : public ASTTest {
701 public:
702  ComplexTypeInterfaceASTTest()
703      : ASTTest("android/os/IComplexTypeInterface.aidl",
704                kComplexTypeInterfaceAIDL) {
705    io_delegate_.SetFileContents("foo/IFooType.aidl",
706                                 "package foo; interface IFooType {}");
707  }
708};
709
710TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) {
711  unique_ptr<AidlInterface> interface = Parse();
712  ASSERT_NE(interface, nullptr);
713  unique_ptr<Document> doc = internals::BuildClientHeader(types_, *interface);
714  Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput);
715}
716
717TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) {
718  unique_ptr<AidlInterface> interface = Parse();
719  ASSERT_NE(interface, nullptr);
720  unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface);
721  Compare(doc.get(), kExpectedComplexTypeClientSourceOutput);
722}
723
724TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) {
725  unique_ptr<AidlInterface> interface = Parse();
726  ASSERT_NE(interface, nullptr);
727  unique_ptr<Document> doc = internals::BuildServerHeader(types_, *interface);
728  Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput);
729}
730
731TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) {
732  unique_ptr<AidlInterface> interface = Parse();
733  ASSERT_NE(interface, nullptr);
734  unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface);
735  Compare(doc.get(), kExpectedComplexTypeServerSourceOutput);
736}
737
738TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) {
739  unique_ptr<AidlInterface> interface = Parse();
740  ASSERT_NE(interface, nullptr);
741  unique_ptr<Document> doc = internals::BuildInterfaceHeader(types_, *interface);
742  Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput);
743}
744
745TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) {
746  unique_ptr<AidlInterface> interface = Parse();
747  ASSERT_NE(interface, nullptr);
748  unique_ptr<Document> doc = internals::BuildInterfaceSource(types_, *interface);
749  Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput);
750}
751
752namespace test_io_handling {
753
754const char kInputPath[] = "a/IFoo.aidl";
755const char kOutputPath[] = "output.cpp";
756const char kHeaderDir[] = "headers";
757const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
758
759}  // namespace test_io_handling
760
761class IoErrorHandlingTest : public ASTTest {
762 public:
763  IoErrorHandlingTest ()
764      : ASTTest(test_io_handling::kInputPath,
765                "package a; interface IFoo {}"),
766        options_(GetOptions()) {}
767
768  const unique_ptr<CppOptions> options_;
769
770 private:
771  static unique_ptr<CppOptions> GetOptions() {
772    using namespace test_io_handling;
773
774    const int argc = 4;
775    const char* cmdline[argc] = {
776      "aidl-cpp", kInputPath, kHeaderDir, kOutputPath
777    };
778    return CppOptions::Parse(argc, cmdline);
779  }
780};
781
782TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
783  // Confirm that this is working correctly without I/O problems.
784  const unique_ptr<AidlInterface> interface = Parse();
785  ASSERT_NE(interface, nullptr);
786  ASSERT_TRUE(GenerateCpp(*options_, types_, *interface, io_delegate_));
787}
788
789TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
790  using namespace test_io_handling;
791  const unique_ptr<AidlInterface> interface = Parse();
792  ASSERT_NE(interface, nullptr);
793
794  // Simulate issues closing the interface header.
795  const string header_path =
796      StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
797                   kInterfaceHeaderRelPath);
798  io_delegate_.AddBrokenFilePath(header_path);
799  ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_));
800  // We should never attempt to write the C++ file if we fail writing headers.
801  ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
802  // We should remove partial results.
803  ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path));
804}
805
806TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) {
807  using test_io_handling::kOutputPath;
808  const unique_ptr<AidlInterface> interface = Parse();
809  ASSERT_NE(interface, nullptr);
810
811  // Simulate issues closing the cpp file.
812  io_delegate_.AddBrokenFilePath(kOutputPath);
813  ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_));
814  // We should remove partial results.
815  ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
816}
817
818}  // namespace cpp
819}  // namespace aidl
820}  // namespace android
821