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

Side by Side Diff: base/unguessable_token_unittest.cc

Issue 2353663003: Add base::UnguessableToken << operator (Closed)
Patch Set: Addressed comment. Created 4 years, 3 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 | « base/unguessable_token.cc ('k') | no next file » | 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) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "base/unguessable_token.h" 5 #include "base/unguessable_token.h"
6 6
7 #include <sstream>
7 #include <type_traits> 8 #include <type_traits>
8 9
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 13
13 void TestSmallerThanOperator(const UnguessableToken& a, 14 void TestSmallerThanOperator(const UnguessableToken& a,
14 const UnguessableToken& b) { 15 const UnguessableToken& b) {
15 EXPECT_TRUE(a < b); 16 EXPECT_TRUE(a < b);
16 EXPECT_FALSE(b < a); 17 EXPECT_FALSE(b < a);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 64
64 UnguessableToken Deserialized = UnguessableToken::Deserialize(high, low); 65 UnguessableToken Deserialized = UnguessableToken::Deserialize(high, low);
65 EXPECT_EQ(token, Deserialized); 66 EXPECT_EQ(token, Deserialized);
66 } 67 }
67 68
68 TEST(UnguessableTokenTest, VerifyToString) { 69 TEST(UnguessableTokenTest, VerifyToString) {
69 UnguessableToken token = UnguessableToken::Deserialize(0x123, 0xABC); 70 UnguessableToken token = UnguessableToken::Deserialize(0x123, 0xABC);
70 std::string expected = "(0000012300000ABC)"; 71 std::string expected = "(0000012300000ABC)";
71 72
72 EXPECT_EQ(expected, token.ToString()); 73 EXPECT_EQ(expected, token.ToString());
74
75 std::stringstream stream;
76 stream << token;
77 EXPECT_EQ(expected, stream.str());
73 } 78 }
74 79
75 TEST(UnguessableTokenTest, VerifySmallerThanOperator) { 80 TEST(UnguessableTokenTest, VerifySmallerThanOperator) {
76 // Deserialize is used for testing purposes. 81 // Deserialize is used for testing purposes.
77 // Use UnguessableToken::Create() in production code instead. 82 // Use UnguessableToken::Create() in production code instead.
78 { 83 {
79 SCOPED_TRACE("a.low < b.low and a.high == b.high."); 84 SCOPED_TRACE("a.low < b.low and a.high == b.high.");
80 TestSmallerThanOperator(UnguessableToken::Deserialize(0, 1), 85 TestSmallerThanOperator(UnguessableToken::Deserialize(0, 1),
81 UnguessableToken::Deserialize(0, 5)); 86 UnguessableToken::Deserialize(0, 5));
82 } 87 }
(...skipping 22 matching lines...) Expand all
105 UnguessableTokenHash()(token)); 110 UnguessableTokenHash()(token));
106 } 111 }
107 112
108 TEST(UnguessableTokenTest, VerifyBasicUniqueness) { 113 TEST(UnguessableTokenTest, VerifyBasicUniqueness) {
109 EXPECT_NE(UnguessableToken::Create(), UnguessableToken::Create()); 114 EXPECT_NE(UnguessableToken::Create(), UnguessableToken::Create());
110 115
111 UnguessableToken token = UnguessableToken::Create(); 116 UnguessableToken token = UnguessableToken::Create();
112 EXPECT_NE(token.GetHighForSerialization(), token.GetLowForSerialization()); 117 EXPECT_NE(token.GetHighForSerialization(), token.GetLowForSerialization());
113 } 118 }
114 } 119 }
OLDNEW
« no previous file with comments | « base/unguessable_token.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698