00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
00028 #include <string.h>
00029 #include <map>
00030 #include "MessageService/MsgService.h"
00031 #include "LeakChecker/Lea.h"
00032 #include "LeakChecker/LeaClassMonitor.h"
00033 #include "LeakChecker/LeaLeakChecker.h"
00034 #include "LeakChecker/test/LeaTestA.h"
00035 #include "LeakChecker/test/LeaValidate.h"
00036
00037 ClassImp(LeaValidate)
00038
00039
00040
00041
00042 CVSID("$Id: LeaValidate.cxx,v 1.2 2003/03/25 07:29:35 west Exp $");
00043
00044
00045
00046
00047
00048
00049
00050 LeaValidate::LeaValidate() :
00051 fNumFail(0),
00052 fNumPass(0)
00053 {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 MSG("Lea",Msg::kVerbose) << "LeaValidate ctor 1 at " << this
00068 << "\n";
00069
00070 }
00071
00072
00073
00074
00075 LeaValidate::~LeaValidate() {
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 MSG("Lea",Msg::kVerbose) << "LeaValidate dtor at " << this << "\n";
00090
00091 }
00092
00093
00094
00095
00096
00097 Bool_t LeaValidate::RunAllTests() {
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 Bool_t ok = kTRUE;
00115
00116 for ( Int_t testNum = 1; testNum <= kNUMTESTS; testNum++ ) {
00117 if ( ! RunTest(testNum) ) ok = kFALSE;
00118 }
00119 return ok;
00120 }
00121
00122
00123
00124
00125 Bool_t LeaValidate::RunTest(Int_t testNum) {
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 switch ( testNum ) {
00147 case 1: return Test_1();
00148 }
00149 MSG("Lea",Msg::kError) << "Undefined test: " << testNum << "\n";
00150 return kFALSE;
00151
00152 }
00153
00154
00155 Bool_t LeaValidate::Test_1() {
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 Bool_t ok = kTRUE;
00176
00177 LeaLeakChecker* lea = LeaLeakChecker::Instance();
00178 lea->Reset();
00179
00180 LeaTestA* a1 = new LeaTestA;
00181 LeaTestA* a2 = new LeaTestA;
00182
00183
00184
00185 if ( lea->GetNumActive("LeaTestA") != 2
00186 || lea->GetNumActive("LeaTestB") != 0 ) {
00187 MSG("Lea",Msg::kError) << "Wrong number active." << endl
00188 << "Should be 2,0, but is " << lea->GetNumActive("LeaTestA")
00189 << "," << lea->GetNumActive("LeaTestB") << endl;
00190 ok = kFALSE;
00191 }
00192 {
00193 LeaTestB b1;
00194 LeaTestB b2;
00195 }
00196
00197 delete a1;
00198 a1 = 0;
00199 delete a2;
00200 a2 = 0;
00201
00202 if ( lea->GetNumActive() != 0
00203 || lea->GetNumCreated("LeaTestA") != 2
00204 || lea->GetNumCreated("LeaTestB") != 2 ) {
00205 MSG("Lea",Msg::kError) << "Wrong number active,created A,B" << endl
00206 << " should be 0,2,2 but is:- " << endl << lea;
00207 ok = kFALSE;
00208 }
00209
00210
00211
00212 lea->Reset();
00213
00214 {
00215 map<Int_t,LeaTestA> table;
00216 LeaTestA a;
00217 table[1] = a;
00218 table[2] = a;
00219 table[3] = a;
00220 }
00221
00222 if ( lea->GetNumActive() != 0 ) {
00223 MSG("Lea",Msg::kError) << "Wrong number active" << endl
00224 << " should be 0 but is:- " << endl << lea;
00225 ok = kFALSE;
00226 }
00227
00228
00229 MSG("Lea",Msg::kInfo)
00230 << "Test 1: Counts of stack and heap objects ...... ";
00231 MSG("Lea",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00232 MSG("Lea",Msg::kInfo) << "\n";
00233
00234 if ( ok ) fNumPass++; else fNumFail++;
00235
00236 return ok;
00237
00238 }