Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webrtc/base/network_unittest.cc

Issue 1470363002: Revert "GetDefaultLocalAddress should return false when the address is invalid" (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/network.cc ('k') | webrtc/p2p/base/stunport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
104 }; 103 };
105 104
106 // Test that the Network ctor works properly. 105 // Test that the Network ctor works properly.
107 TEST_F(NetworkTest, TestNetworkConstruct) { 106 TEST_F(NetworkTest, TestNetworkConstruct) {
108 Network ipv4_network1("test_eth0", "Test Network Adapter 1", 107 Network ipv4_network1("test_eth0", "Test Network Adapter 1",
109 IPAddress(0x12345600U), 24); 108 IPAddress(0x12345600U), 24);
110 EXPECT_EQ("test_eth0", ipv4_network1.name()); 109 EXPECT_EQ("test_eth0", ipv4_network1.name());
111 EXPECT_EQ("Test Network Adapter 1", ipv4_network1.description()); 110 EXPECT_EQ("Test Network Adapter 1", ipv4_network1.description());
112 EXPECT_EQ(IPAddress(0x12345600U), ipv4_network1.prefix()); 111 EXPECT_EQ(IPAddress(0x12345600U), ipv4_network1.prefix());
113 EXPECT_EQ(24, ipv4_network1.prefix_length()); 112 EXPECT_EQ(24, ipv4_network1.prefix_length());
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 network_monitor->OnNetworksChanged(); 841 network_monitor->OnNetworksChanged();
843 EXPECT_TRUE_WAIT(callback_called_, 1000); 842 EXPECT_TRUE_WAIT(callback_called_, 1000);
844 843
845 // Network manager is stopped; the network monitor is removed. 844 // Network manager is stopped; the network monitor is removed.
846 manager.StopUpdating(); 845 manager.StopUpdating();
847 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr); 846 EXPECT_TRUE(GetNetworkMonitor(manager) == nullptr);
848 847
849 NetworkMonitorFactory::ReleaseFactory(factory); 848 NetworkMonitorFactory::ReleaseFactory(factory);
850 } 849 }
851 850
852 TEST_F(NetworkTest, DefaultLocalAddress) { 851 TEST_F(NetworkTest, DefaultPrivateAddress) {
853 TestBasicNetworkManager manager; 852 TestBasicNetworkManager manager;
854 manager.StartUpdating(); 853 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.
863 std::vector<Network*> networks; 854 std::vector<Network*> networks;
864 manager.GetNetworks(&networks); 855 manager.GetNetworks(&networks);
865 for (auto& network : networks) { 856 for (auto& network : networks) {
866 if (network->GetBestIP().family() == AF_INET) { 857 if (network->GetBestIP().family() == AF_INET) {
867 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress()); 858 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET) != IPAddress());
868 } else if (network->GetBestIP().family() == AF_INET6) { 859 } else if (network->GetBestIP().family() == AF_INET6) {
869 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress()); 860 EXPECT_TRUE(manager.QueryDefaultLocalAddress(AF_INET6) != IPAddress());
870 } 861 }
871 } 862 }
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));
880 manager.StopUpdating(); 863 manager.StopUpdating();
881 } 864 }
882 865
883 } // namespace rtc 866 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/network.cc ('k') | webrtc/p2p/base/stunport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698