From f9d1222a38e36cae892f5b626d96a0c9bf312dc4 Mon Sep 17 00:00:00 2001 From: Kevin Dewald Date: Fri, 27 Sep 2024 00:23:07 -0700 Subject: [PATCH] Removed unused functions in production code. --- .../include/simpledbus/advanced/RemoteProxy.h | 8 ---- simpledbus/src/advanced/RemoteProxy.cpp | 20 --------- simpledbus/test/src/test_proxy_children.cpp | 24 +++++++---- simpledbus/test/src/test_proxy_interfaces.cpp | 42 ++++++++----------- simpledbus/test/src/test_proxy_lifetime.cpp | 2 +- 5 files changed, 35 insertions(+), 61 deletions(-) diff --git a/simpledbus/include/simpledbus/advanced/RemoteProxy.h b/simpledbus/include/simpledbus/advanced/RemoteProxy.h index 409207ee..d0e5540d 100644 --- a/simpledbus/include/simpledbus/advanced/RemoteProxy.h +++ b/simpledbus/include/simpledbus/advanced/RemoteProxy.h @@ -32,10 +32,8 @@ class RemoteProxy : public ProxyBase { std::string introspect(); // ----- INTERFACE HANDLING ----- - size_t interfaces_count(); bool interfaces_loaded(); void interfaces_load(Holder managed_interfaces); - void interfaces_reload(Holder managed_interfaces); void interfaces_unload(Holder removed_interfaces); // ----- CHILD HANDLING ----- @@ -76,12 +74,6 @@ class RemoteProxy : public ProxyBase { } protected: - bool _valid; - std::string _path; - std::string _bus_name; - - std::shared_ptr _conn; - std::map> _interfaces; std::map> _children; diff --git a/simpledbus/src/advanced/RemoteProxy.cpp b/simpledbus/src/advanced/RemoteProxy.cpp index 378550be..99933a28 100644 --- a/simpledbus/src/advanced/RemoteProxy.cpp +++ b/simpledbus/src/advanced/RemoteProxy.cpp @@ -48,17 +48,6 @@ std::shared_ptr RemoteProxy::interface_get(const std::string& n return _interfaces[name]; } -size_t RemoteProxy::interfaces_count() { - size_t count = 0; - std::scoped_lock lock(_interface_access_mutex); - for (auto& [iface_name, interface] : _interfaces) { - if (interface->is_loaded()) { - count++; - } - } - return count; -} - void RemoteProxy::interfaces_load(Holder managed_interfaces) { auto managed_interface = managed_interfaces.get_dict_string(); @@ -73,15 +62,6 @@ void RemoteProxy::interfaces_load(Holder managed_interfaces) { } } -void RemoteProxy::interfaces_reload(Holder managed_interfaces) { - std::scoped_lock lock(_interface_access_mutex); - for (auto& [iface_name, interface] : _interfaces) { - interface->unload(); - } - - interfaces_load(managed_interfaces); -} - void RemoteProxy::interfaces_unload(SimpleDBus::Holder removed_interfaces) { std::scoped_lock lock(_interface_access_mutex); for (auto& option : removed_interfaces.get_array()) { diff --git a/simpledbus/test/src/test_proxy_children.cpp b/simpledbus/test/src/test_proxy_children.cpp index ef41d28f..e47fdbb8 100644 --- a/simpledbus/test/src/test_proxy_children.cpp +++ b/simpledbus/test/src/test_proxy_children.cpp @@ -4,7 +4,17 @@ using namespace SimpleDBus; -TEST(ProxyChildren, AppendChild) { +static size_t count_interfaces(RemoteProxy& proxy) { + size_t count = 0; + for (auto& [iface_name, interface] : proxy.interfaces()) { + if (interface->is_loaded()) { + count++; + } + } + return count; +} + +TEST(RemoteProxyChildren, AppendChild) { RemoteProxy p = RemoteProxy(nullptr, "", "/a/b"); p.path_add("/a/b/c", Holder()); @@ -13,7 +23,7 @@ TEST(ProxyChildren, AppendChild) { EXPECT_EQ("/a/b/c", p.children().at("/a/b/c")->path()); } -TEST(ProxyChildren, AppendRepeatedChild) { +TEST(RemoteProxyChildren, AppendRepeatedChild) { RemoteProxy p = RemoteProxy(nullptr, "", "/a/b"); p.path_add("/a/b/c", Holder()); @@ -22,7 +32,7 @@ TEST(ProxyChildren, AppendRepeatedChild) { EXPECT_EQ(1, p.children().size()); } -TEST(ProxyChildren, AppendExtendedChild) { +TEST(RemoteProxyChildren, AppendExtendedChild) { RemoteProxy p = RemoteProxy(nullptr, "", "/"); p.path_add("/a/b/c/d", Holder()); @@ -42,7 +52,7 @@ TEST(ProxyChildren, AppendExtendedChild) { ASSERT_EQ(1, p_a_b_c->children().count("/a/b/c/d")); } -TEST(ProxyChildren, RemoveSelf) { +TEST(RemoteProxyChildren, RemoveSelf) { RemoteProxy p = RemoteProxy(nullptr, "", "/"); // Should notify that the proxy can be safely deleted, as nothing worth keeping is left @@ -64,7 +74,7 @@ TEST(ProxyChildren, RemoveSelf) { ASSERT_EQ(0, p.children().size()); } -TEST(ProxyChildren, RemoveChildNoInterfaces) { +TEST(RemoteProxyChildren, RemoveChildNoInterfaces) { RemoteProxy p = RemoteProxy(nullptr, "", "/"); p.path_add("/a", Holder()); @@ -81,7 +91,7 @@ TEST(ProxyChildren, RemoveChildNoInterfaces) { ASSERT_EQ(0, p.children().size()); } -TEST(ProxyChildren, RemoveChildWithInterfaces) { +TEST(RemoteProxyChildren, RemoveChildWithInterfaces) { RemoteProxy p = RemoteProxy(nullptr, "", "/"); Holder managed_interfaces = Holder::create_dict(); @@ -97,7 +107,7 @@ TEST(ProxyChildren, RemoveChildWithInterfaces) { ASSERT_EQ(1, p.children().size()); { std::shared_ptr p_a = std::dynamic_pointer_cast(p.children().at("/a")); - ASSERT_EQ(1, p_a->interfaces_count()); + ASSERT_EQ(1, count_interfaces(*p_a)); ASSERT_EQ(1, p_a->interfaces().count("i.1")); } diff --git a/simpledbus/test/src/test_proxy_interfaces.cpp b/simpledbus/test/src/test_proxy_interfaces.cpp index 8434bd62..7b253e82 100644 --- a/simpledbus/test/src/test_proxy_interfaces.cpp +++ b/simpledbus/test/src/test_proxy_interfaces.cpp @@ -4,7 +4,17 @@ using namespace SimpleDBus; -TEST(ProxyInterfaces, LoadInterfaces) { +static size_t count_interfaces(RemoteProxy& proxy) { + size_t count = 0; + for (auto& [iface_name, interface] : proxy.interfaces()) { + if (interface->is_loaded()) { + count++; + } + } + return count; +} + +TEST(RemoteProxyInterfaces, LoadInterfaces) { Holder managed_interfaces = Holder::create_dict(); managed_interfaces.dict_append(Holder::STRING, "i.1", Holder()); @@ -20,7 +30,7 @@ TEST(ProxyInterfaces, LoadInterfaces) { EXPECT_EQ(1, h.interfaces().count("i.1")); } -TEST(ProxyInterfaces, UnloadInterfaces) { +TEST(RemoteProxyInterfaces, UnloadInterfaces) { Holder managed_interfaces = Holder::create_dict(); managed_interfaces.dict_append(Holder::STRING, "i.1", Holder()); managed_interfaces.dict_append(Holder::STRING, "i.2", Holder()); @@ -28,13 +38,13 @@ TEST(ProxyInterfaces, UnloadInterfaces) { RemoteProxy h = RemoteProxy(nullptr, "", "/"); h.interfaces_load(managed_interfaces); - EXPECT_EQ(3, h.interfaces_count()); + EXPECT_EQ(3, count_interfaces(h)); Holder removed_interfaces = Holder::create_array(); removed_interfaces.array_append(Holder::create_string("i.3")); h.interfaces_unload(removed_interfaces); - EXPECT_EQ(2, h.interfaces_count()); + EXPECT_EQ(2, count_interfaces(h)); EXPECT_TRUE(h.interfaces_loaded()); EXPECT_FALSE(h.interfaces().at("i.3")->is_loaded()); @@ -42,7 +52,7 @@ TEST(ProxyInterfaces, UnloadInterfaces) { removed_interfaces.array_append(Holder::create_string("i.2")); h.interfaces_unload(removed_interfaces); - EXPECT_EQ(1, h.interfaces_count()); + EXPECT_EQ(1, count_interfaces(h)); EXPECT_TRUE(h.interfaces_loaded()); EXPECT_FALSE(h.interfaces().at("i.2")->is_loaded()); @@ -50,25 +60,7 @@ TEST(ProxyInterfaces, UnloadInterfaces) { removed_interfaces.array_append(Holder::create_string("i.1")); h.interfaces_unload(removed_interfaces); - EXPECT_EQ(0, h.interfaces_count()); + EXPECT_EQ(0, count_interfaces(h)); EXPECT_FALSE(h.interfaces_loaded()); EXPECT_FALSE(h.interfaces().at("i.1")->is_loaded()); -} - -TEST(ProxyInterfaces, ReloadInterfaces) { - Holder managed_interfaces = Holder::create_dict(); - managed_interfaces.dict_append(Holder::STRING, "i.1", Holder()); - managed_interfaces.dict_append(Holder::STRING, "i.2", Holder()); - managed_interfaces.dict_append(Holder::STRING, "i.3", Holder()); - - RemoteProxy h = RemoteProxy(nullptr, "", "/"); - h.interfaces_load(managed_interfaces); - EXPECT_EQ(3, h.interfaces_count()); - - managed_interfaces = Holder::create_dict(); - managed_interfaces.dict_append(Holder::STRING, "i.1", Holder()); - managed_interfaces.dict_append(Holder::STRING, "i.3", Holder()); - h.interfaces_reload(managed_interfaces); - - EXPECT_EQ(2, h.interfaces_count()); -} +} \ No newline at end of file diff --git a/simpledbus/test/src/test_proxy_lifetime.cpp b/simpledbus/test/src/test_proxy_lifetime.cpp index 7f35f180..7f4e8e2a 100644 --- a/simpledbus/test/src/test_proxy_lifetime.cpp +++ b/simpledbus/test/src/test_proxy_lifetime.cpp @@ -4,7 +4,7 @@ using namespace SimpleDBus; -TEST(ProxyLifetime, Validity) { +TEST(RemoteProxyLifetime, Validity) { RemoteProxy p = RemoteProxy(nullptr, "", "/"); // A newly created proxy should always be valid.