blob: 65333b710e46e4c1db8ee344ea5e249ec69f9d78 [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{
8 protected:
9 decltype(sdbusplus::bus::new_default()) bus =
10 sdbusplus::bus::new_default();
11};
12
13TEST_F(ListNames, NoServiceNameWithoutRequestName)
14{
15 auto names = bus.list_names_acquired();
16
17 EXPECT_EQ(names.cend(),
18 std::find(names.cbegin(), names.cend(), this_name));
19}
20
21TEST_F(ListNames, HasServiceNameAfterRequestName)
22{
23 bus.request_name(this_name);
24 auto names = bus.list_names_acquired();
25
26 auto i = std::find(names.cbegin(), names.cend(), this_name);
27
28 ASSERT_NE(names.cend(), i);
29 EXPECT_EQ(this_name, *i);
30}
31
32TEST_F(ListNames, HasUniqueName)
33{
34 auto names = bus.list_names_acquired();
35
36 ASSERT_FALSE(bus.get_unique_name().empty());
37 EXPECT_NE(names.cend(),
38 std::find(names.cbegin(), names.cend(), bus.get_unique_name()));
39}
40
41
42TEST_F(ListNames, HasDbusServer)
43{
44 auto names = bus.list_names_acquired();
45
46 auto dbus_server = "org.freedesktop.DBus";
47 auto i = std::find(names.cbegin(), names.cend(), dbus_server);
48
49 ASSERT_NE(names.cend(), i);
50 EXPECT_EQ(dbus_server, *i);
51}