isc::NotImplemented);
}
-// This test fixture is templated so that we can share (most of) the test
-// cases with different types of data sources. Note that in test cases
-// we need to use 'this' to refer to member variables of the test class.
-template <typename ACCESSOR_TYPE>
-class DatabaseClientTest : public ::testing::Test {
+// This is the type used as the test parameter. Note that this is
+// intentionally a plain old type (i.e. a function pointer), not a class;
+// otherwise it could cause initialization fiasco at the instantiation time.
+typedef boost::shared_ptr<DatabaseAccessor> (*AccessorCreator)();
+
+// This test fixture is parametized so that we can share (most of) the test
+// cases with different types of data sources.
+class DatabaseClientTest : public ::testing::TestWithParam<AccessorCreator> {
public:
DatabaseClientTest() : zname_("example.org"), qname_("www.example.org"),
qclass_(RRClass::IN()), qtype_(RRType::A()),
"Error setting up; command failed: " << install_cmd);
}
- current_accessor_ = new ACCESSOR_TYPE();
- is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_) != NULL);
- client_.reset(new DatabaseClient(qclass_,
- boost::shared_ptr<ACCESSOR_TYPE>(
- current_accessor_)));
+ current_accessor_ = (*GetParam())();
+ is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_.get()) !=
+ NULL);
+ client_.reset(new DatabaseClient(qclass_, current_accessor_));
}
/**
if (is_mock_) {
EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
}
- EXPECT_EQ(current_accessor_, &finder->getAccessor());
+ EXPECT_EQ(current_accessor_.get(), &finder->getAccessor());
}
boost::shared_ptr<DatabaseClient::Finder> getFinder() {
void checkLastAdded(const char* const expected[]) const {
if (is_mock_) {
const MockAccessor* mock_accessor =
- dynamic_cast<const MockAccessor*>(current_accessor_);
+ dynamic_cast<const MockAccessor*>(current_accessor_.get());
for (int i = 0; i < DatabaseAccessor::ADD_COLUMN_COUNT; ++i) {
EXPECT_EQ(expected[i],
mock_accessor->getLatestClone()->getLastAdded()[i]);
void setUpdateAccessor() {
if (is_mock_) {
const MockAccessor* mock_accessor =
- dynamic_cast<const MockAccessor*>(current_accessor_);
+ dynamic_cast<const MockAccessor*>(current_accessor_.get());
update_accessor_ = mock_accessor->getLatestClone();
}
}
void checkJournal(const vector<JournalEntry>& expected) {
if (is_mock_) {
const MockAccessor* mock_accessor =
- dynamic_cast<const MockAccessor*>(current_accessor_);
+ dynamic_cast<const MockAccessor*>(current_accessor_.get());
mock_accessor->checkJournal(expected);
} else {
// For other generic databases, retrieve the diff using the
// is of that type.
bool is_mock_;
- // Will be deleted by client_, just keep the current value for comparison.
- ACCESSOR_TYPE* current_accessor_;
+ boost::shared_ptr<DatabaseAccessor> current_accessor_;
boost::shared_ptr<DatabaseClient> client_;
const std::string database_name_;
// complete workaround, but for a short term workaround we'll reduce the
// number of tested accessor classes (thus reducing the amount of code
// to be compiled) for this particular environment.
+#if 0
#if defined(__clang__) && defined(__FreeBSD__)
typedef ::testing::Types<MockAccessor> TestAccessorTypes;
#else
#endif
TYPED_TEST_CASE(DatabaseClientTest, TestAccessorTypes);
+#endif
+boost::shared_ptr<DatabaseAccessor>
+createMockAccessor() {
+ return (boost::shared_ptr<DatabaseAccessor>(new MockAccessor()));
+}
+
+boost::shared_ptr<DatabaseAccessor>
+createSQLite3Accessor() {
+ return (boost::shared_ptr<DatabaseAccessor>(new TestSQLite3Accessor()));
+}
+
+INSTANTIATE_TEST_CASE_P(, DatabaseClientTest,
+ ::testing::Values(createMockAccessor,
+ createSQLite3Accessor));
+
+#if 0
// In some cases the entire test fixture is for the mock accessor only.
// We use the usual TEST_F for them with the corresponding specialized class
// to make the code simpler.
this->qclass_, RRType::A()),
RRsetCollectionError);
}
+#endif // 0
}