OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include <stdint.h> |
| 6 |
| 7 #include <limits> |
| 8 |
6 #include "base/logging.h" | 9 #include "base/logging.h" |
7 #include "net/base/int128.h" | 10 #include "net/base/int128.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
10 | |
11 TEST(Int128, AllTests) { | 13 TEST(Int128, AllTests) { |
12 uint128 zero(0); | 14 uint128 zero(0); |
13 uint128 one(1); | 15 uint128 one(1); |
14 uint128 one_2arg(0, 1); | 16 uint128 one_2arg(0, 1); |
15 uint128 two(0, 2); | 17 uint128 two(0, 2); |
16 uint128 three(0, 3); | 18 uint128 three(0, 3); |
17 uint128 big(2000, 2); | 19 uint128 big(2000, 2); |
18 uint128 big_minus_one(2000, 1); | 20 uint128 big_minus_one(2000, 1); |
19 uint128 bigger(2001, 1); | 21 uint128 bigger(2001, 1); |
20 uint128 biggest(kuint128max); | 22 uint128 biggest(kuint128max); |
21 uint128 high_low(1, 0); | 23 uint128 high_low(1, 0); |
22 uint128 low_high(0, kuint64max); | 24 uint128 low_high(0, std::numeric_limits<uint64_t>::max()); |
23 EXPECT_LT(one, two); | 25 EXPECT_LT(one, two); |
24 EXPECT_GT(two, one); | 26 EXPECT_GT(two, one); |
25 EXPECT_LT(one, big); | 27 EXPECT_LT(one, big); |
26 EXPECT_LT(one, big); | 28 EXPECT_LT(one, big); |
27 EXPECT_EQ(one, one_2arg); | 29 EXPECT_EQ(one, one_2arg); |
28 EXPECT_NE(one, two); | 30 EXPECT_NE(one, two); |
29 EXPECT_GT(big, one); | 31 EXPECT_GT(big, one); |
30 EXPECT_GE(big, two); | 32 EXPECT_GE(big, two); |
31 EXPECT_GE(big, big_minus_one); | 33 EXPECT_GE(big, big_minus_one); |
32 EXPECT_GT(big, big_minus_one); | 34 EXPECT_GT(big, big_minus_one); |
(...skipping 18 matching lines...) Expand all Loading... |
51 EXPECT_EQ(big, big << 0); | 53 EXPECT_EQ(big, big << 0); |
52 EXPECT_EQ(big, big >> 0); | 54 EXPECT_EQ(big, big >> 0); |
53 EXPECT_GT(big << 1, big); | 55 EXPECT_GT(big << 1, big); |
54 EXPECT_LT(big >> 1, big); | 56 EXPECT_LT(big >> 1, big); |
55 EXPECT_EQ(big, (big << 10) >> 10); | 57 EXPECT_EQ(big, (big << 10) >> 10); |
56 EXPECT_EQ(big, (big >> 1) << 1); | 58 EXPECT_EQ(big, (big >> 1) << 1); |
57 EXPECT_EQ(one, (one << 80) >> 80); | 59 EXPECT_EQ(one, (one << 80) >> 80); |
58 EXPECT_EQ(zero, (one >> 80) << 80); | 60 EXPECT_EQ(zero, (one >> 80) << 80); |
59 EXPECT_EQ(zero, big >> 128); | 61 EXPECT_EQ(zero, big >> 128); |
60 EXPECT_EQ(zero, big << 128); | 62 EXPECT_EQ(zero, big << 128); |
61 EXPECT_EQ(Uint128High64(biggest), kuint64max); | 63 EXPECT_EQ(Uint128High64(biggest), std::numeric_limits<uint64_t>::max()); |
62 EXPECT_EQ(Uint128Low64(biggest), kuint64max); | 64 EXPECT_EQ(Uint128Low64(biggest), std::numeric_limits<uint64_t>::max()); |
63 EXPECT_EQ(zero + one, one); | 65 EXPECT_EQ(zero + one, one); |
64 EXPECT_EQ(one + one, two); | 66 EXPECT_EQ(one + one, two); |
65 EXPECT_EQ(big_minus_one + one, big); | 67 EXPECT_EQ(big_minus_one + one, big); |
66 EXPECT_EQ(one - one, zero); | 68 EXPECT_EQ(one - one, zero); |
67 EXPECT_EQ(one - zero, one); | 69 EXPECT_EQ(one - zero, one); |
68 EXPECT_EQ(zero - one, biggest); | 70 EXPECT_EQ(zero - one, biggest); |
69 EXPECT_EQ(big - big, zero); | 71 EXPECT_EQ(big - big, zero); |
70 EXPECT_EQ(big - one, big_minus_one); | 72 EXPECT_EQ(big - one, big_minus_one); |
71 EXPECT_EQ(big + kuint64max, bigger); | 73 EXPECT_EQ(big + std::numeric_limits<uint64_t>::max(), bigger); |
72 EXPECT_EQ(biggest + 1, zero); | 74 EXPECT_EQ(biggest + 1, zero); |
73 EXPECT_EQ(zero - 1, biggest); | 75 EXPECT_EQ(zero - 1, biggest); |
74 EXPECT_EQ(high_low - one, low_high); | 76 EXPECT_EQ(high_low - one, low_high); |
75 EXPECT_EQ(low_high + one, high_low); | 77 EXPECT_EQ(low_high + one, high_low); |
76 EXPECT_EQ(Uint128High64((uint128(1) << 64) - 1), 0u); | 78 EXPECT_EQ(Uint128High64((uint128(1) << 64) - 1), 0u); |
77 EXPECT_EQ(Uint128Low64((uint128(1) << 64) - 1), kuint64max); | 79 EXPECT_EQ(Uint128Low64((uint128(1) << 64) - 1), |
| 80 std::numeric_limits<uint64_t>::max()); |
78 EXPECT_TRUE(!!one); | 81 EXPECT_TRUE(!!one); |
79 EXPECT_TRUE(!!high_low); | 82 EXPECT_TRUE(!!high_low); |
80 EXPECT_FALSE(!!zero); | 83 EXPECT_FALSE(!!zero); |
81 EXPECT_FALSE(!one); | 84 EXPECT_FALSE(!one); |
82 EXPECT_FALSE(!high_low); | 85 EXPECT_FALSE(!high_low); |
83 EXPECT_TRUE(!zero); | 86 EXPECT_TRUE(!zero); |
84 EXPECT_TRUE(zero == 0); | 87 EXPECT_TRUE(zero == 0); |
85 EXPECT_FALSE(zero != 0); | 88 EXPECT_FALSE(zero != 0); |
86 EXPECT_FALSE(one == 0); | 89 EXPECT_FALSE(one == 0); |
87 EXPECT_TRUE(one != 0); | 90 EXPECT_TRUE(one != 0); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 uint128 x1(1, 2); | 253 uint128 x1(1, 2); |
251 uint128 x2(2, 4); | 254 uint128 x2(2, 4); |
252 x1 += x1; | 255 x1 += x1; |
253 EXPECT_EQ(x2, x1); | 256 EXPECT_EQ(x2, x1); |
254 | 257 |
255 uint128 x3(1, 1ull << 63); | 258 uint128 x3(1, 1ull << 63); |
256 uint128 x4(3, 0); | 259 uint128 x4(3, 0); |
257 x3 += x3; | 260 x3 += x3; |
258 EXPECT_EQ(x4, x3); | 261 EXPECT_EQ(x4, x3); |
259 } | 262 } |
OLD | NEW |