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 = sdbusplus::bus::new_default(); 10 }; 11 12 TEST_F(ListNames, NoServiceNameWithoutRequestName) 13 { 14 auto names = bus.list_names_acquired(); 15 16 EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name)); 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 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 } 49