source: rtems/testsuites/samples/cdtest/main.cc @ 2936b425

4.104.114.84.95
Last change on this file since 2936b425 was 2936b425, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 23, 1998 at 5:45:05 PM

Solaris port updates from Chris Johns

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 *  This routine is the initialization task for this test program.
3 *  It is called from init_exec and has the responsibility for creating
4 *  and starting the tasks that make up the test.  If the time of day
5 *  clock is required for the test, it should also be set to a known
6 *  value by this function.
7 *
8 *  Input parameters:  NONE
9 *
10 *  Output parameters:  NONE
11 *
12 *  COPYRIGHT (c) 1994 by Division Incorporated
13 *  Based in part on OAR works.
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.OARcorp.com/rtems/license.html.
18 *
19 *  $Id$
20 */
21
22#include <rtems.h>
23#include <stdio.h>
24#include <stdlib.h>
25#ifdef RTEMS_TEST_IO_STREAM
26#include <iostream.h>
27#endif
28
29extern "C" {
30extern rtems_task main_task(rtems_task_argument);
31}
32
33static int num_inst = 0;
34
35class A {
36public:
37    A(void)
38    {
39        num_inst++;
40        printf(
41          "Hey I'm in base class constructor number %d for %p.\n",
42          num_inst,
43          this
44        );
45
46        /*
47         * Make sure we use some space
48         */
49
50        string = new char[50];
51        sprintf(string, "Instantiation order %d", num_inst);
52    };
53
54    virtual ~A()
55    {
56        printf(
57          "Hey I'm in base class destructor number %d for %p.\n",
58          num_inst,
59          this
60        );
61        print();
62        num_inst--;
63    };
64
65    virtual void print()  { printf("%s\n", string); };
66
67protected:
68    char  *string;
69};
70
71class B : public A {
72public:
73    B(void)
74    {
75        num_inst++;
76        printf(
77          "Hey I'm in derived class constructor number %d for %p.\n",
78          num_inst,
79          this
80        );
81
82        /*
83         * Make sure we use some space
84         */
85
86        string = new char[50];
87        sprintf(string, "Instantiation order %d", num_inst);
88    };
89
90    ~B()
91    {
92        printf(
93          "Hey I'm in derived class destructor number %d for %p.\n",
94          num_inst,
95          this
96        );
97              print();
98        num_inst--;
99    };
100
101    void print()  { printf("Derived class - %s\n", string); }
102};
103
104
105A foo;
106B foobar;
107
108void
109cdtest(void)
110{
111    A bar, blech, blah;
112    B bleak;
113
114#ifdef RTEMS_TEST_IO_STREAM
115    cout << "Testing a C++ I/O stream" << endl;
116#else
117    printf("IO Stream not tested\n");
118#endif
119
120    bar = blech;
121}
122
123//
124// main equivalent
125//      It can not be called 'main' since the bsp owns that name
126//      in many implementations in order to get global constructors
127//      run.
128//
129//      Ref: c/src/lib/libbsp/hppa1_1/pxfl/startup/bspstart.c
130//
131
132
133rtems_task main_task(
134  rtems_task_argument
135)
136{
137    printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" );
138
139    cdtest();
140
141    printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" );
142
143    exit(0);
144}
Note: See TracBrowser for help on using the repository browser.