summaryrefslogtreecommitdiff
path: root/tools/unit-test/slang-unit-test.cpp
blob: a31614c057362abe4d4b64d809a75b601b428313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 });
}