diff options
| author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2016-10-19 11:54:14 -0400 |
|---|---|---|
| committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2016-11-08 14:43:56 -0500 |
| commit | 49aefb3176d0a4c6d60ece4884d3850bcf9f75ca (patch) | |
| tree | b27c6be4d3cca5d494acad86977166f5488ff852 /test | |
| parent | bf066a6396771214b2a9c47444b991f2750c0cfc (diff) | |
| download | phosphor-inventory-manager-49aefb3176d0a4c6d60ece4884d3850bcf9f75ca.tar.gz phosphor-inventory-manager-49aefb3176d0a4c6d60ece4884d3850bcf9f75ca.zip | |
Add manager skeleton
Add stubbed Notify implementation and register for generated
signal callbacks.
Add a unit test; which, at this point does little more than
verify we don't coredump on startup.
Change-Id: I0cda71935947c0d082612a5c52e2b7eba98516ab
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile.am | 8 | ||||
| -rw-r--r-- | test/test.cpp | 77 |
2 files changed, 85 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..4026307 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,8 @@ +check_PROGRAMS = phosphor-inventory-test + +phosphor_inventory_test_SOURCES = \ + test.cpp +phosphor_inventory_test_LDFLAGS = $(SYSTEMD_LIBS) +phosphor_inventory_test_CFLAGS = $(SYSTEMD_CFLAGS) +phosphor_inventory_test_LDADD = ${top_builddir}/manager.o \ + ${top_builddir}/server.o diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..350684b --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,77 @@ +/** + * Copyright © 2016 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "manager.hpp" +#include "../config.h" +#include <cassert> + +constexpr auto SERVICE = "phosphor.inventory.test"; +constexpr auto INTERFACE = IFACE; +constexpr auto ROOT = "/testing/inventory"; + +auto server_thread(void *data) +{ + auto mgr = static_cast<phosphor::inventory::manager::Manager*>(data); + + mgr->run(); + + return static_cast<void *>(nullptr); +} + +void runTests(phosphor::inventory::manager::Manager &mgr) +{ + auto b = sdbusplus::bus::new_default(); + + // make sure the notify method works + { + auto m = b.new_method_call(SERVICE, ROOT, INTERFACE, "Notify"); + m.append("/foo"); + + using var = sdbusplus::message::variant<std::string>; + using inner = std::map<std::string, var>; + using outer = std::map<std::string, inner>; + + inner i = {{"test.property", "a"}}; + outer o = {{"test.iface", i}}; + + m.append(o); + auto reply = b.call(m); + auto cleanup = sdbusplus::message::message(reply); + assert(sd_bus_message_get_errno(reply) == 0); + } + + mgr.shutdown(); +} + +int main() +{ + auto mgr = phosphor::inventory::manager::Manager( + sdbusplus::bus::new_system(), + SERVICE, ROOT, INTERFACE); + + pthread_t t; + { + pthread_create(&t, NULL, server_thread, &mgr); + } + + runTests(mgr); + + // Wait for server thread to exit. + pthread_join(t, NULL); + + return 0; +} + +// vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |

