00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #pragma once
00012
00013 #include "TestToolBox/ErrorEvents.h"
00014 #include "TestToolBox/Synchronizer.h"
00015
00016
00017
00018 namespace TestToolBox
00019 {
00020
00021
00022
00023
00024
00025
00026
00027 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00028 void ErrorEvent<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::ReportChildError (int in_indentation)
00029 {
00030 ErrorList::iterator it;
00031 for (ErrorList::iterator it = m_listOfChildErrors.begin();
00032 it != m_listOfChildErrors.end(); ++it)
00033 {
00034 HandlingInstruction instruct =
00035 ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::Get()->GetHandlingInstruction (*it);
00036 if (instruct.m_notificationAction != ACTION_IGNORE)
00037 {
00038 std::string errInfoTxt;
00039 for (int i = 1; i<= in_indentation; ++i)
00040 errInfoTxt += " ";
00041 errInfoTxt += (*it).GetDescription();
00042 TestEvents::Get()->Act(errInfoTxt);
00043 }
00044
00045 (*it).ReportChildError(in_indentation+2);
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00056 bool ErrorEvent<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::FindExtErrorId (
00057 ErrorId inExtErrorId,
00058 typename ErrorList::iterator& out_rIt,
00059 ErrorList*& out_rpErrorList)
00060 {
00061 bool found = false;
00062 for (ErrorList::iterator it = m_listOfChildErrors.begin();
00063 it != m_listOfChildErrors.end(); ++it)
00064 {
00065 if ((*it).m_externalErrorId == inExtErrorId)
00066 {
00067 out_rIt = it;
00068 out_rpErrorList = &m_listOfChildErrors;
00069 found = true;
00070 break;
00071 }
00072 }
00073
00074 if (!found)
00075 {
00076 for (ErrorList::iterator it = m_listOfChildErrors.begin();
00077 it != m_listOfChildErrors.end(); ++it)
00078 {
00079 found =(*it).FindExtErrorId(inExtErrorId, out_rIt, out_rpErrorList);
00080 if (found) break;
00081 }
00082 }
00083 return found;
00084 }
00085
00086
00087
00088
00089
00090
00091 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00092 ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::ErrorEvents (void)
00093 :
00094 m_errorList (),
00095 m_immediateLog (true),
00096 m_syncOnError (false),
00097 m_deleteStoredErrorsAfterReport (true),
00098 m_defaultHandlingInstruction (ACTION_ERROR_CONTINUE_TEST_CASE)
00099 {}
00100
00101
00102
00103
00104
00105
00106 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00107 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::SetNotificationActionForErrorMsgNum (
00108 long in_errorMsgNum,
00109 NotificationAction in_notificationAction)
00110 {
00111 AutoLock o (this);
00112 m_instructionForErrorMsgNum[in_errorMsgNum].m_notificationAction= in_notificationAction;
00113 }
00114
00115
00116
00117
00118
00119
00120 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00121 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::IgnoreErrorContainingTextPattern (
00122 std::string const & in_text)
00123 {
00124 AutoLock o (this);
00125 m_errorTextPatternsToIgnore.insert(in_text);
00126 }
00127
00128
00129
00130
00131
00132
00133 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00134 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::ClearStoredTextPatterns (void)
00135 {
00136 AutoLock o (this);
00137 m_errorTextPatternsToIgnore.clear();
00138 }
00139
00140
00141
00142
00143
00144
00145 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00146 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::CreateError (
00147 std::string const & in_rDescription,
00148 long in_errMsgNum = 0,
00149 ErrorId in_extErrorId = ErrorId(),
00150 long in_intErrorId = 0,
00151 Category in_category = Category(),
00152 Severity in_severity = Severity())
00153 {
00154 AutoLock o (this);
00155
00156 ErrorEventType error (in_rDescription,in_errMsgNum,
00157 in_extErrorId, in_intErrorId, in_category, in_severity);
00158 m_errorList.push_back(error);
00159
00160 HandlingInstruction instruct =
00161 GetHandlingInstruction (error);
00162
00163 if (instruct.m_notificationAction != ACTION_IGNORE)
00164 {
00165
00166 if (m_immediateLog)
00167 {
00168 TestEvents::Get()->Info("Error-Info: " + error.GetDescription());
00169 }
00170
00171
00172 if (m_syncOnError)
00173 {
00174 TTB_SYNC();
00175 }
00176 }
00177 }
00178
00179
00180
00181
00182
00183
00184 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00185 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::AddAsChildError (
00186 ErrorId inExtErrorIdParent,
00187 ErrorId inExtErrorIdChild)
00188 {
00189 AutoLock o (this);
00190
00191 ErrorEventType childError;
00192
00193
00194 typename ErrorList::iterator itChild;
00195 ErrorList* pErrorListChild;
00196
00197 if (FindExtErrorId(inExtErrorIdChild, itChild,pErrorListChild))
00198 {
00199 childError = *itChild;
00200 pErrorListChild->erase(itChild);
00201
00202 typename ErrorList::iterator itParent;
00203 ErrorList* pErrorListParent;
00204 if (FindExtErrorId(inExtErrorIdParent, itParent,pErrorListParent))
00205 {
00206 itParent->m_listOfChildErrors.push_back(childError);
00207 }
00208 }
00209 }
00210
00211
00212
00213
00214
00215
00216 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00217 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::ReportStoredErrors (void)
00218 {
00219 AutoLock o (this);
00220
00221 if (m_errorList.empty())
00222 {
00223 TestEvents::Get()->Act("No errors stored");
00224 }
00225 else
00226 {
00227 ErrorList::iterator it;
00228 for (ErrorList::iterator it = m_errorList.begin();
00229 it != m_errorList.end(); ++it)
00230 {
00231 HandlingInstruction instruct =
00232 GetHandlingInstruction (*it);
00233 if (instruct.m_notificationAction != ACTION_IGNORE)
00234 {
00235
00236 TestEvents::Get()->Act((*it).GetDescription());
00237 }
00238 (*it).ReportChildError(2);
00239 }
00240
00241 if (m_deleteStoredErrorsAfterReport)
00242 {
00243 m_errorList.clear();
00244 }
00245
00246 }
00247 }
00248
00249
00250
00251
00252
00253 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00254 void ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::DeleteStoredErrors (void)
00255 {
00256 AutoLock o (this);
00257 m_errorList.clear();
00258 }
00259
00260
00261
00262
00263
00264
00265 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00266 bool ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::ErrorOk (
00267 T_ERROR_ID in_extErrorId)
00268 {
00269 if (in_extErrorId == T_ERROR_ID())
00270 {
00271 return true;
00272 }
00273 else
00274 {
00275 AutoLock o (this);
00276 ErrorList::iterator itErrList;
00277 ErrorList* pErrorList;
00278 bool found = FindExtErrorId(in_extErrorId, itErrList, pErrorList);
00279 if (found)
00280 {
00281 TestEvents::Get()->Act((*itErrList).GetDescription());
00282 (*itErrList).ReportChildError(2);
00283 }
00284 return false;
00285 }
00286 }
00287
00288
00289
00290
00291
00292
00293 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00294 bool ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::FindExtErrorId (
00295 ErrorId inExtErrorId,
00296 typename ErrorList::iterator& out_rIt,
00297 ErrorList*& out_rpErrorList)
00298 {
00299 bool found = false;
00300 for (ErrorList::iterator it = m_errorList.begin();
00301 it != m_errorList.end(); ++it)
00302 {
00303 if ((*it).m_externalErrorId == inExtErrorId)
00304 {
00305 out_rIt = it;
00306 out_rpErrorList = &m_errorList;
00307 found = true;
00308 break;
00309 }
00310 }
00311
00312 if (!found)
00313 {
00314 for (ErrorList::iterator it = m_errorList.begin();
00315 it != m_errorList.end(); ++it)
00316 {
00317 found =(*it).FindExtErrorId(inExtErrorId, out_rIt, out_rpErrorList);
00318 if (found) break;
00319 }
00320 }
00321
00322 return found;
00323 }
00324
00325
00326
00327
00328
00329 template<typename T_CATEGORY, typename T_ERROR_ID,typename T_SEVERITY>
00330 HandlingInstruction ErrorEvents<T_CATEGORY,T_ERROR_ID,T_SEVERITY>::GetHandlingInstruction (
00331 typename ErrorEventType const & in_rErrorEvent)
00332 {
00333 HandlingInstruction instructionErrorId;
00334 HandlingInstruction instructionCategory;
00335 HandlingInstruction instructionSeverity;
00336
00337
00338 for (std::set<std::string>::iterator itPattern = m_errorTextPatternsToIgnore.begin();
00339 itPattern != m_errorTextPatternsToIgnore.end(); ++itPattern)
00340 {
00341 if (in_rErrorEvent.m_description.find(*itPattern)!=std::string::npos)
00342 {
00343
00344 return HandlingInstruction(ACTION_IGNORE);
00345 }
00346 }
00347
00348
00349 std::map<long,HandlingInstruction>::iterator posErrorMsgNum
00350 = m_instructionForErrorMsgNum.find(in_rErrorEvent.m_errorMsgNum);
00351 if (posErrorMsgNum != m_instructionForErrorMsgNum.end())
00352 {
00353 instructionErrorId = m_instructionForErrorMsgNum[in_rErrorEvent.m_errorMsgNum];
00354 return instructionErrorId;
00355 }
00356
00357
00358
00359 return m_defaultHandlingInstruction;
00360 }
00361
00362 };
00363
00364
00365
00366