Skip to content

Commit c46d7a8

Browse files
committed
refactor tests
1 parent 39170ce commit c46d7a8

1 file changed

Lines changed: 19 additions & 95 deletions

File tree

test/testerrorlogger.cpp

Lines changed: 19 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ class TestErrorLogger : public TestFixture {
7777

7878
TEST_CASE(isCriticalErrorId);
7979

80-
TEST_CASE(ErrorMessageReportTypeMisraC);
81-
TEST_CASE(ErrorMessageReportTypeMisraCpp);
82-
TEST_CASE(ErrorMessageReportTypeMisraCDirective);
83-
TEST_CASE(ErrorMessageReportTypeCertC);
80+
TEST_CASE(TestReportType);
8481
}
8582

8683
void TestPatternSearchReplace(const std::string& idPlaceholder, const std::string& id) const {
@@ -317,104 +314,31 @@ class TestErrorLogger : public TestFixture {
317314
}
318315
}
319316

320-
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+
{
321322
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
322-
const auto reportType = ReportType::misraC2012;
323323
const auto mapping = createGuidelineMapping(reportType);
324-
const std::string format = "{severity} {id}";
325-
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "unusedVariable", Certainty::normal);
326-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
327-
msg.classification = getClassification(msg.guideline, reportType);
328-
ASSERT_EQUALS("Advisory", msg.classification);
329-
ASSERT_EQUALS("2.8", msg.guideline);
330-
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
331-
}
332-
333-
void ErrorMessageReportTypeMisraCpp() const {
334-
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
335-
const std::string format = "{severity} {id}";
336-
337-
{
338-
const auto reportType = ReportType::misraCpp2023;
339-
const auto mapping = createGuidelineMapping(reportType);
340-
ErrorMessage msg(locs, emptyString, Severity::warning, "", "premium-misra-cpp-2023-6.8.4", Certainty::normal);
341-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
342-
msg.classification = getClassification(msg.guideline, reportType);
343-
ASSERT_EQUALS("Advisory", msg.classification);
344-
ASSERT_EQUALS("6.8.4", msg.guideline);
345-
ASSERT_EQUALS("Advisory 6.8.4", msg.toString(true, format, ""));
346-
}
347-
348-
{
349-
const auto reportType = ReportType::misraCpp2023;
350-
const auto mapping = createGuidelineMapping(reportType);
351-
ErrorMessage msg(locs, emptyString, Severity::warning, "", "misra-cpp-2023-6.8.4", Certainty::normal);
352-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
353-
msg.classification = getClassification(msg.guideline, reportType);
354-
ASSERT_EQUALS("Advisory", msg.classification);
355-
ASSERT_EQUALS("6.8.4", msg.guideline);
356-
ASSERT_EQUALS("Advisory 6.8.4", msg.toString(true, format, ""));
357-
}
358-
359-
{
360-
const auto reportType = ReportType::misraCpp2023;
361-
const auto mapping = createGuidelineMapping(reportType);
362-
ErrorMessage msg(locs, emptyString, Severity::style, "", "premium-misra-cpp-2023-19.6.1", Certainty::normal);
363-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
364-
msg.classification = getClassification(msg.guideline, reportType);
365-
ASSERT_EQUALS("Advisory", msg.classification);
366-
ASSERT_EQUALS("19.6.1", msg.guideline);
367-
ASSERT_EQUALS("Advisory 19.6.1", msg.toString(true, format, ""));
368-
}
369324

370-
{
371-
const auto reportType = ReportType::misraCpp2008;
372-
const auto mapping = createGuidelineMapping(reportType);
373-
ErrorMessage msg(locs, emptyString, Severity::style, "", "premium-misra-cpp-2008-3-4-1", Certainty::normal);
374-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
375-
msg.classification = getClassification(msg.guideline, reportType);
376-
ASSERT_EQUALS("Required", msg.classification);
377-
ASSERT_EQUALS("3-4-1", msg.guideline);
378-
ASSERT_EQUALS("Required 3-4-1", msg.toString(true, format, ""));
379-
}
380-
381-
{
382-
const auto reportType = ReportType::misraCpp2008;
383-
const auto mapping = createGuidelineMapping(reportType);
384-
ErrorMessage msg(locs, emptyString, Severity::style, "", "misra-cpp-2008-3-4-1", Certainty::normal);
385-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
386-
msg.classification = getClassification(msg.guideline, reportType);
387-
ASSERT_EQUALS("Required", msg.classification);
388-
ASSERT_EQUALS("3-4-1", msg.guideline);
389-
ASSERT_EQUALS("Required 3-4-1", msg.toString(true, format, ""));
390-
}
391-
392-
}
393-
394-
void ErrorMessageReportTypeMisraCDirective() const {
395-
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
396-
const auto reportType = ReportType::misraC2012;
397-
const auto mapping = createGuidelineMapping(reportType);
398-
const std::string format = "{severity} {id}";
399-
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);
400326
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
401327
msg.classification = getClassification(msg.guideline, reportType);
402-
ASSERT_EQUALS("Advisory", msg.classification);
403-
ASSERT_EQUALS("Dir 4.6", msg.guideline);
404-
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);
405331
}
406332

407-
void ErrorMessageReportTypeCertC() const {
408-
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
409-
const auto reportType = ReportType::certC;
410-
const auto mapping = createGuidelineMapping(reportType);
411-
const std::string format = "{severity} {id}";
412-
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "resourceLeak", Certainty::normal);
413-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
414-
msg.classification = getClassification(msg.guideline, reportType);
415-
ASSERT_EQUALS("L3", msg.classification);
416-
ASSERT_EQUALS("FIO42-C", msg.guideline);
417-
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::warning, "misra-cpp-2023-6.8.4", "Advisory", "6.8.4");
337+
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-19.6.1", "Advisory", "19.6.1");
338+
testReportType(ReportType::misraCpp2008, Severity::style, "premium-misra-cpp-2008-3-4-1", "Required", "3-4-1");
339+
testReportType(ReportType::misraCpp2008, Severity::style, "misra-cpp-2008-3-4-1", "Required", "3-4-1");
340+
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-dir-4.6", "Advisory", "Dir 4.6");
341+
testReportType(ReportType::certC, Severity::error, "resourceLeak", "L3", "FIO42-C");
418342
}
419343

420344
void CustomFormat() const {

0 commit comments

Comments
 (0)