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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months 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 | « net/base/net_util_posix.cc ('k') | net/base/net_util_win.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 58
59 namespace net { 59 namespace net {
60 60
61 namespace { 61 namespace {
62 62
63 struct HeaderCase { 63 struct HeaderCase {
64 const char* const header_name; 64 const char* const header_name;
65 const char* const expected; 65 const char* const expected;
66 }; 66 };
67 67
68 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_CHROMEOS)
69 const char kWiFiSSID[] = "TestWiFi";
70 const char kInterfaceWithDifferentSSID[] = "wlan999";
71
72 std::string TestGetInterfaceSSID(const std::string& ifname) {
73 return (ifname == kInterfaceWithDifferentSSID) ? "AnotherSSID" : kWiFiSSID;
74 }
75 #endif
76
68 // Fills in sockaddr for the given 32-bit address (IPv4.) 77 // Fills in sockaddr for the given 32-bit address (IPv4.)
69 // |bytes| should be an array of length 4. 78 // |bytes| should be an array of length 4.
70 void MakeIPv4Address(const uint8* bytes, int port, SockaddrStorage* storage) { 79 void MakeIPv4Address(const uint8* bytes, int port, SockaddrStorage* storage) {
71 memset(&storage->addr_storage, 0, sizeof(storage->addr_storage)); 80 memset(&storage->addr_storage, 0, sizeof(storage->addr_storage));
72 storage->addr_len = sizeof(struct sockaddr_in); 81 storage->addr_len = sizeof(struct sockaddr_in);
73 struct sockaddr_in* addr4 = reinterpret_cast<sockaddr_in*>(storage->addr); 82 struct sockaddr_in* addr4 = reinterpret_cast<sockaddr_in*>(storage->addr);
74 addr4->sin_port = base::HostToNet16(port); 83 addr4->sin_port = base::HostToNet16(port);
75 addr4->sin_family = AF_INET; 84 addr4->sin_family = AF_INET;
76 memcpy(&addr4->sin_addr, bytes, 4); 85 memcpy(&addr4->sin_addr, bytes, 4);
77 } 86 }
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 EXPECT_EQ(results[0].friendly_name, "FriendlyInterfaceName"); 1308 EXPECT_EQ(results[0].friendly_name, "FriendlyInterfaceName");
1300 EXPECT_EQ(results[0].name, ifname_em1); 1309 EXPECT_EQ(results[0].name, ifname_em1);
1301 EXPECT_EQ(results[0].prefix_length, 1ul); 1310 EXPECT_EQ(results[0].prefix_length, 1ul);
1302 EXPECT_EQ(results[0].address, ipv6_address); 1311 EXPECT_EQ(results[0].address, ipv6_address);
1303 EXPECT_EQ(results[0].ip_address_attributes, IP_ADDRESS_ATTRIBUTE_DEPRECATED); 1312 EXPECT_EQ(results[0].ip_address_attributes, IP_ADDRESS_ATTRIBUTE_DEPRECATED);
1304 results.clear(); 1313 results.clear();
1305 } 1314 }
1306 1315
1307 #endif // !OS_MACOSX && !OS_WIN && !OS_NACL 1316 #endif // !OS_MACOSX && !OS_WIN && !OS_NACL
1308 1317
1318 TEST(NetUtilTest, GetWifiSSID) {
1319 // We can't check the result of GetWifiSSID() directly, since the result
1320 // will differ across machines. Simply exercise the code path and hope that it
1321 // doesn't crash.
1322 EXPECT_NE((const char*)NULL, GetWifiSSID().c_str());
1323 }
1324
1325 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_CHROMEOS)
1326 TEST(NetUtilTest, GetWifiSSIDFromInterfaceList) {
1327 NetworkInterfaceList list;
1328 EXPECT_EQ(std::string(), net::internal::GetWifiSSIDFromInterfaceListInternal(
1329 list, TestGetInterfaceSSID));
1330
1331 NetworkInterface interface1;
1332 interface1.name = "wlan0";
1333 interface1.type = NetworkChangeNotifier::CONNECTION_WIFI;
1334 list.push_back(interface1);
1335 ASSERT_EQ(1u, list.size());
1336 EXPECT_EQ(std::string(kWiFiSSID),
1337 net::internal::GetWifiSSIDFromInterfaceListInternal(
1338 list, TestGetInterfaceSSID));
1339
1340 NetworkInterface interface2;
1341 interface2.name = "wlan1";
1342 interface2.type = NetworkChangeNotifier::CONNECTION_WIFI;
1343 list.push_back(interface2);
1344 ASSERT_EQ(2u, list.size());
1345 EXPECT_EQ(std::string(kWiFiSSID),
1346 net::internal::GetWifiSSIDFromInterfaceListInternal(
1347 list, TestGetInterfaceSSID));
1348
1349 NetworkInterface interface3;
1350 interface3.name = kInterfaceWithDifferentSSID;
1351 interface3.type = NetworkChangeNotifier::CONNECTION_WIFI;
1352 list.push_back(interface3);
1353 ASSERT_EQ(3u, list.size());
1354 EXPECT_EQ(std::string(), net::internal::GetWifiSSIDFromInterfaceListInternal(
1355 list, TestGetInterfaceSSID));
1356
1357 list.pop_back();
1358 NetworkInterface interface4;
1359 interface4.name = "eth0";
1360 interface4.type = NetworkChangeNotifier::CONNECTION_ETHERNET;
1361 list.push_back(interface4);
1362 ASSERT_EQ(3u, list.size());
1363 EXPECT_EQ(std::string(), net::internal::GetWifiSSIDFromInterfaceListInternal(
1364 list, TestGetInterfaceSSID));
1365 }
1366 #endif // OS_LINUX
1367
1309 namespace { 1368 namespace {
1310 1369
1311 #if defined(OS_WIN) 1370 #if defined(OS_WIN)
1312 bool read_int_or_bool(DWORD data_size, 1371 bool read_int_or_bool(DWORD data_size,
1313 PVOID data) { 1372 PVOID data) {
1314 switch (data_size) { 1373 switch (data_size) {
1315 case 1: 1374 case 1:
1316 return !!*reinterpret_cast<uint8*>(data); 1375 return !!*reinterpret_cast<uint8*>(data);
1317 case 4: 1376 case 4:
1318 return !!*reinterpret_cast<uint32*>(data); 1377 return !!*reinterpret_cast<uint32*>(data);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { 1548 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) {
1490 const NonUniqueNameTestData& test_data = GetParam(); 1549 const NonUniqueNameTestData& test_data = GetParam();
1491 1550
1492 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); 1551 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
1493 } 1552 }
1494 1553
1495 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, 1554 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest,
1496 testing::ValuesIn(kNonUniqueNameTestData)); 1555 testing::ValuesIn(kNonUniqueNameTestData));
1497 1556
1498 } // namespace net 1557 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util_posix.cc ('k') | net/base/net_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698