Browse Source

[1207] initialize FakeClient in FakeContainer constructor

and store it as a scoped ptr
Jelte Jansen 13 years ago
parent
commit
393bf630ec
1 changed files with 14 additions and 18 deletions
  1. 14 18
      src/bin/auth/tests/auth_srv_unittest.cc

+ 14 - 18
src/bin/auth/tests/auth_srv_unittest.cc

@@ -17,6 +17,7 @@
 #include <vector>
 #include <vector>
 
 
 #include <boost/shared_ptr.hpp>
 #include <boost/shared_ptr.hpp>
+#include <boost/scoped_ptr.hpp>
 
 
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
 
 
@@ -1280,25 +1281,25 @@ public:
     ///
     ///
     /// The initializer creates a fresh instance of a memory datasource,
     /// The initializer creates a fresh instance of a memory datasource,
     /// which is ignored for the rest (but we do not allow 'null' containers
     /// 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",
         DataSourceClientContainer("memory",
                                   Element::fromJSON("{\"type\": \"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() {
     isc::datasrc::DataSourceClient& getInstance() {
         return (*client_);
         return (*client_);
     }
     }
 
 
 private:
 private:
-    isc::datasrc::DataSourceClient* const client_;
+    const boost::scoped_ptr<isc::datasrc::DataSourceClient> client_;
 };
 };
 
 
 } // end anonymous namespace for throwing proxy classes
 } // end anonymous namespace for throwing proxy classes
@@ -1310,14 +1311,11 @@ private:
 TEST_F(AuthSrvTest, queryWithInMemoryClientProxy) {
 TEST_F(AuthSrvTest, queryWithInMemoryClientProxy) {
     // Set real inmem client to proxy
     // Set real inmem client to proxy
     updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true);
     updateConfig(&server, CONFIG_INMEMORY_EXAMPLE, true);
-
-    FakeClient* fake_client(
-        new FakeClient(server.getInMemoryClientContainer(rrclass),
-                       THROW_NEVER, false));
     EXPECT_TRUE(server.hasInMemoryClient());
     EXPECT_TRUE(server.hasInMemoryClient());
 
 
     isc::datasrc::DataSourceClientContainerPtr fake_client_container(
     isc::datasrc::DataSourceClientContainerPtr fake_client_container(
-        new FakeContainer(fake_client));
+        new FakeContainer(server.getInMemoryClientContainer(rrclass),
+                          THROW_NEVER, false));
     server.setInMemoryClient(rrclass, fake_client_container);
     server.setInMemoryClient(rrclass, fake_client_container);
 
 
     createDataFromFile("nsec3query_nodnssec_fromWire.wire");
     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
     // Set it to throw on findZone(), this should result in
     // SERVFAIL on any exception
     // SERVFAIL on any exception
-    FakeClient* fake_client(
-        new FakeClient(
+    isc::datasrc::DataSourceClientContainerPtr fake_client_container(
+        new FakeContainer(
             server->getInMemoryClientContainer(isc::dns::RRClass::IN()),
             server->getInMemoryClientContainer(isc::dns::RRClass::IN()),
             throw_when, isc_exception, rrset));
             throw_when, isc_exception, rrset));
-    isc::datasrc::DataSourceClientContainerPtr fake_client_container(
-        new FakeContainer(fake_client));
 
 
     ASSERT_TRUE(server->hasInMemoryClient());
     ASSERT_TRUE(server->hasInMemoryClient());
     server->setInMemoryClient(isc::dns::RRClass::IN(), fake_client_container);
     server->setInMemoryClient(isc::dns::RRClass::IN(), fake_client_container);