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