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

Unified Diff: base/big_endian_unittest.cc

Issue 427153002: Add unsigned 64-bit integer support to BigEndianReader and BigEndianWriter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « base/big_endian.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/big_endian_unittest.cc
diff --git a/base/big_endian_unittest.cc b/base/big_endian_unittest.cc
index b57aeb29ac97c2b29991de887ae48e5e9664733a..0e4b3f1812b7643d66268a5fe53f0afebd0247ec 100644
--- a/base/big_endian_unittest.cc
+++ b/base/big_endian_unittest.cc
@@ -10,11 +10,13 @@
namespace base {
TEST(BigEndianReaderTest, ReadsValues) {
- char data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC };
+ char data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF,
+ 0x1A, 0x2B, 0x3C, 0x4D, 0x5E };
char buf[2];
uint8 u8;
uint16 u16;
uint32 u32;
+ uint64 u64;
base::StringPiece piece;
BigEndianReader reader(data, sizeof(data));
@@ -30,6 +32,8 @@ TEST(BigEndianReaderTest, ReadsValues) {
EXPECT_EQ(0x0506, u16);
EXPECT_TRUE(reader.ReadU32(&u32));
EXPECT_EQ(0x0708090Au, u32);
+ EXPECT_TRUE(reader.ReadU64(&u64));
+ EXPECT_EQ(0x0B0C0D0E0F1A2B3Cllu, u64);
base::StringPiece expected(reader.ptr(), 2);
EXPECT_TRUE(reader.ReadPiece(&piece, 2));
EXPECT_EQ(2u, piece.size());
@@ -37,16 +41,20 @@ TEST(BigEndianReaderTest, ReadsValues) {
}
TEST(BigEndianReaderTest, RespectsLength) {
- char data[4];
+ char data[8];
char buf[2];
uint8 u8;
uint16 u16;
uint32 u32;
+ uint64 u64;
base::StringPiece piece;
BigEndianReader reader(data, sizeof(data));
- // 4 left
- EXPECT_FALSE(reader.Skip(6));
+ // 8 left
+ EXPECT_FALSE(reader.Skip(9));
EXPECT_TRUE(reader.Skip(1));
+ // 7 left
+ EXPECT_FALSE(reader.ReadU64(&u64));
+ EXPECT_TRUE(reader.Skip(4));
// 3 left
EXPECT_FALSE(reader.ReadU32(&u32));
EXPECT_FALSE(reader.ReadPiece(&piece, 4));
@@ -61,7 +69,8 @@ TEST(BigEndianReaderTest, RespectsLength) {
}
TEST(BigEndianWriterTest, WritesValues) {
- char expected[] = { 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0xA };
+ char expected[] = { 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 0xA, 0xB, 0xC, 0xD, 0xE,
+ 0xF, 0x1A, 0x2B, 0x3C };
char data[sizeof(expected)];
char buf[] = { 0x2, 0x3 };
memset(data, 0, sizeof(data));
@@ -72,19 +81,24 @@ TEST(BigEndianWriterTest, WritesValues) {
EXPECT_TRUE(writer.WriteU8(0x4));
EXPECT_TRUE(writer.WriteU16(0x0506));
EXPECT_TRUE(writer.WriteU32(0x0708090A));
+ EXPECT_TRUE(writer.WriteU64(0x0B0C0D0E0F1A2B3Cllu));
EXPECT_EQ(0, memcmp(expected, data, sizeof(expected)));
}
TEST(BigEndianWriterTest, RespectsLength) {
- char data[4];
+ char data[8];
char buf[2];
uint8 u8 = 0;
uint16 u16 = 0;
uint32 u32 = 0;
+ uint64 u64 = 0;
BigEndianWriter writer(data, sizeof(data));
- // 4 left
- EXPECT_FALSE(writer.Skip(6));
+ // 8 left
+ EXPECT_FALSE(writer.Skip(9));
EXPECT_TRUE(writer.Skip(1));
+ // 7 left
+ EXPECT_FALSE(writer.WriteU64(u64));
+ EXPECT_TRUE(writer.Skip(4));
// 3 left
EXPECT_FALSE(writer.WriteU32(u32));
EXPECT_TRUE(writer.Skip(2));
« no previous file with comments | « base/big_endian.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698