// Copyright 2021 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_TEST_FAKE_CONNECTIVITY_MANAGER_H_ #define THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_CONNECTIVITY_MANAGER_H_ #include #include #include #include "absl/container/flat_hash_map.h" #include "absl/strings/string_view.h" #include "sharing/internal/public/connectivity_manager.h" namespace nearby { class FakeConnectivityManager : public ConnectivityManager { public: bool IsLanConnected() override { return is_lan_connected_; } bool IsInternetConnected() override { return is_internet_connected_; } bool IsHPRealtekDevice() override { return is_hp_realtek_device_; } void SetIsHPRealtekDevice(bool is_hp_realtek_device) { is_hp_realtek_device_ = is_hp_realtek_device; } ConnectionType GetConnectionType() override { return connection_type_; } void RegisterConnectionListener( absl::string_view listener_name, std::function callback) override { listeners_.emplace(listener_name, std::move(callback)); } void UnregisterConnectionListener(absl::string_view listener_name) override { listeners_.erase(listener_name); } // Mocks connectivity methods. void SetLanConnected(bool connected) { is_lan_connected_ = connected; for (auto& listener : listeners_) { listener.second(connection_type_, is_lan_connected_, is_internet_connected_); } } void SetInternetConnected(bool connected) { is_internet_connected_ = connected; for (auto& listener : listeners_) { listener.second(connection_type_, is_lan_connected_, is_internet_connected_); } } // Mocks connectivity methods. void SetConnectionType(ConnectionType connection_type) { connection_type_ = connection_type; for (auto& listener : listeners_) { listener.second(connection_type_, is_lan_connected_, is_internet_connected_); } } int GetListenerCount() const { return listeners_.size(); } private: bool is_lan_connected_ = true; bool is_internet_connected_ = true; bool is_hp_realtek_device_ = false; ConnectionType connection_type_ = ConnectionType::kWifi; absl::flat_hash_map> listeners_; }; } // namespace nearby #endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_TEST_FAKE_CONNECTIVITY_MANAGER_H_