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 "tests/test_data.h"
18 
19 namespace android {
20 namespace aidl {
21 namespace test_data {
22 namespace ping_responder {
23 
24 const char kCanonicalName[] = "android.os.IPingResponder";
25 const char kInterfaceDefinition[] = R"(
26 package android.os;
27 
28 import bar.Unused;
29 
30 interface IPingResponder {
31   String Ping(String input);
32 
33   @nullable
34   String NullablePing(@nullable String input);
35 
36   @utf8InCpp
37   String Utf8Ping(@utf8InCpp String input);
38 
39   @utf8InCpp @nullable
40   String NullableUtf8Ping(@utf8InCpp @nullable String input);
41 }
42 )";
43 
44 const char kCppOutputPath[] = "some/path/to/output.cpp";
45 
46 const char kCppParcelableHeader[] = "cpp-header-str";
47 
48 const char* kImportedParcelables[] = {
49   "bar.Unused",
50   nullptr,
51 };
52 
53 const char* kImportedInterfaces[] = {
54   nullptr,
55 };
56 
57 const char kGenHeaderDir[] = "some/path";
58 const char kGenInterfaceHeaderPath[] = "some/path/android/os/IPingResponder.h";
59 const char kGenClientHeaderPath[] = "some/path/android/os/BpPingResponder.h";
60 const char kGenServerHeaderPath[] = "some/path/android/os/BnPingResponder.h";
61 
62 const char kExpectedCppDepsOutput[] =
63 R"(some/path/to/output.cpp : \
64   android/os/IPingResponder.aidl \
65   ./bar/Unused.aidl
66 
67 android/os/IPingResponder.aidl :
68 ./bar/Unused.aidl :
69 
70 some/path/android/os/BpPingResponder.h \
71     some/path/android/os/BnPingResponder.h \
72     some/path/android/os/IPingResponder.h : \
73     android/os/IPingResponder.aidl \
74     ./bar/Unused.aidl
75 )";
76 
77 const char kExpectedCppOutput[] =
78 R"(#include <android/os/IPingResponder.h>
79 #include <android/os/BpPingResponder.h>
80 
81 namespace android {
82 
83 namespace os {
84 
85 IMPLEMENT_META_INTERFACE(PingResponder, "android.os.IPingResponder")
86 
87 }  // namespace os
88 
89 }  // namespace android
90 #include <android/os/BpPingResponder.h>
91 #include <binder/Parcel.h>
92 
93 namespace android {
94 
95 namespace os {
96 
97 BpPingResponder::BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl)
98     : BpInterface<IPingResponder>(_aidl_impl){
99 }
100 
101 ::android::binder::Status BpPingResponder::Ping(const ::android::String16& input, ::android::String16* _aidl_return) {
102 ::android::Parcel _aidl_data;
103 ::android::Parcel _aidl_reply;
104 ::android::status_t _aidl_ret_status = ::android::OK;
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;
109 }
110 _aidl_ret_status = _aidl_data.writeString16(input);
111 if (((_aidl_ret_status) != (::android::OK))) {
112 goto _aidl_error;
113 }
114 _aidl_ret_status = remote()->transact(IPingResponder::PING, _aidl_data, &_aidl_reply);
115 if (((_aidl_ret_status) != (::android::OK))) {
116 goto _aidl_error;
117 }
118 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
119 if (((_aidl_ret_status) != (::android::OK))) {
120 goto _aidl_error;
121 }
122 if (!_aidl_status.isOk()) {
123 return _aidl_status;
124 }
125 _aidl_ret_status = _aidl_reply.readString16(_aidl_return);
126 if (((_aidl_ret_status) != (::android::OK))) {
127 goto _aidl_error;
128 }
129 _aidl_error:
130 _aidl_status.setFromStatusT(_aidl_ret_status);
131 return _aidl_status;
132 }
133 
134 ::android::binder::Status BpPingResponder::NullablePing(const ::std::unique_ptr<::android::String16>& input, ::std::unique_ptr<::android::String16>* _aidl_return) {
135 ::android::Parcel _aidl_data;
136 ::android::Parcel _aidl_reply;
137 ::android::status_t _aidl_ret_status = ::android::OK;
138 ::android::binder::Status _aidl_status;
139 _aidl_ret_status = _aidl_data.writeInterfaceToken(getInterfaceDescriptor());
140 if (((_aidl_ret_status) != (::android::OK))) {
141 goto _aidl_error;
142 }
143 _aidl_ret_status = _aidl_data.writeString16(input);
144 if (((_aidl_ret_status) != (::android::OK))) {
145 goto _aidl_error;
146 }
147 _aidl_ret_status = remote()->transact(IPingResponder::NULLABLEPING, _aidl_data, &_aidl_reply);
148 if (((_aidl_ret_status) != (::android::OK))) {
149 goto _aidl_error;
150 }
151 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
152 if (((_aidl_ret_status) != (::android::OK))) {
153 goto _aidl_error;
154 }
155 if (!_aidl_status.isOk()) {
156 return _aidl_status;
157 }
158 _aidl_ret_status = _aidl_reply.readString16(_aidl_return);
159 if (((_aidl_ret_status) != (::android::OK))) {
160 goto _aidl_error;
161 }
162 _aidl_error:
163 _aidl_status.setFromStatusT(_aidl_ret_status);
164 return _aidl_status;
165 }
166 
167 ::android::binder::Status BpPingResponder::Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) {
168 ::android::Parcel _aidl_data;
169 ::android::Parcel _aidl_reply;
170 ::android::status_t _aidl_ret_status = ::android::OK;
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;
175 }
176 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input);
177 if (((_aidl_ret_status) != (::android::OK))) {
178 goto _aidl_error;
179 }
180 _aidl_ret_status = remote()->transact(IPingResponder::UTF8PING, _aidl_data, &_aidl_reply);
181 if (((_aidl_ret_status) != (::android::OK))) {
182 goto _aidl_error;
183 }
184 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
185 if (((_aidl_ret_status) != (::android::OK))) {
186 goto _aidl_error;
187 }
188 if (!_aidl_status.isOk()) {
189 return _aidl_status;
190 }
191 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return);
192 if (((_aidl_ret_status) != (::android::OK))) {
193 goto _aidl_error;
194 }
195 _aidl_error:
196 _aidl_status.setFromStatusT(_aidl_ret_status);
197 return _aidl_status;
198 }
199 
200 ::android::binder::Status BpPingResponder::NullableUtf8Ping(const ::std::unique_ptr<::std::string>& input, ::std::unique_ptr<::std::string>* _aidl_return) {
201 ::android::Parcel _aidl_data;
202 ::android::Parcel _aidl_reply;
203 ::android::status_t _aidl_ret_status = ::android::OK;
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;
208 }
209 _aidl_ret_status = _aidl_data.writeUtf8AsUtf16(input);
210 if (((_aidl_ret_status) != (::android::OK))) {
211 goto _aidl_error;
212 }
213 _aidl_ret_status = remote()->transact(IPingResponder::NULLABLEUTF8PING, _aidl_data, &_aidl_reply);
214 if (((_aidl_ret_status) != (::android::OK))) {
215 goto _aidl_error;
216 }
217 _aidl_ret_status = _aidl_status.readFromParcel(_aidl_reply);
218 if (((_aidl_ret_status) != (::android::OK))) {
219 goto _aidl_error;
220 }
221 if (!_aidl_status.isOk()) {
222 return _aidl_status;
223 }
224 _aidl_ret_status = _aidl_reply.readUtf8FromUtf16(_aidl_return);
225 if (((_aidl_ret_status) != (::android::OK))) {
226 goto _aidl_error;
227 }
228 _aidl_error:
229 _aidl_status.setFromStatusT(_aidl_ret_status);
230 return _aidl_status;
231 }
232 
233 }  // namespace os
234 
235 }  // namespace android
236 #include <android/os/BnPingResponder.h>
237 #include <binder/Parcel.h>
238 
239 namespace android {
240 
241 namespace os {
242 
243 ::android::status_t BnPingResponder::onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags) {
244 ::android::status_t _aidl_ret_status = ::android::OK;
245 switch (_aidl_code) {
246 case Call::PING:
247 {
248 ::android::String16 in_input;
249 ::android::String16 _aidl_return;
250 if (!(_aidl_data.checkInterface(this))) {
251 _aidl_ret_status = ::android::BAD_TYPE;
252 break;
253 }
254 _aidl_ret_status = _aidl_data.readString16(&in_input);
255 if (((_aidl_ret_status) != (::android::OK))) {
256 break;
257 }
258 ::android::binder::Status _aidl_status(Ping(in_input, &_aidl_return));
259 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
260 if (((_aidl_ret_status) != (::android::OK))) {
261 break;
262 }
263 if (!_aidl_status.isOk()) {
264 break;
265 }
266 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return);
267 if (((_aidl_ret_status) != (::android::OK))) {
268 break;
269 }
270 }
271 break;
272 case Call::NULLABLEPING:
273 {
274 ::std::unique_ptr<::android::String16> in_input;
275 ::std::unique_ptr<::android::String16> _aidl_return;
276 if (!(_aidl_data.checkInterface(this))) {
277 _aidl_ret_status = ::android::BAD_TYPE;
278 break;
279 }
280 _aidl_ret_status = _aidl_data.readString16(&in_input);
281 if (((_aidl_ret_status) != (::android::OK))) {
282 break;
283 }
284 ::android::binder::Status _aidl_status(NullablePing(in_input, &_aidl_return));
285 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
286 if (((_aidl_ret_status) != (::android::OK))) {
287 break;
288 }
289 if (!_aidl_status.isOk()) {
290 break;
291 }
292 _aidl_ret_status = _aidl_reply->writeString16(_aidl_return);
293 if (((_aidl_ret_status) != (::android::OK))) {
294 break;
295 }
296 }
297 break;
298 case Call::UTF8PING:
299 {
300 ::std::string in_input;
301 ::std::string _aidl_return;
302 if (!(_aidl_data.checkInterface(this))) {
303 _aidl_ret_status = ::android::BAD_TYPE;
304 break;
305 }
306 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input);
307 if (((_aidl_ret_status) != (::android::OK))) {
308 break;
309 }
310 ::android::binder::Status _aidl_status(Utf8Ping(in_input, &_aidl_return));
311 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
312 if (((_aidl_ret_status) != (::android::OK))) {
313 break;
314 }
315 if (!_aidl_status.isOk()) {
316 break;
317 }
318 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return);
319 if (((_aidl_ret_status) != (::android::OK))) {
320 break;
321 }
322 }
323 break;
324 case Call::NULLABLEUTF8PING:
325 {
326 ::std::unique_ptr<::std::string> in_input;
327 ::std::unique_ptr<::std::string> _aidl_return;
328 if (!(_aidl_data.checkInterface(this))) {
329 _aidl_ret_status = ::android::BAD_TYPE;
330 break;
331 }
332 _aidl_ret_status = _aidl_data.readUtf8FromUtf16(&in_input);
333 if (((_aidl_ret_status) != (::android::OK))) {
334 break;
335 }
336 ::android::binder::Status _aidl_status(NullableUtf8Ping(in_input, &_aidl_return));
337 _aidl_ret_status = _aidl_status.writeToParcel(_aidl_reply);
338 if (((_aidl_ret_status) != (::android::OK))) {
339 break;
340 }
341 if (!_aidl_status.isOk()) {
342 break;
343 }
344 _aidl_ret_status = _aidl_reply->writeUtf8AsUtf16(_aidl_return);
345 if (((_aidl_ret_status) != (::android::OK))) {
346 break;
347 }
348 }
349 break;
350 default:
351 {
352 _aidl_ret_status = ::android::BBinder::onTransact(_aidl_code, _aidl_data, _aidl_reply, _aidl_flags);
353 }
354 break;
355 }
356 if (_aidl_ret_status == ::android::UNEXPECTED_NULL) {
357 _aidl_ret_status = ::android::binder::Status::fromExceptionCode(::android::binder::Status::EX_NULL_POINTER).writeToParcel(_aidl_reply);
358 }
359 return _aidl_ret_status;
360 }
361 
362 }  // namespace os
363 
364 }  // namespace android
365 )";
366 
367 const char kExpectedIHeaderOutput[] =
368 R"(#ifndef AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_
369 #define AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_
370 
371 #include <binder/IBinder.h>
372 #include <binder/IInterface.h>
373 #include <binder/Status.h>
374 #include <memory>
375 #include <string>
376 #include <utils/String16.h>
377 #include <utils/StrongPointer.h>
378 
379 namespace android {
380 
381 namespace os {
382 
383 class IPingResponder : public ::android::IInterface {
384 public:
385 DECLARE_META_INTERFACE(PingResponder)
386 virtual ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) = 0;
387 virtual ::android::binder::Status NullablePing(const ::std::unique_ptr<::android::String16>& input, ::std::unique_ptr<::android::String16>* _aidl_return) = 0;
388 virtual ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) = 0;
389 virtual ::android::binder::Status NullableUtf8Ping(const ::std::unique_ptr<::std::string>& input, ::std::unique_ptr<::std::string>* _aidl_return) = 0;
390 enum Call {
391   PING = ::android::IBinder::FIRST_CALL_TRANSACTION + 0,
392   NULLABLEPING = ::android::IBinder::FIRST_CALL_TRANSACTION + 1,
393   UTF8PING = ::android::IBinder::FIRST_CALL_TRANSACTION + 2,
394   NULLABLEUTF8PING = ::android::IBinder::FIRST_CALL_TRANSACTION + 3,
395 };
396 };  // class IPingResponder
397 
398 }  // namespace os
399 
400 }  // namespace android
401 
402 #endif  // AIDL_GENERATED_ANDROID_OS_I_PING_RESPONDER_H_
403 )";
404 
405 const char kExpectedBpHeaderOutput[] =
406 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_
407 #define AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_
408 
409 #include <binder/IBinder.h>
410 #include <binder/IInterface.h>
411 #include <utils/Errors.h>
412 #include <android/os/IPingResponder.h>
413 
414 namespace android {
415 
416 namespace os {
417 
418 class BpPingResponder : public ::android::BpInterface<IPingResponder> {
419 public:
420 explicit BpPingResponder(const ::android::sp<::android::IBinder>& _aidl_impl);
421 virtual ~BpPingResponder() = default;
422 ::android::binder::Status Ping(const ::android::String16& input, ::android::String16* _aidl_return) override;
423 ::android::binder::Status NullablePing(const ::std::unique_ptr<::android::String16>& input, ::std::unique_ptr<::android::String16>* _aidl_return) override;
424 ::android::binder::Status Utf8Ping(const ::std::string& input, ::std::string* _aidl_return) override;
425 ::android::binder::Status NullableUtf8Ping(const ::std::unique_ptr<::std::string>& input, ::std::unique_ptr<::std::string>* _aidl_return) override;
426 };  // class BpPingResponder
427 
428 }  // namespace os
429 
430 }  // namespace android
431 
432 #endif  // AIDL_GENERATED_ANDROID_OS_BP_PING_RESPONDER_H_
433 )";
434 
435 const char kExpectedBnHeaderOutput[] =
436 R"(#ifndef AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_
437 #define AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_
438 
439 #include <binder/IInterface.h>
440 #include <android/os/IPingResponder.h>
441 
442 namespace android {
443 
444 namespace os {
445 
446 class BnPingResponder : public ::android::BnInterface<IPingResponder> {
447 public:
448 ::android::status_t onTransact(uint32_t _aidl_code, const ::android::Parcel& _aidl_data, ::android::Parcel* _aidl_reply, uint32_t _aidl_flags = 0) override;
449 };  // class BnPingResponder
450 
451 }  // namespace os
452 
453 }  // namespace android
454 
455 #endif  // AIDL_GENERATED_ANDROID_OS_BN_PING_RESPONDER_H_
456 )";
457 
458 }  // namespace ping_responder
459 }  // namespace test_data
460 }  // namespace aidl
461 }  // namespace android
462