Bug: angleproject:5906
Change-Id: If1ccacfc81e3e01b4bdbd10d47cf4ec860e3fe0b
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3645494
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Shahbaz Youssefi 2022-05-13 10:50:47 -04:00 коммит произвёл Angle LUCI CQ
Родитель 36f5e6ce55
Коммит 20820bb4b3
3 изменённых файлов: 121 добавлений и 62 удалений

Просмотреть файл

@ -383,10 +383,11 @@ def _CheckNonAsciiInSourceFiles(input_api, output_api):
def _CheckCommentBeforeTestInTestFiles(input_api, output_api):
"""Require a comment before TEST_P() tests. """
"""Require a comment before TEST_P() and other tests. """
def test_files(f):
return input_api.FilterSourceFile(f, files_to_check=(r'^src\/tests\/.+\.cpp$',))
return input_api.FilterSourceFile(
f, files_to_check=(r'^src\/tests\/.+\.cpp$', r'^src\/.+_unittest\.cpp$'))
tests_with_no_comment = []
for f in input_api.AffectedSourceFiles(test_files):
@ -398,7 +399,9 @@ def _CheckCommentBeforeTestInTestFiles(input_api, output_api):
continue
new_line_is_comment = line.startswith(' //') or line.startswith('+//')
new_line_is_test_declaration = line.startswith('+TEST_P(')
new_line_is_test_declaration = (
line.startswith('+TEST_P(') or line.startswith('+TEST(') or
line.startswith('+TYPED_TEST('))
if new_line_is_test_declaration and not last_line_was_comment:
tests_with_no_comment.append(line[1:])

Просмотреть файл

