[go: nahoru, domu]

Add base::UnguessableToken << operator

base::UnguessableToken seems to fit the Google C++ style guide's
criterion on overloading << as a streaming operator. Notably:
-- It represents a value.
-- There is an easy human-readable string reprensetation of the value
(0 padded HEX).

This change adds an overload to the << operator, as syntactic sugar.

BUG=648441
TEST= Modified a UT to test the operator.

Review-Url: https://codereview.chromium.org/2353663003
Cr-Commit-Position: refs/heads/master@{#419647}
diff --git a/base/unguessable_token_unittest.cc b/base/unguessable_token_unittest.cc
index c4c435fe..dcc5db9 100644
--- a/base/unguessable_token_unittest.cc
+++ b/base/unguessable_token_unittest.cc
@@ -4,6 +4,7 @@
 
 #include "base/unguessable_token.h"
 
+#include <sstream>
 #include <type_traits>
 
 #include "testing/gtest/include/gtest/gtest.h"
@@ -70,6 +71,10 @@
   std::string expected = "(0000012300000ABC)";
 
   EXPECT_EQ(expected, token.ToString());
+
+  std::stringstream stream;
+  stream << token;
+  EXPECT_EQ(expected, stream.str());
 }
 
 TEST(UnguessableTokenTest, VerifySmallerThanOperator) {