From 8e3cfd04f89772f058bb73efa6849a651a4bc67f Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Wed, 1 May 2024 12:03:49 -0700 Subject: [PATCH] Add tests for sharing_platform_base. PiperOrigin-RevId: 629794040 --- sharing/internal/api/BUILD | 4 ++ .../internal/api/mock_fast_init_ble_beacon.h | 36 +++++++++++ .../api/mock_fast_initiation_manager.h | 60 +++++++++++++++++++ sharing/internal/api/mock_shell.h | 42 +++++++++++++ sharing/internal/api/mock_wifi_adapter.h | 55 +++++++++++++++++ 5 files changed, 197 insertions(+) create mode 100644 sharing/internal/api/mock_fast_init_ble_beacon.h create mode 100644 sharing/internal/api/mock_fast_initiation_manager.h create mode 100644 sharing/internal/api/mock_shell.h create mode 100644 sharing/internal/api/mock_wifi_adapter.h diff --git a/sharing/internal/api/BUILD b/sharing/internal/api/BUILD index a4bcb660..c69a8eb2 100644 --- a/sharing/internal/api/BUILD +++ b/sharing/internal/api/BUILD @@ -61,10 +61,14 @@ cc_library( "fake_nearby_share_client.h", "mock_app_info.h", "mock_bluetooth_adapter.h", + "mock_fast_init_ble_beacon.h", + "mock_fast_initiation_manager.h", "mock_network_monitor.h", "mock_public_certificate_db.h", "mock_sharing_platform.h", + "mock_shell.h", "mock_system_info.h", + "mock_wifi_adapter.h", ], visibility = ["//visibility:public"], deps = [ diff --git a/sharing/internal/api/mock_fast_init_ble_beacon.h b/sharing/internal/api/mock_fast_init_ble_beacon.h new file mode 100644 index 00000000..977d99c1 --- /dev/null +++ b/sharing/internal/api/mock_fast_init_ble_beacon.h @@ -0,0 +1,36 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INIT_BLE_BEACON_H_ +#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INIT_BLE_BEACON_H_ + +#include "gmock/gmock.h" +#include "sharing/internal/api/fast_init_ble_beacon.h" + +namespace nearby::sharing::api { + +class MockFastInitBleBeacon : public nearby::api::FastInitBleBeacon { + public: + MockFastInitBleBeacon() = default; + MockFastInitBleBeacon(const MockFastInitBleBeacon&) = delete; + MockFastInitBleBeacon& operator=(const MockFastInitBleBeacon&) = delete; + ~MockFastInitBleBeacon() override = default; + + MOCK_METHOD(void, SerializeToByteArray, (), (override)); + MOCK_METHOD(void, ParseFromByteArray, (), (override)); +}; + +} // namespace nearby::sharing::api + +#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INIT_BLE_BEACON_H_ diff --git a/sharing/internal/api/mock_fast_initiation_manager.h b/sharing/internal/api/mock_fast_initiation_manager.h new file mode 100644 index 00000000..7f06f8bd --- /dev/null +++ b/sharing/internal/api/mock_fast_initiation_manager.h @@ -0,0 +1,60 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INITIATION_MANAGER_H_ +#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INITIATION_MANAGER_H_ + +#include + +#include "gmock/gmock.h" +#include "sharing/internal/api/fast_init_ble_beacon.h" +#include "sharing/internal/api/fast_initiation_manager.h" + +namespace nearby::sharing::api { + +class MockFastInitiationManager : public nearby::api::FastInitiationManager { + public: + MockFastInitiationManager() = default; + MockFastInitiationManager(const MockFastInitiationManager&) = delete; + MockFastInitiationManager& operator=(const MockFastInitiationManager&) = + delete; + ~MockFastInitiationManager() override = default; + + MOCK_METHOD(void, StartAdvertising, + (nearby::api::FastInitBleBeacon::FastInitType type, + std::function callback, + std::function + error_callback), + (override)); + + MOCK_METHOD(void, StopAdvertising, (std::function callback), + (override)); + + MOCK_METHOD(void, StartScanning, + (std::function devices_discovered_callback, + std::function devices_not_discovered_callback, + std::function + error_callback), + (override)); + + MOCK_METHOD(void, StopScanning, (std::function callback), (override)); + + MOCK_METHOD(bool, IsAdvertising, (), (override)); + + MOCK_METHOD(bool, IsScanning, (), (override)); +}; + +} // namespace nearby::sharing::api + +#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_FAST_INITIATION_MANAGER_H_ diff --git a/sharing/internal/api/mock_shell.h b/sharing/internal/api/mock_shell.h new file mode 100644 index 00000000..b75a4171 --- /dev/null +++ b/sharing/internal/api/mock_shell.h @@ -0,0 +1,42 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_ +#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_ + +#include // NOLINT +#include + +#include "gmock/gmock.h" +#include "absl/status/status.h" +#include "sharing/internal/api/shell.h" + +namespace nearby::sharing::api { + +class MockShell : public nearby::api::Shell { + public: + MockShell() = default; + MockShell(const MockShell&) = delete; + MockShell& operator=(const MockShell&) = delete; + ~MockShell() override = default; + + MOCK_METHOD(void, Open, + (const std::filesystem::path& path, + std::function callback), + (override)); +}; + +} // namespace nearby::sharing::api + +#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_SHELL_H_ diff --git a/sharing/internal/api/mock_wifi_adapter.h b/sharing/internal/api/mock_wifi_adapter.h new file mode 100644 index 00000000..76e301dd --- /dev/null +++ b/sharing/internal/api/mock_wifi_adapter.h @@ -0,0 +1,55 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_WIFI_ADAPTER_H_ +#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_WIFI_ADAPTER_H_ + +#include +#include +#include + +#include "gmock/gmock.h" +#include "absl/status/status.h" +#include "absl/strings/string_view.h" +#include "sharing/internal/api/wifi_adapter.h" + +namespace nearby::sharing::api { + +class MockWifiAdapter : public nearby::sharing::api::WifiAdapter { + public: + MockWifiAdapter() = default; + MockWifiAdapter(const MockWifiAdapter&) = delete; + MockWifiAdapter& operator=(const MockWifiAdapter&) = delete; + ~MockWifiAdapter() override = default; + + MOCK_METHOD(bool, IsPresent, (), (const, override)); + MOCK_METHOD(bool, IsPowered, (), (const, override)); + MOCK_METHOD(PermissionStatus, GetOsPermissionStatus, (), (const, override)); + MOCK_METHOD(void, SetPowered, + (bool powered, std::function success_callback, + std::function error_callback), + (override)); + MOCK_METHOD(std::optional, GetAdapterId, (), (const, override)); + MOCK_METHOD(void, AddObserver, (Observer * observer), (override)); + MOCK_METHOD(void, RemoveObserver, (Observer * observer), (override)); + MOCK_METHOD(bool, HasObserver, (Observer * observer), (override)); + MOCK_METHOD(void, JoinNetwork, + (absl::string_view ssid, absl::string_view password, + std::function callback), + (override)); +}; + +} // namespace nearby::sharing::api + +#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_MOCK_WIFI_ADAPTER_H_