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