]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/infra/v2_0/tests/cxxsupp.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / infra / v2_0 / tests / cxxsupp.cxx
1 //==========================================================================
2 //
3 //        cxxsupp.cxx
4 //
5 //        C++ runtime support test
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 2003 Nick Garnett <nickg@calivar.com>
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting the copyright
37 // holders.
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):     nickg
44 // Contributors:  nickg
45 // Date:          2003-04-01
46 // Description:   Simple test for C++ runtime support.
47 //
48 //####DESCRIPTIONEND####
49 //==========================================================================
50
51 #include <pkgconf/hal.h>
52 #include <pkgconf/isoinfra.h>
53
54 #include <cyg/infra/testcase.h>
55 #include <cyg/infra/diag.h>
56
57 // The H8300 does not have C++ support in its toolchain
58 #ifndef CYGPKG_HAL_H8300
59
60 #include <new>
61
62 //==========================================================================
63
64 class Pure
65 {
66 protected:    
67     int instance;
68 public:
69     Pure(int i);
70     virtual ~Pure() {}
71     virtual void pure_fun1(void) = 0;
72     virtual void pure_fun2(void) = 0;
73     virtual void impure_fun1(void);
74     inline void inline_fun1(void);
75 };
76
77 Pure::Pure(int i)
78 {
79     instance = i;
80     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);    
81 }
82
83 void Pure::impure_fun1()
84 {
85     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
86 }
87
88 inline void Pure::inline_fun1()
89 {
90     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
91 }
92
93 //==========================================================================
94
95 class Derived : public Pure
96 {
97 public:
98     Derived(int i);
99     virtual ~Derived() {}
100     void pure_fun1(void);
101     void pure_fun2(void);
102     void impure_fun2(void);
103 };
104
105 Derived::Derived(int i)
106     : Pure(i)
107 {
108     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
109 }
110
111 void Derived::pure_fun1(void)
112 {
113     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
114 }
115
116 void Derived::pure_fun2(void)
117 {
118     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
119 }
120
121
122 void Derived::impure_fun2(void)
123 {
124     diag_printf("%s(%d) called\n",__PRETTY_FUNCTION__,instance);
125 }
126
127 //==========================================================================
128
129 __externC void
130 cyg_start( void )
131 {
132
133     CYG_TEST_INIT();
134     
135     Derived derived(1);
136     Pure *pure = &derived;
137
138     CYG_TEST_INFO("Calling derived members");
139     derived.pure_fun1();
140     derived.pure_fun2();
141     derived.impure_fun1();
142     derived.impure_fun2();
143     derived.inline_fun1();
144
145     CYG_TEST_INFO("Calling pure members");
146     pure->pure_fun1();
147     pure->pure_fun2();
148     pure->impure_fun1();
149     pure->inline_fun1();
150
151 #if CYGINT_ISO_MALLOC
152     Derived *derived2 = new Derived(2);
153     Pure *pure2 = derived2;
154     
155     CYG_TEST_INFO("Calling derived2 members");
156     derived2->pure_fun1();
157     derived2->pure_fun2();
158     derived2->impure_fun1();
159     derived2->impure_fun2();
160     derived2->inline_fun1();
161
162     CYG_TEST_INFO("Calling pure2 members");
163     pure2->pure_fun1();
164     pure2->pure_fun2();
165     pure2->impure_fun1();
166     pure2->inline_fun1();
167
168     delete derived2;
169     
170 #else
171     CYG_TEST_INFO("No malloc support, new and delete not tested");
172 #endif
173     
174     CYG_TEST_PASS_FINISH("C++ Support OK");
175 }
176
177 //==========================================================================
178
179 #else
180
181 __externC void
182 cyg_start( void )
183 {
184
185     CYG_TEST_INIT();
186
187     CYG_TEST_NA("C++ not supported on this architecture\n");
188 }
189
190 #endif
191
192 //==========================================================================
193 // EOF cxxsupp.cxx