Chromium Code Reviews| 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()); |
| +} |
| +} |