| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 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 | |
| 17 | #include <string> |
| 18 | |
| Elliott Hughes | 0a62067 | 2015-12-04 13:53:18 -0800 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 20 | #include <gtest/gtest.h> |
| 21 | |
| Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 22 | #include "aidl.h" |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 23 | #include "aidl_language.h" |
| 24 | #include "ast_cpp.h" |
| 25 | #include "code_writer.h" |
| Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 26 | #include "generate_cpp.h" |
| Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 27 | #include "os.h" |
| Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 28 | #include "tests/fake_io_delegate.h" |
| Casey Dahlin | 80ada3d | 2015-10-20 20:33:56 -0700 | [diff] [blame] | 29 | #include "tests/test_util.h" |
| Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 30 | #include "type_cpp.h" |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 31 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 32 | using ::android::aidl::test::FakeIoDelegate; |
| 33 | using ::android::base::StringPrintf; |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 34 | using std::string; |
| 35 | using std::unique_ptr; |
| 36 | |
| 37 | namespace android { |
| 38 | namespace aidl { |
| Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 39 | namespace cpp { |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 40 | namespace { |
| 41 | |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 42 | const string kComplexTypeInterfaceAIDL = |
| 43 | R"(package android.os; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 44 | import foo.IFooType; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 45 | interface IComplexTypeInterface { |
| Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 46 | const int MY_CONSTANT = 3; |
| Casey Dahlin | cb5317d | 2015-12-03 15:43:33 -0800 | [diff] [blame] | 47 | int[] Send(in @nullable int[] goes_in, inout double[] goes_in_and_out, out boolean[] goes_out); |
| Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 48 | oneway void Piff(int times); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 49 | IFooType TakesABinder(IFooType f); |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 50 | List<String> StringListMethod(in java.util.List<String> input, out List<String> output); |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 51 | List<IBinder> BinderListMethod(in java.util.List<IBinder> input, out List<IBinder> output); |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 52 | FileDescriptor TakesAFileDescriptor(in FileDescriptor f); |
| 53 | FileDescriptor[] TakesAFileDescriptorArray(in FileDescriptor[] f); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 54 | })"; |
| 55 | |
| 56 | const char kExpectedComplexTypeClientHeaderOutput[] = |
| 57 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_ |
| 58 | #define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_ |
| 59 | |
| 60 | #include <binder/IBinder.h> |
| 61 | #include <binder/IInterface.h> |
| 62 | #include <utils/Errors.h> |
| 63 | #include <android/os/IComplexTypeInterface.h> |
| 64 | |
| 65 | namespace android { |
| 66 | |
| 67 | namespace os { |
| 68 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 69 | class BpComplexTypeInterface : public ::android::BpInterface<IComplexTypeInterface> { |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 70 | public: |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 71 | explicit BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 72 | virtual ~BpComplexTypeInterface() = default; |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 73 | ::android::binder::Status Send(const ::std::unique_ptr<::std::vector<int32_t>>& goes_in, ::std::vector<double>* goes_in_and_out, ::std::vector<bool>* goes_out, ::std::vector<int32_t>* _aidl_return) override; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 74 | ::android::binder::Status Piff(int32_t times) override; |
| 75 | ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) override; |
| 76 | ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) override; |
| 77 | ::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; |
| 78 | ::android::binder::Status TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) override; |
| 79 | ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) override; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 80 | }; // class BpComplexTypeInterface |
| 81 | |
| 82 | } // namespace os |
| 83 | |
| 84 | } // namespace android |
| 85 | |
| Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame^] | 86 | #endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_ |
| 87 | )"; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 88 | |
| 89 | const char kExpectedComplexTypeClientSourceOutput[] = |
| 90 | R"(#include <android/os/BpComplexTypeInterface.h> |
| 91 | #include <binder/Parcel.h> |
| 92 | |
| 93 | namespace android { |
| 94 | |
| 95 | namespace os { |
| 96 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 97 | BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl) |
| 98 | : BpInterface<IComplexTypeInterface>(_aidl_impl){ |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 101 | ::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) { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 102 | ::android::Parcel _aidl_data; |
| 103 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 104 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 105 | ::android::binder::Status _aidl_status; |
| 106 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 107 | if (((_aidl_ret_status) != (::android::OK))) { |
| 108 | goto _aidl_error; |
| Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 109 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 110 | _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in); |
| 111 | if (((_aidl_ret_status) != (::android::OK))) { |
| 112 | goto _aidl_error; |
| Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 113 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 114 | _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out); |
| 115 | if (((_aidl_ret_status) != (::android::OK))) { |
| 116 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 117 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 118 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply); |
| 119 | if (((_aidl_ret_status) != (::android::OK))) { |
| 120 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 121 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 122 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 123 | if (((_aidl_ret_status) != (::android::OK))) { |
| 124 | goto _aidl_error; |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 125 | } |
| 126 | if (!_aidl_status.isOk()) { |
| 127 | return _aidl_status; |
| Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 128 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 129 | _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return); |
| 130 | if (((_aidl_ret_status) != (::android::OK))) { |
| 131 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 132 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 133 | _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out); |
| 134 | if (((_aidl_ret_status) != (::android::OK))) { |
| 135 | goto _aidl_error; |
| Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 136 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 137 | _aidl_ret_status = _aidl_reply.readBoolVector(goes_out); |
| 138 | if (((_aidl_ret_status) != (::android::OK))) { |
| 139 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 140 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 141 | _aidl_error: |
| 142 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 143 | return _aidl_status; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 146 | ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) { |
| 147 | ::android::Parcel _aidl_data; |
| 148 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 149 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 150 | ::android::binder::Status _aidl_status; |
| 151 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 152 | if (((_aidl_ret_status) != (::android::OK))) { |
| 153 | goto _aidl_error; |
| Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 154 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 155 | _aidl_ret_status = _aidl_data.writeInt32(times); |
| 156 | if (((_aidl_ret_status) != (::android::OK))) { |
| 157 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 158 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 159 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY); |
| 160 | if (((_aidl_ret_status) != (::android::OK))) { |
| 161 | goto _aidl_error; |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 162 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 163 | _aidl_error: |
| 164 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 165 | return _aidl_status; |
| Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 168 | ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) { |
| 169 | ::android::Parcel _aidl_data; |
| 170 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 171 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 172 | ::android::binder::Status _aidl_status; |
| 173 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 174 | if (((_aidl_ret_status) != (::android::OK))) { |
| 175 | goto _aidl_error; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 176 | } |
| Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 177 | _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f)); |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 178 | if (((_aidl_ret_status) != (::android::OK))) { |
| 179 | goto _aidl_error; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 180 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 181 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply); |
| 182 | if (((_aidl_ret_status) != (::android::OK))) { |
| 183 | goto _aidl_error; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 184 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 185 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 186 | if (((_aidl_ret_status) != (::android::OK))) { |
| 187 | goto _aidl_error; |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 188 | } |
| 189 | if (!_aidl_status.isOk()) { |
| 190 | return _aidl_status; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 191 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 192 | _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return); |
| 193 | if (((_aidl_ret_status) != (::android::OK))) { |
| 194 | goto _aidl_error; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 195 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 196 | _aidl_error: |
| 197 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 198 | return _aidl_status; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 201 | ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) { |
| 202 | ::android::Parcel _aidl_data; |
| 203 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 204 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 205 | ::android::binder::Status _aidl_status; |
| 206 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 207 | if (((_aidl_ret_status) != (::android::OK))) { |
| 208 | goto _aidl_error; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 209 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 210 | _aidl_ret_status = _aidl_data.writeString16Vector(input); |
| 211 | if (((_aidl_ret_status) != (::android::OK))) { |
| 212 | goto _aidl_error; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 213 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 214 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply); |
| 215 | if (((_aidl_ret_status) != (::android::OK))) { |
| 216 | goto _aidl_error; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 217 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 218 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 219 | if (((_aidl_ret_status) != (::android::OK))) { |
| 220 | goto _aidl_error; |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 221 | } |
| 222 | if (!_aidl_status.isOk()) { |
| 223 | return _aidl_status; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 224 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 225 | _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return); |
| 226 | if (((_aidl_ret_status) != (::android::OK))) { |
| 227 | goto _aidl_error; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 228 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 229 | _aidl_ret_status = _aidl_reply.readString16Vector(output); |
| 230 | if (((_aidl_ret_status) != (::android::OK))) { |
| 231 | goto _aidl_error; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 232 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 233 | _aidl_error: |
| 234 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 235 | return _aidl_status; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 238 | ::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) { |
| 239 | ::android::Parcel _aidl_data; |
| 240 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 241 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 242 | ::android::binder::Status _aidl_status; |
| 243 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 244 | if (((_aidl_ret_status) != (::android::OK))) { |
| 245 | goto _aidl_error; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 246 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 247 | _aidl_ret_status = _aidl_data.writeStrongBinderVector(input); |
| 248 | if (((_aidl_ret_status) != (::android::OK))) { |
| 249 | goto _aidl_error; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 250 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 251 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply); |
| 252 | if (((_aidl_ret_status) != (::android::OK))) { |
| 253 | goto _aidl_error; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 254 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 255 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 256 | if (((_aidl_ret_status) != (::android::OK))) { |
| 257 | goto _aidl_error; |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 258 | } |
| 259 | if (!_aidl_status.isOk()) { |
| 260 | return _aidl_status; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 261 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 262 | _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return); |
| 263 | if (((_aidl_ret_status) != (::android::OK))) { |
| 264 | goto _aidl_error; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 265 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 266 | _aidl_ret_status = _aidl_reply.readStrongBinderVector(output); |
| 267 | if (((_aidl_ret_status) != (::android::OK))) { |
| 268 | goto _aidl_error; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 269 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 270 | _aidl_error: |
| 271 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 272 | return _aidl_status; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 275 | ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) { |
| 276 | ::android::Parcel _aidl_data; |
| 277 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 278 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 279 | ::android::binder::Status _aidl_status; |
| 280 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 281 | if (((_aidl_ret_status) != (::android::OK))) { |
| 282 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 283 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 284 | _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f); |
| 285 | if (((_aidl_ret_status) != (::android::OK))) { |
| 286 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 287 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 288 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply); |
| 289 | if (((_aidl_ret_status) != (::android::OK))) { |
| 290 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 291 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 292 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 293 | if (((_aidl_ret_status) != (::android::OK))) { |
| 294 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 295 | } |
| 296 | if (!_aidl_status.isOk()) { |
| 297 | return _aidl_status; |
| 298 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 299 | _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return); |
| 300 | if (((_aidl_ret_status) != (::android::OK))) { |
| 301 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 302 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 303 | _aidl_error: |
| 304 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 305 | return _aidl_status; |
| 306 | } |
| 307 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 308 | ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) { |
| 309 | ::android::Parcel _aidl_data; |
| 310 | ::android::Parcel _aidl_reply; |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 311 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 312 | ::android::binder::Status _aidl_status; |
| 313 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 314 | if (((_aidl_ret_status) != (::android::OK))) { |
| 315 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 316 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 317 | _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f); |
| 318 | if (((_aidl_ret_status) != (::android::OK))) { |
| 319 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 320 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 321 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply); |
| 322 | if (((_aidl_ret_status) != (::android::OK))) { |
| 323 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 324 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 325 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 326 | if (((_aidl_ret_status) != (::android::OK))) { |
| 327 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 328 | } |
| 329 | if (!_aidl_status.isOk()) { |
| 330 | return _aidl_status; |
| 331 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 332 | _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return); |
| 333 | if (((_aidl_ret_status) != (::android::OK))) { |
| 334 | goto _aidl_error; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 335 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 336 | _aidl_error: |
| 337 | _aidl_status.setFromStatusT(_aidl_ret_status); |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 338 | return _aidl_status; |
| 339 | } |
| 340 | |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 341 | } // namespace os |
| 342 | |
| 343 | } // namespace android |
| 344 | )"; |
| 345 | |
| 346 | const char kExpectedComplexTypeServerHeaderOutput[] = |
| 347 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_ |
| 348 | #define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_ |
| 349 | |
| 350 | #include <binder/IInterface.h> |
| 351 | #include <android/os/IComplexTypeInterface.h> |
| 352 | |
| 353 | namespace android { |
| 354 | |
| 355 | namespace os { |
| 356 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 357 | class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> { |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 358 | public: |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 359 | ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags = 0) override; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 360 | }; // class BnComplexTypeInterface |
| 361 | |
| 362 | } // namespace os |
| 363 | |
| 364 | } // namespace android |
| 365 | |
| Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame^] | 366 | #endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_ |
| 367 | )"; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 368 | |
| 369 | const char kExpectedComplexTypeServerSourceOutput[] = |
| 370 | R"(#include <android/os/BnComplexTypeInterface.h> |
| 371 | #include <binder/Parcel.h> |
| 372 | |
| 373 | namespace android { |
| 374 | |
| 375 | namespace os { |
| 376 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 377 | ::android::status_t BnComplexTypeInterface::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) { |
| Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 378 | ::android::status_t _aidl_ret_status = ::android::OK; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 379 | switch (_aidl_code) { |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 380 | case Call::SEND: |
| 381 | { |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 382 | ::std::unique_ptr<::std::vector<int32_t>> in_goes_in; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 383 | ::std::vector<double> in_goes_in_and_out; |
| 384 | ::std::vector<bool> out_goes_out; |
| 385 | ::std::vector<int32_t> _aidl_return; |
| 386 | if (!(_aidl_data.checkInterface(this))) { |
| 387 | _aidl_ret_status = ::android::BAD_TYPE; |
| Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 388 | break; |
| 389 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 390 | _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in); |
| 391 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 392 | break; |
| 393 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 394 | _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out); |
| 395 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 396 | break; |
| 397 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 398 | ::android::binder::Status _aidl_status(Send(in_goes_in, &in_goes_in_and_out, &out_goes_out, &_aidl_return)); |
| 399 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 400 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 401 | break; |
| 402 | } |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 403 | if (!_aidl_status.isOk()) { |
| Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 404 | break; |
| 405 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 406 | _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return); |
| 407 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 408 | break; |
| 409 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 410 | _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out); |
| 411 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 412 | break; |
| 413 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 414 | _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out); |
| 415 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 416 | break; |
| 417 | } |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 418 | } |
| 419 | break; |
| Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 420 | case Call::PIFF: |
| 421 | { |
| 422 | int32_t in_times; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 423 | if (!(_aidl_data.checkInterface(this))) { |
| 424 | _aidl_ret_status = ::android::BAD_TYPE; |
| Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 425 | break; |
| 426 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 427 | _aidl_ret_status = _aidl_data.readInt32(&in_times); |
| 428 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 429 | break; |
| 430 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 431 | ::android::binder::Status _aidl_status(Piff(in_times)); |
| Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 432 | } |
| 433 | break; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 434 | case Call::TAKESABINDER: |
| 435 | { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 436 | ::android::sp<::foo::IFooType> in_f; |
| 437 | ::android::sp<::foo::IFooType> _aidl_return; |
| 438 | if (!(_aidl_data.checkInterface(this))) { |
| 439 | _aidl_ret_status = ::android::BAD_TYPE; |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 440 | break; |
| 441 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 442 | _aidl_ret_status = _aidl_data.readStrongBinder(&in_f); |
| 443 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 444 | break; |
| 445 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 446 | ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return)); |
| 447 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 448 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 449 | break; |
| 450 | } |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 451 | if (!_aidl_status.isOk()) { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 452 | break; |
| 453 | } |
| Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame] | 454 | _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return)); |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 455 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 456 | break; |
| 457 | } |
| 458 | } |
| 459 | break; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 460 | case Call::STRINGLISTMETHOD: |
| 461 | { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 462 | ::std::vector<::android::String16> in_input; |
| 463 | ::std::vector<::android::String16> out_output; |
| 464 | ::std::vector<::android::String16> _aidl_return; |
| 465 | if (!(_aidl_data.checkInterface(this))) { |
| 466 | _aidl_ret_status = ::android::BAD_TYPE; |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 467 | break; |
| 468 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 469 | _aidl_ret_status = _aidl_data.readString16Vector(&in_input); |
| 470 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 471 | break; |
| 472 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 473 | ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return)); |
| 474 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 475 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 476 | break; |
| 477 | } |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 478 | if (!_aidl_status.isOk()) { |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 479 | break; |
| 480 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 481 | _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return); |
| 482 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 483 | break; |
| 484 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 485 | _aidl_ret_status = _aidl_reply->writeString16Vector(out_output); |
| 486 | if (((_aidl_ret_status) != (::android::OK))) { |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 487 | break; |
| 488 | } |
| 489 | } |
| 490 | break; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 491 | case Call::BINDERLISTMETHOD: |
| 492 | { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 493 | ::std::vector<::android::sp<::android::IBinder>> in_input; |
| 494 | ::std::vector<::android::sp<::android::IBinder>> out_output; |
| 495 | ::std::vector<::android::sp<::android::IBinder>> _aidl_return; |
| 496 | if (!(_aidl_data.checkInterface(this))) { |
| 497 | _aidl_ret_status = ::android::BAD_TYPE; |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 498 | break; |
| 499 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 500 | _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input); |
| 501 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 502 | break; |
| 503 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 504 | ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return)); |
| 505 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 506 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 507 | break; |
| 508 | } |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 509 | if (!_aidl_status.isOk()) { |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 510 | break; |
| 511 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 512 | _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return); |
| 513 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 514 | break; |
| 515 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 516 | _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output); |
| 517 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 518 | break; |
| 519 | } |
| 520 | } |
| 521 | break; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 522 | case Call::TAKESAFILEDESCRIPTOR: |
| 523 | { |
| 524 | ::ScopedFd in_f; |
| 525 | ::ScopedFd _aidl_return; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 526 | if (!(_aidl_data.checkInterface(this))) { |
| 527 | _aidl_ret_status = ::android::BAD_TYPE; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 528 | break; |
| 529 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 530 | _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f); |
| 531 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 532 | break; |
| 533 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 534 | ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return)); |
| 535 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 536 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 537 | break; |
| 538 | } |
| 539 | if (!_aidl_status.isOk()) { |
| 540 | break; |
| 541 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 542 | _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return); |
| 543 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 544 | break; |
| 545 | } |
| 546 | } |
| 547 | break; |
| 548 | case Call::TAKESAFILEDESCRIPTORARRAY: |
| 549 | { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 550 | ::std::vector<::ScopedFd> in_f; |
| 551 | ::std::vector<::ScopedFd> _aidl_return; |
| 552 | if (!(_aidl_data.checkInterface(this))) { |
| 553 | _aidl_ret_status = ::android::BAD_TYPE; |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 554 | break; |
| 555 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 556 | _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f); |
| 557 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 558 | break; |
| 559 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 560 | ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return)); |
| 561 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 562 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 563 | break; |
| 564 | } |
| 565 | if (!_aidl_status.isOk()) { |
| 566 | break; |
| 567 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 568 | _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return); |
| 569 | if (((_aidl_ret_status) != (::android::OK))) { |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 570 | break; |
| 571 | } |
| 572 | } |
| 573 | break; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 574 | default: |
| 575 | { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 576 | _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 577 | } |
| 578 | break; |
| 579 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 580 | if (_aidl_ret_status == ::android::UNEXPECTED_NULL) { |
| 581 | _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply); |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 582 | } |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 583 | return _aidl_ret_status; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | } // namespace os |
| 587 | |
| 588 | } // namespace android |
| 589 | )"; |
| 590 | |
| 591 | const char kExpectedComplexTypeInterfaceHeaderOutput[] = |
| 592 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_ |
| 593 | #define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_ |
| 594 | |
| 595 | #include <binder/IBinder.h> |
| 596 | #include <binder/IInterface.h> |
| Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 597 | #include <binder/Status.h> |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 598 | #include <cstdint> |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 599 | #include <foo/IFooType.h> |
| Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 600 | #include <nativehelper/ScopedFd.h> |
| Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 601 | #include <utils/String16.h> |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 602 | #include <utils/StrongPointer.h> |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 603 | #include <vector> |
| 604 | |
| 605 | namespace android { |
| 606 | |
| 607 | namespace os { |
| 608 | |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 609 | class IComplexTypeInterface : public ::android::IInterface { |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 610 | public: |
| Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame^] | 611 | DECLARE_META_INTERFACE(ComplexTypeInterface) |
| Christopher Wiley | fd7dc03 | 2016-02-02 17:58:39 -0800 | [diff] [blame] | 612 | enum : int32_t { |
| 613 | MY_CONSTANT = 3, |
| 614 | }; |
| Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 615 | 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; |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 616 | virtual ::android::binder::Status Piff(int32_t times) = 0; |
| 617 | virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0; |
| 618 | virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0; |
| 619 | 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; |
| 620 | virtual ::android::binder::Status TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) = 0; |
| 621 | virtual ::android::binder::Status TakesAFileDescriptorArray(const ::std::vector<::ScopedFd>& f, ::std::vector<::ScopedFd>* _aidl_return) = 0; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 622 | enum Call { |
| Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 623 | SEND = ::android::IBinder::FIRST_CALL_TRANSACTION + 0, |
| 624 | PIFF = ::android::IBinder::FIRST_CALL_TRANSACTION + 1, |
| 625 | TAKESABINDER = ::android::IBinder::FIRST_CALL_TRANSACTION + 2, |
| 626 | STRINGLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 3, |
| 627 | BINDERLISTMETHOD = ::android::IBinder::FIRST_CALL_TRANSACTION + 4, |
| 628 | TAKESAFILEDESCRIPTOR = ::android::IBinder::FIRST_CALL_TRANSACTION + 5, |
| 629 | TAKESAFILEDESCRIPTORARRAY = ::android::IBinder::FIRST_CALL_TRANSACTION + 6, |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 630 | }; |
| 631 | }; // class IComplexTypeInterface |
| 632 | |
| 633 | } // namespace os |
| 634 | |
| 635 | } // namespace android |
| 636 | |
| Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame^] | 637 | #endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_ |
| 638 | )"; |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 639 | |
| 640 | const char kExpectedComplexTypeInterfaceSourceOutput[] = |
| 641 | R"(#include <android/os/IComplexTypeInterface.h> |
| 642 | #include <android/os/BpComplexTypeInterface.h> |
| 643 | |
| 644 | namespace android { |
| 645 | |
| 646 | namespace os { |
| 647 | |
| Christopher Wiley | 11a9d79 | 2016-02-24 17:20:33 -0800 | [diff] [blame^] | 648 | IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface") |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 649 | |
| 650 | } // namespace os |
| 651 | |
| 652 | } // namespace android |
| 653 | )"; |
| 654 | |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 655 | } // namespace |
| 656 | |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 657 | class ASTTest : public ::testing::Test { |
| Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 658 | protected: |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 659 | ASTTest(string file_path, string file_contents) |
| 660 | : file_path_(file_path), |
| Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 661 | file_contents_(file_contents) { |
| 662 | types_.Init(); |
| 663 | } |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 664 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 665 | unique_ptr<AidlInterface> Parse() { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 666 | io_delegate_.SetFileContents(file_path_, file_contents_); |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 667 | |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 668 | unique_ptr<AidlInterface> ret; |
| 669 | std::vector<std::unique_ptr<AidlImport>> imports; |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 670 | AidlError err = ::android::aidl::internals::load_and_validate_aidl( |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 671 | {}, // no preprocessed files |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 672 | {"."}, |
| 673 | file_path_, |
| 674 | io_delegate_, |
| 675 | &types_, |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 676 | &ret, |
| 677 | &imports); |
| Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 678 | |
| Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 679 | if (err != AidlError::OK) |
| Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 680 | return nullptr; |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 681 | |
| Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 682 | return ret; |
| Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 683 | } |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 684 | |
| Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 685 | void Compare(Document* doc, const char* expected) { |
| 686 | string output; |
| 687 | unique_ptr<CodeWriter> cw = GetStringWriter(&output); |
| 688 | |
| 689 | doc->Write(cw.get()); |
| 690 | |
| Casey Dahlin | 80ada3d | 2015-10-20 20:33:56 -0700 | [diff] [blame] | 691 | if (expected == output) { |
| 692 | return; // Success |
| 693 | } |
| 694 | |
| 695 | test::PrintDiff(expected, output); |
| 696 | FAIL() << "Document contents did not match expected contents"; |
| Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 697 | } |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 698 | |
| 699 | const string file_path_; |
| 700 | const string file_contents_; |
| 701 | FakeIoDelegate io_delegate_; |
| 702 | TypeNamespace types_; |
| Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 703 | }; |
| 704 | |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 705 | class ComplexTypeInterfaceASTTest : public ASTTest { |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 706 | public: |
| 707 | ComplexTypeInterfaceASTTest() |
| 708 | : ASTTest("android/os/IComplexTypeInterface.aidl", |
| 709 | kComplexTypeInterfaceAIDL) { |
| 710 | io_delegate_.SetFileContents("foo/IFooType.aidl", |
| 711 | "package foo; interface IFooType {}"); |
| 712 | } |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 713 | }; |
| 714 | |
| 715 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) { |
| 716 | unique_ptr<AidlInterface> interface = Parse(); |
| 717 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 718 | unique_ptr<Document> doc = internals::BuildClientHeader(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 719 | Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput); |
| 720 | } |
| 721 | |
| 722 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) { |
| 723 | unique_ptr<AidlInterface> interface = Parse(); |
| 724 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 725 | unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 726 | Compare(doc.get(), kExpectedComplexTypeClientSourceOutput); |
| 727 | } |
| 728 | |
| 729 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) { |
| 730 | unique_ptr<AidlInterface> interface = Parse(); |
| 731 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 732 | unique_ptr<Document> doc = internals::BuildServerHeader(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 733 | Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput); |
| 734 | } |
| 735 | |
| 736 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) { |
| 737 | unique_ptr<AidlInterface> interface = Parse(); |
| 738 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 739 | unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 740 | Compare(doc.get(), kExpectedComplexTypeServerSourceOutput); |
| 741 | } |
| 742 | |
| 743 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) { |
| 744 | unique_ptr<AidlInterface> interface = Parse(); |
| 745 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 746 | unique_ptr<Document> doc = internals::BuildInterfaceHeader(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 747 | Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput); |
| 748 | } |
| 749 | |
| 750 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) { |
| 751 | unique_ptr<AidlInterface> interface = Parse(); |
| 752 | ASSERT_NE(interface, nullptr); |
| Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 753 | unique_ptr<Document> doc = internals::BuildInterfaceSource(types_, *interface); |
| Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 754 | Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput); |
| Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 757 | namespace test_io_handling { |
| 758 | |
| 759 | const char kInputPath[] = "a/IFoo.aidl"; |
| 760 | const char kOutputPath[] = "output.cpp"; |
| 761 | const char kHeaderDir[] = "headers"; |
| 762 | const char kInterfaceHeaderRelPath[] = "a/IFoo.h"; |
| 763 | |
| 764 | } // namespace test_io_handling |
| 765 | |
| 766 | class IoErrorHandlingTest : public ASTTest { |
| 767 | public: |
| 768 | IoErrorHandlingTest () |
| 769 | : ASTTest(test_io_handling::kInputPath, |
| 770 | "package a; interface IFoo {}"), |
| 771 | options_(GetOptions()) {} |
| 772 | |
| 773 | const unique_ptr<CppOptions> options_; |
| 774 | |
| 775 | private: |
| 776 | static unique_ptr<CppOptions> GetOptions() { |
| 777 | using namespace test_io_handling; |
| 778 | |
| 779 | const int argc = 4; |
| 780 | const char* cmdline[argc] = { |
| 781 | "aidl-cpp", kInputPath, kHeaderDir, kOutputPath |
| 782 | }; |
| 783 | return CppOptions::Parse(argc, cmdline); |
| 784 | } |
| 785 | }; |
| 786 | |
| 787 | TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) { |
| 788 | // Confirm that this is working correctly without I/O problems. |
| 789 | const unique_ptr<AidlInterface> interface = Parse(); |
| 790 | ASSERT_NE(interface, nullptr); |
| 791 | ASSERT_TRUE(GenerateCpp(*options_, types_, *interface, io_delegate_)); |
| 792 | } |
| 793 | |
| 794 | TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) { |
| 795 | using namespace test_io_handling; |
| 796 | const unique_ptr<AidlInterface> interface = Parse(); |
| 797 | ASSERT_NE(interface, nullptr); |
| 798 | |
| 799 | // Simulate issues closing the interface header. |
| 800 | const string header_path = |
| 801 | StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR, |
| 802 | kInterfaceHeaderRelPath); |
| 803 | io_delegate_.AddBrokenFilePath(header_path); |
| 804 | ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_)); |
| 805 | // We should never attempt to write the C++ file if we fail writing headers. |
| 806 | ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr)); |
| 807 | // We should remove partial results. |
| 808 | ASSERT_TRUE(io_delegate_.PathWasRemoved(header_path)); |
| 809 | } |
| 810 | |
| 811 | TEST_F(IoErrorHandlingTest, HandlesBadCppWrite) { |
| 812 | using test_io_handling::kOutputPath; |
| 813 | const unique_ptr<AidlInterface> interface = Parse(); |
| 814 | ASSERT_NE(interface, nullptr); |
| 815 | |
| 816 | // Simulate issues closing the cpp file. |
| 817 | io_delegate_.AddBrokenFilePath(kOutputPath); |
| 818 | ASSERT_FALSE(GenerateCpp(*options_, types_, *interface, io_delegate_)); |
| 819 | // We should remove partial results. |
| 820 | ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath)); |
| 821 | } |
| 822 | |
| Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 823 | } // namespace cpp |
| Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 824 | } // namespace aidl |
| 825 | } // namespace android |