summaryrefslogtreecommitdiff
path: root/tools/unit-test/slang-unit-test.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-09-22 10:06:59 -0700
committerGitHub <noreply@github.com>2021-09-22 10:06:59 -0700
commitb9b398d038b524f15a86ff27cd6888d54e8754e0 (patch)
tree4fe46f864065a58db20edccd261e5794326ab2a1 /tools/unit-test/slang-unit-test.cpp
parent6e9cee69b3588ddae09b08b9f580f59ad899983f (diff)
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 <yhe@nvidia.com>
Diffstat (limited to 'tools/unit-test/slang-unit-test.cpp')
-rw-r--r--tools/unit-test/slang-unit-test.cpp48
1 files changed, 48 insertions, 0 deletions
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<SlangUnitTest> 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 });
+}