summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-05-17 20:42:52 +0000
committerZachary Turner <zturner@google.com>2017-05-17 20:42:52 +0000
commitd2b418bfe2f568065d98b428e54d94cadb4d2437 (patch)
treeeee4db202f243f9fe8038f6329ce08ffd75c16e3 /llvm/unittests/Support
parent98f2946ab3eb128ef2bd2c5e63585bff9a0cc68f (diff)
downloadbcm5719-llvm-d2b418bfe2f568065d98b428e54d94cadb4d2437.tar.gz
bcm5719-llvm-d2b418bfe2f568065d98b428e54d94cadb4d2437.zip
Add some helpers for manipulating BinaryStreamRefs.
llvm-svn: 303297
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/BinaryStreamTest.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/Support/BinaryStreamTest.cpp b/llvm/unittests/Support/BinaryStreamTest.cpp
index ec3b0effc9e..1ce74cbb722 100644
--- a/llvm/unittests/Support/BinaryStreamTest.cpp
+++ b/llvm/unittests/Support/BinaryStreamTest.cpp
@@ -289,6 +289,39 @@ TEST_F(BinaryStreamTest, StreamRefBounds) {
}
}
+TEST_F(BinaryStreamTest, DropOperations) {
+ std::vector<uint8_t> InputData = {1, 2, 3, 4, 5, 4, 3, 2, 1};
+ auto RefData = makeArrayRef(InputData);
+ initializeInput(InputData, 1);
+
+ ArrayRef<uint8_t> Result;
+ BinaryStreamRef Original(InputData, support::little);
+ ASSERT_EQ(InputData.size(), Original.getLength());
+
+ EXPECT_NO_ERROR(Original.readBytes(0, InputData.size(), Result));
+ EXPECT_EQ(RefData, Result);
+
+ auto Dropped = Original.drop_front(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_front(2), Result);
+
+ Dropped = Original.drop_back(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_back(2), Result);
+
+ Dropped = Original.keep_front(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.take_front(2), Result);
+
+ Dropped = Original.keep_back(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.take_back(2), Result);
+
+ Dropped = Original.drop_symmetric(2);
+ EXPECT_NO_ERROR(Dropped.readBytes(0, Dropped.getLength(), Result));
+ EXPECT_EQ(RefData.drop_front(2).drop_back(2), Result);
+}
+
// Test that we can write to a BinaryStream without a StreamWriter.
TEST_F(BinaryStreamTest, MutableBinaryByteStreamBounds) {
std::vector<uint8_t> InputData = {'T', 'e', 's', 't', '\0'};
OpenPOWER on IntegriCloud