blob: a1967d9c07b16b0e501f969329ee187aa744782b [file] [log] [blame]
Patrick Williamsb4041d42017-04-27 21:49:00 -05001#include <gtest/gtest.h>
2#include <sdbusplus/bus.hpp>
3
4constexpr auto this_name = "xyz.openbmc_project.sdbusplus.test.ListNames";
5
6class ListNames : public ::testing::Test
7{
Andrew Geissler072da3e2018-01-18 07:21:42 -08008 protected:
9 decltype(sdbusplus::bus::new_default()) bus = sdbusplus::bus::new_default();
Patrick Williamsb4041d42017-04-27 21:49:00 -050010};
11
12TEST_F(ListNames, NoServiceNameWithoutRequestName)
13{
14 auto names = bus.list_names_acquired();
15
Andrew Geissler072da3e2018-01-18 07:21:42 -080016 EXPECT_EQ(names.cend(), std::find(names.cbegin(), names.cend(), this_name));
Patrick Williamsb4041d42017-04-27 21:49:00 -050017}
18
19TEST_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
30TEST_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 Williamsb4041d42017-04-27 21:49:00 -050039TEST_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}