unit-test: Test need_to_introspect function
Testing: Verified 100% code coverage of processing.cpp
Change-Id: I5ebdebe3fdcecbf250a23754f8b5c7db81bfaaa3
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/src/main.cpp b/src/main.cpp
index 5870aea..dea80f8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,7 +6,6 @@
#include <atomic>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/container/flat_map.hpp>
-#include <boost/container/flat_set.hpp>
#include <chrono>
#include <iomanip>
#include <iostream>
@@ -65,8 +64,8 @@
AssociationOwnersType associationOwners;
-static boost::container::flat_set<std::string> service_whitelist;
-static boost::container::flat_set<std::string> service_blacklist;
+static WhiteBlackList service_whitelist;
+static WhiteBlackList service_blacklist;
/** Exception thrown when a path is not found in the object list. */
struct NotFoundException final : public sdbusplus::exception_t
@@ -540,21 +539,6 @@
"Introspect");
}
-bool need_to_introspect(const std::string& process_name)
-{
- auto inWhitelist =
- std::find_if(service_whitelist.begin(), service_whitelist.end(),
- [&process_name](const auto& prefix) {
- return boost::starts_with(process_name, prefix);
- }) != service_whitelist.end();
-
- // This holds full service names, not prefixes
- auto inBlacklist =
- service_blacklist.find(process_name) != service_blacklist.end();
-
- return inWhitelist && !inBlacklist;
-}
-
void start_new_introspect(
sdbusplus::asio::connection* system_bus, boost::asio::io_service& io,
interface_map_type& interface_map, const std::string& process_name,
@@ -564,7 +548,7 @@
#endif
sdbusplus::asio::object_server& objectServer)
{
- if (need_to_introspect(process_name))
+ if (needToIntrospect(process_name, service_whitelist, service_blacklist))
{
std::shared_ptr<InProgressIntrospect> transaction =
std::make_shared<InProgressIntrospect>(system_bus, io, process_name
@@ -626,7 +610,8 @@
#endif
for (const std::string& process_name : process_names)
{
- if (need_to_introspect(process_name))
+ if (needToIntrospect(process_name, service_whitelist,
+ service_blacklist))
{
start_new_introspect(system_bus, io, interface_map,
process_name,
@@ -835,7 +820,8 @@
std::chrono::steady_clock::now());
#endif
// New daemon added
- if (need_to_introspect(name))
+ if (needToIntrospect(name, service_whitelist,
+ service_blacklist))
{
name_owners[new_owner] = name;
start_new_introspect(system_bus.get(), io, interface_map,
@@ -867,7 +853,8 @@
{
return; // only introspect well-known
}
- if (need_to_introspect(well_known))
+ if (needToIntrospect(well_known, service_whitelist,
+ service_blacklist))
{
auto& iface_list = interface_map[obj_path.str];