Store iterator bitset by-value instead of by-reference.
The by-reference method was giving strange problems when using a non-
LValue as argument to IterateBitSet.
BUG=angleproject:1040
Change-Id: Iec10f7256a5b19b239804e0beba4ae675f53f876
Reviewed-on: https://chromium-review.googlesource.com/293840
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/common/BitSetIterator_unittest.cpp b/src/common/BitSetIterator_unittest.cpp
index b1411d9..da913e1 100644
--- a/src/common/BitSetIterator_unittest.cpp
+++ b/src/common/BitSetIterator_unittest.cpp
@@ -21,6 +21,7 @@
std::bitset<40> mStateBits;
};
+// Simple iterator test.
TEST_F(BitSetIteratorTest, Iterator)
{
std::set<unsigned long> originalValues;
@@ -45,4 +46,42 @@
EXPECT_EQ(originalValues.size(), readValues.size());
}
+// Test an empty iterator.
+TEST_F(BitSetIteratorTest, EmptySet)
+{
+ for (unsigned long bit : IterateBitSet(mStateBits))
+ {
+ UNUSED_TRACE_VARIABLE(bit);
+ FAIL() << "Should not be reached";
+ }
+}
+
+// Test iterating a result of combining two bitsets.
+TEST_F(BitSetIteratorTest, NonLValueBitset)
+{
+ std::bitset<40> otherBits;
+
+ mStateBits.set(1);
+ mStateBits.set(2);
+ mStateBits.set(3);
+ mStateBits.set(4);
+
+ otherBits.set(0);
+ otherBits.set(1);
+ otherBits.set(3);
+ otherBits.set(5);
+
+ std::set<unsigned long> seenBits;
+
+ for (unsigned long bit : IterateBitSet(mStateBits & otherBits))
+ {
+ EXPECT_EQ(0u, seenBits.count(bit));
+ seenBits.insert(bit);
+ EXPECT_TRUE(mStateBits[bit]);
+ EXPECT_TRUE(otherBits[bit]);
+ }
+
+ EXPECT_EQ((mStateBits & otherBits).count(), seenBits.size());
+}
+
} // anonymous namespace