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

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

Issue 100703002: Added net::NetworkInterface::interface_index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« 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 <algorithm> 9 #include <algorithm>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/scoped_native_library.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/sys_byteorder.h" 19 #include "base/sys_byteorder.h"
19 #include "base/test/test_file_util.h" 20 #include "base/test/test_file_util.h"
20 #include "base/time/time.h" 21 #include "base/time/time.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
25 #if defined(OS_WIN)
26 #include <iphlpapi.h>
27 #include <objbase.h>
28 #include "base/win/windows_version.h"
29 #elif !defined(OS_ANDROID)
30 #include <net/if.h>
31 #endif // OS_WIN
32
24 namespace net { 33 namespace net {
25 34
26 namespace { 35 namespace {
27 36
28 static const size_t kNpos = base::string16::npos; 37 static const size_t kNpos = base::string16::npos;
29 38
30 struct FileCase { 39 struct FileCase {
31 const wchar_t* file; 40 const wchar_t* file;
32 const char* url; 41 const char* url;
33 }; 42 };
(...skipping 3269 matching lines...) Expand 10 before | Expand all | Expand 10 after
3303 bool all_zeroes = true; 3312 bool all_zeroes = true;
3304 for (size_t i = 0; i < it->address.size(); ++i) { 3313 for (size_t i = 0; i < it->address.size(); ++i) {
3305 if (it->address[i] != 0) { 3314 if (it->address[i] != 0) {
3306 all_zeroes = false; 3315 all_zeroes = false;
3307 break; 3316 break;
3308 } 3317 }
3309 } 3318 }
3310 EXPECT_FALSE(all_zeroes); 3319 EXPECT_FALSE(all_zeroes);
3311 EXPECT_GT(it->network_prefix, 1u); 3320 EXPECT_GT(it->network_prefix, 1u);
3312 EXPECT_LE(it->network_prefix, it->address.size() * 8); 3321 EXPECT_LE(it->network_prefix, it->address.size() * 8);
3322
3323 #if defined(OS_WIN)
3324 // On Windows |name| is NET_LUID.
3325 base::ScopedNativeLibrary phlpapi_lib(
3326 base::FilePath(FILE_PATH_LITERAL("iphlpapi.dll")));
3327 ASSERT_TRUE(phlpapi_lib.is_valid());
3328 typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX,
3329 PNET_LUID);
3330 ConvertInterfaceIndexToLuid interface_to_luid =
3331 reinterpret_cast<ConvertInterfaceIndexToLuid>(
3332 phlpapi_lib.GetFunctionPointer("ConvertInterfaceIndexToLuid"));
3333
3334 typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*,
3335 GUID*);
3336 ConvertInterfaceLuidToGuid luid_to_guid =
3337 reinterpret_cast<ConvertInterfaceLuidToGuid>(
3338 phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid"));
3339
3340 if (interface_to_luid && luid_to_guid) {
3341 NET_LUID luid;
3342 EXPECT_EQ(interface_to_luid(it->interface_index, &luid), NO_ERROR);
3343 GUID guid;
3344 EXPECT_EQ(luid_to_guid(&luid, &guid), NO_ERROR);
3345 LPOLESTR name;
3346 StringFromCLSID(guid, &name);
3347 EXPECT_STREQ(UTF8ToWide(it->name).c_str(), name);
3348 CoTaskMemFree(name);
3349 continue;
3350 } else {
3351 EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA);
3352 EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x.
3353 EXPECT_NE(it->interface_index, 0u); // 0 means to use default.
3354 }
3355 #elif !defined(OS_ANDROID)
3356 char name[IF_NAMESIZE];
3357 EXPECT_TRUE(if_indextoname(it->interface_index, name));
3358 EXPECT_STREQ(it->name.c_str(), name);
3359 #endif
3313 } 3360 }
3314 } 3361 }
3315 3362
3316 static const base::FilePath::CharType* kSafePortableBasenames[] = { 3363 static const base::FilePath::CharType* kSafePortableBasenames[] = {
3317 FILE_PATH_LITERAL("a"), 3364 FILE_PATH_LITERAL("a"),
3318 FILE_PATH_LITERAL("a.txt"), 3365 FILE_PATH_LITERAL("a.txt"),
3319 FILE_PATH_LITERAL("a b.txt"), 3366 FILE_PATH_LITERAL("a b.txt"),
3320 FILE_PATH_LITERAL("a-b.txt"), 3367 FILE_PATH_LITERAL("a-b.txt"),
3321 FILE_PATH_LITERAL("My Computer"), 3368 FILE_PATH_LITERAL("My Computer"),
3322 FILE_PATH_LITERAL(" Computer"), 3369 FILE_PATH_LITERAL(" Computer"),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3469 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { 3516 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) {
3470 const NonUniqueNameTestData& test_data = GetParam(); 3517 const NonUniqueNameTestData& test_data = GetParam();
3471 3518
3472 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); 3519 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname));
3473 } 3520 }
3474 3521
3475 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, 3522 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest,
3476 testing::ValuesIn(kNonUniqueNameTestData)); 3523 testing::ValuesIn(kNonUniqueNameTestData));
3477 3524
3478 } // namespace net 3525 } // 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