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 | |
| 86 | #endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_)"; |
| 87 | |
| 88 | const char kExpectedComplexTypeClientSourceOutput[] = |
| 89 | R"(#include <android/os/BpComplexTypeInterface.h> |
| 90 | #include <binder/Parcel.h> |
| 91 | |
| 92 | namespace android { |
| 93 | |
| 94 | namespace os { |
| 95 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 96 | BpComplexTypeInterface::BpComplexTypeInterface(const ::android::sp<::android::IBinder>& _aidl_impl) |
| 97 | : BpInterface<IComplexTypeInterface>(_aidl_impl){ |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 100 | ::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] | 101 | ::android::Parcel _aidl_data; |
| 102 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 103 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 104 | ::android::binder::Status _aidl_status; |
| 105 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 106 | if (((_aidl_ret_status) != (::android::OK))) { |
| 107 | goto _aidl_error; |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 108 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 109 | _aidl_ret_status = _aidl_data.writeInt32Vector(goes_in); |
| 110 | if (((_aidl_ret_status) != (::android::OK))) { |
| 111 | goto _aidl_error; |
Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 112 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 113 | _aidl_ret_status = _aidl_data.writeDoubleVector(*goes_in_and_out); |
| 114 | if (((_aidl_ret_status) != (::android::OK))) { |
| 115 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 116 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 117 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::SEND, _aidl_data, &_aidl_reply); |
| 118 | if (((_aidl_ret_status) != (::android::OK))) { |
| 119 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 120 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 121 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 122 | if (((_aidl_ret_status) != (::android::OK))) { |
| 123 | goto _aidl_error; |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 124 | } |
| 125 | if (!_aidl_status.isOk()) { |
| 126 | return _aidl_status; |
Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 127 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 128 | _aidl_ret_status = _aidl_reply.readInt32Vector(_aidl_return); |
| 129 | if (((_aidl_ret_status) != (::android::OK))) { |
| 130 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 131 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 132 | _aidl_ret_status = _aidl_reply.readDoubleVector(goes_in_and_out); |
| 133 | if (((_aidl_ret_status) != (::android::OK))) { |
| 134 | goto _aidl_error; |
Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 135 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 136 | _aidl_ret_status = _aidl_reply.readBoolVector(goes_out); |
| 137 | if (((_aidl_ret_status) != (::android::OK))) { |
| 138 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 139 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 140 | _aidl_error: |
| 141 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 142 | return _aidl_status; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 145 | ::android::binder::Status BpComplexTypeInterface::Piff(int32_t times) { |
| 146 | ::android::Parcel _aidl_data; |
| 147 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 148 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 149 | ::android::binder::Status _aidl_status; |
| 150 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 151 | if (((_aidl_ret_status) != (::android::OK))) { |
| 152 | goto _aidl_error; |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 153 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 154 | _aidl_ret_status = _aidl_data.writeInt32(times); |
| 155 | if (((_aidl_ret_status) != (::android::OK))) { |
| 156 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 157 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 158 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::PIFF, _aidl_data, &_aidl_reply, ::android::IBinder::FLAG_ONEWAY); |
| 159 | if (((_aidl_ret_status) != (::android::OK))) { |
| 160 | goto _aidl_error; |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 161 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 162 | _aidl_error: |
| 163 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 164 | return _aidl_status; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 167 | ::android::binder::Status BpComplexTypeInterface::TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) { |
| 168 | ::android::Parcel _aidl_data; |
| 169 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 170 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 171 | ::android::binder::Status _aidl_status; |
| 172 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 173 | if (((_aidl_ret_status) != (::android::OK))) { |
| 174 | goto _aidl_error; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 175 | } |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame^] | 176 | _aidl_ret_status = _aidl_data.writeStrongBinder(::foo::IFooType::asBinder(f)); |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 177 | if (((_aidl_ret_status) != (::android::OK))) { |
| 178 | goto _aidl_error; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 179 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 180 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESABINDER, _aidl_data, &_aidl_reply); |
| 181 | if (((_aidl_ret_status) != (::android::OK))) { |
| 182 | goto _aidl_error; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 183 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 184 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 185 | if (((_aidl_ret_status) != (::android::OK))) { |
| 186 | goto _aidl_error; |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 187 | } |
| 188 | if (!_aidl_status.isOk()) { |
| 189 | return _aidl_status; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 190 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 191 | _aidl_ret_status = _aidl_reply.readStrongBinder(_aidl_return); |
| 192 | if (((_aidl_ret_status) != (::android::OK))) { |
| 193 | goto _aidl_error; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 194 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 195 | _aidl_error: |
| 196 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 197 | return _aidl_status; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 200 | ::android::binder::Status BpComplexTypeInterface::StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) { |
| 201 | ::android::Parcel _aidl_data; |
| 202 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 203 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 204 | ::android::binder::Status _aidl_status; |
| 205 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 206 | if (((_aidl_ret_status) != (::android::OK))) { |
| 207 | goto _aidl_error; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 208 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 209 | _aidl_ret_status = _aidl_data.writeString16Vector(input); |
| 210 | if (((_aidl_ret_status) != (::android::OK))) { |
| 211 | goto _aidl_error; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 212 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 213 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::STRINGLISTMETHOD, _aidl_data, &_aidl_reply); |
| 214 | if (((_aidl_ret_status) != (::android::OK))) { |
| 215 | goto _aidl_error; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 216 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 217 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 218 | if (((_aidl_ret_status) != (::android::OK))) { |
| 219 | goto _aidl_error; |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 220 | } |
| 221 | if (!_aidl_status.isOk()) { |
| 222 | return _aidl_status; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 223 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 224 | _aidl_ret_status = _aidl_reply.readString16Vector(_aidl_return); |
| 225 | if (((_aidl_ret_status) != (::android::OK))) { |
| 226 | goto _aidl_error; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 227 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 228 | _aidl_ret_status = _aidl_reply.readString16Vector(output); |
| 229 | if (((_aidl_ret_status) != (::android::OK))) { |
| 230 | goto _aidl_error; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 231 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 232 | _aidl_error: |
| 233 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 234 | return _aidl_status; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 237 | ::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) { |
| 238 | ::android::Parcel _aidl_data; |
| 239 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 240 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 241 | ::android::binder::Status _aidl_status; |
| 242 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 243 | if (((_aidl_ret_status) != (::android::OK))) { |
| 244 | goto _aidl_error; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 245 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 246 | _aidl_ret_status = _aidl_data.writeStrongBinderVector(input); |
| 247 | if (((_aidl_ret_status) != (::android::OK))) { |
| 248 | goto _aidl_error; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 249 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 250 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::BINDERLISTMETHOD, _aidl_data, &_aidl_reply); |
| 251 | if (((_aidl_ret_status) != (::android::OK))) { |
| 252 | goto _aidl_error; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 253 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 254 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 255 | if (((_aidl_ret_status) != (::android::OK))) { |
| 256 | goto _aidl_error; |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 257 | } |
| 258 | if (!_aidl_status.isOk()) { |
| 259 | return _aidl_status; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 260 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 261 | _aidl_ret_status = _aidl_reply.readStrongBinderVector(_aidl_return); |
| 262 | if (((_aidl_ret_status) != (::android::OK))) { |
| 263 | goto _aidl_error; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 264 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 265 | _aidl_ret_status = _aidl_reply.readStrongBinderVector(output); |
| 266 | if (((_aidl_ret_status) != (::android::OK))) { |
| 267 | goto _aidl_error; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 268 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 269 | _aidl_error: |
| 270 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 271 | return _aidl_status; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 274 | ::android::binder::Status BpComplexTypeInterface::TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) { |
| 275 | ::android::Parcel _aidl_data; |
| 276 | ::android::Parcel _aidl_reply; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 277 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 278 | ::android::binder::Status _aidl_status; |
| 279 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 280 | if (((_aidl_ret_status) != (::android::OK))) { |
| 281 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 282 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 283 | _aidl_ret_status = _aidl_data.writeUniqueFileDescriptor(f); |
| 284 | if (((_aidl_ret_status) != (::android::OK))) { |
| 285 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 286 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 287 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTOR, _aidl_data, &_aidl_reply); |
| 288 | if (((_aidl_ret_status) != (::android::OK))) { |
| 289 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 290 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 291 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 292 | if (((_aidl_ret_status) != (::android::OK))) { |
| 293 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 294 | } |
| 295 | if (!_aidl_status.isOk()) { |
| 296 | return _aidl_status; |
| 297 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 298 | _aidl_ret_status = _aidl_reply.readUniqueFileDescriptor(_aidl_return); |
| 299 | if (((_aidl_ret_status) != (::android::OK))) { |
| 300 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 301 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 302 | _aidl_error: |
| 303 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 304 | return _aidl_status; |
| 305 | } |
| 306 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 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; |
Christopher Wiley | 1095712 | 2015-12-04 14:35:38 -0800 | [diff] [blame] | 310 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 311 | ::android::binder::Status _aidl_status; |
| 312 | _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor()); |
| 313 | if (((_aidl_ret_status) != (::android::OK))) { |
| 314 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 315 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 316 | _aidl_ret_status = _aidl_data.writeUniqueFileDescriptorVector(f); |
| 317 | if (((_aidl_ret_status) != (::android::OK))) { |
| 318 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 319 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 320 | _aidl_ret_status = remote()->transact(IComplexTypeInterface::TAKESAFILEDESCRIPTORARRAY, _aidl_data, &_aidl_reply); |
| 321 | if (((_aidl_ret_status) != (::android::OK))) { |
| 322 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 323 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 324 | _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply); |
| 325 | if (((_aidl_ret_status) != (::android::OK))) { |
| 326 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 327 | } |
| 328 | if (!_aidl_status.isOk()) { |
| 329 | return _aidl_status; |
| 330 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 331 | _aidl_ret_status = _aidl_reply.readUniqueFileDescriptorVector(_aidl_return); |
| 332 | if (((_aidl_ret_status) != (::android::OK))) { |
| 333 | goto _aidl_error; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 334 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 335 | _aidl_error: |
| 336 | _aidl_status.setFromStatusT(_aidl_ret_status); |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 337 | return _aidl_status; |
| 338 | } |
| 339 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 340 | } // namespace os |
| 341 | |
| 342 | } // namespace android |
| 343 | )"; |
| 344 | |
| 345 | const char kExpectedComplexTypeServerHeaderOutput[] = |
| 346 | R"(#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 | |
| 352 | namespace android { |
| 353 | |
| 354 | namespace os { |
| 355 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 356 | class BnComplexTypeInterface : public ::android::BnInterface<IComplexTypeInterface> { |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 357 | public: |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 358 | ::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] | 359 | }; // class BnComplexTypeInterface |
| 360 | |
| 361 | } // namespace os |
| 362 | |
| 363 | } // namespace android |
| 364 | |
| 365 | #endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_)"; |
| 366 | |
| 367 | const char kExpectedComplexTypeServerSourceOutput[] = |
| 368 | R"(#include <android/os/BnComplexTypeInterface.h> |
| 369 | #include <binder/Parcel.h> |
| 370 | |
| 371 | namespace android { |
| 372 | |
| 373 | namespace os { |
| 374 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 375 | ::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] | 376 | ::android::status_t _aidl_ret_status = ::android::OK; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 377 | switch (_aidl_code) { |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 378 | case Call::SEND: |
| 379 | { |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 380 | ::std::unique_ptr<::std::vector<int32_t>> in_goes_in; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 381 | ::std::vector<double> in_goes_in_and_out; |
| 382 | ::std::vector<bool> out_goes_out; |
| 383 | ::std::vector<int32_t> _aidl_return; |
| 384 | if (!(_aidl_data.checkInterface(this))) { |
| 385 | _aidl_ret_status = ::android::BAD_TYPE; |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 386 | break; |
| 387 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 388 | _aidl_ret_status = _aidl_data.readInt32Vector(&in_goes_in); |
| 389 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 390 | break; |
| 391 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 392 | _aidl_ret_status = _aidl_data.readDoubleVector(&in_goes_in_and_out); |
| 393 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 394 | break; |
| 395 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 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); |
| 398 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 399 | break; |
| 400 | } |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 401 | if (!_aidl_status.isOk()) { |
Christopher Wiley | 2aaeda8 | 2015-10-19 15:16:49 -0700 | [diff] [blame] | 402 | break; |
| 403 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 404 | _aidl_ret_status = _aidl_reply->writeInt32Vector(_aidl_return); |
| 405 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 406 | break; |
| 407 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 408 | _aidl_ret_status = _aidl_reply->writeDoubleVector(in_goes_in_and_out); |
| 409 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | bb96782 | 2015-10-27 14:04:53 -0700 | [diff] [blame] | 410 | break; |
| 411 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 412 | _aidl_ret_status = _aidl_reply->writeBoolVector(out_goes_out); |
| 413 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 414 | break; |
| 415 | } |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 416 | } |
| 417 | break; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 418 | case Call::PIFF: |
| 419 | { |
| 420 | int32_t in_times; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 421 | if (!(_aidl_data.checkInterface(this))) { |
| 422 | _aidl_ret_status = ::android::BAD_TYPE; |
Christopher Wiley | 8993cb5 | 2015-10-21 09:53:24 -0700 | [diff] [blame] | 423 | break; |
| 424 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 425 | _aidl_ret_status = _aidl_data.readInt32(&in_times); |
| 426 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 0eb903e | 2015-10-20 17:07:08 -0700 | [diff] [blame] | 427 | break; |
| 428 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 429 | ::android::binder::Status _aidl_status(Piff(in_times)); |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame] | 430 | } |
| 431 | break; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 432 | case Call::TAKESABINDER: |
| 433 | { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 434 | ::android::sp<::foo::IFooType> in_f; |
| 435 | ::android::sp<::foo::IFooType> _aidl_return; |
| 436 | if (!(_aidl_data.checkInterface(this))) { |
| 437 | _aidl_ret_status = ::android::BAD_TYPE; |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 438 | break; |
| 439 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 440 | _aidl_ret_status = _aidl_data.readStrongBinder(&in_f); |
| 441 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 442 | break; |
| 443 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 444 | ::android::binder::Status _aidl_status(TakesABinder(in_f, &_aidl_return)); |
| 445 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 446 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 447 | break; |
| 448 | } |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 449 | if (!_aidl_status.isOk()) { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 450 | break; |
| 451 | } |
Casey Dahlin | 2dbab06 | 2016-01-05 17:41:08 -0800 | [diff] [blame^] | 452 | _aidl_ret_status = _aidl_reply->writeStrongBinder(::foo::IFooType::asBinder(_aidl_return)); |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 453 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | } |
| 457 | break; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 458 | case Call::STRINGLISTMETHOD: |
| 459 | { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 460 | ::std::vector<::android::String16> in_input; |
| 461 | ::std::vector<::android::String16> out_output; |
| 462 | ::std::vector<::android::String16> _aidl_return; |
| 463 | if (!(_aidl_data.checkInterface(this))) { |
| 464 | _aidl_ret_status = ::android::BAD_TYPE; |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 465 | break; |
| 466 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 467 | _aidl_ret_status = _aidl_data.readString16Vector(&in_input); |
| 468 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 469 | break; |
| 470 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 471 | ::android::binder::Status _aidl_status(StringListMethod(in_input, &out_output, &_aidl_return)); |
| 472 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 473 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 474 | break; |
| 475 | } |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 476 | if (!_aidl_status.isOk()) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 477 | break; |
| 478 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 479 | _aidl_ret_status = _aidl_reply->writeString16Vector(_aidl_return); |
| 480 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 481 | break; |
| 482 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 483 | _aidl_ret_status = _aidl_reply->writeString16Vector(out_output); |
| 484 | if (((_aidl_ret_status) != (::android::OK))) { |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 485 | break; |
| 486 | } |
| 487 | } |
| 488 | break; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 489 | case Call::BINDERLISTMETHOD: |
| 490 | { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 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; |
| 494 | if (!(_aidl_data.checkInterface(this))) { |
| 495 | _aidl_ret_status = ::android::BAD_TYPE; |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 496 | break; |
| 497 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 498 | _aidl_ret_status = _aidl_data.readStrongBinderVector(&in_input); |
| 499 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 500 | break; |
| 501 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 502 | ::android::binder::Status _aidl_status(BinderListMethod(in_input, &out_output, &_aidl_return)); |
| 503 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 504 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 505 | break; |
| 506 | } |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 507 | if (!_aidl_status.isOk()) { |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 508 | break; |
| 509 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 510 | _aidl_ret_status = _aidl_reply->writeStrongBinderVector(_aidl_return); |
| 511 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 512 | break; |
| 513 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 514 | _aidl_ret_status = _aidl_reply->writeStrongBinderVector(out_output); |
| 515 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | 7ecd69f | 2015-11-03 13:52:38 -0800 | [diff] [blame] | 516 | break; |
| 517 | } |
| 518 | } |
| 519 | break; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 520 | case Call::TAKESAFILEDESCRIPTOR: |
| 521 | { |
| 522 | ::ScopedFd in_f; |
| 523 | ::ScopedFd _aidl_return; |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 524 | if (!(_aidl_data.checkInterface(this))) { |
| 525 | _aidl_ret_status = ::android::BAD_TYPE; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 526 | break; |
| 527 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 528 | _aidl_ret_status = _aidl_data.readUniqueFileDescriptor(&in_f); |
| 529 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 530 | break; |
| 531 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 532 | ::android::binder::Status _aidl_status(TakesAFileDescriptor(in_f, &_aidl_return)); |
| 533 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 534 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 535 | break; |
| 536 | } |
| 537 | if (!_aidl_status.isOk()) { |
| 538 | break; |
| 539 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 540 | _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptor(_aidl_return); |
| 541 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 542 | break; |
| 543 | } |
| 544 | } |
| 545 | break; |
| 546 | case Call::TAKESAFILEDESCRIPTORARRAY: |
| 547 | { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 548 | ::std::vector<::ScopedFd> in_f; |
| 549 | ::std::vector<::ScopedFd> _aidl_return; |
| 550 | if (!(_aidl_data.checkInterface(this))) { |
| 551 | _aidl_ret_status = ::android::BAD_TYPE; |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 552 | break; |
| 553 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 554 | _aidl_ret_status = _aidl_data.readUniqueFileDescriptorVector(&in_f); |
| 555 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 556 | break; |
| 557 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 558 | ::android::binder::Status _aidl_status(TakesAFileDescriptorArray(in_f, &_aidl_return)); |
| 559 | _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply); |
| 560 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 561 | break; |
| 562 | } |
| 563 | if (!_aidl_status.isOk()) { |
| 564 | break; |
| 565 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 566 | _aidl_ret_status = _aidl_reply->writeUniqueFileDescriptorVector(_aidl_return); |
| 567 | if (((_aidl_ret_status) != (::android::OK))) { |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 568 | break; |
| 569 | } |
| 570 | } |
| 571 | break; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 572 | default: |
| 573 | { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 574 | _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] | 575 | } |
| 576 | break; |
| 577 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 578 | if (_aidl_ret_status == ::android::UNEXPECTED_NULL) { |
| 579 | _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] | 580 | } |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 581 | return _aidl_ret_status; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | } // namespace os |
| 585 | |
| 586 | } // namespace android |
| 587 | )"; |
| 588 | |
| 589 | const char kExpectedComplexTypeInterfaceHeaderOutput[] = |
| 590 | R"(#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> |
Christopher Wiley | 433c8bb | 2015-11-12 14:20:46 -0800 | [diff] [blame] | 595 | #include <binder/Status.h> |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 596 | #include <cstdint> |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 597 | #include <foo/IFooType.h> |
Casey Dahlin | a4ba4b6 | 2015-11-02 15:43:30 -0800 | [diff] [blame] | 598 | #include <nativehelper/ScopedFd.h> |
Christopher Wiley | 56c9bf3 | 2015-10-30 10:41:12 -0700 | [diff] [blame] | 599 | #include <utils/String16.h> |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 600 | #include <utils/StrongPointer.h> |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 601 | #include <vector> |
| 602 | |
| 603 | namespace android { |
| 604 | |
| 605 | namespace os { |
| 606 | |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 607 | class IComplexTypeInterface : public ::android::IInterface { |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 608 | public: |
| 609 | DECLARE_META_INTERFACE(ComplexTypeInterface); |
Casey Dahlin | d40e2fe | 2015-11-24 14:06:52 -0800 | [diff] [blame] | 610 | static constexpr int32_t MY_CONSTANT = 3; |
Casey Dahlin | 57dbe24 | 2015-12-04 11:44:02 -0800 | [diff] [blame] | 611 | 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] | 612 | virtual ::android::binder::Status Piff(int32_t times) = 0; |
| 613 | virtual ::android::binder::Status TakesABinder(const ::android::sp<::foo::IFooType>& f, ::android::sp<::foo::IFooType>* _aidl_return) = 0; |
| 614 | virtual ::android::binder::Status StringListMethod(const ::std::vector<::android::String16>& input, ::std::vector<::android::String16>* output, ::std::vector<::android::String16>* _aidl_return) = 0; |
| 615 | 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; |
| 616 | virtual ::android::binder::Status TakesAFileDescriptor(const ::ScopedFd& f, ::ScopedFd* _aidl_return) = 0; |
| 617 | 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] | 618 | enum Call { |
Casey Dahlin | b8d9e88 | 2015-11-24 10:57:23 -0800 | [diff] [blame] | 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, |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 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 | |
| 635 | const char kExpectedComplexTypeInterfaceSourceOutput[] = |
| 636 | R"(#include <android/os/IComplexTypeInterface.h> |
| 637 | #include <android/os/BpComplexTypeInterface.h> |
| 638 | |
| 639 | namespace android { |
| 640 | |
| 641 | namespace os { |
| 642 | |
| 643 | IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface"); |
| 644 | |
| 645 | } // namespace os |
| 646 | |
| 647 | } // namespace android |
| 648 | )"; |
| 649 | |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 650 | } // namespace |
| 651 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 652 | class ASTTest : public ::testing::Test { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 653 | protected: |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 654 | ASTTest(string file_path, string file_contents) |
| 655 | : file_path_(file_path), |
Christopher Wiley | 5679952 | 2015-10-31 10:17:04 -0700 | [diff] [blame] | 656 | file_contents_(file_contents) { |
| 657 | types_.Init(); |
| 658 | } |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 659 | |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 660 | unique_ptr<AidlInterface> Parse() { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 661 | io_delegate_.SetFileContents(file_path_, file_contents_); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 662 | |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 663 | unique_ptr<AidlInterface> ret; |
| 664 | std::vector<std::unique_ptr<AidlImport>> imports; |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 665 | AidlError err = ::android::aidl::internals::load_and_validate_aidl( |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 666 | {}, // no preprocessed files |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 667 | {"."}, |
| 668 | file_path_, |
| 669 | io_delegate_, |
| 670 | &types_, |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 671 | &ret, |
| 672 | &imports); |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 673 | |
Christopher Wiley | 632801d | 2015-11-05 14:15:49 -0800 | [diff] [blame] | 674 | if (err != AidlError::OK) |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 675 | return nullptr; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 676 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 677 | return ret; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 678 | } |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 679 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 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 | |
Casey Dahlin | 80ada3d | 2015-10-20 20:33:56 -0700 | [diff] [blame] | 686 | if (expected == output) { |
| 687 | return; // Success |
| 688 | } |
| 689 | |
| 690 | test::PrintDiff(expected, output); |
| 691 | FAIL() << "Document contents did not match expected contents"; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 692 | } |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 693 | |
| 694 | const string file_path_; |
| 695 | const string file_contents_; |
| 696 | FakeIoDelegate io_delegate_; |
| 697 | TypeNamespace types_; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 698 | }; |
| 699 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 700 | class ComplexTypeInterfaceASTTest : public ASTTest { |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 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 | } |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) { |
| 711 | unique_ptr<AidlInterface> interface = Parse(); |
| 712 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 713 | unique_ptr<Document> doc = internals::BuildClientHeader(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 714 | Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput); |
| 715 | } |
| 716 | |
| 717 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) { |
| 718 | unique_ptr<AidlInterface> interface = Parse(); |
| 719 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 720 | unique_ptr<Document> doc = internals::BuildClientSource(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 721 | Compare(doc.get(), kExpectedComplexTypeClientSourceOutput); |
| 722 | } |
| 723 | |
| 724 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) { |
| 725 | unique_ptr<AidlInterface> interface = Parse(); |
| 726 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 727 | unique_ptr<Document> doc = internals::BuildServerHeader(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 728 | Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput); |
| 729 | } |
| 730 | |
| 731 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) { |
| 732 | unique_ptr<AidlInterface> interface = Parse(); |
| 733 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 734 | unique_ptr<Document> doc = internals::BuildServerSource(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 735 | Compare(doc.get(), kExpectedComplexTypeServerSourceOutput); |
| 736 | } |
| 737 | |
| 738 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) { |
| 739 | unique_ptr<AidlInterface> interface = Parse(); |
| 740 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 741 | unique_ptr<Document> doc = internals::BuildInterfaceHeader(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 742 | Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput); |
| 743 | } |
| 744 | |
| 745 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) { |
| 746 | unique_ptr<AidlInterface> interface = Parse(); |
| 747 | ASSERT_NE(interface, nullptr); |
Casey Dahlin | 389781f | 2015-10-22 13:13:21 -0700 | [diff] [blame] | 748 | unique_ptr<Document> doc = internals::BuildInterfaceSource(types_, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 749 | Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput); |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Christopher Wiley | 9d6e0b2 | 2015-11-13 12:18:16 -0800 | [diff] [blame] | 752 | namespace test_io_handling { |
| 753 | |
| 754 | const char kInputPath[] = "a/IFoo.aidl"; |
| 755 | const char kOutputPath[] = "output.cpp"; |
| 756 | const char kHeaderDir[] = "headers"; |
| 757 | const char kInterfaceHeaderRelPath[] = "a/IFoo.h"; |
| 758 | |
| 759 | } // namespace test_io_handling |
| 760 | |
| 761 | class 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 | |
| 782 | TEST_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 | |
| 789 | TEST_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 | |
| 806 | TEST_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 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 818 | } // namespace cpp |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 819 | } // namespace aidl |
| 820 | } // namespace android |