01a45d2fcb89f366c1b2439206a48982e14b50e6
[oota-llvm.git] / test / FrontendC / unnamed-addr.c
1 // RUN: %llvmgcc -S %s -o - | FileCheck %s
2 // <rdar://problem/9402870>
3 typedef struct __TestResult TestResult;
4 typedef struct __TestResult* TestResultRef;
5
6 typedef struct __TestImplement TestImplement;
7 typedef struct __TestImplement* TestImplementRef;
8
9 typedef char*(*TestNameFunction)(void*);
10 typedef void(*TestRunFunction)(void*,TestResult*);
11 typedef int(*TestCountTestCasesFunction)(void*);
12
13 struct __TestImplement {
14     TestNameFunction name;
15     TestRunFunction run;
16     TestCountTestCasesFunction countTestCases;
17 };
18
19 typedef struct __Test Test;
20 typedef struct __Test* TestRef;
21
22 struct __Test {
23     TestImplement* isa;
24 };
25
26 typedef struct __TestCase TestCase;
27 typedef struct __TestCase* TestCaseRef;
28
29 struct __TestCase {
30     TestImplement* isa;
31     const char *name;
32     void(*setUp)(void);
33     void(*tearDown)(void);
34     void(*runTest)(void);
35 };
36
37 extern const TestImplement TestCaseImplement;
38
39 typedef struct __TestFixture TestFixture;
40 typedef struct __TestFixture* TestFixtureRef;
41
42 struct __TestFixture {
43     const char *name;
44     void(*test)(void);
45 };
46
47 typedef struct __TestCaller TestCaller;
48 typedef struct __TestCaller* TestCallerRef;
49
50 struct __TestCaller {
51     TestImplement* isa;
52     const char *name;
53     void(*setUp)(void);
54     void(*tearDown)(void);
55     int numberOfFixtuers;
56     TestFixture *fixtuers;
57 };
58
59 extern const TestImplement TestCallerImplement;
60
61 void PassToFunction(const TestImplement*);
62
63 const char* TestCaller_name(TestCaller* self) {
64   return self->name;
65 }
66
67 void 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
79 int 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
87 const TestImplement TestCallerImplement = {
88   (TestNameFunction)TestCaller_name,
89   (TestRunFunction)TestCaller_run,
90   (TestCountTestCasesFunction)TestCaller_countTestCases,
91 };