@@ -77,9 +77,7 @@ class TestErrorLogger : public TestFixture {
77
77
78
78
TEST_CASE (isCriticalErrorId);
79
79
80
- TEST_CASE (ErrorMessageReportTypeMisraC);
81
- TEST_CASE (ErrorMessageReportTypeMisraCDirective);
82
- TEST_CASE (ErrorMessageReportTypeCertC);
80
+ TEST_CASE (TestReportType);
83
81
}
84
82
85
83
void TestPatternSearchReplace (const std::string& idPlaceholder, const std::string& id) const {
@@ -316,43 +314,30 @@ class TestErrorLogger : public TestFixture {
316
314
}
317
315
}
318
316
319
- void ErrorMessageReportTypeMisraC () const {
317
+ #define testReportType (reportType, severity, errorId, expectedClassification, expectedGuideline ) \
318
+ testReportType_ (__FILE__, __LINE__, reportType, severity, errorId, expectedClassification, expectedGuideline)
319
+ void testReportType_ (const char *file, int line, ReportType reportType, Severity severity, const std::string &errorId,
320
+ const std::string &expectedClassification, const std::string &expectedGuideline) const
321
+ {
320
322
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
321
- const auto reportType = ReportType::misraC2012;
322
323
const auto mapping = createGuidelineMapping (reportType);
323
- const std::string format = " {severity} {id}" ;
324
- ErrorMessage msg (std::move (locs), emptyString, Severity::error, " " , " unusedVariable" , Certainty::normal);
325
- msg.guideline = getGuideline (msg.id , reportType, mapping, msg.severity );
326
- msg.classification = getClassification (msg.guideline , reportType);
327
- ASSERT_EQUALS (" Advisory" , msg.classification );
328
- ASSERT_EQUALS (" 2.8" , msg.guideline );
329
- ASSERT_EQUALS (" Advisory 2.8" , msg.toString (true , format, " " ));
330
- }
331
324
332
- void ErrorMessageReportTypeMisraCDirective () const {
333
- std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
334
- const auto reportType = ReportType::misraC2012;
335
- const auto mapping = createGuidelineMapping (reportType);
336
- const std::string format = " {severity} {id}" ;
337
- ErrorMessage msg (std::move (locs), emptyString, Severity::style, " " , " premium-misra-c-2012-dir-4.6" , Certainty::normal);
325
+ ErrorMessage msg (std::move (locs), emptyString, severity, " " , errorId, Certainty::normal);
338
326
msg.guideline = getGuideline (msg.id , reportType, mapping, msg.severity );
339
327
msg.classification = getClassification (msg.guideline , reportType);
340
- ASSERT_EQUALS ( " Advisory " , msg. classification );
341
- ASSERT_EQUALS ( " Dir 4.6 " , msg.guideline );
342
- ASSERT_EQUALS ( " Advisory Dir 4.6 " , msg.toString ( true , format, " " ) );
328
+
329
+ ASSERT_EQUALS_LOC (expectedClassification , msg.classification , file, line );
330
+ ASSERT_EQUALS_LOC (expectedGuideline , msg.guideline , file, line );
343
331
}
344
332
345
- void ErrorMessageReportTypeCertC () const {
346
- std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
347
- const auto reportType = ReportType::certC;
348
- const auto mapping = createGuidelineMapping (reportType);
349
- const std::string format = " {severity} {id}" ;
350
- ErrorMessage msg (std::move (locs), emptyString, Severity::error, " " , " resourceLeak" , Certainty::normal);
351
- msg.guideline = getGuideline (msg.id , reportType, mapping, msg.severity );
352
- msg.classification = getClassification (msg.guideline , reportType);
353
- ASSERT_EQUALS (" L3" , msg.classification );
354
- ASSERT_EQUALS (" FIO42-C" , msg.guideline );
355
- ASSERT_EQUALS (" L3 FIO42-C" , msg.toString (true , format, " " ));
333
+ void TestReportType () const {
334
+ testReportType (ReportType::misraC2012, Severity::error, " unusedVariable" , " Advisory" , " 2.8" );
335
+ testReportType (ReportType::misraCpp2023, Severity::warning, " premium-misra-cpp-2023-6.8.4" , " Advisory" , " 6.8.4" );
336
+ testReportType (ReportType::misraCpp2023, Severity::style, " premium-misra-cpp-2023-19.6.1" , " Advisory" , " 19.6.1" );
337
+ testReportType (ReportType::misraCpp2008, Severity::style, " premium-misra-cpp-2008-3-4-1" , " Required" , " 3-4-1" );
338
+ testReportType (ReportType::misraC2012, Severity::style, " premium-misra-c-2012-dir-4.6" , " Advisory" , " Dir 4.6" );
339
+ testReportType (ReportType::misraC2012, Severity::style, " misra-c2012-dir-4.6" , " Advisory" , " Dir 4.6" );
340
+ testReportType (ReportType::certC, Severity::error, " resourceLeak" , " L3" , " FIO42-C" );
356
341
}
357
342
358
343
void CustomFormat () const {
0 commit comments