]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/virtfun-hp.cc
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / virtfun-hp.cc
1 // Pls try the following program on virtual functions and try to do print on
2 // most of the code in main(). Almost none of them works !
3
4 //
5 // The inheritance structure is:
6 //
7 // V : VA VB
8 // A : (V)
9 // B : A
10 // D : AD (V)
11 // C : (V)
12 // E : B (V) D C
13 //
14
15 class VA
16 {
17 public:
18 int va;
19 };
20
21 class VB
22 {
23 public:
24 int vb;
25 int fvb();
26 virtual vvb();
27 };
28
29 class V : public VA, public VB
30 {
31 public:
32 int f();
33 virtual vv();
34 int w;
35 };
36
37 class A : virtual public V
38 {
39 public:
40 virtual int f();
41 private:
42 int a;
43 };
44
45 class B : public A
46 {
47 public:
48 int f();
49 private:
50 int b;
51 };
52
53 class C : public virtual V
54 {
55 public:
56 int c;
57 };
58
59 class AD
60 {
61 public:
62 virtual int vg() = 0;
63 };
64
65 class D : public AD, virtual public V
66 {
67 public:
68 static void s();
69 virtual int vg();
70 virtual int vd();
71 int fd();
72 int d;
73 };
74
75 class E : public B, virtual public V, public D, public C
76 {
77 public:
78 int f();
79 int vg();
80 int vv();
81 int e;
82 };
83
84 D dd;
85 D* ppd = ⅆ
86 AD* pAd = ⅆ
87
88 A a;
89 B b;
90 C c;
91 D d;
92 E e;
93 V v;
94 VB vb;
95
96
97 A* pAa = &a;
98 A* pAe = &e;
99
100 B* pBe = &e;
101
102 D* pDd = &d;
103 D* pDe = &e;
104
105 V* pVa = &a;
106 V* pVv = &v;
107 V* pVe = &e;
108 V* pVd = &d;
109
110 AD* pADe = &e;
111
112 E* pEe = &e;
113
114 VB* pVB = &vb;
115
116 void init()
117 {
118 a.vb = 1;
119 b.vb = 2;
120 c.vb = 3;
121 d.vb = 4;
122 e.vb = 5;
123 v.vb = 6;
124 vb.vb = 7;
125
126 d.d = 1;
127 e.d = 2;
128 }
129
130 extern "C" printf(const char *, ...);
131
132 int all_count = 0;
133 int failed_count = 0;
134
135 #define TEST(EXPR, EXPECTED) \
136 ret = EXPR; \
137 if (ret != EXPECTED) {\
138 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
139 failed_count++; } \
140 all_count++;
141
142 int ret;
143
144 void test_calls()
145 {
146 TEST(pAe->f(), 20);
147 TEST(pAa->f(), 1);
148
149 TEST(pDe->vg(), 202);
150 TEST(pADe->vg(), 202);
151 TEST(pDd->vg(), 101);
152
153 TEST(pEe->vvb(), 411);
154
155 TEST(pVB->vvb(), 407);
156
157 TEST(pBe->vvb(), 411);
158 TEST(pDe->vvb(), 411);
159
160 TEST(pEe->vd(), 282);
161 TEST(pEe->fvb(), 311);
162
163 TEST(pEe->D::vg(), 102);
164 printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
165 }
166
167 int main()
168 {
169
170 init();
171
172 e.w = 7;
173 e.vb = 11;
174
175 test_calls();
176 return 0;
177
178 }
179
180 int A::f() {return 1;}
181 int B::f() {return 2;}
182 void D::s() {}
183 int E::f() {return 20;}
184 int D::vg() {return 100+d;}
185 int E::vg() {return 200+d;}
186 int V::f() {return 600+w;}
187 int V::vv() {return 400+w;}
188 int E::vv() {return 450+w;}
189 int D::fd() {return 250+d;}
190 int D::vd() {return 280+d;}
191 int VB::fvb() {return 300+vb;}
192 int VB::vvb() {return 400+vb;}