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

Side by Side Diff: base/nonce_unittest.cc

Issue 2333443002: Add base::UnguessableToken (Closed)
Patch Set: Fixed a UT 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/nonce.h"
6
7 #include <type_traits>
8
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace base {
12
13 void TestSmallerThanOperator(const Nonce& a, const Nonce& b) {
14 EXPECT_TRUE(a < b);
15 EXPECT_FALSE(b < a);
16 }
17
18 TEST(NonceTest, VerifyEqualityOperators) {
19 // Deserialize is used for testing purposes.
20 // Use Nonce::Generate() to generate nonces in productions code instead.
21 Nonce nonce = Nonce::Deserialize(1, 2);
22 Nonce same_nonce = Nonce::Deserialize(1, 2);
23 Nonce diff_nonce = Nonce::Deserialize(1, 3);
24
25 EXPECT_TRUE(nonce == nonce);
26 EXPECT_FALSE(nonce != nonce);
27
28 EXPECT_TRUE(nonce == same_nonce);
29 EXPECT_FALSE(nonce != same_nonce);
30
31 EXPECT_FALSE(nonce == diff_nonce);
32 EXPECT_FALSE(diff_nonce == nonce);
33 EXPECT_TRUE(nonce != diff_nonce);
34 EXPECT_TRUE(diff_nonce != nonce);
35 }
36
37 TEST(NonceTest, VerifyConstructors) {
38 Nonce nonce = Nonce::Generate();
39 EXPECT_FALSE(nonce.is_empty());
40
41 EXPECT_EQ(nonce, Nonce::Deserialize(nonce.high(), nonce.low()));
42 EXPECT_EQ(nonce, Nonce(nonce));
43
44 EXPECT_TRUE(Nonce().is_empty());
45 }
46
47 TEST(NonceTest, VerifySmallerThanOperator) {
48 // Deserialize is used for testing purposes.
49 // Use Nonce::Generate() to generate nonces in productions code instead.
50
51 // a.low < b.low and a.high == b.high.
52 TestSmallerThanOperator(Nonce::Deserialize(0, 1), Nonce::Deserialize(0, 5));
53
54 // a.low == b.low and a.high < b.high.
55 TestSmallerThanOperator(Nonce::Deserialize(1, 0), Nonce::Deserialize(5, 0));
56
57 // a.low < b.low and a.high < b.high.
58 TestSmallerThanOperator(Nonce::Deserialize(1, 1), Nonce::Deserialize(5, 5));
59
60 // a.low > b.low and a.high < b.high.
61 TestSmallerThanOperator(Nonce::Deserialize(1, 10), Nonce::Deserialize(10, 1));
62 }
63
64 TEST(NonceTest, VerifyHash) {
65 Nonce nonce = Nonce::Generate();
66 EXPECT_EQ(base::HashInts64(nonce.high(), nonce.low()), NonceHash{}(nonce));
67 }
68
69 TEST(NonceTest, VerifyBasicUniqueness) {
70 EXPECT_NE(Nonce::Generate(), Nonce::Generate());
71 }
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698