source: rtems/c/src/tests/samples/cdtest/main.cc @ 91daf55

4.104.114.84.95
Last change on this file since 91daf55 was 98e4ebf5, checked in by Joel Sherrill <joel.sherrill@…>, on 10/08/97 at 15:45:54

Fixed typo in the pointer to the license terms.

  • 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#ifdef RTEMS_TEST_IO_STREAM
25#include <iostream.h>
26#endif
27
28extern "C" {
29extern rtems_task main_task(rtems_task_argument);
30}
31
32static int num_inst = 0;
33
34class A {
35public:
36    A(void)
37    {
38        num_inst++;
39        printf(
40          "Hey I'm in base class constructor number %d for %p.\n",
41          num_inst,
42          this
43        );
44
45        /*
46         * Make sure we use some space
47         */
48
49        string = new char[50];
50        sprintf(string, "Instantiation order %d", num_inst);
51    };
52
53    virtual ~A()
54    {
55        printf(
56          "Hey I'm in base class destructor number %d for %p.\n",
57          num_inst,
58          this
59        );
60        print();
61        num_inst--;
62    };
63
64    virtual void print()  { printf("%s\n", string); };
65
66protected:
67    char  *string;
68};
69
70class B : public A {
71public:
72    B(void)
73    {
74        num_inst++;
75        printf(
76          "Hey I'm in derived class constructor number %d for %p.\n",
77          num_inst,
78          this
79        );
80
81        /*
82         * Make sure we use some space
83         */
84
85        string = new char[50];
86        sprintf(string, "Instantiation order %d", num_inst);
87    };
88
89    ~B()
90    {
91        printf(
92          "Hey I'm in derived class destructor number %d for %p.\n",
93          num_inst,
94          this
95        );
96              print();
97        num_inst--;
98    };
99
100    void print()  { printf("Derived class - %s\n", string); }
101};
102
103
104A foo;
105B foobar;
106
107void
108cdtest(void)
109{
110    A bar, blech, blah;
111    B bleak;
112
113#ifdef RTEMS_TEST_IO_STREAM
114    cout << "Testing a C++ I/O stream" << endl;
115#else
116    printf("IO Stream not tested\n");
117#endif
118
119    bar = blech;
120}
121
122//
123// main equivalent
124//      It can not be called 'main' since the bsp owns that name
125//      in many implementations in order to get global constructors
126//      run.
127//
128//      Ref: c/src/lib/libbsp/hppa1_1/pxfl/startup/bspstart.c
129//
130
131
132rtems_task main_task(
133  rtems_task_argument ignored
134)
135{
136    printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" );
137
138    cdtest();
139
140    printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" );
141
142    exit(0);
143}
Note: See TracBrowser for help on using the repository browser.