diff --git a/api/test/network_emulation_manager.cc b/api/test/network_emulation_manager.cc index e23c09b6ac..5b7cd1507a 100644 --- a/api/test/network_emulation_manager.cc +++ b/api/test/network_emulation_manager.cc @@ -50,10 +50,19 @@ NetworkEmulationManager::SimulatedNetworkNode::Builder::loss(double loss_rate) { NetworkEmulationManager::SimulatedNetworkNode NetworkEmulationManager::SimulatedNetworkNode::Builder::Build() const { + RTC_CHECK(net_); + return Build(net_); +} + +NetworkEmulationManager::SimulatedNetworkNode +NetworkEmulationManager::SimulatedNetworkNode::Builder::Build( + NetworkEmulationManager* net) const { + RTC_CHECK(net); + RTC_CHECK(net_ == nullptr || net_ == net); SimulatedNetworkNode res; auto behavior = std::make_unique(config_); res.simulation = behavior.get(); - res.node = net_->CreateEmulatedNode(std::move(behavior)); + res.node = net->CreateEmulatedNode(std::move(behavior)); return res; } } // namespace webrtc diff --git a/api/test/network_emulation_manager.h b/api/test/network_emulation_manager.h index b368aef19d..8a67993cd6 100644 --- a/api/test/network_emulation_manager.h +++ b/api/test/network_emulation_manager.h @@ -83,6 +83,7 @@ class NetworkEmulationManager { class Builder { public: explicit Builder(NetworkEmulationManager* net) : net_(net) {} + Builder() : net_(nullptr) {} Builder(const Builder&) = default; // Sets the config state, note that this will replace any previously set // values. @@ -92,6 +93,7 @@ class NetworkEmulationManager { Builder& capacity_Mbps(int link_capacity_Mbps); Builder& loss(double loss_rate); SimulatedNetworkNode Build() const; + SimulatedNetworkNode Build(NetworkEmulationManager* net) const; private: NetworkEmulationManager* const net_;