• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 <algorithm>
18 #include <vector>
19 
20 #include <android-base/logging.h>
21 #include <binder/Status.h>
22 #include <utils/StrongPointer.h>
23 
24 #include "android/aidl/tests/ITestService.h"
25 
26 namespace android {
27 namespace aidl {
28 namespace tests {
29 namespace client {
30 
31 template <typename T, typename U, typename V>
RepeatPrimitive(const android::sp<android::aidl::tests::ITestService> & service,android::binder::Status (android::aidl::tests::ITestService::* func)(T,V *),U input)32 bool RepeatPrimitive(
33     const android::sp<android::aidl::tests::ITestService>& service,
34     android::binder::Status(android::aidl::tests::ITestService::*func)(T, V*),
35     U input) {
36   V reply;
37   android::binder::Status status = (*service.*func)(input, &reply);
38   if (!status.isOk() || input != reply) {
39     LOG(ERROR) << "Failed to repeat primitive. status=" << status.toString8()
40                << ".";
41     return false;
42   }
43   return true;
44 }
45 
46 template <typename T>
ReverseArray(const android::sp<android::aidl::tests::ITestService> & service,android::binder::Status (android::aidl::tests::ITestService::* func)(const std::vector<T> &,std::vector<T> *,std::vector<T> *),std::vector<T> input)47 bool ReverseArray(
48     const android::sp<android::aidl::tests::ITestService>& service,
49     android::binder::Status(android::aidl::tests::ITestService::*func)(
50         const std::vector<T>&, std::vector<T>*, std::vector<T>*),
51         std::vector<T> input) {
52   std::vector<T> actual_reversed;
53   std::vector<T> actual_repeated;
54   android::binder::Status status = (*service.*func)(
55       input, &actual_repeated, &actual_reversed);
56   if (!status.isOk()) {
57     LOG(ERROR) << "Failed to repeat array. status=" << status.toString8()
58                << ".";
59     return false;
60   }
61   if (input != actual_repeated) {
62     LOG(ERROR) << "Repeated version of array did not match";
63     LOG(ERROR) << "input.size()=" << input.size()
64                << " repeated.size()=" << actual_repeated.size();
65     return false;
66   }
67   std::reverse(input.begin(), input.end());
68   if (input != actual_reversed) {
69     LOG(ERROR) << "Reversed version of array did not match";
70     return false;
71   }
72   return true;
73 }
74 
75 }  // namespace client
76 }  // namespace tests
77 }  // namespace aidl
78 }  // namespace android
79