Patrick Williams | b4041d4 | 2017-04-27 21:49:00 -0500 | [diff] [blame] | 1 | #include <gtest/gtest.h> |
| 2 | #include <sdbusplus/bus.hpp> |
| 3 | |
| 4 | constexpr auto this_name = "xyz.openbmc_project.sdbusplus.test.ListNames"; |
| 5 | |
| 6 | class ListNames : public ::testing::Test |
| 7 | { |
| 8 | protected: |
| 9 | decltype(sdbusplus::bus::new_default()) bus = |
| 10 | sdbusplus::bus::new_default(); |
| 11 | }; |
| 12 | |
| 13 | TEST_F(ListNames, NoServiceNameWithoutRequestName) |
| 14 | { |
| 15 | auto names = bus.list_names_acquired(); |
| 16 | |
| 17 | EXPECT_EQ(names.cend(), |
| 18 | std::find(names.cbegin(), names.cend(), this_name)); |
| 19 | } |
| 20 | |
| 21 | TEST_F(ListNames, HasServiceNameAfterRequestName) |
| 22 | { |
| 23 | bus.request_name(this_name); |
| 24 | auto names = bus.list_names_acquired(); |
| 25 | |
| 26 | auto i = std::find(names.cbegin(), names.cend(), this_name); |
| 27 | |
| 28 | ASSERT_NE(names.cend(), i); |
| 29 | EXPECT_EQ(this_name, *i); |
| 30 | } |
| 31 | |
| 32 | TEST_F(ListNames, HasUniqueName) |
| 33 | { |
| 34 | auto names = bus.list_names_acquired(); |
| 35 | |
| 36 | ASSERT_FALSE(bus.get_unique_name().empty()); |
| 37 | EXPECT_NE(names.cend(), |
| 38 | std::find(names.cbegin(), names.cend(), bus.get_unique_name())); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | TEST_F(ListNames, HasDbusServer) |
| 43 | { |
| 44 | auto names = bus.list_names_acquired(); |
| 45 | |
| 46 | auto dbus_server = "org.freedesktop.DBus"; |
| 47 | auto i = std::find(names.cbegin(), names.cend(), dbus_server); |
| 48 | |
| 49 | ASSERT_NE(names.cend(), i); |
| 50 | EXPECT_EQ(dbus_server, *i); |
| 51 | } |