Hash :
b3a60aa9
Author :
Date :
2015-08-14T14:44:06
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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// BitSetIteratorTest:
// Test the IterableBitSet class.
//
#include <gtest/gtest.h>
#include "common/BitSetIterator.h"
using namespace angle;
namespace
{
class BitSetIteratorTest : public testing::Test
{
protected:
std::bitset<40> mStateBits;
};
// Simple iterator test.
TEST_F(BitSetIteratorTest, Iterator)
{
std::set<unsigned long> originalValues;
originalValues.insert(2);
originalValues.insert(6);
originalValues.insert(8);
originalValues.insert(35);
for (unsigned long value : originalValues)
{
mStateBits.set(value);
}
std::set<unsigned long> readValues;
for (unsigned long bit : IterateBitSet(mStateBits))
{
EXPECT_EQ(1u, originalValues.count(bit));
EXPECT_EQ(0u, readValues.count(bit));
readValues.insert(bit);
}
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