blob: beadf96a8163990c3b86948384064e1a4664f533 [file] [log] [blame]
Samuel Tan546d27d2015-12-03 15:06:01 -08001/*
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 "aidl_test_client_primitives.h"
18
19#include <iostream>
Jooyung Han7a9aceb2019-12-17 14:18:15 +000020#include <iterator>
Samuel Tan546d27d2015-12-03 15:06:01 -080021#include <vector>
22
23#include <utils/String16.h>
24#include <utils/String8.h>
25
Daniel Normanee8674f2019-09-20 16:07:00 -070026#include "android/aidl/tests/ByteEnum.h"
Samuel Tan546d27d2015-12-03 15:06:01 -080027#include "android/aidl/tests/INamedCallback.h"
Daniel Normanee8674f2019-09-20 16:07:00 -070028#include "android/aidl/tests/IntEnum.h"
29#include "android/aidl/tests/LongEnum.h"
Samuel Tan546d27d2015-12-03 15:06:01 -080030
Christopher Wileyc7958332016-02-01 09:56:03 -080031#include "test_helpers.h"
32
Samuel Tan546d27d2015-12-03 15:06:01 -080033// libutils:
34using android::sp;
35using android::String16;
36using android::String8;
37
38// libbinder:
39using android::binder::Status;
40
41// generated
42using android::aidl::tests::ITestService;
43using android::aidl::tests::INamedCallback;
44
45using std::cerr;
46using std::cout;
47using std::endl;
48using std::vector;
49
50namespace android {
51namespace aidl {
52namespace tests {
53namespace client {
54
Samuel Tan546d27d2015-12-03 15:06:01 -080055bool ConfirmPrimitiveRepeat(const sp<ITestService>& s) {
56 cout << "Confirming passing and returning primitives works." << endl;
57
58 if (!RepeatPrimitive(s, &ITestService::RepeatBoolean, true) ||
59 !RepeatPrimitive(s, &ITestService::RepeatByte, int8_t{-128}) ||
60 !RepeatPrimitive(s, &ITestService::RepeatChar, char16_t{'A'}) ||
61 !RepeatPrimitive(s, &ITestService::RepeatInt, int32_t{1 << 30}) ||
Chih-Hung Hsiehf04d1022018-12-12 14:46:05 -080062 !RepeatPrimitive(s, &ITestService::RepeatLong, int64_t{1LL << 60}) ||
Daniel Normanee8674f2019-09-20 16:07:00 -070063 !RepeatPrimitive(s, &ITestService::RepeatFloat, float{1.0f / 3.0f}) ||
64 !RepeatPrimitive(s, &ITestService::RepeatDouble, double{1.0 / 3.0}) ||
65 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT) ||
66 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT2) ||
67 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT3) ||
68 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT4) ||
69 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT5) ||
70 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT6) ||
71 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT7) ||
72 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT8) ||
73 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT9) ||
74 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT10) ||
75 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT11) ||
76 !RepeatPrimitive(s, &ITestService::RepeatInt, ITestService::TEST_CONSTANT12) ||
77 !RepeatPrimitive(s, &ITestService::RepeatByteEnum, ByteEnum::FOO) ||
78 !RepeatPrimitive(s, &ITestService::RepeatIntEnum, IntEnum::BAR) ||
79 !RepeatPrimitive(s, &ITestService::RepeatLongEnum, LongEnum::FOO)) {
Samuel Tan546d27d2015-12-03 15:06:01 -080080 return false;
81 }
82
83 vector<String16> inputs = {
84 String16("Deliver us from evil."),
85 String16(),
86 String16("\0\0", 2),
Christopher Wileydca2ecf2016-01-29 10:55:43 -080087 // This is actually two unicode code points:
88 // U+10437: The 'small letter yee' character in the deseret alphabet
89 // U+20AC: A euro sign
90 String16("\xD8\x01\xDC\x37\x20\xAC"),
Christopher Wiley69b44cf2016-05-03 13:43:33 -070091 ITestService::STRING_TEST_CONSTANT(),
92 ITestService::STRING_TEST_CONSTANT2(),
Samuel Tan546d27d2015-12-03 15:06:01 -080093 };
94 for (const auto& input : inputs) {
95 String16 reply;
96 Status status = s->RepeatString(input, &reply);
97 if (!status.isOk() || input != reply) {
98 cerr << "Failed while requesting service to repeat String16=\""
99 << String8(input).string()
100 << "\". Got status=" << status.toString8() << endl;
101 return false;
102 }
103 }
104 return true;
105}
106
Samuel Tan546d27d2015-12-03 15:06:01 -0800107bool ConfirmReverseArrays(const sp<ITestService>& s) {
108 cout << "Confirming passing and returning arrays works." << endl;
109
Daniel Normanee8674f2019-09-20 16:07:00 -0700110 if (!ReverseArray(s, &ITestService::ReverseBoolean, {true, false, false}) ||
111 !ReverseArray(s, &ITestService::ReverseByte, {uint8_t{255}, uint8_t{0}, uint8_t{127}}) ||
112 !ReverseArray(s, &ITestService::ReverseChar, {char16_t{'A'}, char16_t{'B'}, char16_t{'C'}}) ||
113 !ReverseArray(s, &ITestService::ReverseInt, {1, 2, 3}) ||
114 !ReverseArray(s, &ITestService::ReverseLong, {-1LL, 0LL, int64_t{1LL << 60}}) ||
115 !ReverseArray(s, &ITestService::ReverseFloat, {-0.3f, -0.7f, 8.0f}) ||
116 !ReverseArray(s, &ITestService::ReverseDouble, {1.0 / 3.0, 1.0 / 7.0, 42.0}) ||
Samuel Tan546d27d2015-12-03 15:06:01 -0800117 !ReverseArray(s, &ITestService::ReverseString,
Daniel Normanee8674f2019-09-20 16:07:00 -0700118 {String16{"f"}, String16{"a"}, String16{"b"}}) ||
119 !ReverseArray(s, &ITestService::ReverseByteEnum,
120 {ByteEnum::FOO, ByteEnum::BAR, ByteEnum::BAR}) ||
Jooyung Han7a9aceb2019-12-17 14:18:15 +0000121 !ReverseArray(s, &ITestService::ReverseByteEnum,
122 {std::begin(::android::enum_range<ByteEnum>()),
123 std::end(::android::enum_range<ByteEnum>())}) ||
Daniel Normanee8674f2019-09-20 16:07:00 -0700124 !ReverseArray(s, &ITestService::ReverseIntEnum, {IntEnum::FOO, IntEnum::BAR, IntEnum::BAR}) ||
125 !ReverseArray(s, &ITestService::ReverseLongEnum,
126 {LongEnum::FOO, LongEnum::BAR, LongEnum::BAR})) {
Samuel Tan546d27d2015-12-03 15:06:01 -0800127 return false;
128 }
129
130 return true;
131}
132
133bool ConfirmReverseLists(const sp<ITestService>& s) {
134 cout << "Confirming passing and returning List<T> works." << endl;
135
136 if (!ReverseArray(s, &ITestService::ReverseStringList,
137 {String16{"f"}, String16{"a"}, String16{"b"}})) {
138 return false;
139 }
140
141 return true;
142}
143
144bool ConfirmReverseBinderLists(const sp<ITestService>& s) {
145 Status status;
146 cout << "Confirming passing and returning List<T> works with binders." << endl;
147
148 vector<String16> names = {
149 String16{"Larry"},
150 String16{"Curly"},
151 String16{"Moe"}
152 };
153
154 vector<sp<IBinder>> input;
155
156 for (int i = 0; i < 3; i++) {
157 sp<INamedCallback> got;
158
159 status = s->GetOtherTestService(names[i], &got);
160 if (!status.isOk()) {
161 cerr << "Could not retrieve service for test." << endl;
162 return false;
163 }
164
165 input.push_back(INamedCallback::asBinder(got));
166 }
167
168 vector<sp<IBinder>> output;
169 vector<sp<IBinder>> reversed;
170
171 status = s->ReverseNamedCallbackList(input, &output, &reversed);
172 if (!status.isOk()) {
173 cerr << "Failed to reverse named callback list." << endl;
174 }
175
176 if (output.size() != 3) {
177 cerr << "ReverseNamedCallbackList gave repetition with wrong length." << endl;
178 return false;
179 }
180
181 if (reversed.size() != 3) {
182 cerr << "ReverseNamedCallbackList gave reversal with wrong length." << endl;
183 return false;
184 }
185
186 for (int i = 0; i < 3; i++) {
187 String16 ret;
188 sp<INamedCallback> named_callback =
189 android::interface_cast<INamedCallback>(output[i]);
190 status = named_callback->GetName(&ret);
191
192 if (!status.isOk()) {
193 cerr << "Could not query INamedCallback from output" << endl;
194 return false;
195 }
196
197 if (ret != names[i]) {
198 cerr << "Output had wrong INamedCallback" << endl;
199 return false;
200 }
201 }
202
203 for (int i = 0; i < 3; i++) {
204 String16 ret;
205 sp<INamedCallback> named_callback =
206 android::interface_cast<INamedCallback>(reversed[i]);
207 status = named_callback->GetName(&ret);
208
209 if (!status.isOk()) {
210 cerr << "Could not query INamedCallback from reversed output" << endl;
211 return false;
212 }
213
214 if (ret != names[2 - i]) {
215 cerr << "Reversed output had wrong INamedCallback" << endl;
216 return false;
217 }
218 }
219
220 return true;
221}
222
Will McVickerd7d18df2019-09-12 13:40:50 -0700223bool ConfirmIntfConstantExpressions(const sp<ITestService>& s) {
224 (void)s;
225 bool ret = true;
226
227 if (ITestService::A1 != 1) {
228 cerr << "ITestService::A1 should be 1 but is " << ITestService::A1 << endl;
229 ret = false;
230 }
231 if (ITestService::A2 != 1) {
232 cerr << "ITestService::A2 should be 1 but is " << ITestService::A2 << endl;
233 ret = false;
234 }
235 if (ITestService::A3 != 1) {
236 cerr << "ITestService::A3 should be 1 but is " << ITestService::A3 << endl;
237 ret = false;
238 }
239 if (ITestService::A4 != 1) {
240 cerr << "ITestService::A4 should be 1 but is " << ITestService::A4 << endl;
241 ret = false;
242 }
243 if (ITestService::A5 != 1) {
244 cerr << "ITestService::A5 should be 1 but is " << ITestService::A5 << endl;
245 ret = false;
246 }
247 if (ITestService::A6 != 1) {
248 cerr << "ITestService::A6 should be 1 but is " << ITestService::A6 << endl;
249 ret = false;
250 }
251 if (ITestService::A7 != 1) {
252 cerr << "ITestService::A7 should be 1 but is " << ITestService::A7 << endl;
253 ret = false;
254 }
255 if (ITestService::A8 != 1) {
256 cerr << "ITestService::A8 should be 1 but is " << ITestService::A8 << endl;
257 ret = false;
258 }
259 if (ITestService::A9 != 1) {
260 cerr << "ITestService::A9 should be 1 but is " << ITestService::A9 << endl;
261 ret = false;
262 }
263 if (ITestService::A10 != 1) {
264 cerr << "ITestService::A10 should be 1 but is " << ITestService::A10 << endl;
265 ret = false;
266 }
267 if (ITestService::A11 != 1) {
268 cerr << "ITestService::A11 should be 1 but is " << ITestService::A11 << endl;
269 ret = false;
270 }
271 if (ITestService::A12 != 1) {
272 cerr << "ITestService::A12 should be 1 but is " << ITestService::A12 << endl;
273 ret = false;
274 }
275 if (ITestService::A13 != 1) {
276 cerr << "ITestService::A13 should be 1 but is " << ITestService::A13 << endl;
277 ret = false;
278 }
279 if (ITestService::A14 != 1) {
280 cerr << "ITestService::A14 should be 1 but is " << ITestService::A14 << endl;
281 ret = false;
282 }
283 if (ITestService::A15 != 1) {
284 cerr << "ITestService::A15 should be 1 but is " << ITestService::A15 << endl;
285 ret = false;
286 }
287 if (ITestService::A16 != 1) {
288 cerr << "ITestService::A16 should be 1 but is " << ITestService::A16 << endl;
289 ret = false;
290 }
291 if (ITestService::A17 != 1) {
292 cerr << "ITestService::A17 should be 1 but is " << ITestService::A17 << endl;
293 ret = false;
294 }
295 if (ITestService::A18 != 1) {
296 cerr << "ITestService::A18 should be 1 but is " << ITestService::A18 << endl;
297 ret = false;
298 }
299 if (ITestService::A19 != 1) {
300 cerr << "ITestService::A19 should be 1 but is " << ITestService::A19 << endl;
301 ret = false;
302 }
303 if (ITestService::A20 != 1) {
304 cerr << "ITestService::A20 should be 1 but is " << ITestService::A20 << endl;
305 ret = false;
306 }
307 if (ITestService::A21 != 1) {
308 cerr << "ITestService::A21 should be 1 but is " << ITestService::A21 << endl;
309 ret = false;
310 }
311 if (ITestService::A22 != 1) {
312 cerr << "ITestService::A22 should be 1 but is " << ITestService::A22 << endl;
313 ret = false;
314 }
315 if (ITestService::A23 != 1) {
316 cerr << "ITestService::A23 should be 1 but is " << ITestService::A23 << endl;
317 ret = false;
318 }
319 if (ITestService::A24 != 1) {
320 cerr << "ITestService::A24 should be 1 but is " << ITestService::A24 << endl;
321 ret = false;
322 }
323 if (ITestService::A25 != 1) {
324 cerr << "ITestService::A25 should be 1 but is " << ITestService::A25 << endl;
325 ret = false;
326 }
327 if (ITestService::A26 != 1) {
328 cerr << "ITestService::A26 should be 1 but is " << ITestService::A26 << endl;
329 ret = false;
330 }
331 if (ITestService::A27 != 1) {
332 cerr << "ITestService::A27 should be 1 but is " << ITestService::A27 << endl;
333 ret = false;
334 }
335 if (ITestService::A28 != 1) {
336 cerr << "ITestService::A28 should be 1 but is " << ITestService::A28 << endl;
337 ret = false;
338 }
339 if (ITestService::A29 != 1) {
340 cerr << "ITestService::A29 should be 1 but is " << ITestService::A29 << endl;
341 ret = false;
342 }
343 if (ITestService::A30 != 1) {
344 cerr << "ITestService::A30 should be 1 but is " << ITestService::A30 << endl;
345 ret = false;
346 }
347 if (ITestService::A31 != 1) {
348 cerr << "ITestService::A31 should be 1 but is " << ITestService::A31 << endl;
349 ret = false;
350 }
351 if (ITestService::A32 != 1) {
352 cerr << "ITestService::A32 should be 1 but is " << ITestService::A32 << endl;
353 ret = false;
354 }
355 if (ITestService::A33 != 1) {
356 cerr << "ITestService::A33 should be 1 but is " << ITestService::A33 << endl;
357 ret = false;
358 }
359 if (ITestService::A34 != 1) {
360 cerr << "ITestService::A34 should be 1 but is " << ITestService::A34 << endl;
361 ret = false;
362 }
363 if (ITestService::A35 != 1) {
364 cerr << "ITestService::A35 should be 1 but is " << ITestService::A35 << endl;
365 ret = false;
366 }
367 if (ITestService::A36 != 1) {
368 cerr << "ITestService::A36 should be 1 but is " << ITestService::A36 << endl;
369 ret = false;
370 }
371 if (ITestService::A37 != 1) {
372 cerr << "ITestService::A37 should be 1 but is " << ITestService::A37 << endl;
373 ret = false;
374 }
375 if (ITestService::A38 != 1) {
376 cerr << "ITestService::A38 should be 1 but is " << ITestService::A38 << endl;
377 ret = false;
378 }
379 if (ITestService::A39 != 1) {
380 cerr << "ITestService::A39 should be 1 but is " << ITestService::A39 << endl;
381 ret = false;
382 }
383 if (ITestService::A40 != 1) {
384 cerr << "ITestService::A40 should be 1 but is " << ITestService::A40 << endl;
385 ret = false;
386 }
387 if (ITestService::A41 != 1) {
388 cerr << "ITestService::A41 should be 1 but is " << ITestService::A41 << endl;
389 ret = false;
390 }
391 if (ITestService::A42 != 1) {
392 cerr << "ITestService::A42 should be 1 but is " << ITestService::A42 << endl;
393 ret = false;
394 }
395 if (ITestService::A43 != 1) {
396 cerr << "ITestService::A43 should be 1 but is " << ITestService::A43 << endl;
397 ret = false;
398 }
399 if (ITestService::A44 != 1) {
400 cerr << "ITestService::A44 should be 1 but is " << ITestService::A44 << endl;
401 ret = false;
402 }
403 if (ITestService::A45 != 1) {
404 cerr << "ITestService::A45 should be 1 but is " << ITestService::A45 << endl;
405 ret = false;
406 }
407 if (ITestService::A46 != 1) {
408 cerr << "ITestService::A46 should be 1 but is " << ITestService::A46 << endl;
409 ret = false;
410 }
411 if (ITestService::A47 != 1) {
412 cerr << "ITestService::A47 should be 1 but is " << ITestService::A47 << endl;
413 ret = false;
414 }
415 if (ITestService::A48 != 1) {
416 cerr << "ITestService::A48 should be 1 but is " << ITestService::A48 << endl;
417 ret = false;
418 }
419 if (ITestService::A49 != 1) {
420 cerr << "ITestService::A49 should be 1 but is " << ITestService::A49 << endl;
421 ret = false;
422 }
423 if (ITestService::A50 != 1) {
424 cerr << "ITestService::A50 should be 1 but is " << ITestService::A50 << endl;
425 ret = false;
426 }
427 if (ITestService::A51 != 1) {
428 cerr << "ITestService::A51 should be 1 but is " << ITestService::A51 << endl;
429 ret = false;
430 }
431 if (ITestService::A52 != 1) {
432 cerr << "ITestService::A52 should be 1 but is " << ITestService::A52 << endl;
433 ret = false;
434 }
435 if (ITestService::A53 != 1) {
436 cerr << "ITestService::A53 should be 1 but is " << ITestService::A53 << endl;
437 ret = false;
438 }
439 if (ITestService::A54 != 1) {
440 cerr << "ITestService::A54 should be 1 but is " << ITestService::A54 << endl;
441 ret = false;
442 }
443 if (ITestService::A55 != 1) {
444 cerr << "ITestService::A55 should be 1 but is " << ITestService::A55 << endl;
445 ret = false;
446 }
447 if (ITestService::A56 != 1) {
448 cerr << "ITestService::A56 should be 1 but is " << ITestService::A56 << endl;
449 ret = false;
450 }
451 if (ITestService::A57 != 1) {
452 cerr << "ITestService::A57 should be 1 but is " << ITestService::A57 << endl;
453 ret = false;
454 }
455
456 return ret;
457}
458
Samuel Tan546d27d2015-12-03 15:06:01 -0800459} // namespace client
460} // namespace tests
461} // namespace aidl
462} // namespace android