blob: 403964cb2fa933808daf87b5e03e64ed283b5ec3 [file] [log] [blame]
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -07001#include <gtest/gtest.h>
2#include <sdeventplus/internal/utils.hpp>
3#include <stdexcept>
4#include <system_error>
5
6namespace sdeventplus
7{
8namespace internal
9{
10namespace
11{
12
13TEST(UtilsTest, PerformCallbackSuccess)
14{
William A. Kennington III4e9e6042018-07-17 16:54:36 -070015 EXPECT_EQ(0, performCallback(nullptr, []() {}));
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -070016}
17
18TEST(UtilsTest, SetPrepareSystemError)
19{
William A. Kennington III4e9e6042018-07-17 16:54:36 -070020 EXPECT_EQ(-EBUSY, performCallback("system_error", []() {
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -070021 throw std::system_error(EBUSY, std::generic_category());
22 }));
23}
24
25TEST(UtilsTest, SetPrepareException)
26{
William A. Kennington III4e9e6042018-07-17 16:54:36 -070027 EXPECT_EQ(-ENOSYS, performCallback("runtime_error", []() {
28 throw std::runtime_error("Exception");
29 }));
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -070030}
31
32TEST(UtilsTest, SetPrepareUnknownException)
33{
William A. Kennington III4e9e6042018-07-17 16:54:36 -070034 EXPECT_EQ(-ENOSYS,
35 performCallback("unknown", []() { throw static_cast<int>(1); }));
William A. Kennington IIIfeef68f2018-07-17 14:40:14 -070036}
37
38} // namespace
39} // namespace internal
40} // namespace sdeventplus