xref: /openbmc/sdbusplus/test/bus/list_names.cpp (revision 95269dbc)
1 #include <sdbusplus/bus.hpp>
2 
3 #include <gtest/gtest.h>
4 
5 constexpr auto this_name = "xyz.openbmc_project.sdbusplus.test.ListNames";
6 
7 class ListNames : public ::testing::Test
8 {
9   protected:
10     decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default();
11 };
12 
TEST_F(ListNames,NoServiceNameWithoutRequestName)13 TEST_F(ListNames, NoServiceNameWithoutRequestName)
14 {
15     auto names = bus.list_names_acquired();
16 
17     EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name));
18 }
19 
TEST_F(ListNames,HasServiceNameAfterRequestName)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 
TEST_F(ListNames,HasUniqueName)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 
TEST_F(ListNames,HasDbusServer)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 }
50