blob: 2f7598ff27638ba0d3d269a6f1030c5e21ade5ea [file] [log] [blame]
Bill Wendling76dd0de2011-06-02 22:26:15 +00001// RUN: %llvmgxx -S %s -o - | FileCheck %s
Bill Wendlingeffc34e2011-06-02 22:12:42 +00002// <rdar://problem/9402870>
Bill Wendling76dd0de2011-06-02 22:26:15 +00003extern "C" {
Bill Wendlingeffc34e2011-06-02 22:12:42 +00004typedef struct __TestResult TestResult;
5typedef struct __TestResult* TestResultRef;
6
7typedef struct __TestImplement TestImplement;
8typedef struct __TestImplement* TestImplementRef;
9
10typedef char*(*TestNameFunction)(void*);
11typedef void(*TestRunFunction)(void*,TestResult*);
12typedef int(*TestCountTestCasesFunction)(void*);
13
14struct __TestImplement {
15 TestNameFunction name;
16 TestRunFunction run;
17 TestCountTestCasesFunction countTestCases;
18};
19
20typedef struct __Test Test;
21typedef struct __Test* TestRef;
22
23struct __Test {
24 TestImplement* isa;
25};
26
27typedef struct __TestCase TestCase;
28typedef struct __TestCase* TestCaseRef;
29
30struct __TestCase {
31 TestImplement* isa;
32 const char *name;
33 void(*setUp)(void);
34 void(*tearDown)(void);
35 void(*runTest)(void);
36};
37
38extern const TestImplement TestCaseImplement;
39
40typedef struct __TestFixture TestFixture;
41typedef struct __TestFixture* TestFixtureRef;
42
43struct __TestFixture {
44 const char *name;
45 void(*test)(void);
46};
47
48typedef struct __TestCaller TestCaller;
49typedef struct __TestCaller* TestCallerRef;
50
51struct __TestCaller {
52 TestImplement* isa;
53 const char *name;
54 void(*setUp)(void);
55 void(*tearDown)(void);
56 int numberOfFixtuers;
57 TestFixture *fixtuers;
58};
59
60extern const TestImplement TestCallerImplement;
Bill Wendling76dd0de2011-06-02 22:26:15 +000061}
Bill Wendlingeffc34e2011-06-02 22:12:42 +000062
63void PassToFunction(const TestImplement*);
64
65const char* TestCaller_name(TestCaller* self) {
66 return self->name;
67}
68
69void 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
81int TestCaller_countTestCases(TestCaller* self) {
82 PassToFunction(&TestCallerImplement);
83 return self->numberOfFixtuers;
84}
85
Bill Wendling76dd0de2011-06-02 22:26:15 +000086// CHECK: @_ZZ14TestCaller_runP12__TestCallerP12__TestResultE3C.0 = internal unnamed_addr constant
Bill Wendlingeffc34e2011-06-02 22:12:42 +000087// CHECK-NOT: @TestCaseImplement = external unnamed_addr constant %struct.TestImplement
88// CHECK: @TestCaseImplement = external constant %struct.TestImplement
89const TestImplement TestCallerImplement = {
90 (TestNameFunction)TestCaller_name,
91 (TestRunFunction)TestCaller_run,
92 (TestCountTestCasesFunction)TestCaller_countTestCases,
93};