OLD | NEW |
---|---|
(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 "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace base { | |
10 | |
11 void TestSmallerThanOperator(const Nonce& a, const Nonce& b) { | |
12 EXPECT_TRUE(a < b); | |
13 EXPECT_FALSE(b < a); | |
14 } | |
15 | |
16 TEST(NonceTest, VerifyEqualityOperators) { | |
17 Nonce nonce(1, 2); | |
18 Nonce nonce_other(3, 4); | |
19 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.
| |
20 EXPECT_FALSE(nonce != nonce); | |
21 EXPECT_FALSE(nonce == nonce_other); | |
22 EXPECT_FALSE(nonce_other == nonce); | |
23 EXPECT_TRUE(nonce != nonce_other); | |
24 EXPECT_TRUE(nonce_other != nonce); | |
25 } | |
26 | |
27 TEST(NonceTest, VerifyConstructor) { | |
28 Nonce nonce = Nonce::Generate(); | |
29 EXPECT_FALSE(nonce.is_null()); | |
30 EXPECT_EQ(nonce, Nonce(nonce.high, nonce.low)); | |
31 | |
32 EXPECT_TRUE(Nonce().is_null()); | |
33 } | |
34 | |
35 TEST(NonceTest, VerifySmallerThanOperator) { | |
36 // a.low < b.low and a.high == b.high. | |
37 TestSmallerThanOperator(Nonce(0, 1), Nonce(0, 5)); | |
38 | |
39 // a.low == b.low and a.high < b.high. | |
40 TestSmallerThanOperator(Nonce(1, 0), Nonce(5, 0)); | |
41 | |
42 // a.low < b.low and a.high < b.high. | |
43 TestSmallerThanOperator(Nonce(1, 1), Nonce(5, 5)); | |
44 | |
45 // a.low > b.low and a.high < b.high. | |
46 TestSmallerThanOperator(Nonce(1, 100), Nonce(100, 1)); | |
47 } | |
48 | |
49 TEST(NonceTest, VerifyHash) { | |
50 Nonce nonce = Nonce::Generate(); | |
51 EXPECT_EQ(nonce.hash(), std::hash<base::Nonce>{}(nonce)); | |
52 } | |
53 | |
54 TEST(NonceTest, VerifyBasicUniqueness) { | |
55 EXPECT_NE(Nonce::Generate(), Nonce::Generate()); | |
56 } | |
57 } | |
OLD | NEW |