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

Unified Diff: base/nonce_unittest.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« base/nonce.h ('K') | « base/nonce.cc ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/nonce_unittest.cc
diff --git a/base/nonce_unittest.cc b/base/nonce_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c59283c81507e2eff61b29456012fa33757c283e
--- /dev/null
+++ b/base/nonce_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/nonce.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+void TestSmallerThanOperator(const Nonce& a, const Nonce& b) {
+ EXPECT_TRUE(a < b);
+ EXPECT_FALSE(b < a);
+}
+
+TEST(NonceTest, VerifyEqualityOperators) {
+ Nonce nonce(1, 2);
+ Nonce nonce_other(3, 4);
+ EXPECT_TRUE(nonce == nonce);
danakj 2016/09/12 20:41:57 can you compare 2 different Nonces with the same i
tguilbert 2016/09/12 23:53:34 Done.
+ EXPECT_FALSE(nonce != nonce);
+ EXPECT_FALSE(nonce == nonce_other);
+ EXPECT_FALSE(nonce_other == nonce);
+ EXPECT_TRUE(nonce != nonce_other);
+ EXPECT_TRUE(nonce_other != nonce);
+}
+
+TEST(NonceTest, VerifyConstructor) {
+ Nonce nonce = Nonce::Generate();
+ EXPECT_FALSE(nonce.is_null());
+ EXPECT_EQ(nonce, Nonce(nonce.high, nonce.low));
+
+ EXPECT_TRUE(Nonce().is_null());
+}
+
+TEST(NonceTest, VerifySmallerThanOperator) {
+ // a.low < b.low and a.high == b.high.
+ TestSmallerThanOperator(Nonce(0, 1), Nonce(0, 5));
+
+ // a.low == b.low and a.high < b.high.
+ TestSmallerThanOperator(Nonce(1, 0), Nonce(5, 0));
+
+ // a.low < b.low and a.high < b.high.
+ TestSmallerThanOperator(Nonce(1, 1), Nonce(5, 5));
+
+ // a.low > b.low and a.high < b.high.
+ TestSmallerThanOperator(Nonce(1, 100), Nonce(100, 1));
+}
+
+TEST(NonceTest, VerifyHash) {
+ Nonce nonce = Nonce::Generate();
+ EXPECT_EQ(nonce.hash(), std::hash<base::Nonce>{}(nonce));
+}
+
+TEST(NonceTest, VerifyBasicUniqueness) {
+ EXPECT_NE(Nonce::Generate(), Nonce::Generate());
+}
+}
« base/nonce.h ('K') | « base/nonce.cc ('k') | ipc/ipc_message_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698