OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 #endif // defined(WEBRTC_POSIX) | 94 #endif // defined(WEBRTC_POSIX) |
95 | 95 |
96 protected: | 96 protected: |
97 bool callback_called_; | 97 bool callback_called_; |
98 }; | 98 }; |
99 | 99 |
100 class TestBasicNetworkManager : public BasicNetworkManager { | 100 class TestBasicNetworkManager : public BasicNetworkManager { |
101 public: | 101 public: |
102 using BasicNetworkManager::QueryDefaultLocalAddress; | 102 using BasicNetworkManager::QueryDefaultLocalAddress; |
| 103 using BasicNetworkManager::set_default_local_addresses; |
103 }; | 104 }; |
104 | 105 |
105 // Test that the Network ctor works properly. | 106 // Test that the Network ctor works properly. |
106 TEST_F(NetworkTest, TestNetworkConstruct) { | 107 TEST_F(NetworkTest, TestNetworkConstruct) { |
107 Network ipv4_network1("test_eth0", "Test Network Adapter 1", | 108 Network ipv4_network1("test_eth0", "Test Network Adapter 1", |
108 IPAddress(0x12345600U), 24); | 109 IPAddress(0x12345600U), 24); |
109 EXPECT_EQ("test_eth0", ipv4_network1.name()); | 110 EXPECT_EQ("test_eth0", ipv4_network1.name()); |
110 EXPECT_EQ("Test Network Adapter 1", ipv4_network1.description()); | 111 EXPECT_EQ("Test Network Adapter 1", ipv4_network1.description()); |
111 EXPECT_EQ(IPAddress(0x12345600U), ipv4_network1.prefix()); | 112 EXPECT_EQ(IPAddress(0x12345600U), ipv4_network1.prefix()); |
112 EXPECT_EQ(24, ipv4_network1.prefix_length()); | 113 EXPECT_EQ(24, ipv4_network1.prefix_length()); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 network_monitor->OnNetworksChanged(); | 842 network_monitor->OnNetworksChanged(); |
842 EXPECT_TRUE_WAIT(callback_called_, 1000); | 843 EXPECT_TRUE_WAIT(callback_called_, 1000); |
843 | 844 |
844 // Network manager is stopped; the network monitor is removed. | 845 // Network manager is stopped; the network monitor is removed. |
845 manager.StopUpdating(); | 846 manager.StopUpdating(); |
846 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr); | 847 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr); |
847 | 848 |
848 NetworkMonitorFactory::ReleaseFactory(factory); | 849 NetworkMonitorFactory::ReleaseFactory(factory); |
849 } | 850 } |
850 | 851 |
851 TEST_F(NetworkTest, DefaultPrivateAddress) { | 852 TEST_F(NetworkTest, DefaultLocalAddress) { |
852 TestBasicNetworkManager manager; | 853 TestBasicNetworkManager manager; |
853 manager.StartUpdating(); | 854 manager.StartUpdating(); |
| 855 IPAddress ip; |
| 856 |
| 857 // GetDefaultLocalAddress should return false when not set. |
| 858 EXPECT_FALSE(manager.GetDefaultLocalAddress(AF_INET, &ip)); |
| 859 EXPECT_FALSE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); |
| 860 |
| 861 // Make sure we can query default local address when an address for such |
| 862 // address family exists. |
854 std::vector<Network*> networks; | 863 std::vector<Network*> networks; |
855 manager.GetNetworks(&networks); | 864 manager.GetNetworks(&networks); |
856 for (auto& network : networks) { | 865 for (auto& network : networks) { |
857 if (network->GetBestIP().family() == AF_INET) { | 866 if (network->GetBestIP().family() == AF_INET) { |
858 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress()); | 867 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress()); |
859 } else if (network->GetBestIP().family() == AF_INET6) { | 868 } else if (network->GetBestIP().family() == AF_INET6) { |
860 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress()); | 869 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress()); |
861 } | 870 } |
862 } | 871 } |
| 872 |
| 873 // GetDefaultLocalAddress should return the valid default address after set. |
| 874 manager.set_default_local_addresses(GetLoopbackIP(AF_INET), |
| 875 GetLoopbackIP(AF_INET6)); |
| 876 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET, &ip)); |
| 877 EXPECT_EQ(ip, GetLoopbackIP(AF_INET)); |
| 878 EXPECT_TRUE(manager.GetDefaultLocalAddress(AF_INET6, &ip)); |
| 879 EXPECT_EQ(ip, GetLoopbackIP(AF_INET6)); |
863 manager.StopUpdating(); | 880 manager.StopUpdating(); |
864 } | 881 } |
865 | 882 |
866 } // namespace rtc | 883 } // namespace rtc |
OLD | NEW |