| 56 | } // end anonymous namespace |
| 57 | |
| 58 | TEST(FrameworkEventTest, testFrameworkEvents) |
| 59 | { |
| 60 | // The OSGi spec assigns specific values to event types for future extensibility. |
| 61 | // Ensure we don't deviate from those assigned values. |
| 62 | // Test assigned event type values |
| 63 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_STARTED, static_cast<FrameworkEvent::Type>(1)); |
| 64 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_ERROR, static_cast<FrameworkEvent::Type>(2)); |
| 65 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_INFO, static_cast<FrameworkEvent::Type>(32)); |
| 66 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_WARNING, static_cast<FrameworkEvent::Type>(16)); |
| 67 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_STOPPED, static_cast<FrameworkEvent::Type>(64)); |
| 68 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_STOPPED_UPDATE, static_cast<FrameworkEvent::Type>(128)); |
| 69 | ASSERT_EQ(FrameworkEvent::Type::FRAMEWORK_WAIT_TIMEDOUT, static_cast<FrameworkEvent::Type>(512)); |
| 70 | |
| 71 | // @todo mock the framework. We only need a Bundle object to construct a FrameworkEvent object. |
| 72 | auto const f = FrameworkFactory().NewFramework(); |
| 73 | |
| 74 | std::string default_exception_message(GetMessageFromStdExceptionPtr(nullptr)); |
| 75 | |
| 76 | FrameworkEvent invalid_event; |
| 77 | |
| 78 | // Test for invalid FrameworkEvent construction. |
| 79 | ASSERT_FALSE(invalid_event); |
| 80 | // Test invalid event GetType() |
| 81 | ASSERT_EQ(invalid_event.GetType(), FrameworkEvent::Type::FRAMEWORK_ERROR); |
| 82 | // Test invalid event GetBundle() |
| 83 | ASSERT_FALSE(invalid_event.GetBundle()); |
| 84 | // Test invalid event GetThrowable() |
| 85 | ASSERT_EQ(GetMessageFromStdExceptionPtr(invalid_event.GetThrowable()), default_exception_message); |
| 86 | |
| 87 | FrameworkEvent error_event(FrameworkEvent::Type::FRAMEWORK_ERROR, |
| 88 | f, |
| 89 | "test framework error event", |
| 90 | std::make_exception_ptr(std::runtime_error("test exception"))); |
| 91 | |
| 92 | // Test FrameworkEvent construction - error type |
| 93 | ASSERT_TRUE(error_event); |
| 94 | ASSERT_EQ(error_event.GetType(), FrameworkEvent::Type::FRAMEWORK_ERROR); |
| 95 | ASSERT_EQ(error_event.GetBundle(), f); |
| 96 | ASSERT_EQ(GetMessageFromStdExceptionPtr(error_event.GetThrowable()), std::string("test exception")); |
| 97 | |
| 98 | bool exception_caught = false; |
| 99 | try |
| 100 | { |
| 101 | std::rethrow_exception(error_event.GetThrowable()); |
| 102 | } |
| 103 | catch (std::exception const& ex) |
| 104 | { |
| 105 | exception_caught = true; |
| 106 | |
| 107 | // Test FrameworkEvent::Type::FRAMEWORK_ERROR exception |
| 108 | ASSERT_EQ(ex.what(), std::string("test exception")); |
| 109 | // Test that the correct exception type was thrown |
| 110 | ASSERT_EQ(std::string(typeid(std::runtime_error).name()), typeid(ex).name()); |
| 111 | } |
| 112 | |
| 113 | // Test throw/catch a FrameworkEvent exception |
| 114 | ASSERT_TRUE(exception_caught); |
| 115 |
nothing calls this directly
no test coverage detected