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 | { |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 8 | protected: |
| 9 | decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default(); |
Patrick Williams | b4041d4 | 2017-04-27 21:49:00 -0500 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | TEST_F(ListNames, NoServiceNameWithoutRequestName) |
| 13 | { |
| 14 | auto names = bus.list_names_acquired(); |
| 15 | |
Andrew Geissler | 072da3e | 2018-01-18 07:21:42 -0800 | [diff] [blame] | 16 | EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name)); |
Patrick Williams | b4041d4 | 2017-04-27 21:49:00 -0500 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | TEST_F(ListNames, HasServiceNameAfterRequestName) |
| 20 | { |
| 21 | bus.request_name(this_name); |
| 22 | auto names = bus.list_names_acquired(); |
| 23 | |
| 24 | auto i = std::find(names.cbegin(), names.cend(), this_name); |
| 25 | |
| 26 | ASSERT_NE(names.cend(), i); |
| 27 | EXPECT_EQ(this_name, *i); |
| 28 | } |
| 29 | |
| 30 | TEST_F(ListNames, HasUniqueName) |
| 31 | { |
| 32 | auto names = bus.list_names_acquired(); |
| 33 | |
| 34 | ASSERT_FALSE(bus.get_unique_name().empty()); |
| 35 | EXPECT_NE(names.cend(), |
| 36 | std::find(names.cbegin(), names.cend(), bus.get_unique_name())); |
| 37 | } |
| 38 | |
Patrick Williams | b4041d4 | 2017-04-27 21:49:00 -0500 | [diff] [blame] | 39 | TEST_F(ListNames, HasDbusServer) |
| 40 | { |
| 41 | auto names = bus.list_names_acquired(); |
| 42 | |
| 43 | auto dbus_server = "org.freedesktop.DBus"; |
| 44 | auto i = std::find(names.cbegin(), names.cend(), dbus_server); |
| 45 | |
| 46 | ASSERT_NE(names.cend(), i); |
| 47 | EXPECT_EQ(dbus_server, *i); |
| 48 | } |