@ -504,13 +504,14 @@ class BitSetArray final
{
public:
using BaseBitSet = priv::BaseBitSetType;
BitSetArray();
BitSetArray(const BitSetArray<N> &other);
using value_type = BaseBitSet::value_type;
using param_type = BaseBitSet::param_type;
constexpr BitSetArray();
constexpr explicit BitSetArray(std::initializer_list<param_type> init);
BitSetArray(const BitSetArray<N> &other);
class Reference final
{
public:
@ -633,7 +634,7 @@ class BitSetArray final
constexpr std::size_t size() const { return N; }
Iterator begin() const { return Iterator(*this, 0); }
Iterator end() const { return Iterator(*this, kArraySize); }
unsigned long to_ulong() const
constexpr unsigned long to_ulong() const
{
// TODO(anglebug.com/5628): Handle serializing more than kDefaultBitSetSize
for (std::size_t index = 1; index < kArraySize; index++)
@ -644,45 +645,45 @@ class BitSetArray final
}
// Assignment operators
BitSetArray &operator=(const BitSetArray &other);
BitSetArray &operator&=(const BitSetArray &other);
BitSetArray &operator|=(const BitSetArray &other);
BitSetArray &operator^=(const BitSetArray &other);
constexpr BitSetArray &operator=(const BitSetArray &other);
constexpr BitSetArray &operator&=(const BitSetArray &other);
constexpr BitSetArray &operator|=(const BitSetArray &other);
constexpr BitSetArray &operator^=(const BitSetArray &other);
// Bitwise operators
BitSetArray<N> operator&(const angle::BitSetArray<N> &other) const;
BitSetArray<N> operator|(const angle::BitSetArray<N> &other) const;
BitSetArray<N> operator^(const angle::BitSetArray<N> &other) const;
constexpr BitSetArray<N> operator&(const angle::BitSetArray<N> &other) const;
constexpr BitSetArray<N> operator|(const angle::BitSetArray<N> &other) const;
constexpr BitSetArray<N> operator^(const angle::BitSetArray<N> &other) const;
// Relational Operators
bool operator==(const angle::BitSetArray<N> &other) const;
bool operator!=(const angle::BitSetArray<N> &other) const;
constexpr bool operator==(const angle::BitSetArray<N> &other) const;
constexpr bool operator!=(const angle::BitSetArray<N> &other) const;
// Unary operators
BitSetArray operator~() const;
bool operator[](std::size_t pos) const;
Reference operator[](std::size_t pos)
constexpr BitSetArray operator~() const;
constexpr bool operator[](std::size_t pos) const;
constexpr Reference operator[](std::size_t pos)
{
ASSERT(pos < size());
return Reference(*this, pos);
}
// Setter, getters and other helper methods
BitSetArray &set();
BitSetArray &set(std::size_t pos, bool value = true);
BitSetArray &reset();
BitSetArray &reset(std::size_t pos);
bool test(std::size_t pos) const;
bool all() const;
bool any() const;
bool none() const;
std::size_t count() const;
bool intersects(const BitSetArray &other) const;
BitSetArray<N> &flip();
param_type first() const;
param_type last() const;
constexpr BitSetArray &set();
constexpr BitSetArray &set(std::size_t pos, bool value = true);
constexpr BitSetArray &reset();
constexpr BitSetArray &reset(std::size_t pos);
constexpr bool test(std::size_t pos) const;
constexpr bool all() const;
constexpr bool any() const;
constexpr bool none() const;
constexpr std::size_t count() const;
constexpr bool intersects(const BitSetArray &other) const;
constexpr BitSetArray<N> &flip();
constexpr param_type first() const;
constexpr param_type last() const;
value_type bits(size_t index) const;
constexpr value_type bits(size_t index) const;
private:
static constexpr std::size_t kDefaultBitSetSizeMinusOne = priv::kDefaultBitSetSize - 1;
@ -698,12 +699,25 @@ class BitSetArray final
};
template <std::size_t N>
BitSetArray<N>::BitSetArray()
constexpr BitSetArray<N>::BitSetArray()
{
static_assert(N > priv::kDefaultBitSetSize, "BitSetArray type can't support requested size.");
reset();
}
template <std::size_t N>
constexpr BitSetArray<N>::BitSetArray(std::initializer_list<param_type> init)
{
reset();
for (param_type element : init)
{
size_t index = element >> kShiftForDivision;
size_t offset = element & kDefaultBitSetSizeMinusOne;
mBaseBitSetArray[index].set(offset, true);
}
}
template <size_t N>
BitSetArray<N>::BitSetArray(const BitSetArray<N> &other)
{
@ -774,7 +788,7 @@ std::size_t BitSetArray<N>::Iterator::operator*() const
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::operator=(const BitSetArray<N> &other)
constexpr BitSetArray<N> &BitSetArray<N>::operator=(const BitSetArray<N> &other)
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -784,7 +798,7 @@ BitSetArray<N> &BitSetArray<N>::operator=(const BitSetArray<N> &other)
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::operator&=(const BitSetArray<N> &other)
constexpr BitSetArray<N> &BitSetArray<N>::operator&=(const BitSetArray<N> &other)
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -794,7 +808,7 @@ BitSetArray<N> &BitSetArray<N>::operator&=(const BitSetArray<N> &other)
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::operator|=(const BitSetArray<N> &other)
constexpr BitSetArray<N> &BitSetArray<N>::operator|=(const BitSetArray<N> &other)
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -804,7 +818,7 @@ BitSetArray<N> &BitSetArray<N>::operator|=(const BitSetArray<N> &other)
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::operator^=(const BitSetArray<N> &other)
constexpr BitSetArray<N> &BitSetArray<N>::operator^=(const BitSetArray<N> &other)
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -814,7 +828,7 @@ BitSetArray<N> &BitSetArray<N>::operator^=(const BitSetArray<N> &other)
}
template <std::size_t N>
BitSetArray<N> BitSetArray<N>::operator&(const angle::BitSetArray<N> &other) const
constexpr BitSetArray<N> BitSetArray<N>::operator&(const angle::BitSetArray<N> &other) const
{
angle::BitSetArray<N> result(other);
result &= *this;
@ -822,7 +836,7 @@ BitSetArray<N> BitSetArray<N>::operator&(const angle::BitSetArray<N> &other) con
}
template <std::size_t N>
BitSetArray<N> BitSetArray<N>::operator|(const angle::BitSetArray<N> &other) const
constexpr BitSetArray<N> BitSetArray<N>::operator|(const angle::BitSetArray<N> &other) const
{
angle::BitSetArray<N> result(other);
result |= *this;
@ -830,7 +844,7 @@ BitSetArray<N> BitSetArray<N>::operator|(const angle::BitSetArray<N> &other) con
}
template <std::size_t N>
BitSetArray<N> BitSetArray<N>::operator^(const angle::BitSetArray<N> &other) const
constexpr BitSetArray<N> BitSetArray<N>::operator^(const angle::BitSetArray<N> &other) const
{
angle::BitSetArray<N> result(other);
result ^= *this;
@ -838,7 +852,7 @@ BitSetArray<N> BitSetArray<N>::operator^(const angle::BitSetArray<N> &other) con
}
template <std::size_t N>
bool BitSetArray<N>::operator==(const angle::BitSetArray<N> &other) const
constexpr bool BitSetArray<N>::operator==(const angle::BitSetArray<N> &other) const
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -851,13 +865,13 @@ bool BitSetArray<N>::operator==(const angle::BitSetArray<N> &other) const
}
template <std::size_t N>
bool BitSetArray<N>::operator!=(const angle::BitSetArray<N> &other) const
constexpr bool BitSetArray<N>::operator!=(const angle::BitSetArray<N> &other) const
{
return !(*this == other);
}
template <std::size_t N>
BitSetArray<N> BitSetArray<N>::operator~() const
constexpr BitSetArray<N> BitSetArray<N>::operator~() const
{
angle::BitSetArray<N> result;
for (std::size_t index = 0; index < kArraySize; index++)
@ -871,14 +885,14 @@ BitSetArray<N> BitSetArray<N>::operator~() const
}
template <std::size_t N>
bool BitSetArray<N>::operator[](std::size_t pos) const
constexpr bool BitSetArray<N>::operator[](std::size_t pos) const
{
ASSERT(pos < size());
return test(pos);
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::set()
constexpr BitSetArray<N> &BitSetArray<N>::set()
{
for (BaseBitSet &baseBitSet : mBaseBitSetArray)
{
@ -891,7 +905,7 @@ BitSetArray<N> &BitSetArray<N>::set()
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::set(std::size_t pos, bool value)
constexpr BitSetArray<N> &BitSetArray<N>::set(std::size_t pos, bool value)
{
ASSERT(pos < size());
// Get the index and offset, then set the bit
@ -902,7 +916,7 @@ BitSetArray<N> &BitSetArray<N>::set(std::size_t pos, bool value)
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::reset()
constexpr BitSetArray<N> &BitSetArray<N>::reset()
{
for (BaseBitSet &baseBitSet : mBaseBitSetArray)
{
@ -912,14 +926,14 @@ BitSetArray<N> &BitSetArray<N>::reset()
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::reset(std::size_t pos)
constexpr BitSetArray<N> &BitSetArray<N>::reset(std::size_t pos)
{
ASSERT(pos < size());
return set(pos, false);
}
template <std::size_t N>
bool BitSetArray<N>::test(std::size_t pos) const
constexpr bool BitSetArray<N>::test(std::size_t pos) const
{
ASSERT(pos < size());
// Get the index and offset, then test the bit
@ -929,9 +943,9 @@ bool BitSetArray<N>::test(std::size_t pos) const
}
template <std::size_t N>
bool BitSetArray<N>::all() const
constexpr bool BitSetArray<N>::all() const
{
static priv::BaseBitSetType kLastElementBitSet = priv::BaseBitSetType(kLastElementMask);
constexpr priv::BaseBitSetType kLastElementBitSet = priv::BaseBitSetType(kLastElementMask);
for (std::size_t index = 0; index < kArraySize - 1; index++)
{
@ -946,7 +960,7 @@ bool BitSetArray<N>::all() const
}
template <std::size_t N>
bool BitSetArray<N>::any() const
constexpr bool BitSetArray<N>::any() const
{
for (const BaseBitSet &baseBitSet : mBaseBitSetArray)
{
@ -959,7 +973,7 @@ bool BitSetArray<N>::any() const
}
template <std::size_t N>
bool BitSetArray<N>::none() const
constexpr bool BitSetArray<N>::none() const
{
for (const BaseBitSet &baseBitSet : mBaseBitSetArray)
{
@ -972,7 +986,7 @@ bool BitSetArray<N>::none() const
}
template <std::size_t N>
std::size_t BitSetArray<N>::count() const
constexpr std::size_t BitSetArray<N>::count() const
{
size_t count = 0;
for (const BaseBitSet &baseBitSet : mBaseBitSetArray)
@ -983,7 +997,7 @@ std::size_t BitSetArray<N>::count() const
}
template <std::size_t N>
bool BitSetArray<N>::intersects(const BitSetArray<N> &other) const
constexpr bool BitSetArray<N>::intersects(const BitSetArray<N> &other) const
{
for (std::size_t index = 0; index < kArraySize; index++)
{
@ -996,7 +1010,7 @@ bool BitSetArray<N>::intersects(const BitSetArray<N> &other) const
}
template <std::size_t N>
BitSetArray<N> &BitSetArray<N>::flip()
constexpr BitSetArray<N> &BitSetArray<N>::flip()
{
for (BaseBitSet &baseBitSet : mBaseBitSetArray)
{
@ -1009,7 +1023,7 @@ BitSetArray<N> &BitSetArray<N>::flip()
}
template <std::size_t N>
typename BitSetArray<N>::param_type BitSetArray<N>::first() const
constexpr typename BitSetArray<N>::param_type BitSetArray<N>::first() const
{
ASSERT(any());
for (size_t arrayIndex = 0; arrayIndex < kArraySize; ++arrayIndex)
@ -1025,7 +1039,7 @@ typename BitSetArray<N>::param_type BitSetArray<N>::first() const
}
template <std::size_t N>
typename BitSetArray<N>::param_type BitSetArray<N>::last() const
constexpr typename BitSetArray<N>::param_type BitSetArray<N>::last() const
{
ASSERT(any());
for (size_t arrayIndex = kArraySize; arrayIndex > 0; --arrayIndex)
@ -1041,7 +1055,7 @@ typename BitSetArray<N>::param_type BitSetArray<N>::last() const
}
template <std::size_t N>
typename BitSetArray<N>::value_type BitSetArray<N>::bits(size_t index) const
constexpr typename BitSetArray<N>::value_type BitSetArray<N>::bits(size_t index) const
{
return mBaseBitSetArray[index].bits();
}

Просмотреть файл

@ -100,6 +100,26 @@ TYPED_TEST(BitSetTest, Basic)
EXPECT_EQ(mBits.count(), 0u);
}
// Test that BitSetT's initializer list constructor works correctly.
TYPED_TEST(BitSetTest, InitializerList)
{
TypeParam bits = TypeParam{
2, 5, 6, 9, 10,
};
for (size_t i = 0; i < bits.size(); ++i)
{
if (i == 2 || i == 5 || i == 6 || i == 9 || i == 10)
{
EXPECT_TRUE(bits[i]) << i;
}
else
{
EXPECT_FALSE(bits[i]) << i;
}
}
}
TYPED_TEST(BitSetTest, BitwiseOperators)
{
TypeParam mBits = this->mBits;
@ -568,6 +588,28 @@ TYPED_TEST(BitSetArrayTest, BasicTest)
}
}
// Test that BitSetArray's initializer list constructor works correctly.
TEST(BitSetArrayTest, InitializerList)
{
BitSetArray<500> bits = BitSetArray<500>{
0, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132, 143, 154, 165,
176, 187, 198, 209, 220, 231, 242, 253, 264, 275, 286, 297, 308, 319, 330, 341,
352, 363, 374, 385, 396, 407, 418, 429, 440, 451, 462, 473, 484, 495,
};
for (size_t i = 0; i < bits.size(); ++i)
{
if (i % 11 == 0)
{
EXPECT_TRUE(bits[i]) << i;
}
else
{
EXPECT_FALSE(bits[i]) << i;
}
}
}
TYPED_TEST(BitSetArrayTest, IterationWithGaps)
{
TypeParam &mBits = this->mBitSet;