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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 | 174 |
175 UNIT_TEST_CASE(LowBits) { | 175 UNIT_TEST_CASE(LowBits) { |
176 EXPECT_EQ(0xff00, Utils::Low16Bits(0xffff00)); | 176 EXPECT_EQ(0xff00, Utils::Low16Bits(0xffff00)); |
177 EXPECT_EQ(0xff, Utils::High16Bits(0xffff00)); | 177 EXPECT_EQ(0xff, Utils::High16Bits(0xffff00)); |
178 EXPECT_EQ(0xff00, Utils::Low32Bits(0xff0000ff00LL)); | 178 EXPECT_EQ(0xff00, Utils::Low32Bits(0xff0000ff00LL)); |
179 EXPECT_EQ(0xff, Utils::High32Bits(0xff0000ff00LL)); | 179 EXPECT_EQ(0xff, Utils::High32Bits(0xff0000ff00LL)); |
180 EXPECT_EQ(0x00ff0000ff00LL, Utils::LowHighTo64Bits(0xff00, 0x00ff)); | 180 EXPECT_EQ(0x00ff0000ff00LL, Utils::LowHighTo64Bits(0xff00, 0x00ff)); |
181 } | 181 } |
182 | 182 |
| 183 |
| 184 UNIT_TEST_CASE(Endianity) { |
| 185 uint16_t value16be = Utils::HostToBigEndian16(0xf1); |
| 186 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16be)[0]); |
| 187 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16be)[1]); |
| 188 |
| 189 uint16_t value16le = Utils::HostToLittleEndian16(0xf1); |
| 190 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16le)[0]); |
| 191 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16le)[1]); |
| 192 |
| 193 uint32_t value32be = Utils::HostToBigEndian32(0xf1f2); |
| 194 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[0]); |
| 195 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[1]); |
| 196 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32be)[2]); |
| 197 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32be)[3]); |
| 198 |
| 199 uint32_t value32le = Utils::HostToLittleEndian32(0xf1f2); |
| 200 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32le)[0]); |
| 201 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32le)[1]); |
| 202 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[2]); |
| 203 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[3]); |
| 204 |
| 205 uint64_t value64be = Utils::HostToBigEndian64(0xf1f2f3f4); |
| 206 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[0]); |
| 207 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[1]); |
| 208 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[2]); |
| 209 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[3]); |
| 210 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64be)[4]); |
| 211 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64be)[5]); |
| 212 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64be)[6]); |
| 213 EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64be)[7]); |
| 214 |
| 215 uint64_t value64le = Utils::HostToLittleEndian64(0xf1f2f3f4); |
| 216 EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64le)[0]); |
| 217 EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]); |
| 218 EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]); |
| 219 EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]); |
| 220 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]); |
| 221 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]); |
| 222 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]); |
| 223 EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]); |
| 224 } |
| 225 |
183 } // namespace dart | 226 } // namespace dart |
OLD | NEW |