From: Jelte Jansen Date: Wed, 16 May 2012 09:58:11 +0000 (+0200) Subject: [1207] initialize FakeClient in FakeContainer constructor X-Git-Tag: trac2351_base~226^2~90^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=393bf630eca3e1735e5d2c2dbf79bd79df6d9790;p=thirdparty%2Fkea.git [1207] initialize FakeClient in FakeContainer constructor and store it as a scoped ptr --- diff --git a/src/bin/auth/tests/auth_srv_unittest.cc b/src/bin/auth/tests/auth_srv_unittest.cc index 54bb8d7831..f3e62a45fb 100644 --- a/src/bin/auth/tests/auth_srv_unittest.cc +++ b/src/bin/auth/tests/auth_srv_unittest.cc @@ -17,6 +17,7 @@ #include #include +#include #include @@ -1280,25 +1281,25 @@ public: /// /// The initializer creates a fresh instance of a memory datasource, /// which is ignored for the rest (but we do not allow 'null' containers - /// atm, and this is only needed in these tests) + /// atm, and this is only needed in these tests, this may be changed + /// if we generalize the container class a bit more) /// - /// The client given will be deleted upon destruction of this container - FakeContainer(isc::datasrc::DataSourceClient* client) : + /// It will also create a FakeClient, with the given arguments, which + /// is actually used when the instance is requested. + FakeContainer(isc::datasrc::DataSourceClientContainerPtr real_client, + ThrowWhen throw_when, bool isc_exception, + ConstRRsetPtr fake_rrset = ConstRRsetPtr()) : DataSourceClientContainer("memory", Element::fromJSON("{\"type\": \"memory\"}")), - client_(client) + client_(new FakeClient(real_client, throw_when, isc_exception, fake_rrset)) {} - ~FakeContainer() { - delete client_; - } - isc::datasrc::DataSourceClient& getInstance() { return (*client_); } private: - isc::datasrc::DataSourceClient* const client_; + const boost::scoped_ptr client_; }; } // end anonymous namespace for throwing proxy classes @@ -1310,14 +1311,11 @@ private: TEST_F(AuthSrvTest, queryWithInMemoryClientProxy) { // Set real inmem client to proxy updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true); - - FakeClient* fake_client( - new FakeClient(server.getInMemoryClientContainer(rrclass), - THROW_NEVER, false)); EXPECT_TRUE(server.hasInMemoryClient()); isc::datasrc::DataSourceClientContainerPtr fake_client_container( - new FakeContainer(fake_client)); + new FakeContainer(server.getInMemoryClientContainer(rrclass), + THROW_NEVER, false)); server.setInMemoryClient(rrclass, fake_client_container); createDataFromFile("nsec3query_nodnssec_fromWire.wire"); @@ -1344,12 +1342,10 @@ setupThrow(AuthSrv* server, const char *config, ThrowWhen throw_when, // Set it to throw on findZone(), this should result in // SERVFAIL on any exception - FakeClient* fake_client( - new FakeClient( + isc::datasrc::DataSourceClientContainerPtr fake_client_container( + new FakeContainer( server->getInMemoryClientContainer(isc::dns::RRClass::IN()), throw_when, isc_exception, rrset)); - isc::datasrc::DataSourceClientContainerPtr fake_client_container( - new FakeContainer(fake_client)); ASSERT_TRUE(server->hasInMemoryClient()); server->setInMemoryClient(isc::dns::RRClass::IN(), fake_client_container);