Commit 8ba0a7bc authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2850] Add tests to check that resetHeader() is called by ZoneWriter class

Initially I thought it was not possible to test this as
ZoneTableSegment::create() was used to create the zone table segment,
but it seems it's possible to do it this way using a mock class.
parent db8cec0c
......@@ -38,10 +38,25 @@ namespace {
class TestException {};
class ZoneTableSegmentHelper : public ZoneTableSegmentMock {
public:
ZoneTableSegmentHelper(const isc::dns::RRClass& rrclass,
isc::util::MemorySegment& mem_sgmt) :
ZoneTableSegmentMock(rrclass, mem_sgmt),
reset_header_called_(false)
{}
virtual void resetHeader() {
reset_header_called_ = true;
}
bool reset_header_called_;
};
class ZoneWriterTest : public ::testing::Test {
protected:
ZoneWriterTest() :
segment_(ZoneTableSegment::create(RRClass::IN(), "local")),
segment_(new ZoneTableSegmentHelper(RRClass::IN(), mem_sgmt_)),
writer_(new
ZoneWriter(*segment_,
bind(&ZoneWriterTest::loadAction, this, _1),
......@@ -55,7 +70,8 @@ protected:
// Release the writer
writer_.reset();
}
scoped_ptr<ZoneTableSegment> segment_;
MemorySegmentMock mem_sgmt_;
scoped_ptr<ZoneTableSegmentHelper> segment_;
scoped_ptr<ZoneWriter> writer_;
bool load_called_;
bool load_throw_;
......@@ -123,14 +139,18 @@ TEST_F(ZoneWriterTest, constructForReadOnlySegment) {
TEST_F(ZoneWriterTest, correctCall) {
// Nothing called before we call it
EXPECT_FALSE(load_called_);
EXPECT_FALSE(segment_->reset_header_called_);
// Just the load gets called now
EXPECT_NO_THROW(writer_->load());
EXPECT_TRUE(load_called_);
EXPECT_TRUE(segment_->reset_header_called_);
load_called_ = false;
segment_->reset_header_called_ = false;
EXPECT_NO_THROW(writer_->install());
EXPECT_FALSE(load_called_);
EXPECT_TRUE(segment_->reset_header_called_);
// We don't check explicitly how this works, but call it to free memory. If
// everything is freed should be checked inside the TearDown.
......@@ -141,15 +161,19 @@ TEST_F(ZoneWriterTest, loadTwice) {
// Load it the first time
EXPECT_NO_THROW(writer_->load());
EXPECT_TRUE(load_called_);
EXPECT_TRUE(segment_->reset_header_called_);
load_called_ = false;
segment_->reset_header_called_ = false;
// The second time, it should not be possible
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
EXPECT_FALSE(load_called_);
EXPECT_FALSE(segment_->reset_header_called_);
// The object should not be damaged, try installing and clearing now
EXPECT_NO_THROW(writer_->install());
EXPECT_FALSE(load_called_);
EXPECT_TRUE(segment_->reset_header_called_);
// We don't check explicitly how this works, but call it to free memory. If
// everything is freed should be checked inside the TearDown.
......@@ -164,15 +188,18 @@ TEST_F(ZoneWriterTest, loadLater) {
EXPECT_NO_THROW(writer_->install());
// Reset so we see nothing is called now
load_called_ = false;
segment_->reset_header_called_ = false;
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
EXPECT_FALSE(load_called_);
EXPECT_FALSE(segment_->reset_header_called_);
// Cleanup and try loading again. Still shouldn't work.
EXPECT_NO_THROW(writer_->cleanup());
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
EXPECT_FALSE(load_called_);
EXPECT_FALSE(segment_->reset_header_called_);
}
// Try calling install at various bad times
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment