summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian McCarthy <amccarth@google.com>2017-05-16 22:11:25 +0000
committerAdrian McCarthy <amccarth@google.com>2017-05-16 22:11:25 +0000
commitec694113c8ee22f78990aa166c562ff36db3e3c1 (patch)
tree2910c0a50d669590f51b6c01bfb36d5fb9da40c7
parent4dc5a1e8694d7d2c4abac63171ce2409f8aba97b (diff)
downloadbcm5719-llvm-ec694113c8ee22f78990aa166c562ff36db3e3c1.tar.gz
bcm5719-llvm-ec694113c8ee22f78990aa166c562ff36db3e3c1.zip
Add test for FixedStreamArrayIterator::operator->
The operator-> implementation comes from iterator_facade_base, so it should just work given that the iterator has a tested operator*. But r302257 showed that required careful handling of for the const qualifier. This patch ensures the fix in r302257 doesn't regress. Differential Revision: https://reviews.llvm.org/D33249 llvm-svn: 303215
-rw-r--r--llvm/unittests/Support/BinaryStreamTest.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/llvm/unittests/Support/BinaryStreamTest.cpp b/llvm/unittests/Support/BinaryStreamTest.cpp
index 41567dad622..ec3b0effc9e 100644
--- a/llvm/unittests/Support/BinaryStreamTest.cpp
+++ b/llvm/unittests/Support/BinaryStreamTest.cpp
@@ -16,6 +16,7 @@
#include "gtest/gtest.h"
#include <unordered_map>
+#include <utility>
using namespace llvm;
using namespace llvm::support;
@@ -117,7 +118,7 @@ private:
// Buffer is organized like this:
// -------------------------------------------------
- // | N/2 | N/2+1 | ... | N-1 | 0 | 1 | ... | N-2-1 |
+ // | N/2 | N/2+1 | ... | N-1 | 0 | 1 | ... | N/2-1 |
// -------------------------------------------------
// So reads from the beginning actually come from the middle.
MutableArrayRef<uint8_t> Data;
@@ -348,6 +349,30 @@ TEST_F(BinaryStreamTest, FixedStreamArray) {
}
}
+// Ensure FixedStreamArrayIterator::operator-> works.
+// Added for coverage of r302257.
+TEST_F(BinaryStreamTest, FixedStreamArrayIteratorArrow) {
+ std::vector<std::pair<uint32_t, uint32_t>> Pairs = {{867, 5309}, {555, 1212}};
+ ArrayRef<uint8_t> PairBytes(reinterpret_cast<uint8_t *>(Pairs.data()),
+ Pairs.size() * sizeof(Pairs[0]));
+
+ initializeInput(PairBytes, alignof(uint32_t));
+
+ for (auto &Stream : Streams) {
+ ASSERT_EQ(InputData.size(), Stream.Input->getLength());
+
+ const FixedStreamArray<std::pair<uint32_t, uint32_t>> Array(*Stream.Input);
+ auto Iter = Array.begin();
+ ASSERT_EQ(Pairs[0].first, Iter->first);
+ ASSERT_EQ(Pairs[0].second, Iter->second);
+ ++Iter;
+ ASSERT_EQ(Pairs[1].first, Iter->first);
+ ASSERT_EQ(Pairs[1].second, Iter->second);
+ ++Iter;
+ ASSERT_EQ(Array.end(), Iter);
+ }
+}
+
// Test that VarStreamArray works correctly.
TEST_F(BinaryStreamTest, VarStreamArray) {
StringLiteral Strings("1. Test2. Longer Test3. Really Long Test4. Super "
@@ -686,7 +711,7 @@ TEST_F(BinaryStreamTest, BinaryItemStream) {
std::vector<Foo> Foos = {{1, 1.0}, {2, 2.0}, {3, 3.0}};
BumpPtrAllocator Allocator;
for (const auto &F : Foos) {
- uint8_t *Ptr = static_cast<uint8_t *>(Allocator.Allocate(sizeof(Foo),
+ uint8_t *Ptr = static_cast<uint8_t *>(Allocator.Allocate(sizeof(Foo),
alignof(Foo)));
MutableArrayRef<uint8_t> Buffer(Ptr, sizeof(Foo));
MutableBinaryByteStream Stream(Buffer, llvm::support::big);
OpenPOWER on IntegriCloud