1/* This test script is part of GDB, the GNU debugger. 2 3 Copyright 1993, 1994, 1997, 1998, 1999, 2003, 2004, 4 Free Software Foundation, Inc. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20// Pls try the following program on virtual functions and try to do print on 21// most of the code in main(). Almost none of them works ! 22 23// 24// The inheritance structure is: 25// 26// V : VA VB 27// A : (V) 28// B : A 29// D : AD (V) 30// C : (V) 31// E : B (V) D C 32// 33 34class VA 35{ 36public: 37 int va; 38}; 39 40class VB 41{ 42public: 43 int vb; 44 int fvb(); 45 virtual int vvb(); 46}; 47 48class V : public VA, public VB 49{ 50public: 51 int f(); 52 virtual int vv(); 53 int w; 54}; 55 56class A : virtual public V 57{ 58public: 59 virtual int f(); 60private: 61 int a; 62}; 63 64class B : public A 65{ 66public: 67 int f(); 68private: 69 int b; 70}; 71 72class C : public virtual V 73{ 74public: 75 int c; 76}; 77 78class AD 79{ 80public: 81 virtual int vg() = 0; 82}; 83 84class D : public AD, virtual public V 85{ 86public: 87 static void s(); 88 virtual int vg(); 89 virtual int vd(); 90 int fd(); 91 int d; 92}; 93 94class E : public B, virtual public V, public D, public C 95{ 96public: 97 int f(); 98 int vg(); 99 int vv(); 100 int e; 101}; 102 103D dd; 104D* ppd = ⅆ 105AD* pAd = ⅆ 106 107A a; 108B b; 109C c; 110D d; 111E e; 112V v; 113VB vb; 114 115 116A* pAa = &a; 117A* pAe = &e; 118 119B* pBe = &e; 120 121D* pDd = &d; 122D* pDe = &e; 123 124V* pVa = &a; 125V* pVv = &v; 126V* pVe = &e; 127V* pVd = &d; 128 129AD* pADe = &e; 130 131E* pEe = &e; 132 133VB* pVB = &vb; 134 135void init() 136{ 137 a.vb = 1; 138 b.vb = 2; 139 c.vb = 3; 140 d.vb = 4; 141 e.vb = 5; 142 v.vb = 6; 143 vb.vb = 7; 144 145 d.d = 1; 146 e.d = 2; 147} 148 149extern "C" int printf(const char *, ...); 150 151int all_count = 0; 152int failed_count = 0; 153 154#define TEST(EXPR, EXPECTED) \ 155 ret = EXPR; \ 156 if (ret != EXPECTED) {\ 157 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \ 158 failed_count++; } \ 159 all_count++; 160 161int ret; 162 163void test_calls() 164{ 165 TEST(pAe->f(), 20); 166 TEST(pAa->f(), 1); 167 168 TEST(pDe->vg(), 202); 169 TEST(pADe->vg(), 202); 170 TEST(pDd->vg(), 101); 171 172 TEST(pEe->vvb(), 411); 173 174 TEST(pVB->vvb(), 407); 175 176 TEST(pBe->vvb(), 411); 177 TEST(pDe->vvb(), 411); 178 179 TEST(pEe->vd(), 282); 180 TEST(pEe->fvb(), 311); 181 182 TEST(pEe->D::vg(), 102); 183 printf("Did %d tests, of which %d failed.\n", all_count, failed_count); 184} 185#ifdef usestubs 186extern "C" { 187 void set_debug_traps(); 188 void breakpoint(); 189}; 190#endif 191 192int main() 193{ 194#ifdef usestubs 195 set_debug_traps(); 196 breakpoint(); 197#endif 198 init(); 199 200 e.w = 7; 201 e.vb = 11; 202 203 test_calls(); 204 return 0; 205 206} 207 208int A::f() {return 1;} 209int B::f() {return 2;} 210void D::s() {} 211int E::f() {return 20;} 212int D::vg() {return 100+d;} 213int E::vg() {return 200+d;} 214int V::f() {return 600+w;} 215int V::vv() {return 400+w;} 216int E::vv() {return 450+w;} 217int D::fd() {return 250+d;} 218int D::vd() {return 280+d;} 219int VB::fvb() {return 300+vb;} 220int VB::vvb() {return 400+vb;} 221