diff options
| author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-12 16:11:24 -0500 |
|---|---|---|
| committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-12 16:53:38 -0500 |
| commit | 7b33777b4c9098bbd6d23ba8ef4e6434622c03d1 (patch) | |
| tree | 2c9c795e6aef0a3dde55a309490595cc475bc52c /test | |
| parent | 1ab880a1a03ff8a59e8490395d2181af180983f3 (diff) | |
| download | phosphor-inventory-manager-7b33777b4c9098bbd6d23ba8ef4e6434622c03d1.tar.gz phosphor-inventory-manager-7b33777b4c9098bbd6d23ba8ef4e6434622c03d1.zip | |
Run astyle
Change-Id: Iec4802e9837465a7deb1fd7fd57a2068cc18c50d
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/test.cpp | 152 |
1 files changed, 78 insertions, 74 deletions
diff --git a/test/test.cpp b/test/test.cpp index 13b8934..550e83f 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -23,13 +23,13 @@ constexpr auto SERVICE = "phosphor.inventory.test"; constexpr auto INTERFACE = IFACE; constexpr auto ROOT = "/testing/inventory"; -auto server_thread(void *data) +auto server_thread(void* data) { auto mgr = static_cast<phosphor::inventory::manager::Manager*>(data); mgr->run(); - return static_cast<void *>(nullptr); + return static_cast<void*>(nullptr); } /** @class SignalQueue @@ -38,109 +38,113 @@ auto server_thread(void *data) class SignalQueue { public: - ~SignalQueue() = default; - SignalQueue() = delete; - SignalQueue(const SignalQueue &) = delete; - SignalQueue(SignalQueue &&) = default; - SignalQueue& operator=(const SignalQueue &) = delete; - SignalQueue& operator=(SignalQueue &&) = default; - explicit SignalQueue(const std::string &match) : - _bus(sdbusplus::bus::new_default()), - _match(_bus, match.c_str(), &callback, this), - _next(nullptr) - { - } + ~SignalQueue() = default; + SignalQueue() = delete; + SignalQueue(const SignalQueue&) = delete; + SignalQueue(SignalQueue&&) = default; + SignalQueue& operator=(const SignalQueue&) = delete; + SignalQueue& operator=(SignalQueue&&) = default; + explicit SignalQueue(const std::string& match) : + _bus(sdbusplus::bus::new_default()), + _match(_bus, match.c_str(), &callback, this), + _next(nullptr) + { + } - auto &&pop(unsigned timeout=1000000) - { - while(timeout > 0 && !_next) + auto&& pop(unsigned timeout = 1000000) { - _bus.process_discard(); - _bus.wait(50000); - timeout -= 50000; + while (timeout > 0 && !_next) + { + _bus.process_discard(); + _bus.wait(50000); + timeout -= 50000; + } + return std::move(_next); } - return std::move(_next); - } private: - static int callback(sd_bus_message *m, void *context, sd_bus_error *) - { - auto *me = static_cast<SignalQueue *>(context); - sd_bus_message_ref(m); - sdbusplus::message::message msg{m}; - me->_next = std::move(msg); - return 0; - } + static int callback(sd_bus_message* m, void* context, sd_bus_error*) + { + auto* me = static_cast<SignalQueue*>(context); + sd_bus_message_ref(m); + sdbusplus::message::message msg{m}; + me->_next = std::move(msg); + return 0; + } - sdbusplus::bus::bus _bus; - sdbusplus::server::match::match _match; - sdbusplus::message::message _next; + sdbusplus::bus::bus _bus; + sdbusplus::server::match::match _match; + sdbusplus::message::message _next; }; template <typename ...T> -using Object = std::map< - std::string, - std::map< - std::string, - sdbusplus::message::variant<T...>>>; +using Object = std::map < + std::string, + std::map < + std::string, + sdbusplus::message::variant<T... >>>; using ObjectPath = std::string; /**@brief Find a subset of interfaces and properties in an object. */ template <typename ...T> -auto hasProperties(const Object<T...> &l, const Object<T...> &r) +auto hasProperties(const Object<T...>& l, const Object<T...>& r) { Object<T...> result; std::set_difference( - r.cbegin(), - r.cend(), - l.cbegin(), - l.cend(), - std::inserter(result, result.end())); + r.cbegin(), + r.cend(), + l.cbegin(), + l.cend(), + std::inserter(result, result.end())); return result.empty(); } /**@brief Check an object for one or more interfaces. */ template <typename ...T> -auto hasInterfaces(const std::vector<std::string> &l, const Object<T...> &r) +auto hasInterfaces(const std::vector<std::string>& l, const Object<T...>& r) { std::vector<std::string> stripped, interfaces; std::transform( - r.cbegin(), - r.cend(), - std::back_inserter(stripped), - [](auto &p){ return p.first; }); + r.cbegin(), + r.cend(), + std::back_inserter(stripped), + [](auto & p) + { + return p.first; + }); std::set_difference( - stripped.cbegin(), - stripped.cend(), - l.cbegin(), - l.cend(), - std::back_inserter(interfaces)); + stripped.cbegin(), + stripped.cend(), + l.cbegin(), + l.cend(), + std::back_inserter(interfaces)); return interfaces.empty(); } -void runTests(phosphor::inventory::manager::Manager &mgr) +void runTests(phosphor::inventory::manager::Manager& mgr) { const std::string root{ROOT}; auto b = sdbusplus::bus::new_default(); auto notify = [&]() { return b.new_method_call( - SERVICE, - ROOT, - INTERFACE, - "Notify"); + SERVICE, + ROOT, + INTERFACE, + "Notify"); }; - auto set = [&](const std::string &path) + auto set = [&](const std::string & path) { return b.new_method_call( - SERVICE, - path.c_str(), - "org.freedesktop.DBus.Properties", - "Set"); + SERVICE, + path.c_str(), + "org.freedesktop.DBus.Properties", + "Set"); }; - Object<std::string> obj{ + Object<std::string> obj + { { "xyz.openbmc_project.Example.Iface1", {{"ExampleProperty1", "test1"}} @@ -157,7 +161,7 @@ void runTests(phosphor::inventory::manager::Manager &mgr) ObjectPath path{root + relPath}; SignalQueue queue( - "path='" + root + "',member='InterfacesAdded'"); + "path='" + root + "',member='InterfacesAdded'"); auto m = notify(); m.append(relPath); @@ -210,7 +214,7 @@ void runTests(phosphor::inventory::manager::Manager &mgr) // Set a property that should not trigger due to a filter. { SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); + "path='" + root + "',member='InterfacesRemoved'"); auto m = set(triggerOne); m.append("xyz.openbmc_project.Example.Iface2"); m.append("ExampleProperty2"); @@ -223,7 +227,7 @@ void runTests(phosphor::inventory::manager::Manager &mgr) // Set a property that should trigger. { SignalQueue queue( - "path='" + root + "',member='InterfacesRemoved'"); + "path='" + root + "',member='InterfacesRemoved'"); auto m = set(triggerOne); m.append("xyz.openbmc_project.Example.Iface2"); @@ -287,7 +291,7 @@ void runTests(phosphor::inventory::manager::Manager &mgr) // Trigger and validate the change. { SignalQueue queue( - "path='" + changeMe + "',member='PropertiesChanged'"); + "path='" + changeMe + "',member='PropertiesChanged'"); auto m = set(triggerTwo); m.append("xyz.openbmc_project.Example.Iface2"); m.append("ExampleProperty2"); @@ -295,9 +299,9 @@ void runTests(phosphor::inventory::manager::Manager &mgr) b.call(m); std::string sigInterface; - std::map< - std::string, - sdbusplus::message::variant<std::string>> sigProperties; + std::map < + std::string, + sdbusplus::message::variant<std::string >> sigProperties; { std::vector<std::string> interfaces; auto sig{queue.pop()}; @@ -316,8 +320,8 @@ void runTests(phosphor::inventory::manager::Manager &mgr) int main() { auto mgr = phosphor::inventory::manager::Manager( - sdbusplus::bus::new_default(), - SERVICE, ROOT, INTERFACE); + sdbusplus::bus::new_default(), + SERVICE, ROOT, INTERFACE); pthread_t t; { |

