Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2016 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #include "manager.hpp" |
| 17 | #include "../config.h" |
| 18 | #include <cassert> |
| 19 | |
| 20 | constexpr auto SERVICE = "phosphor.inventory.test"; |
| 21 | constexpr auto INTERFACE = IFACE; |
| 22 | constexpr auto ROOT = "/testing/inventory"; |
| 23 | |
| 24 | auto server_thread(void *data) |
| 25 | { |
| 26 | auto mgr = static_cast<phosphor::inventory::manager::Manager*>(data); |
| 27 | |
| 28 | mgr->run(); |
| 29 | |
| 30 | return static_cast<void *>(nullptr); |
| 31 | } |
| 32 | |
| 33 | void runTests(phosphor::inventory::manager::Manager &mgr) |
| 34 | { |
| 35 | auto b = sdbusplus::bus::new_default(); |
| 36 | |
| 37 | // make sure the notify method works |
| 38 | { |
| 39 | auto m = b.new_method_call(SERVICE, ROOT, INTERFACE, "Notify"); |
| 40 | m.append("/foo"); |
| 41 | |
| 42 | using var = sdbusplus::message::variant<std::string>; |
| 43 | using inner = std::map<std::string, var>; |
| 44 | using outer = std::map<std::string, inner>; |
| 45 | |
Brad Bishop | 5fbaa7f | 2016-10-31 10:42:41 -0500 | [diff] [blame] | 46 | inner i = {{"ExampleProperty1", "test"}}; |
| 47 | outer o = {{"xyz.openbmc_project.Example.Iface1", i}}; |
Brad Bishop | 49aefb3 | 2016-10-19 11:54:14 -0400 | [diff] [blame] | 48 | |
| 49 | m.append(o); |
| 50 | auto reply = b.call(m); |
| 51 | auto cleanup = sdbusplus::message::message(reply); |
| 52 | assert(sd_bus_message_get_errno(reply) == 0); |
| 53 | } |
| 54 | |
| 55 | mgr.shutdown(); |
| 56 | } |
| 57 | |
| 58 | int main() |
| 59 | { |
| 60 | auto mgr = phosphor::inventory::manager::Manager( |
| 61 | sdbusplus::bus::new_system(), |
| 62 | SERVICE, ROOT, INTERFACE); |
| 63 | |
| 64 | pthread_t t; |
| 65 | { |
| 66 | pthread_create(&t, NULL, server_thread, &mgr); |
| 67 | } |
| 68 | |
| 69 | runTests(mgr); |
| 70 | |
| 71 | // Wait for server thread to exit. |
| 72 | pthread_join(t, NULL); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |