Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1187)

Unified Diff: runtime/vm/utils_test.cc

Issue 14299008: Add utilities for converting from Host endianity to big endian and little endian formats for the va… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/os_android.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/utils_test.cc
===================================================================
--- runtime/vm/utils_test.cc (revision 21569)
+++ runtime/vm/utils_test.cc (working copy)
@@ -180,4 +180,47 @@
EXPECT_EQ(0x00ff0000ff00LL, Utils::LowHighTo64Bits(0xff00, 0x00ff));
}
+
+UNIT_TEST_CASE(Endianity) {
+ uint16_t value16be = Utils::HostToBigEndian16(0xf1);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16be)[0]);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16be)[1]);
+
+ uint16_t value16le = Utils::HostToLittleEndian16(0xf1);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value16le)[0]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value16le)[1]);
+
+ uint32_t value32be = Utils::HostToBigEndian32(0xf1f2);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[0]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32be)[1]);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32be)[2]);
+ EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32be)[3]);
+
+ uint32_t value32le = Utils::HostToLittleEndian32(0xf1f2);
+ EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value32le)[0]);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value32le)[1]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[2]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value32le)[3]);
+
+ uint64_t value64be = Utils::HostToBigEndian64(0xf1f2f3f4);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[0]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[1]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[2]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64be)[3]);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64be)[4]);
+ EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64be)[5]);
+ EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64be)[6]);
+ EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64be)[7]);
+
+ uint64_t value64le = Utils::HostToLittleEndian64(0xf1f2f3f4);
+ EXPECT_EQ(0xf4, reinterpret_cast<uint8_t*>(&value64le)[0]);
+ EXPECT_EQ(0xf3, reinterpret_cast<uint8_t*>(&value64le)[1]);
+ EXPECT_EQ(0xf2, reinterpret_cast<uint8_t*>(&value64le)[2]);
+ EXPECT_EQ(0xf1, reinterpret_cast<uint8_t*>(&value64le)[3]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[4]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[5]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[6]);
+ EXPECT_EQ(0x0, reinterpret_cast<uint8_t*>(&value64le)[7]);
+}
+
} // namespace dart
« no previous file with comments | « runtime/vm/os_android.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698