[ac7d5ef0] | 1 | /* main |
---|
| 2 | * |
---|
| 3 | * This routine is the initialization task for this test program. |
---|
| 4 | * It is called from init_exec and has the responsibility for creating |
---|
| 5 | * and starting the tasks that make up the test. If the time of day |
---|
| 6 | * clock is required for the test, it should also be set to a known |
---|
| 7 | * value by this function. |
---|
| 8 | * |
---|
| 9 | * Input parameters: NONE |
---|
| 10 | * |
---|
| 11 | * Output parameters: NONE |
---|
| 12 | * |
---|
| 13 | * COPYRIGHT (c) 1994 by Division Incorporated |
---|
| 14 | * |
---|
| 15 | * Based in part on OAR works. |
---|
| 16 | * To anyone who acknowledges that this file is provided "AS IS" |
---|
| 17 | * without any express or implied warranty: |
---|
| 18 | * permission to use, copy, modify, and distribute this file |
---|
| 19 | * for any purpose is hereby granted without fee, provided that |
---|
| 20 | * the above copyright notice and this notice appears in all |
---|
| 21 | * copies, and that the name of Division Incorporated not be |
---|
| 22 | * used in advertising or publicity pertaining to distribution |
---|
| 23 | * of the software without specific, written prior permission. |
---|
| 24 | * Division Incorporated makes no representations about the |
---|
| 25 | * suitability of this software for any purpose. |
---|
| 26 | * |
---|
| 27 | * $Id$ |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #include <rtems.h> |
---|
| 31 | #include <stdio.h> |
---|
| 32 | #include <libcsupport.h> |
---|
| 33 | #include <iostream.h> |
---|
| 34 | |
---|
| 35 | extern "C" { |
---|
| 36 | extern rtems_task main_task(rtems_task_argument); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | static int num_inst = 0; |
---|
| 40 | |
---|
| 41 | class A { |
---|
| 42 | public: |
---|
| 43 | A(void) |
---|
| 44 | { |
---|
| 45 | num_inst++; |
---|
| 46 | printf( |
---|
| 47 | "Hey I'm in base class constructor number %d for %p.\n", |
---|
| 48 | num_inst, |
---|
| 49 | this |
---|
| 50 | ); |
---|
| 51 | |
---|
| 52 | /* |
---|
| 53 | * Make sure we use some space |
---|
| 54 | */ |
---|
| 55 | |
---|
| 56 | string = new char[50]; |
---|
| 57 | sprintf(string, "Instantiation order %d", num_inst); |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | virtual ~A() |
---|
| 61 | { |
---|
| 62 | printf( |
---|
| 63 | "Hey I'm in base class destructor number %d for %p.\n", |
---|
| 64 | num_inst, |
---|
| 65 | this |
---|
| 66 | ); |
---|
| 67 | print(); |
---|
| 68 | num_inst--; |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | virtual void print() { printf("%s\n", string); }; |
---|
| 72 | |
---|
| 73 | protected: |
---|
| 74 | char *string; |
---|
| 75 | }; |
---|
| 76 | |
---|
| 77 | class B : public A { |
---|
| 78 | public: |
---|
| 79 | B(void) |
---|
| 80 | { |
---|
| 81 | num_inst++; |
---|
| 82 | printf( |
---|
| 83 | "Hey I'm in derived class constructor number %d for %p.\n", |
---|
| 84 | num_inst, |
---|
| 85 | this |
---|
| 86 | ); |
---|
| 87 | |
---|
| 88 | /* |
---|
| 89 | * Make sure we use some space |
---|
| 90 | */ |
---|
| 91 | |
---|
| 92 | string = new char[50]; |
---|
| 93 | sprintf(string, "Instantiation order %d", num_inst); |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | ~B() |
---|
| 97 | { |
---|
| 98 | printf( |
---|
| 99 | "Hey I'm in derived class destructor number %d for %p.\n", |
---|
| 100 | num_inst, |
---|
| 101 | this |
---|
| 102 | ); |
---|
| 103 | print(); |
---|
| 104 | num_inst--; |
---|
| 105 | }; |
---|
| 106 | |
---|
| 107 | void print() { printf("Derived class - %s\n", string); } |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | A foo; |
---|
| 112 | B foobar; |
---|
| 113 | |
---|
| 114 | void |
---|
| 115 | cdtest(void) |
---|
| 116 | { |
---|
| 117 | A bar, blech, blah; |
---|
| 118 | B bleak; |
---|
| 119 | |
---|
| 120 | cout << "Testing a C++ I/O stream" << endl; |
---|
| 121 | |
---|
| 122 | bar = blech; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | // |
---|
| 126 | // main equivalent |
---|
| 127 | // It can not be called 'main' since the bsp owns that name |
---|
| 128 | // in many implementations in order to get global constructors |
---|
| 129 | // run. |
---|
| 130 | // |
---|
| 131 | // Ref: c/src/lib/libbsp/hppa1_1/simhppa/startup/bspstart.c |
---|
| 132 | // |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | rtems_task main_task( |
---|
| 136 | rtems_task_argument ignored |
---|
| 137 | ) |
---|
| 138 | { |
---|
| 139 | printf( "\n\n*** CONSTRUCTOR/DESTRUCTOR TEST ***\n" ); |
---|
| 140 | |
---|
| 141 | cdtest(); |
---|
| 142 | |
---|
| 143 | printf( "*** END OF CONSTRUCTOR/DESTRUCTOR TEST ***\n\n\n" ); |
---|
| 144 | |
---|
| 145 | exit(0); |
---|
| 146 | } |
---|