[bitset_t] Add test for walk_bitset

This commit is contained in:
Joe Thornber 2014-09-01 14:15:32 +01:00
parent 5a6b92312e
commit 67865e0732

View File

@ -32,6 +32,26 @@ using namespace testing;
namespace { namespace {
block_address const NR_BLOCKS = 102400; block_address const NR_BLOCKS = 102400;
class bitset_checker : public bitset_detail::bitset_visitor {
public:
bitset_checker(unsigned size, unsigned m)
: size_(size), m_(m) {
}
void visit(uint32_t index, bool value) {
ASSERT_THAT(index, Lt(size_));
ASSERT_THAT(value, Eq(index % 7 ? true : false));
}
void visit(bitset_detail::missing_bits const &d) {
// we aren't expecting any damage
FAIL();
}
private:
unsigned size_, m_;
};
class BitsetTests : public Test { class BitsetTests : public Test {
public: public:
BitsetTests() BitsetTests()
@ -152,7 +172,7 @@ TEST_F(BitsetTests, set_works)
TEST_F(BitsetTests, reopen_works) TEST_F(BitsetTests, reopen_works)
{ {
unsigned const COUNT = 100000; unsigned const COUNT = 100001;
block_address root; block_address root;
{ {
@ -172,4 +192,29 @@ TEST_F(BitsetTests, reopen_works)
} }
} }
TEST_F(BitsetTests, walk_bitset)
{
unsigned const COUNT = 100001;
block_address root;
{
bitset::ptr bs = create_bitset();
bs->grow(COUNT, true);
for (unsigned i = 0; i < COUNT; i += 7)
bs->set(i, false);
root = bs->get_root();
bitset_checker c(COUNT, 7);
bs->walk_bitset(c);
}
{
bitset::ptr bs = open_bitset(root, COUNT);
bitset_checker c(COUNT, 7);
bs->walk_bitset(c);
}
}
//---------------------------------------------------------------- //----------------------------------------------------------------