yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie HermaszewskaCorrect include dir for libslang (#5539)7b570feed

master
1.3 KiB59 linesraw
1#include "slang-unit-test.h"
2
3#include "core/slang-basic.h"
4#include "slang.h"
5
6struct SlangUnitTest
7{
8    const char* name;
9    UnitTestFunc func;
10};
11
12class SlangUnitTestModule : public IUnitTestModule
13{
14public:
15    Slang::List<SlangUnitTest> tests;
16    ITestReporter* testReporter = nullptr;
17
18    virtual SLANG_NO_THROW SlangInt SLANG_MCALL getTestCount() override { return tests.getCount(); }
19    virtual SLANG_NO_THROW const char* SLANG_MCALL getTestName(SlangInt index) override
20    {
21        return tests[index].name;
22    }
23
24    virtual SLANG_NO_THROW UnitTestFunc SLANG_MCALL getTestFunc(SlangInt index) override
25    {
26        return tests[index].func;
27    }
28
29    virtual SLANG_NO_THROW void SLANG_MCALL setTestReporter(ITestReporter* reporter) override
30    {
31        testReporter = reporter;
32    }
33
34    virtual SLANG_NO_THROW void SLANG_MCALL destroy() override { tests = decltype(tests)(); }
35};
36
37SlangUnitTestModule* _getTestModule()
38{
39    static SlangUnitTestModule testModule;
40    return &testModule;
41}
42
43ITestReporter* getTestReporter()
44{
45    return _getTestModule()->testReporter;
46}
47
48extern "C"
49{
50    SLANG_DLL_EXPORT IUnitTestModule* slangUnitTestGetModule()
51    {
52        return _getTestModule();
53    }
54}
55
56UnitTestRegisterHelper::UnitTestRegisterHelper(const char* name, UnitTestFunc testFunc)
57{
58    _getTestModule()->tests.add(SlangUnitTest{name, testFunc});
59}