|
5 | 5 | #include <cstdint> |
6 | 6 | #include <exception> |
7 | 7 | #include <fstream> |
| 8 | +#include <memory> |
8 | 9 | #include <stdexcept> |
9 | 10 | #include <thread> |
10 | 11 | #include <vector> |
@@ -190,6 +191,50 @@ TEST(TaskTest, InternalTimeTest_ThrowsIfTimeoutExceeded) { |
190 | 191 | EXPECT_THROW(task.PostProcessing(), std::runtime_error); |
191 | 192 | } |
192 | 193 |
|
| 194 | +class DummyTask : public ppc::core::Task<int, int> { |
| 195 | + public: |
| 196 | + using Task::Task; |
| 197 | + bool ValidationImpl() override { return true; } |
| 198 | + bool PreProcessingImpl() override { return true; } |
| 199 | + bool RunImpl() override { return true; } |
| 200 | + bool PostProcessingImpl() override { return true; } |
| 201 | +}; |
| 202 | + |
| 203 | +TEST(TaskTest, ValidationThrowsIfCalledTwice) { |
| 204 | + auto test_func = [&] { |
| 205 | + auto task = std::make_shared<DummyTask>(); |
| 206 | + task->Validation(); |
| 207 | + EXPECT_THROW(task->Validation(), std::runtime_error); |
| 208 | + }; |
| 209 | + EXPECT_DEATH_IF_SUPPORTED({ test_func(); }, "ORDER OF FUNCTIONS IS NOT RIGHT"); |
| 210 | +} |
| 211 | + |
| 212 | +TEST(TaskTest, PreProcessingThrowsIfCalledBeforeValidation) { |
| 213 | + auto test_func = [&] { |
| 214 | + auto task = std::make_shared<DummyTask>(); |
| 215 | + EXPECT_THROW(task->PreProcessing(), std::runtime_error); |
| 216 | + }; |
| 217 | + EXPECT_DEATH_IF_SUPPORTED({ test_func(); }, "ORDER OF FUNCTIONS IS NOT RIGHT"); |
| 218 | +} |
| 219 | + |
| 220 | +TEST(TaskTest, RunThrowsIfCalledBeforePreProcessing) { |
| 221 | + auto test_func = [&] { |
| 222 | + auto task = std::make_shared<DummyTask>(); |
| 223 | + EXPECT_THROW(task->Run(), std::runtime_error); |
| 224 | + }; |
| 225 | + EXPECT_DEATH_IF_SUPPORTED({ test_func(); }, "ORDER OF FUNCTIONS IS NOT RIGHT"); |
| 226 | +} |
| 227 | + |
| 228 | +TEST(TaskTest, PostProcessingThrowsIfCalledBeforeRun) { |
| 229 | + auto test_func = [&] { |
| 230 | + auto task = std::make_shared<DummyTask>(); |
| 231 | + task->Validation(); |
| 232 | + task->PreProcessing(); |
| 233 | + EXPECT_THROW(task->PostProcessing(), std::runtime_error); |
| 234 | + }; |
| 235 | + EXPECT_DEATH_IF_SUPPORTED({ test_func(); }, "ORDER OF FUNCTIONS IS NOT RIGHT"); |
| 236 | +} |
| 237 | + |
193 | 238 | int main(int argc, char** argv) { |
194 | 239 | testing::InitGoogleTest(&argc, argv); |
195 | 240 | return RUN_ALL_TESTS(); |
|
0 commit comments