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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_util_unittest.cc
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 8200ad3725513394d80aada25cdc2e6b9596c20c..38cc408cf969ac5b6b88a4a65a777f8fd14640a3 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -10,6 +10,7 @@
#include "base/files/file_path.h"
#include "base/format_macros.h"
+#include "base/scoped_native_library.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -21,6 +22,14 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+#if defined(OS_WIN)
+#include <iphlpapi.h>
+#include <objbase.h>
+#include "base/win/windows_version.h"
+#elif !defined(OS_ANDROID)
+#include <net/if.h>
+#endif // OS_WIN
+
namespace net {
namespace {
@@ -3310,6 +3319,44 @@ TEST(NetUtilTest, GetNetworkList) {
EXPECT_FALSE(all_zeroes);
EXPECT_GT(it->network_prefix, 1u);
EXPECT_LE(it->network_prefix, it->address.size() * 8);
+
+#if defined(OS_WIN)
+ // On Windows |name| is NET_LUID.
+ base::ScopedNativeLibrary phlpapi_lib(
+ base::FilePath(FILE_PATH_LITERAL("iphlpapi.dll")));
+ ASSERT_TRUE(phlpapi_lib.is_valid());
+ typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX,
+ PNET_LUID);
+ ConvertInterfaceIndexToLuid interface_to_luid =
+ reinterpret_cast<ConvertInterfaceIndexToLuid>(
+ phlpapi_lib.GetFunctionPointer("ConvertInterfaceIndexToLuid"));
+
+ typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*,
+ GUID*);
+ ConvertInterfaceLuidToGuid luid_to_guid =
+ reinterpret_cast<ConvertInterfaceLuidToGuid>(
+ phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid"));
+
+ if (interface_to_luid && luid_to_guid) {
+ NET_LUID luid;
+ EXPECT_EQ(interface_to_luid(it->interface_index, &luid), NO_ERROR);
+ GUID guid;
+ EXPECT_EQ(luid_to_guid(&luid, &guid), NO_ERROR);
+ LPOLESTR name;
+ StringFromCLSID(guid, &name);
+ EXPECT_STREQ(UTF8ToWide(it->name).c_str(), name);
+ CoTaskMemFree(name);
+ continue;
+ } else {
+ EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA);
+ EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x.
+ EXPECT_NE(it->interface_index, 0u); // 0 means to use default.
+ }
+#elif !defined(OS_ANDROID)
+ char name[IF_NAMESIZE];
+ EXPECT_TRUE(if_indextoname(it->interface_index, name));
+ EXPECT_STREQ(it->name.c_str(), name);
+#endif
}
}
« 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