[e71ce071] | 1 | /* |
---|
[ac7d5ef0] | 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. |
---|
[e71ce071] | 14 | * |
---|
[98e4ebf5] | 15 | * The license and distribution terms for this file may be |
---|
| 16 | * found in the file LICENSE in this distribution or at |
---|
[e71ce071] | 17 | * http://www.OARcorp.com/rtems/license.html. |
---|
[ac7d5ef0] | 18 | * |
---|
| 19 | * $Id$ |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #include <rtems.h> |
---|
| 23 | #include <stdio.h> |
---|
[2936b425] | 24 | #include <stdlib.h> |
---|
[91333c2] | 25 | #ifdef RTEMS_TEST_IO_STREAM |
---|
[ac7d5ef0] | 26 | #include <iostream.h> |
---|
[91333c2] | 27 | #endif |
---|
[ac7d5ef0] | 28 | |
---|
| 29 | extern "C" { |
---|
| 30 | extern rtems_task main_task(rtems_task_argument); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | static int num_inst = 0; |
---|
| 34 | |
---|
| 35 | class A { |
---|
| 36 | public: |
---|
| 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 | |
---|
| 67 | protected: |
---|
| 68 | char *string; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | class B : public A { |
---|
| 72 | public: |
---|
| 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 | |
---|
| 105 | A foo; |
---|
| 106 | B foobar; |
---|
| 107 | |
---|
| 108 | void |
---|
| 109 | cdtest(void) |
---|
| 110 | { |
---|
| 111 | A bar, blech, blah; |
---|
| 112 | B bleak; |
---|
| 113 | |
---|
[91333c2] | 114 | #ifdef RTEMS_TEST_IO_STREAM |
---|
[ac7d5ef0] | 115 | cout << "Testing a C++ I/O stream" << endl; |
---|
[91333c2] | 116 | #else |
---|
| 117 | printf("IO Stream not tested\n"); |
---|
| 118 | #endif |
---|
[ac7d5ef0] | 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 | |
---|
| 130 | |
---|
| 131 | rtems_task main_task( |
---|
[61fc72c] | 132 | rtems_task_argument |
---|
[ac7d5ef0] | 133 | ) |
---|
| 134 | { |
---|
| 135 | printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" ); |
---|
| 136 | |
---|
| 137 | cdtest(); |
---|
| 138 | |
---|
| 139 | printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" ); |
---|
| 140 | |
---|
| 141 | exit(0); |
---|
| 142 | } |
---|