11#include < gtest/gtest.h>
22
3+ #include < array>
34#include < chrono>
45#include < cstdint>
56#include < filesystem>
67#include < fstream>
78#include < libenvpp/detail/environment.hpp>
89#include < memory>
9- #include < ostream>
1010#include < stdexcept>
11+ #include < string>
1112#include < string_view>
1213#include < thread>
1314#include < vector>
@@ -29,6 +30,7 @@ class TestPerfTask : public ppc::task::Task<InType, OutType> {
2930 this ->GetInput () = in;
3031 }
3132
33+ protected:
3234 bool ValidationImpl () override {
3335 return !this ->GetInput ().empty ();
3436 }
@@ -55,6 +57,7 @@ class FakePerfTask : public TestPerfTask<InType, OutType> {
5557 public:
5658 explicit FakePerfTask (const InType &in) : TestPerfTask<InType, OutType>(in) {}
5759
60+ protected:
5861 bool RunImpl () override {
5962 std::this_thread::sleep_for (std::chrono::seconds (11 ));
6063 return TestPerfTask<InType, OutType>::RunImpl ();
@@ -163,38 +166,31 @@ TEST(PerfTests, CheckPerfTaskFloat) {
163166
164167struct ParamTestCase {
165168 PerfResults::TypeOfRunning input;
166- std::string expected_output;
167- friend void PrintTo (const ParamTestCase ¶m, std::ostream *os) {
168- *os << " { input = " << static_cast <int >(param.input ) << " , expected = " << param.expected_output << " }" ;
169- }
169+ std::string_view expected_output;
170170};
171171
172- class GetStringParamNameParamTest : public ::testing::TestWithParam<ParamTestCase> {};
172+ namespace {
173173
174- TEST_P (GetStringParamNameParamTest, ReturnsExpectedString) {
175- const auto ¶m = GetParam ();
176- EXPECT_EQ (GetStringParamName (param.input ), param.expected_output );
177- }
174+ constexpr std::array<ParamTestCase, 3 > kParamTestCases = {
175+ {{.input = PerfResults::TypeOfRunning::kTaskRun , .expected_output = " task_run" },
176+ {.input = PerfResults::TypeOfRunning::kPipeline , .expected_output = " pipeline" },
177+ {.input = PerfResults::TypeOfRunning::kNone , .expected_output = " none" }}};
178+
179+ } // namespace
178180
179- INSTANTIATE_TEST_SUITE_P (ParamTests, GetStringParamNameParamTest,
180- ::testing::Values (ParamTestCase{PerfResults::TypeOfRunning::kTaskRun , " task_run" },
181- ParamTestCase{PerfResults::TypeOfRunning::kPipeline , " pipeline" },
182- ParamTestCase{PerfResults::TypeOfRunning::kNone , " none" }),
183- [](const ::testing::TestParamInfo<ParamTestCase> &info) {
184- return info.param .expected_output ;
185- });
181+ TEST (GetStringParamNameParamTest, ReturnsExpectedString) {
182+ for (const auto ¶m : kParamTestCases ) {
183+ EXPECT_EQ (GetStringParamName (param.input ), std::string (param.expected_output ));
184+ }
185+ }
186186
187187struct TaskTypeTestCase {
188188 TypeOfTask type;
189- std::string expected;
190- std::string label;
191- friend void PrintTo (const TaskTypeTestCase ¶m, std::ostream *os) {
192- *os << " { type = " << static_cast <int >(param.type ) << " , expected = " << param.expected
193- << " , label = " << param.label << " }" ;
194- }
189+ std::string_view expected;
190+ std::string_view label;
195191};
196192
197- class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase> {
193+ class GetStringTaskTypeTest : public ::testing::Test {
198194 protected:
199195 std::string temp_path;
200196
@@ -211,18 +207,23 @@ class GetStringTaskTypeTest : public ::testing::TestWithParam<TaskTypeTestCase>
211207 }
212208};
213209
214- TEST_P (GetStringTaskTypeTest, ReturnsExpectedString) {
215- const auto ¶m = GetParam ();
216- EXPECT_EQ (GetStringTaskType (param.type , temp_path), param.expected ) << " Failed on: " << param.label ;
217- }
210+ namespace {
211+
212+ constexpr std::array<TaskTypeTestCase, 6 > kTaskTypeTestCases = {
213+ {{.type = TypeOfTask::kALL , .expected = " all_ALL" , .label = " kALL" },
214+ {.type = TypeOfTask::kSTL , .expected = " stl_STL" , .label = " kSTL" },
215+ {.type = TypeOfTask::kOMP , .expected = " omp_OMP" , .label = " kOMP" },
216+ {.type = TypeOfTask::kMPI , .expected = " mpi_MPI" , .label = " kMPI" },
217+ {.type = TypeOfTask::kTBB , .expected = " tbb_TBB" , .label = " kTBB" },
218+ {.type = TypeOfTask::kSEQ , .expected = " seq_SEQ" , .label = " kSEQ" }}};
218219
219- INSTANTIATE_TEST_SUITE_P (AllTypeCases, GetStringTaskTypeTest,
220- ::testing::Values (TaskTypeTestCase{TypeOfTask:: kALL , " all_ALL " , " kALL " },
221- TaskTypeTestCase{TypeOfTask:: kSTL , " stl_STL " , " kSTL " },
222- TaskTypeTestCase{TypeOfTask:: kOMP , " omp_OMP " , " kOMP " },
223- TaskTypeTestCase{TypeOfTask:: kMPI , " mpi_MPI " , " kMPI " },
224- TaskTypeTestCase{TypeOfTask:: kTBB , " tbb_TBB " , " kTBB " },
225- TaskTypeTestCase{TypeOfTask:: kSEQ , " seq_SEQ " , " kSEQ " }));
220+ } // namespace
221+
222+ TEST_F (GetStringTaskTypeTest, ReturnsExpectedString) {
223+ for ( const auto ¶m : kTaskTypeTestCases ) {
224+ EXPECT_EQ ( GetStringTaskType (param. type , temp_path), std::string (param. expected )) << " Failed on: " << param. label ;
225+ }
226+ }
226227
227228TEST (GetStringTaskTypeStandaloneTest, ThrowsIfFileMissing) {
228229 std::string missing_path = " non_existent_settings.json" ;
@@ -284,6 +285,8 @@ TEST(GetStringTaskStatusTest, HandlesEnabledAndDisabled) {
284285class DummyTask : public Task <int , int > {
285286 public:
286287 using Task::Task;
288+
289+ protected:
287290 bool ValidationImpl () override {
288291 return true ;
289292 }
@@ -321,25 +324,16 @@ struct Type {};
321324class Another {};
322325} // namespace my
323326
324- template <typename T>
325- class GetNamespaceTest : public ::testing::Test {};
326-
327- using TestTypes = ::testing::Types<my::nested::Type, my::Another, int >;
328-
329- TYPED_TEST_SUITE (GetNamespaceTest, TestTypes);
327+ TEST (GetNamespaceTest, ExtractsNestedNamespaceCorrectly) {
328+ EXPECT_EQ (ppc::util::GetNamespace<my::nested::Type>(), " ppc::performance::my::nested" );
329+ }
330330
331- TYPED_TEST (GetNamespaceTest, ExtractsNamespaceCorrectly) {
332- std::string k_ns = ppc::util::GetNamespace<TypeParam>();
331+ TEST (GetNamespaceTest, ExtractsParentNamespaceCorrectly) {
332+ EXPECT_EQ (ppc::util::GetNamespace<my::Another>(), " ppc::performance::my" );
333+ }
333334
334- if constexpr (std::is_same_v<TypeParam, my::nested::Type>) {
335- EXPECT_EQ (k_ns, " ppc::performance::my::nested" );
336- } else if constexpr (std::is_same_v<TypeParam, my::Another>) {
337- EXPECT_EQ (k_ns, " ppc::performance::my" );
338- } else if constexpr (std::is_same_v<TypeParam, int >) {
339- EXPECT_EQ (k_ns, " " );
340- } else {
341- FAIL () << " Unhandled type in test" ;
342- }
335+ TEST (GetNamespaceTest, ReturnsEmptyStringForGlobalNamespaceType) {
336+ EXPECT_EQ (ppc::util::GetNamespace<int >(), " " );
343337}
344338
345339TEST (PerfTest, PipelineRunAndTaskRun) {
@@ -385,6 +379,7 @@ TEST(PerfTest, GetStringParamNameTest) {
385379TEST (TaskTest, DestructorInvalidPipelineOrderTerminatesPartialPipeline) {
386380 {
387381 struct BadTask : Task<int , int > {
382+ protected:
388383 bool ValidationImpl () override {
389384 return true ;
390385 }
0 commit comments