blob: 7097edb57507a82725d71fc698e12651bf98be95 [file] [log] [blame]
Christopher Wileyb5e698c2015-10-17 09:32:22 -07001/*
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 Wiley521bb612015-10-22 11:40:30 -070023#include "android/aidl/tests/ITestService.h"
Christopher Wileyb5e698c2015-10-17 09:32:22 -070024
25// libutils:
26using android::OK;
27using android::sp;
28using android::status_t;
29using android::String16;
30
31// libbinder:
32using android::getService;
33
34// generated
Christopher Wiley521bb612015-10-22 11:40:30 -070035using android::aidl::tests::ITestService;
Christopher Wileyb5e698c2015-10-17 09:32:22 -070036
37using std::cerr;
38using std::cout;
39using std::endl;
40
41namespace {
42
Christopher Wiley521bb612015-10-22 11:40:30 -070043const char kServiceName[] = "android.aidl.tests.ITestService";
Christopher Wileyb5e698c2015-10-17 09:32:22 -070044
Christopher Wiley521bb612015-10-22 11:40:30 -070045bool ConfirmBasicPing(const sp<ITestService>& service) {
Christopher Wiley33ad81e2015-10-21 14:41:11 -070046 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 Wiley521bb612015-10-22 11:40:30 -070064bool GetService(sp<ITestService>* service) {
65 cout << "Retrieving test service binder" << endl;
Christopher Wiley33ad81e2015-10-21 14:41:11 -070066 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 Wileyb5e698c2015-10-17 09:32:22 -070075} // namespace
76
Brian Carlstromad3b8062015-10-21 08:54:48 -070077int main(int /* argc */, char * /* argv */ []) {
Christopher Wiley521bb612015-10-22 11:40:30 -070078 sp<ITestService> service;
Christopher Wileyb5e698c2015-10-17 09:32:22 -070079
Christopher Wiley33ad81e2015-10-21 14:41:11 -070080 if (!GetService(&service)) return 1;
81
82 if (!ConfirmBasicPing(service)) return 1;
Christopher Wileyb5e698c2015-10-17 09:32:22 -070083
84 return 0;
85}