Skip to content

Commit 2067b08

Browse files
committed
Increase task.hpp coverage
1 parent fc572e8 commit 2067b08

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

modules/task/tests/task_tests.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ class FakeSlowTask : public TestTask<InType, OutType> {
7474
}
7575
};
7676

77+
// Template specialization for string input
78+
template <>
79+
class TestTask<std::string, size_t> : public ppc::task::Task<std::string, size_t> {
80+
public:
81+
explicit TestTask(const std::string& in) {
82+
this->GetInput() = in;
83+
}
84+
85+
bool ValidationImpl() override {
86+
return !this->GetInput().empty();
87+
}
88+
89+
bool PreProcessingImpl() override {
90+
this->GetOutput() = 0;
91+
return true;
92+
}
93+
94+
bool RunImpl() override {
95+
this->GetOutput() = this->GetInput().size();
96+
return true;
97+
}
98+
99+
bool PostProcessingImpl() override {
100+
return true;
101+
}
102+
};
103+
77104
} // namespace ppc::test
78105

79106
TEST(task_tests, check_int32_t) {
@@ -343,6 +370,72 @@ TEST(TaskTest, PostProcessingThrowsIfCalledBeforeRun) {
343370
EXPECT_THROW(task->PostProcessing(), std::runtime_error);
344371
}
345372

373+
// Test uncovered template instantiations
374+
TEST(task_tests, check_unsigned_types) {
375+
std::vector<unsigned char> uc_in(5, 1);
376+
ppc::test::TestTask<std::vector<unsigned char>, unsigned char> uc_task(uc_in);
377+
uc_task.Validation();
378+
uc_task.PreProcessing();
379+
uc_task.Run();
380+
uc_task.PostProcessing();
381+
EXPECT_EQ(static_cast<size_t>(uc_task.GetOutput()), uc_in.size());
382+
383+
std::vector<unsigned int> ui_in(5, 1);
384+
ppc::test::TestTask<std::vector<unsigned int>, unsigned int> ui_task(ui_in);
385+
ui_task.Validation();
386+
ui_task.PreProcessing();
387+
ui_task.Run();
388+
ui_task.PostProcessing();
389+
EXPECT_EQ(static_cast<size_t>(ui_task.GetOutput()), ui_in.size());
390+
}
391+
392+
// Test all enum values and core functionality
393+
TEST(TaskTest, EnumAndCoreFunctionality) {
394+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kALL), "all");
395+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kMPI), "mpi");
396+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kOMP), "omp");
397+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kSEQ), "seq");
398+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kSTL), "stl");
399+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kTBB), "tbb");
400+
EXPECT_EQ(TypeOfTaskToString(TypeOfTask::kUnknown), "unknown");
401+
402+
std::vector<int> in(5, 1);
403+
ppc::test::TestTask<std::vector<int>, int> task(in);
404+
405+
// Test performance mode
406+
task.GetStateOfTesting() = StateOfTesting::kPerf;
407+
task.Validation();
408+
task.PreProcessing();
409+
task.Run();
410+
task.PostProcessing();
411+
412+
// Test type setters/getters
413+
task.SetTypeOfTask(TypeOfTask::kMPI);
414+
EXPECT_EQ(task.GetDynamicTypeOfTask(), TypeOfTask::kMPI);
415+
EXPECT_EQ(task.GetStatusOfTask(), StatusOfTask::kEnabled);
416+
auto static_type = ppc::test::TestTask<std::vector<int>, int>::GetStaticTypeOfTask();
417+
EXPECT_EQ(static_type, TypeOfTask::kUnknown);
418+
419+
// Test TaskGetter
420+
auto shared_task = TaskGetter<ppc::test::TestTask<std::vector<int>, int>>(in);
421+
EXPECT_NE(shared_task, nullptr);
422+
}
423+
424+
// Test pipeline edge cases
425+
TEST(TaskTest, PipelineEdgeCases) {
426+
std::vector<int> in(5, 1);
427+
ppc::test::TestTask<std::vector<int>, int> task(in);
428+
429+
task.Validation();
430+
task.PreProcessing();
431+
task.Run();
432+
task.Run(); // Multiple runs allowed
433+
task.PostProcessing();
434+
435+
// Validation after completion
436+
EXPECT_NO_THROW(task.Validation());
437+
}
438+
346439
int main(int argc, char** argv) {
347440
return ppc::runners::SimpleInit(argc, argv);
348441
}

0 commit comments

Comments
 (0)