| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -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 <iostream> |
| 18 | |
| 19 | #include <binder/IServiceManager.h> |
| 20 | #include <utils/String16.h> |
| 21 | #include <utils/StrongPointer.h> |
| 22 | |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 23 | #include "android/aidl/tests/ITestService.h" |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 24 | |
| 25 | // libutils: |
| 26 | using android::OK; |
| 27 | using android::sp; |
| 28 | using android::status_t; |
| 29 | using android::String16; |
| 30 | |
| 31 | // libbinder: |
| 32 | using android::getService; |
| 33 | |
| 34 | // generated |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 35 | using android::aidl::tests::ITestService; |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 36 | |
| 37 | using std::cerr; |
| 38 | using std::cout; |
| 39 | using std::endl; |
| 40 | |
| 41 | namespace { |
| 42 | |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 43 | const char kServiceName[] = "android.aidl.tests.ITestService"; |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 44 | |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 45 | bool ConfirmBasicPing(const sp<ITestService>& service) { |
| Christopher Wiley | 33ad81e | 2015-10-21 14:41:11 -0700 | [diff] [blame] | 46 | cout << "Confirming basic ping functionality." << endl; |
| 47 | const int32_t kIncrement = 1 << 20; |
| 48 | for (int32_t i = 0; i < 3; ++i) { |
| 49 | const int32_t token = -kIncrement + i * kIncrement; |
| 50 | int32_t reply = -1; |
| 51 | if (service->Ping(token, &reply) != OK) { |
| 52 | cerr << "Failed to ping server with token=" << token << endl; |
| 53 | return false; |
| 54 | } |
| 55 | if (token != reply) { |
| 56 | cerr << "Server replied to token=" << token |
| 57 | << " with reply=" << reply << endl; |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 64 | bool GetService(sp<ITestService>* service) { |
| 65 | cout << "Retrieving test service binder" << endl; |
| Christopher Wiley | 33ad81e | 2015-10-21 14:41:11 -0700 | [diff] [blame] | 66 | status_t status = getService(String16(kServiceName), service); |
| 67 | if (status != OK) { |
| 68 | cerr << "Failed to get service binder: '" << kServiceName |
| 69 | << "' status=" << status << endl; |
| 70 | return false; |
| 71 | } |
| 72 | return true; |
| 73 | } |
| 74 | |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 75 | } // namespace |
| 76 | |
| Brian Carlstrom | ad3b806 | 2015-10-21 08:54:48 -0700 | [diff] [blame] | 77 | int main(int /* argc */, char * /* argv */ []) { |
| Christopher Wiley | 521bb61 | 2015-10-22 11:40:30 -0700 | [diff] [blame] | 78 | sp<ITestService> service; |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 79 | |
| Christopher Wiley | 33ad81e | 2015-10-21 14:41:11 -0700 | [diff] [blame] | 80 | if (!GetService(&service)) return 1; |
| 81 | |
| 82 | if (!ConfirmBasicPing(service)) return 1; |
| Christopher Wiley | b5e698c | 2015-10-17 09:32:22 -0700 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |