00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #pragma once
00020
00021 #include "TestToolBox/CommonSources/CommonDefinitions.h"
00022 #include "TestToolBox/CommonSources/ObjectLock.h"
00023 #include <map>
00024 #include <list>
00025 #include <set>
00026
00027 namespace TestToolBox
00028 {
00029
00030
00031 enum DefaultSeverity
00032 {
00033 S_UNKNOWN,
00034 S_INFO,
00035 S_WARNING,
00036 S_ERROR,
00037 S_FATAL_ERROR
00038 };
00039
00040
00041 enum NotificationAction
00042 {
00043 ACTION_NOT_SPECIFIED,
00044 ACTION_INFO,
00045 ACTION_ERROR_CONTINUE_TEST_CASE,
00046 ACTION_ERROR_BREAK_TEST_CASE,
00047 ACTION_IGNORE
00048 };
00049
00050
00051 struct HandlingInstruction
00052 {
00053
00054
00055 HandlingInstruction()
00056 :
00057 m_notificationAction (ACTION_NOT_SPECIFIED)
00058 {}
00059
00060 HandlingInstruction(NotificationAction in_notificationAction )
00061 :
00062 m_notificationAction (in_notificationAction)
00063 {}
00064
00065 NotificationAction m_notificationAction;
00066
00067
00068
00069
00070
00071
00072
00073
00074 };
00075
00076
00077 template<typename T_CATEGORY=long, typename T_ERROR_ID=long,typename T_SEVERITY=DefaultSeverity>
00078 class ErrorEvents;
00079
00080
00081 template<typename T_CATEGORY, typename T_ERROR_ID=long,typename T_SEVERITY=DefaultSeverity>
00082 class ErrorEvent
00083 {
00084 public:
00085
00086
00087 typedef T_CATEGORY Category;
00088 typedef T_ERROR_ID ErrorId;
00089 typedef T_SEVERITY Severity;
00090 typedef ErrorEvent<Category,ErrorId,Severity> ErrorEventType;
00091
00092
00093
00094 std::string GetDescription (void)
00095 {return m_description;}
00096
00097
00098 void ReportChildError (int in_indentation);
00099
00100 private:
00101
00102
00103
00104
00105 std::string m_description;
00106
00107
00108
00109 long m_errorMsgNum;
00110
00111
00112 ErrorId m_externalErrorId;
00113
00114
00115
00116 long m_internalErrorId;
00117
00118
00119 Category m_category;
00120
00121
00122 Severity m_severity;
00123
00124
00125 typedef std::list<ErrorEventType> ErrorList;
00126
00127
00128 ErrorList m_listOfChildErrors;
00129
00130 friend class ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>;
00131
00132 private:
00133
00134
00135 ErrorEvent(){};
00136
00137 explicit ErrorEvent (
00138 std::string const & in_rDescription,
00139 long in_errMsgNum = 0,
00140 ErrorId in_extErrorId = ErrorId(),
00141 long in_intErrorId = 0,
00142 Category in_category = Category(),
00143 Severity in_severity = Severity())
00144 :
00145 m_description (in_rDescription),
00146 m_errorMsgNum (in_errMsgNum),
00147 m_externalErrorId (in_extErrorId),
00148 m_internalErrorId (in_intErrorId),
00149 m_category (in_category),
00150 m_severity (in_severity)
00151 {}
00152
00153 bool FindExtErrorId (
00154 ErrorId inExtErrorId,
00155 typename ErrorList::iterator& out_rIt,
00156 ErrorList*& out_rpErrorList);
00157
00158
00159 };
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00175 class ErrorEvents : public AutoCriticalSection
00176 {
00177 private:
00178
00179
00180
00181 explicit ErrorEvents (void);
00182
00183 public:
00184
00185
00186 typedef T_CATEGORY Category;
00187 typedef T_ERROR_ID ErrorId;
00188 typedef T_SEVERITY Severity;
00189 typedef ErrorEvent<Category,ErrorId,Severity> ErrorEventType;
00190
00191
00192
00193
00194 ~ErrorEvents()
00195 {
00196 TRCF("ErrorEvents::~ErrorEvents");
00197 TRC(TL_DEBUG, "Destructor");
00198 }
00199
00200
00201
00202 static ErrorEvents* Get (void)
00203 {if (!s_pErrorEvents) s_pErrorEvents = new ErrorEvents;
00204 return s_pErrorEvents;}
00205 static ErrorEvents* s_pErrorEvents;
00206
00207 static void Cleanup (void)
00208 {delete s_pErrorEvents; s_pErrorEvents = 0;}
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 void SetErrorSync (
00219 bool in_syncOnError)
00220 {m_syncOnError = in_syncOnError;}
00221
00222
00223
00224
00225 void SetImmediateErrorLog (
00226 bool in_immediateLog)
00227 {m_immediateLog = in_immediateLog;}
00228
00229 void DeleteStoredErrorsAfterReport (bool in_autoDelete)
00230 {m_deleteStoredErrorsAfterReport = in_autoDelete;}
00231
00232 void SetNotificationActionForErrorMsgNum (
00233 long in_errorMsgNum,
00234 NotificationAction in_notificationAction);
00235
00236 void IgnoreErrorContainingTextPattern(
00237 std::string const & in_text);
00238
00239 void ClearStoredTextPatterns (void);
00240
00241
00242
00243
00244
00245
00246
00247
00248 void CreateError (
00249 std::string const & in_rDescription,
00250 long in_errMsgNum = 0,
00251 ErrorId in_extErrorId = ErrorId(),
00252 long in_intErrorId = 0,
00253 Category in_category = Category(),
00254 Severity in_severity = Severity());
00255
00256 void AddAsChildError (
00257 ErrorId inExtErrorIdParent,
00258 ErrorId inExtErrorIdChild);
00259
00260
00261
00262
00263
00264
00265
00266 void ReportStoredErrors (void);
00267
00268
00269 void DeleteStoredErrors (void);
00270
00271
00272
00273
00274 bool ErrorOk (
00275 T_ERROR_ID in_extErrorId);
00276
00277
00278
00279 private:
00280
00281
00282 typedef std::list<ErrorEventType> ErrorList;
00283
00284
00285
00286 ErrorList m_errorList;
00287
00288
00289
00290 bool m_immediateLog;
00291 bool m_syncOnError;
00292 bool m_deleteStoredErrorsAfterReport;
00293
00294 HandlingInstruction m_defaultHandlingInstruction;
00295
00296
00297
00298 std::set<std::string> m_errorTextPatternsToIgnore;
00299
00300 std::map<long,HandlingInstruction> m_instructionForErrorMsgNum;
00301 std::map<Category,HandlingInstruction> m_instructionForCategory;
00302 std::map<Severity,HandlingInstruction> m_instructionForSeverity;
00303
00304 friend class ErrorEvent<T_CATEGORY,T_ERROR_ID,T_SEVERITY>;
00305
00306
00307 private:
00308
00309
00310 bool FindExtErrorId (
00311 ErrorId inExtErrorId,
00312 typename ErrorList::iterator& out_rIt,
00313 ErrorList*& out_rpErrorList);
00314
00315 HandlingInstruction GetHandlingInstruction (
00316 typename ErrorEventType const & in_rErrorEvent);
00317
00318
00319 };
00320
00321
00322
00323
00324
00325
00326 };
00327
00328
00329