00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #if !INCLUDED_MOTU_nc_alloc
00021 #define INCLUDED_MOTU_nc_alloc 1
00022
00023 #include "Prefix.h"
00024
00025 # if defined (EH_NEW_HEADERS)
00026 # include <utility>
00027 # else
00028 # include <pair.h>
00029 # endif
00030
00031 extern long alloc_count;
00032 extern long object_count;
00033
00034 struct TestController
00035 {
00036
00037 static void ReportSuccess(int);
00038
00039
00040
00041
00042
00043
00044
00045
00046 static void TrackAllocations( bool );
00047 static bool TrackingEnabled();
00048
00049
00050
00051 static void BeginLeakDetection();
00052
00053
00054 static bool LeakDetectionEnabled();
00055
00056
00057
00058 static bool ReportLeaked();
00059
00060
00061
00062
00063
00064
00065 static void TurnOffExceptions();
00066
00067
00068 static void SetFailureCountdown( long n );
00069
00070
00071 static void CancelFailureCountdown();
00072
00073
00074
00075 static void maybe_fail(long);
00076
00077
00078
00079
00080
00081
00082
00083 static void SetCurrentTestCategory( const char* str );
00084
00085
00086 static void SetCurrentContainer( const char* str );
00087
00088
00089 static void SetCurrentTestName(const char* str);
00090
00091
00092 static void SetVerbose(bool val);
00093
00094 private:
00095 enum { kNotInExceptionTest = -1 };
00096
00097 static void ClearAllocationSet();
00098 static void EndLeakDetection();
00099 static void PrintTestName( bool err=false );
00100
00101 static long& Failure_threshold();
00102 static long possible_failure_count;
00103 static const char* current_test;
00104 static const char* current_test_category;
00105 static const char* current_container;
00106 static bool nc_verbose;
00107 static bool never_fail;
00108 static bool track_allocations;
00109 static bool leak_detection_enabled;
00110 };
00111
00112 extern TestController gTestController;
00113
00114
00115
00116
00117
00118 inline void simulate_possible_failure()
00119 {
00120 gTestController.maybe_fail(0);
00121 }
00122
00123 inline void simulate_constructor()
00124 {
00125 gTestController.maybe_fail(0);
00126 object_count++;
00127 }
00128
00129 inline void simulate_destructor()
00130 {
00131 object_count--;
00132 }
00133
00134 inline void TestController::TrackAllocations( bool track )
00135 {
00136 track_allocations = track;
00137 }
00138
00139 inline bool TestController::TrackingEnabled()
00140 {
00141 return track_allocations;
00142 }
00143
00144 inline void TestController::SetFailureCountdown(long count) {
00145 Failure_threshold() = count;
00146 possible_failure_count = 0;
00147 }
00148
00149 inline void TestController::CancelFailureCountdown() {
00150 Failure_threshold() = kNotInExceptionTest;
00151 }
00152
00153 inline void TestController::BeginLeakDetection()
00154 {
00155 alloc_count = 0;
00156 object_count = 0;
00157 ClearAllocationSet();
00158 leak_detection_enabled = true;
00159 }
00160
00161 inline bool TestController::LeakDetectionEnabled()
00162 {
00163 return leak_detection_enabled;
00164 }
00165
00166 inline void TestController::EndLeakDetection()
00167 {
00168 leak_detection_enabled = false;
00169 }
00170
00171 inline void TestController::SetCurrentTestCategory(const char* str)
00172 {
00173 current_test_category=str;
00174 if (nc_verbose)
00175 PrintTestName();
00176 }
00177
00178 inline void TestController::SetCurrentContainer(const char* str) {
00179 current_container=str;
00180 }
00181
00182 inline void TestController::SetCurrentTestName(const char* str)
00183 {
00184 current_test=str;
00185 }
00186
00187 inline void TestController::SetVerbose(bool val)
00188 {
00189 nc_verbose=val;
00190 }
00191
00192 inline void TestController::TurnOffExceptions()
00193 {
00194 never_fail = true;
00195 }
00196
00197 #endif // INCLUDED_MOTU_nc_alloc