From b9b398d038b524f15a86ff27cd6888d54e8754e0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 22 Sep 2021 10:06:59 -0700 Subject: Add gfx unit testing framework. (#1943) * Add gfx unit testing framework. * Fix compilation error. * Reset gfxDebugCallback after render_test. * Pass enabledApi flags through. * Fix for code review suggestions. Co-authored-by: Yong He --- tools/unit-test/slang-unit-test.cpp | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/unit-test/slang-unit-test.cpp (limited to 'tools/unit-test/slang-unit-test.cpp') diff --git a/tools/unit-test/slang-unit-test.cpp b/tools/unit-test/slang-unit-test.cpp new file mode 100644 index 000000000..a31614c05 --- /dev/null +++ b/tools/unit-test/slang-unit-test.cpp @@ -0,0 +1,48 @@ +#include "slang-unit-test.h" +#include "slang.h" +#include "source/core/slang-basic.h" + +struct SlangUnitTest +{ + const char* name; + slang::UnitTestFunc func; +}; + +class SlangUnitTestModule : public slang::IUnitTestModule +{ +public: + Slang::List tests; + + virtual SlangInt getTestCount() override + { + return tests.getCount(); + } + virtual const char* getTestName(SlangInt index) override + { + return tests[index].name; + } + + virtual slang::UnitTestFunc getTestFunc(SlangInt index) override + { + return tests[index].func; + } +}; + +SlangUnitTestModule* _getTestModule() +{ + static SlangUnitTestModule testModule; + return &testModule; +} + +extern "C" +{ +SLANG_DLL_EXPORT slang::IUnitTestModule* slangUnitTestGetModule() +{ + return _getTestModule(); +} +} + +slang::UnitTestRegisterHelper::UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc) +{ + _getTestModule()->tests.add(SlangUnitTest{ name, testFunc }); +} -- cgit v1.2.3