Bill Wendling | 76dd0de | 2011-06-02 22:26:15 +0000 | [diff] [blame^] | 1 | // RUN: %llvmgxx -S %s -o - | FileCheck %s |
Bill Wendling | effc34e | 2011-06-02 22:12:42 +0000 | [diff] [blame] | 2 | // <rdar://problem/9402870> |
Bill Wendling | 76dd0de | 2011-06-02 22:26:15 +0000 | [diff] [blame^] | 3 | extern "C" { |
Bill Wendling | effc34e | 2011-06-02 22:12:42 +0000 | [diff] [blame] | 4 | typedef struct __TestResult TestResult; |
| 5 | typedef struct __TestResult* TestResultRef; |
| 6 | |
| 7 | typedef struct __TestImplement TestImplement; |
| 8 | typedef struct __TestImplement* TestImplementRef; |
| 9 | |
| 10 | typedef char*(*TestNameFunction)(void*); |
| 11 | typedef void(*TestRunFunction)(void*,TestResult*); |
| 12 | typedef int(*TestCountTestCasesFunction)(void*); |
| 13 | |
| 14 | struct __TestImplement { |
| 15 | TestNameFunction name; |
| 16 | TestRunFunction run; |
| 17 | TestCountTestCasesFunction countTestCases; |
| 18 | }; |
| 19 | |
| 20 | typedef struct __Test Test; |
| 21 | typedef struct __Test* TestRef; |
| 22 | |
| 23 | struct __Test { |
| 24 | TestImplement* isa; |
| 25 | }; |
| 26 | |
| 27 | typedef struct __TestCase TestCase; |
| 28 | typedef struct __TestCase* TestCaseRef; |
| 29 | |
| 30 | struct __TestCase { |
| 31 | TestImplement* isa; |
| 32 | const char *name; |
| 33 | void(*setUp)(void); |
| 34 | void(*tearDown)(void); |
| 35 | void(*runTest)(void); |
| 36 | }; |
| 37 | |
| 38 | extern const TestImplement TestCaseImplement; |
| 39 | |
| 40 | typedef struct __TestFixture TestFixture; |
| 41 | typedef struct __TestFixture* TestFixtureRef; |
| 42 | |
| 43 | struct __TestFixture { |
| 44 | const char *name; |
| 45 | void(*test)(void); |
| 46 | }; |
| 47 | |
| 48 | typedef struct __TestCaller TestCaller; |
| 49 | typedef struct __TestCaller* TestCallerRef; |
| 50 | |
| 51 | struct __TestCaller { |
| 52 | TestImplement* isa; |
| 53 | const char *name; |
| 54 | void(*setUp)(void); |
| 55 | void(*tearDown)(void); |
| 56 | int numberOfFixtuers; |
| 57 | TestFixture *fixtuers; |
| 58 | }; |
| 59 | |
| 60 | extern const TestImplement TestCallerImplement; |
Bill Wendling | 76dd0de | 2011-06-02 22:26:15 +0000 | [diff] [blame^] | 61 | } |
Bill Wendling | effc34e | 2011-06-02 22:12:42 +0000 | [diff] [blame] | 62 | |
| 63 | void PassToFunction(const TestImplement*); |
| 64 | |
| 65 | const char* TestCaller_name(TestCaller* self) { |
| 66 | return self->name; |
| 67 | } |
| 68 | |
| 69 | void TestCaller_run(TestCaller* self,TestResult* result) { |
| 70 | TestCase cs = { (TestImplement*)&TestCaseImplement, 0, 0, 0, 0, }; |
| 71 | int i; |
| 72 | cs.setUp = self->setUp; |
| 73 | cs.tearDown = self->tearDown; |
| 74 | for (i=0; i<self->numberOfFixtuers; i++) { |
| 75 | cs.name = self->fixtuers[i].name; |
| 76 | cs.runTest = self->fixtuers[i].test; |
| 77 | ((Test*)(void *)&cs)->isa->run((void *)&cs,result); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | int TestCaller_countTestCases(TestCaller* self) { |
| 82 | PassToFunction(&TestCallerImplement); |
| 83 | return self->numberOfFixtuers; |
| 84 | } |
| 85 | |
Bill Wendling | 76dd0de | 2011-06-02 22:26:15 +0000 | [diff] [blame^] | 86 | // CHECK: @_ZZ14TestCaller_runP12__TestCallerP12__TestResultE3C.0 = internal unnamed_addr constant |
Bill Wendling | effc34e | 2011-06-02 22:12:42 +0000 | [diff] [blame] | 87 | // CHECK-NOT: @TestCaseImplement = external unnamed_addr constant %struct.TestImplement |
| 88 | // CHECK: @TestCaseImplement = external constant %struct.TestImplement |
| 89 | const TestImplement TestCallerImplement = { |
| 90 | (TestNameFunction)TestCaller_name, |
| 91 | (TestRunFunction)TestCaller_run, |
| 92 | (TestCountTestCasesFunction)TestCaller_countTestCases, |
| 93 | }; |