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 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 21 | #include "aidl.h" |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 22 | #include "aidl_language.h" |
| 23 | #include "ast_cpp.h" |
| 24 | #include "code_writer.h" |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 25 | #include "generate_cpp.h" |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 26 | #include "tests/fake_io_delegate.h" |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 27 | #include "type_cpp.h" |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 28 | |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 29 | using android::aidl::test::FakeIoDelegate; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 30 | using std::string; |
| 31 | using std::unique_ptr; |
| 32 | |
| 33 | namespace android { |
| 34 | namespace aidl { |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 35 | namespace cpp { |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 38 | const string kPrimitiveInterfaceAIDL = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 39 | R"( |
| 40 | package android.os; |
| 41 | |
| 42 | interface IPingResponder { |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 43 | int Ping(String token); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 44 | })"; |
| 45 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 46 | const char kExpectedPrimitiveClientSourceOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 47 | R"(#include <android/os/BpPingResponder.h> |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 48 | #include <binder/Parcel.h> |
| 49 | |
| 50 | namespace android { |
| 51 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 52 | namespace os { |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 53 | |
| 54 | BpPingResponder::BpPingResponder(const android::sp<android::IBinder>& impl) |
| 55 | : BpInterface<IPingResponder>(impl){ |
| 56 | } |
| 57 | |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 58 | android::status_t BpPingResponder::Ping(android::String16 token, int32_t* _aidl_return) { |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 59 | android::Parcel data; |
| 60 | android::Parcel reply; |
| 61 | android::status_t status; |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 62 | status = data.writeString16(token); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 63 | if (status != android::OK) { return status; } |
| 64 | status = remote()->transact(IPingResponder::PING, data, &reply); |
| 65 | if (status != android::OK) { return status; } |
| 66 | status = reply.readInt32(_aidl_return); |
| 67 | if (status != android::OK) { return status; } |
| 68 | return status; |
| 69 | } |
| 70 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 71 | } // namespace os |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 72 | |
| 73 | } // namespace android |
| 74 | )"; |
| 75 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 76 | const char kExpectedPrimitiveServerHeaderOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 77 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ |
| 78 | #define AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_ |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 79 | |
| 80 | #include <binder/IInterface.h> |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 81 | #include <android/os/IPingResponder.h> |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 82 | |
| 83 | namespace android { |
| 84 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 85 | namespace os { |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 86 | |
| 87 | class BnPingResponder : public android::BnInterface<IPingResponder> { |
| 88 | public: |
| 89 | android::status_t onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags = 0) override; |
| 90 | }; // class BnPingResponder |
| 91 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 92 | } // namespace os |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 93 | |
| 94 | } // namespace android |
| 95 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 96 | #endif // AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_)"; |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 97 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 98 | const char kExpectedPrimitiveServerSourceOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 99 | R"(#include <android/os/BnPingResponder.h> |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 100 | #include <binder/Parcel.h> |
| 101 | |
| 102 | namespace android { |
| 103 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 104 | namespace os { |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 105 | |
| 106 | android::status_t BnPingResponder::onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags) { |
Christopher Wiley | 05f4f89 | 2015-10-14 13:30:43 -0700 | [diff] [blame] | 107 | android::status_t status; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 108 | switch (code) { |
| 109 | case Call::PING: |
| 110 | { |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 111 | android::String16 in_token; |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 112 | int32_t _aidl_return; |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 113 | status = data.readString16(&in_token); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 114 | if (status != android::OK) { break; } |
| 115 | status = Ping(in_token, &_aidl_return); |
| 116 | if (status != android::OK) { break; } |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 117 | status = reply->writeInt32(_aidl_return); |
| 118 | if (status != android::OK) { break; } |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 119 | } |
| 120 | break; |
| 121 | default: |
| 122 | { |
| 123 | status = android::BBinder::onTransact(code, data, reply, flags); |
| 124 | } |
| 125 | break; |
| 126 | } |
| 127 | return status; |
| 128 | } |
| 129 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 130 | } // namespace os |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 131 | |
| 132 | } // namespace android |
| 133 | )"; |
| 134 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 135 | const char kExpectedPrimitiveClientHeaderOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 136 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ |
| 137 | #define AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_ |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 138 | |
| 139 | #include <binder/IBinder.h> |
| 140 | #include <binder/IInterface.h> |
| 141 | #include <utils/Errors.h> |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 142 | #include <android/os/IPingResponder.h> |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 143 | |
| 144 | namespace android { |
| 145 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 146 | namespace os { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 147 | |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 148 | class BpPingResponder : public android::BpInterface<IPingResponder> { |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 149 | public: |
Christopher Wiley | b23149d | 2015-10-14 13:52:21 -0700 | [diff] [blame] | 150 | explicit BpPingResponder(const android::sp<android::IBinder>& impl); |
Christopher Wiley | f094d58 | 2015-10-08 15:50:15 -0700 | [diff] [blame] | 151 | virtual ~BpPingResponder() = default; |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 152 | android::status_t Ping(android::String16 token, int32_t* _aidl_return) override; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 153 | }; // class BpPingResponder |
| 154 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 155 | } // namespace os |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 156 | |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 157 | } // namespace android |
| 158 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 159 | #endif // AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_)"; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 160 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 161 | const char kExpectedPrimitiveInterfaceHeaderOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 162 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ |
| 163 | #define AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_ |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 164 | |
| 165 | #include <binder/IBinder.h> |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 166 | #include <binder/IInterface.h> |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 167 | #include <cstdint> |
| 168 | #include <utils/String16.h> |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 169 | |
| 170 | namespace android { |
| 171 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 172 | namespace os { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 173 | |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 174 | class IPingResponder : public android::IInterface { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 175 | public: |
| 176 | DECLARE_META_INTERFACE(PingResponder); |
Casey Dahlin | ce776cf | 2015-10-15 18:45:54 -0700 | [diff] [blame] | 177 | virtual android::status_t Ping(android::String16 token, int32_t* _aidl_return) = 0; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 178 | enum Call { |
| 179 | PING = android::IBinder::FIRST_CALL_TRANSACTION + 0, |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 180 | }; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 181 | }; // class IPingResponder |
| 182 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 183 | } // namespace os |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 184 | |
| 185 | } // namespace android |
Christopher Wiley | 3bb6bc1 | 2015-10-14 10:58:27 -0700 | [diff] [blame] | 186 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 187 | #endif // AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_)"; |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 188 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 189 | const char kExpectedPrimitiveInterfaceSourceOutput[] = |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 190 | R"(#include <android/os/IPingResponder.h> |
| 191 | #include <android/os/BpPingResponder.h> |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 192 | |
| 193 | namespace android { |
| 194 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 195 | namespace os { |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 196 | |
Christopher Wiley | 054afbd | 2015-10-16 17:08:43 -0700 | [diff] [blame] | 197 | IMPLEMENT_META_INTERFACE(PingResponder, "android.os.IPingResponder"); |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 198 | |
Christopher Wiley | b656a3b | 2015-10-16 11:11:09 -0700 | [diff] [blame] | 199 | } // namespace os |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 200 | |
| 201 | } // namespace android |
| 202 | )"; |
| 203 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 204 | const string kComplexTypeInterfaceAIDL = |
| 205 | R"(package android.os; |
| 206 | interface IComplexTypeInterface { |
| 207 | int Send(in int[] token, out boolean[] item); |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 208 | oneway void Piff(int times); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 209 | })"; |
| 210 | |
| 211 | const char kExpectedComplexTypeClientHeaderOutput[] = |
| 212 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_ |
| 213 | #define AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_ |
| 214 | |
| 215 | #include <binder/IBinder.h> |
| 216 | #include <binder/IInterface.h> |
| 217 | #include <utils/Errors.h> |
| 218 | #include <android/os/IComplexTypeInterface.h> |
| 219 | |
| 220 | namespace android { |
| 221 | |
| 222 | namespace os { |
| 223 | |
| 224 | class BpComplexTypeInterface : public android::BpInterface<IComplexTypeInterface> { |
| 225 | public: |
| 226 | explicit BpComplexTypeInterface(const android::sp<android::IBinder>& impl); |
| 227 | virtual ~BpComplexTypeInterface() = default; |
| 228 | android::status_t Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) override; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 229 | android::status_t Piff(int32_t times) override; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 230 | }; // class BpComplexTypeInterface |
| 231 | |
| 232 | } // namespace os |
| 233 | |
| 234 | } // namespace android |
| 235 | |
| 236 | #endif // AIDL_GENERATED_ANDROID_OS_BP_COMPLEX_TYPE_INTERFACE_H_)"; |
| 237 | |
| 238 | const char kExpectedComplexTypeClientSourceOutput[] = |
| 239 | R"(#include <android/os/BpComplexTypeInterface.h> |
| 240 | #include <binder/Parcel.h> |
| 241 | |
| 242 | namespace android { |
| 243 | |
| 244 | namespace os { |
| 245 | |
| 246 | BpComplexTypeInterface::BpComplexTypeInterface(const android::sp<android::IBinder>& impl) |
| 247 | : BpInterface<IPingResponder>(impl){ |
| 248 | } |
| 249 | |
| 250 | android::status_t BpComplexTypeInterface::Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) { |
| 251 | android::Parcel data; |
| 252 | android::Parcel reply; |
| 253 | android::status_t status; |
| 254 | status = data.writeInt32Vector(token); |
| 255 | if (status != android::OK) { return status; } |
| 256 | status = remote()->transact(IComplexTypeInterface::SEND, data, &reply); |
| 257 | if (status != android::OK) { return status; } |
| 258 | status = reply.readInt32(_aidl_return); |
| 259 | if (status != android::OK) { return status; } |
| 260 | status = reply.readBoolVector(item); |
| 261 | if (status != android::OK) { return status; } |
| 262 | return status; |
| 263 | } |
| 264 | |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 265 | android::status_t BpComplexTypeInterface::Piff(int32_t times) { |
| 266 | android::Parcel data; |
| 267 | android::status_t status; |
| 268 | status = data.writeInt32(times); |
| 269 | if (status != android::OK) { return status; } |
| 270 | status = remote()->transact(IComplexTypeInterface::PIFF, data, &reply, android::IBinder::FLAG_ONEWAY); |
| 271 | if (status != android::OK) { return status; } |
| 272 | return status; |
| 273 | } |
| 274 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 275 | } // namespace os |
| 276 | |
| 277 | } // namespace android |
| 278 | )"; |
| 279 | |
| 280 | const char kExpectedComplexTypeServerHeaderOutput[] = |
| 281 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_ |
| 282 | #define AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_ |
| 283 | |
| 284 | #include <binder/IInterface.h> |
| 285 | #include <android/os/IComplexTypeInterface.h> |
| 286 | |
| 287 | namespace android { |
| 288 | |
| 289 | namespace os { |
| 290 | |
| 291 | class BnComplexTypeInterface : public android::BnInterface<IComplexTypeInterface> { |
| 292 | public: |
| 293 | android::status_t onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags = 0) override; |
| 294 | }; // class BnComplexTypeInterface |
| 295 | |
| 296 | } // namespace os |
| 297 | |
| 298 | } // namespace android |
| 299 | |
| 300 | #endif // AIDL_GENERATED_ANDROID_OS_BN_COMPLEX_TYPE_INTERFACE_H_)"; |
| 301 | |
| 302 | const char kExpectedComplexTypeServerSourceOutput[] = |
| 303 | R"(#include <android/os/BnComplexTypeInterface.h> |
| 304 | #include <binder/Parcel.h> |
| 305 | |
| 306 | namespace android { |
| 307 | |
| 308 | namespace os { |
| 309 | |
| 310 | android::status_t BnComplexTypeInterface::onTransact(uint32_t code, const android::Parcel& data, android::Parcel* reply, uint32_t flags) { |
| 311 | android::status_t status; |
| 312 | switch (code) { |
| 313 | case Call::SEND: |
| 314 | { |
| 315 | std::vector<int32_t> in_token; |
| 316 | std::vector<bool> out_item; |
| 317 | int32_t _aidl_return; |
| 318 | status = data.readInt32Vector(&in_token); |
| 319 | if (status != android::OK) { break; } |
| 320 | status = Send(in_token, &out_item, &_aidl_return); |
| 321 | if (status != android::OK) { break; } |
| 322 | status = reply->writeInt32(_aidl_return); |
| 323 | if (status != android::OK) { break; } |
| 324 | status = reply->writeBoolVector(out_item); |
| 325 | if (status != android::OK) { break; } |
| 326 | } |
| 327 | break; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 328 | case Call::PIFF: |
| 329 | { |
| 330 | int32_t in_times; |
| 331 | status = data.readInt32(&in_times); |
| 332 | if (status != android::OK) { break; } |
| 333 | status = Piff(in_times); |
| 334 | if (status != android::OK) { break; } |
| 335 | } |
| 336 | break; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 337 | default: |
| 338 | { |
| 339 | status = android::BBinder::onTransact(code, data, reply, flags); |
| 340 | } |
| 341 | break; |
| 342 | } |
| 343 | return status; |
| 344 | } |
| 345 | |
| 346 | } // namespace os |
| 347 | |
| 348 | } // namespace android |
| 349 | )"; |
| 350 | |
| 351 | const char kExpectedComplexTypeInterfaceHeaderOutput[] = |
| 352 | R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_ |
| 353 | #define AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_ |
| 354 | |
| 355 | #include <binder/IBinder.h> |
| 356 | #include <binder/IInterface.h> |
| 357 | #include <cstdint> |
| 358 | #include <vector> |
| 359 | |
| 360 | namespace android { |
| 361 | |
| 362 | namespace os { |
| 363 | |
| 364 | class IComplexTypeInterface : public android::IInterface { |
| 365 | public: |
| 366 | DECLARE_META_INTERFACE(ComplexTypeInterface); |
| 367 | virtual android::status_t Send(const std::vector<int32_t>& token, std::vector<bool>* item, int32_t* _aidl_return) = 0; |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 368 | virtual android::status_t Piff(int32_t times) = 0; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 369 | enum Call { |
| 370 | SEND = android::IBinder::FIRST_CALL_TRANSACTION + 0, |
Casey Dahlin | 0dd08af | 2015-10-20 18:45:50 -0700 | [diff] [blame^] | 371 | PIFF = android::IBinder::FIRST_CALL_TRANSACTION + 1, |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 372 | }; |
| 373 | }; // class IComplexTypeInterface |
| 374 | |
| 375 | } // namespace os |
| 376 | |
| 377 | } // namespace android |
| 378 | |
| 379 | #endif // AIDL_GENERATED_ANDROID_OS_I_COMPLEX_TYPE_INTERFACE_H_)"; |
| 380 | |
| 381 | const char kExpectedComplexTypeInterfaceSourceOutput[] = |
| 382 | R"(#include <android/os/IComplexTypeInterface.h> |
| 383 | #include <android/os/BpComplexTypeInterface.h> |
| 384 | |
| 385 | namespace android { |
| 386 | |
| 387 | namespace os { |
| 388 | |
| 389 | IMPLEMENT_META_INTERFACE(ComplexTypeInterface, "android.os.IComplexTypeInterface"); |
| 390 | |
| 391 | } // namespace os |
| 392 | |
| 393 | } // namespace android |
| 394 | )"; |
| 395 | |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 396 | } // namespace |
| 397 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 398 | class ASTTest : public ::testing::Test { |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 399 | protected: |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 400 | virtual const string& FilePath() = 0; |
| 401 | virtual const string& FileContents() = 0; |
| 402 | |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 403 | unique_ptr<AidlInterface> Parse() { |
| 404 | FakeIoDelegate io_delegate; |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 405 | io_delegate.SetFileContents(FilePath(), FileContents()); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 406 | |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 407 | cpp::TypeNamespace types; |
| 408 | unique_ptr<AidlInterface> ret; |
| 409 | std::vector<std::unique_ptr<AidlImport>> imports; |
| 410 | int err = ::android::aidl::internals::load_and_validate_aidl( |
| 411 | {}, // no preprocessed files |
| 412 | {}, // no import paths |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 413 | FilePath(), |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 414 | io_delegate, |
| 415 | &types, |
| 416 | &ret, |
| 417 | &imports); |
Christopher Wiley | 4a2884b | 2015-10-07 11:27:45 -0700 | [diff] [blame] | 418 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 419 | if (err) |
| 420 | return nullptr; |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 421 | |
Casey Dahlin | 2cc9316 | 2015-10-02 16:14:17 -0700 | [diff] [blame] | 422 | return ret; |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 423 | } |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 424 | |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 425 | void Compare(Document* doc, const char* expected) { |
| 426 | string output; |
| 427 | unique_ptr<CodeWriter> cw = GetStringWriter(&output); |
| 428 | |
| 429 | doc->Write(cw.get()); |
| 430 | |
| 431 | EXPECT_EQ(expected, output); |
| 432 | } |
| 433 | }; |
| 434 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 435 | class PrimitiveInterfaceASTTest : public ASTTest { |
| 436 | protected: |
| 437 | const string fp_ = "android/os/IPingResponder.aidl"; |
| 438 | const string& FilePath() override { return fp_; } |
| 439 | const string& FileContents() override { return kPrimitiveInterfaceAIDL; } |
| 440 | }; |
| 441 | |
| 442 | TEST_F(PrimitiveInterfaceASTTest, GeneratesClientHeader) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 443 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 444 | ASSERT_NE(interface, nullptr); |
Christopher Wiley | e3550c6 | 2015-09-29 13:26:10 -0700 | [diff] [blame] | 445 | TypeNamespace types; |
| 446 | unique_ptr<Document> doc = internals::BuildClientHeader(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 447 | Compare(doc.get(), kExpectedPrimitiveClientHeaderOutput); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 448 | } |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 449 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 450 | TEST_F(PrimitiveInterfaceASTTest, GeneratesClientSource) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 451 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 452 | ASSERT_NE(interface, nullptr); |
| 453 | TypeNamespace types; |
| 454 | unique_ptr<Document> doc = internals::BuildClientSource(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 455 | Compare(doc.get(), kExpectedPrimitiveClientSourceOutput); |
Christopher Wiley | 36570f4 | 2015-10-08 17:20:11 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 458 | TEST_F(PrimitiveInterfaceASTTest, GeneratesServerHeader) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 459 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 460 | ASSERT_NE(interface, nullptr); |
| 461 | TypeNamespace types; |
| 462 | unique_ptr<Document> doc = internals::BuildServerHeader(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 463 | Compare(doc.get(), kExpectedPrimitiveServerHeaderOutput); |
Christopher Wiley | fd51d60 | 2015-10-14 13:04:48 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 466 | TEST_F(PrimitiveInterfaceASTTest, GeneratesServerSource) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 467 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 468 | ASSERT_NE(interface, nullptr); |
| 469 | TypeNamespace types; |
| 470 | unique_ptr<Document> doc = internals::BuildServerSource(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 471 | Compare(doc.get(), kExpectedPrimitiveServerSourceOutput); |
Christopher Wiley | ad33927 | 2015-10-05 19:11:58 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 474 | TEST_F(PrimitiveInterfaceASTTest, GeneratesInterfaceHeader) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 475 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | 0c732db | 2015-09-29 14:36:44 -0700 | [diff] [blame] | 476 | ASSERT_NE(interface, nullptr); |
| 477 | TypeNamespace types; |
| 478 | unique_ptr<Document> doc = internals::BuildInterfaceHeader(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 479 | Compare(doc.get(), kExpectedPrimitiveInterfaceHeaderOutput); |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 482 | TEST_F(PrimitiveInterfaceASTTest, GeneratesInterfaceSource) { |
Christopher Wiley | 90be4e3 | 2015-10-20 14:55:25 -0700 | [diff] [blame] | 483 | unique_ptr<AidlInterface> interface = Parse(); |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 484 | ASSERT_NE(interface, nullptr); |
| 485 | TypeNamespace types; |
| 486 | unique_ptr<Document> doc = internals::BuildInterfaceSource(types, *interface); |
Casey Dahlin | b096661 | 2015-10-19 16:35:26 -0700 | [diff] [blame] | 487 | Compare(doc.get(), kExpectedPrimitiveInterfaceSourceOutput); |
| 488 | } |
| 489 | |
| 490 | class ComplexTypeInterfaceASTTest : public ASTTest { |
| 491 | protected: |
| 492 | const string fp_ = "android/os/IComplexTypeInterface.aidl"; |
| 493 | const string& FilePath() override { return fp_; } |
| 494 | const string& FileContents() override { return kComplexTypeInterfaceAIDL; } |
| 495 | }; |
| 496 | |
| 497 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientHeader) { |
| 498 | unique_ptr<AidlInterface> interface = Parse(); |
| 499 | ASSERT_NE(interface, nullptr); |
| 500 | TypeNamespace types; |
| 501 | unique_ptr<Document> doc = internals::BuildClientHeader(types, *interface); |
| 502 | Compare(doc.get(), kExpectedComplexTypeClientHeaderOutput); |
| 503 | } |
| 504 | |
| 505 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesClientSource) { |
| 506 | unique_ptr<AidlInterface> interface = Parse(); |
| 507 | ASSERT_NE(interface, nullptr); |
| 508 | TypeNamespace types; |
| 509 | unique_ptr<Document> doc = internals::BuildClientSource(types, *interface); |
| 510 | Compare(doc.get(), kExpectedComplexTypeClientSourceOutput); |
| 511 | } |
| 512 | |
| 513 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerHeader) { |
| 514 | unique_ptr<AidlInterface> interface = Parse(); |
| 515 | ASSERT_NE(interface, nullptr); |
| 516 | TypeNamespace types; |
| 517 | unique_ptr<Document> doc = internals::BuildServerHeader(types, *interface); |
| 518 | Compare(doc.get(), kExpectedComplexTypeServerHeaderOutput); |
| 519 | } |
| 520 | |
| 521 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesServerSource) { |
| 522 | unique_ptr<AidlInterface> interface = Parse(); |
| 523 | ASSERT_NE(interface, nullptr); |
| 524 | TypeNamespace types; |
| 525 | unique_ptr<Document> doc = internals::BuildServerSource(types, *interface); |
| 526 | Compare(doc.get(), kExpectedComplexTypeServerSourceOutput); |
| 527 | } |
| 528 | |
| 529 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceHeader) { |
| 530 | unique_ptr<AidlInterface> interface = Parse(); |
| 531 | ASSERT_NE(interface, nullptr); |
| 532 | TypeNamespace types; |
| 533 | unique_ptr<Document> doc = internals::BuildInterfaceHeader(types, *interface); |
| 534 | Compare(doc.get(), kExpectedComplexTypeInterfaceHeaderOutput); |
| 535 | } |
| 536 | |
| 537 | TEST_F(ComplexTypeInterfaceASTTest, GeneratesInterfaceSource) { |
| 538 | unique_ptr<AidlInterface> interface = Parse(); |
| 539 | ASSERT_NE(interface, nullptr); |
| 540 | TypeNamespace types; |
| 541 | unique_ptr<Document> doc = internals::BuildInterfaceSource(types, *interface); |
| 542 | Compare(doc.get(), kExpectedComplexTypeInterfaceSourceOutput); |
Christopher Wiley | 1dd458d | 2015-09-30 11:05:52 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Christopher Wiley | f944e79 | 2015-09-29 10:00:46 -0700 | [diff] [blame] | 545 | } // namespace cpp |
Casey Dahlin | a834dd4 | 2015-09-23 11:52:15 -0700 | [diff] [blame] | 546 | } // namespace aidl |
| 547 | } // namespace android |