mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove use of dynamic_cast from nearby/sharing.
PiperOrigin-RevId: 634519160
This commit is contained in:
committed by
Copybara-Service
parent
20c0c5aac3
commit
16f820471e
@@ -44,13 +44,13 @@ namespace nearby {
|
||||
|
||||
FakeContext::FakeContext()
|
||||
: fake_clock_(std::make_unique<FakeClock>()),
|
||||
connectivity_manager_(std::make_unique<FakeConnectivityManager>()),
|
||||
bluetooth_adapter_(std::make_unique<FakeBluetoothAdapter>()),
|
||||
wifi_adapter_(std::make_unique<FakeWifiAdapter>()),
|
||||
fast_initiation_manager_(std::make_unique<FakeFastInitiationManager>()),
|
||||
shell_(std::make_unique<FakeShell>()),
|
||||
executor_(std::make_unique<FakeTaskRunner>(
|
||||
dynamic_cast<FakeClock*>(GetClock()), 5)) {}
|
||||
fake_connectivity_manager_(std::make_unique<FakeConnectivityManager>()),
|
||||
fake_bluetooth_adapter_(std::make_unique<FakeBluetoothAdapter>()),
|
||||
fake_wifi_adapter_(std::make_unique<FakeWifiAdapter>()),
|
||||
fake_fast_initiation_manager_(
|
||||
std::make_unique<FakeFastInitiationManager>()),
|
||||
fake_shell_(std::make_unique<FakeShell>()),
|
||||
executor_(std::make_unique<FakeTaskRunner>(fake_clock_.get(), 5)) {}
|
||||
|
||||
Clock* FakeContext::GetClock() const { return fake_clock_.get(); }
|
||||
|
||||
@@ -73,35 +73,35 @@ void FakeContext::CopyText(const absl::string_view text,
|
||||
}
|
||||
|
||||
ConnectivityManager* FakeContext::GetConnectivityManager() const {
|
||||
return connectivity_manager_.get();
|
||||
return fake_connectivity_manager_.get();
|
||||
}
|
||||
|
||||
sharing::api::BluetoothAdapter& FakeContext::GetBluetoothAdapter() const {
|
||||
return *bluetooth_adapter_;
|
||||
return *fake_bluetooth_adapter_;
|
||||
}
|
||||
|
||||
sharing::api::WifiAdapter& FakeContext::GetWifiAdapter() const {
|
||||
return *wifi_adapter_;
|
||||
return *fake_wifi_adapter_;
|
||||
}
|
||||
|
||||
api::FastInitiationManager& FakeContext::GetFastInitiationManager() const {
|
||||
return *fast_initiation_manager_;
|
||||
return *fake_fast_initiation_manager_;
|
||||
}
|
||||
|
||||
std::unique_ptr<TaskRunner> FakeContext::CreateSequencedTaskRunner() const {
|
||||
std::unique_ptr<TaskRunner> task_runner =
|
||||
std::make_unique<FakeTaskRunner>(dynamic_cast<FakeClock*>(GetClock()), 1);
|
||||
std::make_unique<FakeTaskRunner>(fake_clock_.get(), 1);
|
||||
return task_runner;
|
||||
}
|
||||
|
||||
std::unique_ptr<TaskRunner> FakeContext::CreateConcurrentTaskRunner(
|
||||
uint32_t concurrent_count) const {
|
||||
std::unique_ptr<TaskRunner> task_runner = std::make_unique<FakeTaskRunner>(
|
||||
dynamic_cast<FakeClock*>(GetClock()), concurrent_count);
|
||||
std::unique_ptr<TaskRunner> task_runner =
|
||||
std::make_unique<FakeTaskRunner>(fake_clock_.get(), concurrent_count);
|
||||
return task_runner;
|
||||
}
|
||||
|
||||
api::Shell& FakeContext::GetShell() const { return *shell_; }
|
||||
api::Shell& FakeContext::GetShell() const { return *fake_shell_; }
|
||||
|
||||
TaskRunner* FakeContext::GetTaskRunner() { return executor_.get(); }
|
||||
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
#include "sharing/internal/api/wifi_adapter.h"
|
||||
#include "sharing/internal/public/connectivity_manager.h"
|
||||
#include "sharing/internal/public/context.h"
|
||||
#include "sharing/internal/test/fake_bluetooth_adapter.h"
|
||||
#include "sharing/internal/test/fake_connectivity_manager.h"
|
||||
#include "sharing/internal/test/fake_fast_initiation_manager.h"
|
||||
#include "sharing/internal/test/fake_shell.h"
|
||||
#include "sharing/internal/test/fake_wifi_adapter.h"
|
||||
|
||||
namespace nearby {
|
||||
|
||||
@@ -58,14 +63,27 @@ class FakeContext : public Context {
|
||||
TaskRunner* GetTaskRunner() override;
|
||||
|
||||
FakeClock* fake_clock() const { return fake_clock_.get(); }
|
||||
FakeConnectivityManager* fake_connectivity_manager() const {
|
||||
return fake_connectivity_manager_.get();
|
||||
}
|
||||
FakeBluetoothAdapter* fake_bluetooth_adapter() const {
|
||||
return fake_bluetooth_adapter_.get();
|
||||
}
|
||||
FakeWifiAdapter* fake_wifi_adapter() const {
|
||||
return fake_wifi_adapter_.get();
|
||||
}
|
||||
FakeFastInitiationManager* fake_fast_initiation_manager() const {
|
||||
return fake_fast_initiation_manager_.get();
|
||||
}
|
||||
FakeShell* fake_shell() const { return fake_shell_.get(); }
|
||||
|
||||
private:
|
||||
std::unique_ptr<FakeClock> fake_clock_;
|
||||
std::unique_ptr<ConnectivityManager> connectivity_manager_;
|
||||
std::unique_ptr<sharing::api::BluetoothAdapter> bluetooth_adapter_;
|
||||
std::unique_ptr<sharing::api::WifiAdapter> wifi_adapter_;
|
||||
std::unique_ptr<api::FastInitiationManager> fast_initiation_manager_;
|
||||
std::unique_ptr<api::Shell> shell_;
|
||||
std::unique_ptr<FakeConnectivityManager> fake_connectivity_manager_;
|
||||
std::unique_ptr<FakeBluetoothAdapter> fake_bluetooth_adapter_;
|
||||
std::unique_ptr<FakeWifiAdapter> fake_wifi_adapter_;
|
||||
std::unique_ptr<FakeFastInitiationManager> fake_fast_initiation_manager_;
|
||||
std::unique_ptr<FakeShell> fake_shell_;
|
||||
std::unique_ptr<TaskRunner> executor_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user