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 <vector>
18
19#include <android-base/logging.h>
20#include <gtest/gtest.h>
21#include <utils/StrongPointer.h>
22
23#include "android/net/wifi/IClientInterface.h"
24#include "android/net/wifi/IWificond.h"
25#include "wificond/tests/integration/process_utils.h"
26
27using android::net::wifi::IClientInterface;
28using android::net::wifi::IWificond;
29using android::net::wifi::IWifiScannerImpl;
30using android::wificond::tests::integration::ScopedDevModeWificond;
31using std::unique_ptr;
32using std::vector;
33
34namespace android {
35namespace wificond {
36namespace {
37const char kInterfaceName[] = "wlan0";
38
39sp<IWifiScannerImpl> InitInterfaceAndReturnScanner(sp<IWificond> service) {
40  sp<IWifiScannerImpl> scanner;
41  sp<IClientInterface> client_interface;
42  if (!service->createClientInterface(
43      kInterfaceName, &client_interface).isOk()) {
44    LOG(FATAL) << "Failed to create client interface";
45    return nullptr;
46  }
47  if (client_interface == nullptr) {
48    LOG(FATAL) << "Failed to get a valid client interface handler";
49    return nullptr;
50  }
51  if (!client_interface->getWifiScannerImpl(&scanner).isOk()) {
52    LOG(FATAL) << "Failed to get a WifiScannerImpl handler";
53    return nullptr;
54  }
55  return scanner;
56}
57
58}  // namespace
59
60TEST(ScannerTest, CanGetValidWifiScannerImpl) {
61  ScopedDevModeWificond dev_mode;
62  sp<IWificond> service = dev_mode.EnterDevModeOrDie();
63  EXPECT_NE(nullptr, InitInterfaceAndReturnScanner(service).get());
64}
65
66}  // namespace wificond
67}  // namespace android
68