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

Unified Diff: webrtc/base/bytebuffer_unittest.cc

Issue 1844333006: Add WriteUVarint to ByteBufferWriter and ReadUVarint to ByteBufferReader (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix typo Created 4 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 | « webrtc/base/bytebuffer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/bytebuffer_unittest.cc
diff --git a/webrtc/base/bytebuffer_unittest.cc b/webrtc/base/bytebuffer_unittest.cc
index 723641811f2214c13cd2f2d339506354a436d42d..bdbb159b66597316bbbd29b697b21d96a714de4e 100644
--- a/webrtc/base/bytebuffer_unittest.cc
+++ b/webrtc/base/bytebuffer_unittest.cc
@@ -196,4 +196,64 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
}
}
+TEST(ByteBufferTest, TestReadWriteUVarint) {
+ ByteBufferWriter::ByteOrder orders[2] = {ByteBufferWriter::ORDER_HOST,
+ ByteBufferWriter::ORDER_NETWORK};
+ for (ByteBufferWriter::ByteOrder& order : orders) {
+ ByteBufferWriter write_buffer(order);
+ size_t size = 0;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ write_buffer.WriteUVarint(1u);
+ ++size;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ write_buffer.WriteUVarint(2u);
+ ++size;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ write_buffer.WriteUVarint(27u);
+ ++size;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ write_buffer.WriteUVarint(149u);
+ size += 2;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ write_buffer.WriteUVarint(68719476736u);
+ size += 6;
+ EXPECT_EQ(size, write_buffer.Length());
+
+ ByteBufferReader read_buffer(write_buffer.Data(), write_buffer.Length(),
+ order);
+ EXPECT_EQ(size, read_buffer.Length());
+ uint64_t val1, val2, val3, val4, val5;
+
+ ASSERT_TRUE(read_buffer.ReadUVarint(&val1));
+ EXPECT_EQ(1u, val1);
+ --size;
+ EXPECT_EQ(size, read_buffer.Length());
+
+ ASSERT_TRUE(read_buffer.ReadUVarint(&val2));
+ EXPECT_EQ(2u, val2);
+ --size;
+ EXPECT_EQ(size, read_buffer.Length());
+
+ ASSERT_TRUE(read_buffer.ReadUVarint(&val3));
+ EXPECT_EQ(27u, val3);
+ --size;
+ EXPECT_EQ(size, read_buffer.Length());
+
+ ASSERT_TRUE(read_buffer.ReadUVarint(&val4));
+ EXPECT_EQ(149u, val4);
+ size -= 2;
+ EXPECT_EQ(size, read_buffer.Length());
+
+ ASSERT_TRUE(read_buffer.ReadUVarint(&val5));
+ EXPECT_EQ(68719476736u, val5);
+ size -= 6;
+ EXPECT_EQ(size, read_buffer.Length());
+ }
+}
+
} // namespace rtc
« no previous file with comments | « webrtc/base/bytebuffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698