diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc b/third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc index f65299e639..520845d40b 100644 --- a/third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc +++ b/third_party/libwebrtc/rtc_base/byte_buffer_unittest.cc @@ -16,10 +16,26 @@ #include "rtc_base/arraysize.h" #include "rtc_base/byte_order.h" +#include "test/gmock.h" #include "test/gtest.h" namespace rtc { +using ::testing::ElementsAre; + +TEST(ByteBufferTest, WriterAccessors) { + // To be changed into ByteBufferWriter when base type is converted. + ByteBufferWriterT<BufferT<uint8_t>> buffer; + buffer.WriteString("abc"); + EXPECT_EQ(buffer.Length(), 3U); + EXPECT_THAT(buffer.DataView(), ElementsAre('a', 'b', 'c')); + EXPECT_EQ(absl::string_view("abc"), buffer.DataAsStringView()); + + buffer.WriteUInt8(0); + EXPECT_STREQ(buffer.DataAsCharPointer(), "abc"); + EXPECT_STREQ(reinterpret_cast<const char*>(buffer.Data()), "abc"); +} + TEST(ByteBufferTest, TestByteOrder) { uint16_t n16 = 1; uint32_t n32 = 1; @@ -150,7 +166,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) { buffer.Clear(); // Write and read bytes - char write_bytes[] = "foo"; + uint8_t write_bytes[] = "foo"; buffer.WriteBytes(write_bytes, 3); ByteBufferReader read_buf7(buffer); uint8_t read_bytes[3]; @@ -162,7 +178,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) { buffer.Clear(); // Write and read reserved buffer space - char* write_dst = buffer.ReserveWriteBuffer(3); + uint8_t* write_dst = buffer.ReserveWriteBuffer(3); memcpy(write_dst, write_bytes, 3); ByteBufferReader read_buf8(buffer); memset(read_bytes, 0, 3); @@ -194,6 +210,27 @@ TEST(ByteBufferTest, TestReadWriteBuffer) { buffer.Clear(); } +TEST(ByteBufferTest, TestReadStringView) { + const absl::string_view tests[] = {"hello", " ", "string_view"}; + std::string buffer; + for (const auto& test : tests) + buffer += test; + + rtc::ArrayView<const uint8_t> bytes( + reinterpret_cast<const uint8_t*>(&buffer[0]), buffer.size()); + + ByteBufferReader read_buf(bytes); + size_t consumed = 0; + for (const auto& test : tests) { + absl::string_view sv; + EXPECT_TRUE(read_buf.ReadStringView(&sv, test.length())); + EXPECT_EQ(sv.compare(test), 0); + // The returned string view should point directly into the original string. + EXPECT_EQ(&sv[0], &buffer[0 + consumed]); + consumed += sv.size(); + } +} + TEST(ByteBufferTest, TestReadWriteUVarint) { ByteBufferWriter write_buffer; size_t size = 0; |