Commit 167c875a authored by Kartik Hegde's avatar Kartik Hegde Committed by Commit Bot

network_diagnostics: Contain util functions in a namespace

To call utility functions more clearly, wrap them in a "util" namespace.

TEST=unit_tests --gtest_filter=NetworkDiagnosticsUtilTest*
BUG=chromium:956783

Change-Id: I2874dbdbda7fe84c04f7484c876845d75f99f928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438757Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Kartik Hegde <khegde@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812481}
parent 2cfa7fa8
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
namespace chromeos { namespace chromeos {
namespace network_diagnostics { namespace network_diagnostics {
namespace util {
namespace { namespace {
// Returns |num_prefixes| prefixes of size |length|, where no two entries are // Returns |num_prefixes| prefixes of size |length|, where no two entries are
...@@ -80,5 +82,7 @@ Profile* GetUserProfile() { ...@@ -80,5 +82,7 @@ Profile* GetUserProfile() {
return ProfileManager::GetPrimaryUserProfile(); return ProfileManager::GetPrimaryUserProfile();
} }
} // namespace util
} // namespace network_diagnostics } // namespace network_diagnostics
} // namespace chromeos } // namespace chromeos
...@@ -13,6 +13,8 @@ class Profile; ...@@ -13,6 +13,8 @@ class Profile;
namespace chromeos { namespace chromeos {
namespace network_diagnostics { namespace network_diagnostics {
namespace util {
// Returns the Gstatic host suffix. Network diagnostic routines attach a random // Returns the Gstatic host suffix. Network diagnostic routines attach a random
// prefix to |kGstaticHostSuffix| to get a complete hostname. // prefix to |kGstaticHostSuffix| to get a complete hostname.
const char* GetGstaticHostSuffix(); const char* GetGstaticHostSuffix();
...@@ -36,6 +38,8 @@ std::vector<std::string> GetRandomHostsWithFixedHosts(int num_random_hosts, ...@@ -36,6 +38,8 @@ std::vector<std::string> GetRandomHostsWithFixedHosts(int num_random_hosts,
// Returns the profile associated with this account. // Returns the profile associated with this account.
Profile* GetUserProfile(); Profile* GetUserProfile();
} // namespace util
} // namespace network_diagnostics } // namespace network_diagnostics
} // namespace chromeos } // namespace chromeos
......
...@@ -14,7 +14,7 @@ namespace network_diagnostics { ...@@ -14,7 +14,7 @@ namespace network_diagnostics {
TEST(NetworkDiagnosticsUtilTest, TestGetRandomString) { TEST(NetworkDiagnosticsUtilTest, TestGetRandomString) {
int length = 8; int length = 8;
auto random_string = GetRandomString(length); auto random_string = util::GetRandomString(length);
// Ensure that the length equals |length| and all characters are in between // Ensure that the length equals |length| and all characters are in between
// 'a'-'z', inclusive. // 'a'-'z', inclusive.
ASSERT_EQ(length, random_string.size()); ASSERT_EQ(length, random_string.size());
...@@ -27,7 +27,7 @@ TEST(NetworkDiagnosticsUtilTest, TestGetRandomHosts) { ...@@ -27,7 +27,7 @@ TEST(NetworkDiagnosticsUtilTest, TestGetRandomHosts) {
int num_hosts = 10; int num_hosts = 10;
int prefix_length = 8; int prefix_length = 8;
std::vector<std::string> random_hosts = std::vector<std::string> random_hosts =
GetRandomHosts(num_hosts, prefix_length); util::GetRandomHosts(num_hosts, prefix_length);
// Ensure |random_hosts| has unique entries. // Ensure |random_hosts| has unique entries.
std::sort(random_hosts.begin(), random_hosts.end()); std::sort(random_hosts.begin(), random_hosts.end());
ASSERT_TRUE(std::adjacent_find(random_hosts.begin(), random_hosts.end()) == ASSERT_TRUE(std::adjacent_find(random_hosts.begin(), random_hosts.end()) ==
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment