blob: 834b8f2671c0800f257c073779696c85918b868c [file] [log] [blame]
Patrick Williamsb4041d42017-04-27 21:49:00 -05001#include <sdbusplus/bus.hpp>
2
Patrick Venture95269db2018-08-31 09:19:17 -07003#include <gtest/gtest.h>
4
Patrick Williamsb4041d42017-04-27 21:49:00 -05005constexpr auto this_name = "xyz.openbmc_project.sdbusplus.test.ListNames";
6
7class ListNames : public ::testing::Test
8{
Andrew Geissler072da3e2018-01-18 07:21:42 -08009 protected:
10 decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default();
Patrick Williamsb4041d42017-04-27 21:49:00 -050011};
12
13TEST_F(ListNames, NoServiceNameWithoutRequestName)
14{
15 auto names = bus.list_names_acquired();
16
Andrew Geissler072da3e2018-01-18 07:21:42 -080017 EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name));
Patrick Williamsb4041d42017-04-27 21:49:00 -050018}
19
20TEST_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
31TEST_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 Williamsb4041d42017-04-27 21:49:00 -050040TEST_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}