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

Unified Diff: webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc

Issue 1615653011: Fix a bug in webrtc::ByteReader (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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/modules/rtp_rtcp/source/byte_io.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
diff --git a/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc b/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
index 8b626189a018bfe3fd90152ff958c380ee045af0..d0e6cbb6eb1cf3e7f0148359492fd320e968120d 100644
--- a/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
+++ b/webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc
@@ -206,5 +206,43 @@ TEST_F(ByteIoTest, Test64SBitLittleEndian) {
sizeof(int64_t)>(false);
}
+// Sets up a fixed byte array and converts N bytes from the array into a
+// uint64_t. Verifies the value with hard-coded reference.
+TEST(ByteIo, SanityCheckFixedByteArrayUnsignedReadBigEndian) {
+ uint8_t data[8] = {0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88};
+ uint64_t value = ByteReader<uint64_t, 2>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEE), value);
+ value = ByteReader<uint64_t, 3>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDD), value);
+ value = ByteReader<uint64_t, 4>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCC), value);
+ value = ByteReader<uint64_t, 5>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBB), value);
+ value = ByteReader<uint64_t, 6>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA), value);
+ value = ByteReader<uint64_t, 7>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA99), value);
+ value = ByteReader<uint64_t, 8>::ReadBigEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA9988), value);
+}
+
+// Same as above, but for little-endian reading.
+TEST(ByteIo, SanityCheckFixedByteArrayUnsignedReadLittleEndian) {
+ uint8_t data[8] = {0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88};
+ uint64_t value = ByteReader<uint64_t, 2>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xEEFF), value);
+ value = ByteReader<uint64_t, 3>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xDDEEFF), value);
+ value = ByteReader<uint64_t, 4>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xCCDDEEFF), value);
+ value = ByteReader<uint64_t, 5>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xBBCCDDEEFF), value);
+ value = ByteReader<uint64_t, 6>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0xAABBCCDDEEFF), value);
+ value = ByteReader<uint64_t, 7>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0x99AABBCCDDEEFF), value);
+ value = ByteReader<uint64_t, 8>::ReadLittleEndian(data);
+ EXPECT_EQ(static_cast<uint64_t>(0x8899AABBCCDDEEFF), value);
+}
} // namespace
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/byte_io.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698