]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5605a] Added registeredFactory
authorFrancis Dupont <fdupont@isc.org>
Tue, 1 May 2018 21:20:44 +0000 (23:20 +0200)
committerFrancis Dupont <fdupont@isc.org>
Tue, 1 May 2018 21:20:44 +0000 (23:20 +0200)
src/lib/dhcpsrv/host_data_source_factory.cc
src/lib/dhcpsrv/host_data_source_factory.h
src/lib/dhcpsrv/tests/host_data_source_factory_unittest.cc

index ec5cac31fdedb357591b1ec7c09d6a874c64194a..76b8cd595e973eac5157d6ae7c24466ec8117ea3 100644 (file)
@@ -126,6 +126,12 @@ HostDataSourceFactory::deregisterFactory(const string& db_type, bool no_log) {
     }
 }
 
+bool
+HostDataSourceFactory::registeredFactory(const std::string& db_type) {
+    auto index = map_.find(db_type);
+    return (index != map_.end());
+}
+
 void
 HostDataSourceFactory::printRegistered() {
     std::stringstream txt;
index b28f291d0b794158ddb11ca6d1222a4ea85724bf..20f5fe7a577b608a70e49b77213b54aa50e3ca36 100644 (file)
@@ -107,6 +107,12 @@ public:
     static bool deregisterFactory(const std::string& db_type,
                                   bool no_log = false);
 
+    /// @brief Check if a host data source factory was registered
+    ///
+    /// @param db_type database type
+    /// @return true if a factory was registered for db_type, false if not.
+    static bool registeredFactory(const std::string& db_type);
+
     /// @brief Prints out all registered backends.
     ///
     /// We need a dedicated method for this, because we sometimes can't log
index 3d8f7a271130b0980f4c51b6f5d76f1ab59a4d5d..596b908a8e154cfd66c9eaa258c34be4f00d3df7 100644 (file)
@@ -96,6 +96,20 @@ TEST_F(HostDataSourceFactoryTest, registerFactory) {
     EXPECT_FALSE(registerFactory());
 }
 
+// Verify a factory registration can be checked.
+TEST_F(HostDataSourceFactoryTest, registeredFactory) {
+    // Not yet registered
+    EXPECT_FALSE(HostDataSourceFactory::registeredFactory("mem"));
+    EXPECT_FALSE(HostDataSourceFactory::registeredFactory("mem1"));
+
+    // Register mem
+    EXPECT_TRUE(registerFactory());
+
+    // Now mem is registered but not mem1
+    EXPECT_TRUE(HostDataSourceFactory::registeredFactory("mem"));
+    EXPECT_FALSE(HostDataSourceFactory::registeredFactory("mem1"));
+}
+
 // Verify a factory can be registered and deregistered
 TEST_F(HostDataSourceFactoryTest, deregisterFactory) {
     // Does not exist at the beginning
@@ -104,6 +118,7 @@ TEST_F(HostDataSourceFactoryTest, deregisterFactory) {
     // Register and deregister
     EXPECT_TRUE(registerFactory());
     EXPECT_TRUE(HostDataSourceFactory::deregisterFactory("mem"));
+    EXPECT_FALSE(HostDataSourceFactory::registeredFactory("mem"));
 
     // No longer exists
     EXPECT_FALSE(HostDataSourceFactory::deregisterFactory("mem"));