1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <functional>
#include <gtest/gtest.h>
#include <memory>
#include <sdeventplus/internal/utils.hpp>
#include <stdexcept>
#include <system_error>
#include <utility>
namespace sdeventplus
{
namespace internal
{
namespace
{
TEST(UtilsTest, PerformCallbackSuccess)
{
EXPECT_EQ(0, performCallback(nullptr, []() {}));
}
TEST(UtilsTest, PerformCallbackAcceptsReference)
{
auto f =
std::bind([](const std::unique_ptr<int>&) {}, std::make_unique<int>(1));
EXPECT_EQ(0, performCallback(nullptr, f));
}
TEST(UtilsTest, PerformCallbackAcceptsMove)
{
auto f =
std::bind([](const std::unique_ptr<int>&) {}, std::make_unique<int>(1));
EXPECT_EQ(0, performCallback(nullptr, std::move(f)));
}
TEST(UtilsTest, SetPrepareSystemError)
{
EXPECT_EQ(-EBUSY, performCallback("system_error", []() {
throw std::system_error(EBUSY, std::generic_category());
}));
}
TEST(UtilsTest, SetPrepareException)
{
EXPECT_EQ(-ENOSYS, performCallback("runtime_error", []() {
throw std::runtime_error("Exception");
}));
}
TEST(UtilsTest, SetPrepareUnknownException)
{
EXPECT_EQ(-ENOSYS,
performCallback("unknown", []() { throw static_cast<int>(1); }));
}
} // namespace
} // namespace internal
} // namespace sdeventplus
|