OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "platform/utils.h" | 6 #include "platform/utils.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 EXPECT_EQ(1, Utils::Maximum(-1, 1)); | 33 EXPECT_EQ(1, Utils::Maximum(-1, 1)); |
34 EXPECT_EQ(1, Utils::Maximum(1, -1)); | 34 EXPECT_EQ(1, Utils::Maximum(1, -1)); |
35 | 35 |
36 EXPECT_EQ(-1, Utils::Maximum(-1, -2)); | 36 EXPECT_EQ(-1, Utils::Maximum(-1, -2)); |
37 EXPECT_EQ(-1, Utils::Maximum(-2, -1)); | 37 EXPECT_EQ(-1, Utils::Maximum(-2, -1)); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 UNIT_TEST_CASE(IsPowerOfTwo) { | 41 UNIT_TEST_CASE(IsPowerOfTwo) { |
42 EXPECT(Utils::IsPowerOfTwo(0)); | 42 EXPECT(!Utils::IsPowerOfTwo(0)); |
43 EXPECT(Utils::IsPowerOfTwo(1)); | 43 EXPECT(Utils::IsPowerOfTwo(1)); |
44 EXPECT(Utils::IsPowerOfTwo(2)); | 44 EXPECT(Utils::IsPowerOfTwo(2)); |
45 EXPECT(!Utils::IsPowerOfTwo(3)); | 45 EXPECT(!Utils::IsPowerOfTwo(3)); |
46 EXPECT(Utils::IsPowerOfTwo(4)); | 46 EXPECT(Utils::IsPowerOfTwo(4)); |
47 EXPECT(Utils::IsPowerOfTwo(256)); | 47 EXPECT(Utils::IsPowerOfTwo(256)); |
48 | 48 |
49 EXPECT(!Utils::IsPowerOfTwo(-1)); | 49 EXPECT(!Utils::IsPowerOfTwo(-1)); |
50 EXPECT(!Utils::IsPowerOfTwo(-2)); | 50 EXPECT(!Utils::IsPowerOfTwo(-2)); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 UNIT_TEST_CASE(ShiftForPowerOfTwo) { | 54 UNIT_TEST_CASE(ShiftForPowerOfTwo) { |
55 EXPECT_EQ(1, Utils::ShiftForPowerOfTwo(2)); | 55 EXPECT_EQ(1, Utils::ShiftForPowerOfTwo(2)); |
56 EXPECT_EQ(2, Utils::ShiftForPowerOfTwo(4)); | 56 EXPECT_EQ(2, Utils::ShiftForPowerOfTwo(4)); |
57 EXPECT_EQ(8, Utils::ShiftForPowerOfTwo(256)); | 57 EXPECT_EQ(8, Utils::ShiftForPowerOfTwo(256)); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 UNIT_TEST_CASE(IsAligned) { | 61 UNIT_TEST_CASE(IsAligned) { |
62 EXPECT(Utils::IsAligned(0, 0)); | |
63 EXPECT(Utils::IsAligned(0, 1)); | 62 EXPECT(Utils::IsAligned(0, 1)); |
64 EXPECT(Utils::IsAligned(1, 1)); | 63 EXPECT(Utils::IsAligned(1, 1)); |
65 | 64 |
66 EXPECT(Utils::IsAligned(0, 2)); | 65 EXPECT(Utils::IsAligned(0, 2)); |
67 EXPECT(!Utils::IsAligned(1, 2)); | 66 EXPECT(!Utils::IsAligned(1, 2)); |
68 EXPECT(Utils::IsAligned(2, 2)); | 67 EXPECT(Utils::IsAligned(2, 2)); |
69 | 68 |
70 EXPECT(Utils::IsAligned(32, 8)); | 69 EXPECT(Utils::IsAligned(32, 8)); |
71 EXPECT(!Utils::IsAligned(33, 8)); | 70 EXPECT(!Utils::IsAligned(33, 8)); |
72 EXPECT(Utils::IsAligned(40, 8)); | 71 EXPECT(Utils::IsAligned(40, 8)); |
73 } | 72 } |
74 | 73 |
75 | 74 |
76 UNIT_TEST_CASE(RoundDown) { | 75 UNIT_TEST_CASE(RoundDown) { |
77 EXPECT_EQ(0, Utils::RoundDown(0, 0)); | |
78 EXPECT_EQ(0, Utils::RoundDown(22, 32)); | 76 EXPECT_EQ(0, Utils::RoundDown(22, 32)); |
79 EXPECT_EQ(32, Utils::RoundDown(33, 32)); | 77 EXPECT_EQ(32, Utils::RoundDown(33, 32)); |
80 EXPECT_EQ(32, Utils::RoundDown(63, 32)); | 78 EXPECT_EQ(32, Utils::RoundDown(63, 32)); |
81 uword* address = reinterpret_cast<uword*>(63); | 79 uword* address = reinterpret_cast<uword*>(63); |
82 uword* rounddown_address = reinterpret_cast<uword*>(32); | 80 uword* rounddown_address = reinterpret_cast<uword*>(32); |
83 EXPECT_EQ(rounddown_address, Utils::RoundDown(address, 32)); | 81 EXPECT_EQ(rounddown_address, Utils::RoundDown(address, 32)); |
84 } | 82 } |
85 | 83 |
86 | 84 |
87 UNIT_TEST_CASE(RoundUp) { | 85 UNIT_TEST_CASE(RoundUp) { |
88 EXPECT_EQ(0, Utils::RoundUp(0, 0)); | |
89 EXPECT_EQ(0, Utils::RoundUp(1, 0)); | |
90 EXPECT_EQ(32, Utils::RoundUp(22, 32)); | 86 EXPECT_EQ(32, Utils::RoundUp(22, 32)); |
91 EXPECT_EQ(64, Utils::RoundUp(33, 32)); | 87 EXPECT_EQ(64, Utils::RoundUp(33, 32)); |
92 EXPECT_EQ(64, Utils::RoundUp(63, 32)); | 88 EXPECT_EQ(64, Utils::RoundUp(63, 32)); |
93 uword* address = reinterpret_cast<uword*>(63); | 89 uword* address = reinterpret_cast<uword*>(63); |
94 uword* roundup_address = reinterpret_cast<uword*>(64); | 90 uword* roundup_address = reinterpret_cast<uword*>(64); |
95 EXPECT_EQ(roundup_address, Utils::RoundUp(address, 32)); | 91 EXPECT_EQ(roundup_address, Utils::RoundUp(address, 32)); |
96 } | 92 } |
97 | 93 |
98 | 94 |
99 UNIT_TEST_CASE(RoundUpToPowerOfTwo) { | 95 UNIT_TEST_CASE(RoundUpToPowerOfTwo) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]); | 213 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]); |
218 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]); | 214 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]); |
219 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]); | 215 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]); |
220 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]); | 216 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]); |
221 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]); | 217 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]); |
222 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]); | 218 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]); |
223 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]); | 219 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]); |
224 } | 220 } |
225 | 221 |
226 } // namespace dart | 222 } // namespace dart |
OLD | NEW |