99//
1010#pragma once
1111
12+ #include < gtest/gtest.h>
13+ #include < string>
14+
15+ #define HVT_TEST (TestSuiteName, TestName ) \
16+ std::string ParamTestName##TestName(const testing::TestParamInfo<std::string>& info) \
17+ { \
18+ return info.param ; \
19+ } \
20+ class TestName : public ::testing::TestWithParam<std::string> \
21+ { \
22+ public: \
23+ void HVTTest##TestName( \
24+ [[maybe_unused]] const std::string& computedImageName, \
25+ [[maybe_unused]] const std::string& imageFile); \
26+ }; \
27+ /* TODO: Enable "Vulkan" backend when Vulkan support is complete and stable. \
28+ Currently, only "OpenGL" is enabled for testing. */ \
29+ INSTANTIATE_TEST_SUITE_P (TestSuiteName, TestName, ::testing::Values(/* "Vulkan",*/ " OpenGL" ), \
30+ ParamTestName##TestName); \
31+ TEST_P (TestName, TestName) \
32+ { \
33+ TestHelpers::gRunVulkanTests = (GetParam () == " Vulkan" ); \
34+ TestHelpers::gTestNames = TestHelpers::getTestNames ( \
35+ ::testing::UnitTest::GetInstance ()->current_test_info()); \
36+ const std::string imageFile = TestHelpers::gTestNames .suiteName + \
37+ std::string (" /" ) + TestHelpers::gTestNames .fixtureName ; \
38+ const std::string computedImageName = TestHelpers::appendParamToImageFile (imageFile); \
39+ HVTTest##TestName (computedImageName, imageFile); \
40+ } \
41+ void TestName::HVTTest##TestName( \
42+ [[maybe_unused]] const std::string& computedImageName, \
43+ [[maybe_unused]] const std::string& imageFile)
44+
1245namespace TestHelpers
1346{
14- inline bool gRunVulkanTests = false ;
15- } // namespace TestHelpers
47+ struct TestNames
48+ {
49+ // / @brief The name of the test suite extracted from the test information
50+ std::string suiteName;
51+ // / @brief The name of the test fixture extracted from the test suite name
52+ std::string fixtureName;
53+ // / @brief The parameter name extracted from the test name for parameterized tests
54+ std::string paramName;
55+ };
56+
57+ inline bool gRunVulkanTests = false ;
58+ inline TestNames gTestNames = TestNames {};
59+
60+ inline TestNames getTestNames (const ::testing::TestInfo* testInfo)
61+ {
62+ TestNames testNames;
63+ if (testInfo)
64+ {
65+ std::string testSuiteName = testInfo->test_suite_name ();
66+ std::string testName = testInfo->name ();
67+
68+ size_t pos = testSuiteName.find (' /' );
69+ if (pos != std::string::npos)
70+ {
71+ testNames.suiteName = testSuiteName.substr (0 , pos);
72+ testNames.fixtureName = testSuiteName.substr (pos + 1 );
73+ }
74+
75+ pos = testName.find (' /' );
76+ if (pos != std::string::npos)
77+ {
78+ testNames.paramName = testName.substr (pos + 1 );
79+ }
80+ }
81+ return testNames;
82+ }
83+
84+ // / Gets the image file based on the test parameter.
85+ inline std::string getComputedImagePath ()
86+ {
87+ return gTestNames .paramName .empty () ? gTestNames .fixtureName
88+ : (gTestNames .fixtureName + " _" + gTestNames .paramName );
89+ }
90+
91+ // / Appends image file based on the test parameter.
92+ inline std::string appendParamToImageFile (const std::string& fileName)
93+ {
94+ return gTestNames .paramName .empty () ? fileName : (fileName + " _" + gTestNames .paramName );
95+ }
96+
97+ } // namespace TestHelpers
0 commit comments