summaryrefslogtreecommitdiffstats
path: root/test/internal/utils.cpp
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2018-07-17 14:40:14 -0700
committerWilliam A. Kennington III <wak@google.com>2018-07-17 14:40:14 -0700
commitfeef68f751e09d8d5a4f2bf2f2f4cab27de1b73e (patch)
treeb1610bb958a43d3958b630525120501f768bc9fe /test/internal/utils.cpp
parent2d943ead4b1c160a163f284fb5b639f1f076ce49 (diff)
downloadsdeventplus-feef68f751e09d8d5a4f2bf2f2f4cab27de1b73e.tar.gz
sdeventplus-feef68f751e09d8d5a4f2bf2f2f4cab27de1b73e.zip
source/base: Refactor out callback routine
The callback mechanism will be used by other callback methods in the same fashion, so we can template and re-use this functionality
Diffstat (limited to 'test/internal/utils.cpp')
-rw-r--r--test/internal/utils.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/internal/utils.cpp b/test/internal/utils.cpp
new file mode 100644
index 0000000..2a347ca
--- /dev/null
+++ b/test/internal/utils.cpp
@@ -0,0 +1,38 @@
+#include <gtest/gtest.h>
+#include <sdeventplus/internal/utils.hpp>
+#include <stdexcept>
+#include <system_error>
+
+namespace sdeventplus
+{
+namespace internal
+{
+namespace
+{
+
+TEST(UtilsTest, PerformCallbackSuccess)
+{
+ EXPECT_EQ(0, performCallback([]() {}));
+}
+
+TEST(UtilsTest, SetPrepareSystemError)
+{
+ EXPECT_EQ(-EBUSY, performCallback([]() {
+ throw std::system_error(EBUSY, std::generic_category());
+ }));
+}
+
+TEST(UtilsTest, SetPrepareException)
+{
+ EXPECT_EQ(-ENOSYS,
+ performCallback([]() { throw std::runtime_error("Exception"); }));
+}
+
+TEST(UtilsTest, SetPrepareUnknownException)
+{
+ EXPECT_EQ(-ENOSYS, performCallback([]() { throw static_cast<int>(1); }));
+}
+
+} // namespace
+} // namespace internal
+} // namespace sdeventplus
OpenPOWER on IntegriCloud