From 155249abe7385724ff291afc175fe9263c885b59 Mon Sep 17 00:00:00 2001 From: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> Date: Thu, 10 Oct 2024 18:34:14 +0200 Subject: [PATCH] Enforce rule uid in Cpp baselib and example checker bundle Signed-off-by: hoangtungdinh <11166240+hoangtungdinh@users.noreply.github.com> --- examples/checker_bundle_example/src/main.cpp | 75 ++++++------------- examples/checker_bundle_example/src/main.h | 5 -- .../common/result_format/c_checker_bundle.h | 6 -- include/common/result_format/c_issue.h | 10 +-- qc_framework/tests/test_data/3step_config.xml | 6 ++ .../src/result_format/c_checker_bundle.cpp | 20 ----- src/common/src/result_format/c_issue.cpp | 10 +-- .../files/DemoCheckerBundle.xqar | 10 --- .../files/DemoCheckerBundle_config.xml | 6 ++ .../src/example_checker_bundle_tester.cpp | 33 -------- 10 files changed, 40 insertions(+), 141 deletions(-) delete mode 100644 test/function/examples/example_checker_bundle/files/DemoCheckerBundle.xqar diff --git a/examples/checker_bundle_example/src/main.cpp b/examples/checker_bundle_example/src/main.cpp index 9d660dad..5720411b 100644 --- a/examples/checker_bundle_example/src/main.cpp +++ b/examples/checker_bundle_example/src/main.cpp @@ -52,12 +52,7 @@ int main(int argc, char *argv[]) // Default parameters inputParams.SetParam("strResultFile", ssResultFile.str()); - if (StringEndsWith(ToLower(strFilepath), ".xodr")) - { - // Implement here the processing of an XODR. - // This path is currently used for batch integration. - } - else if (StringEndsWith(ToLower(strFilepath), ".xml")) + if (StringEndsWith(ToLower(strFilepath), ".xml")) { // Implement here the processing of an configuration. // This path is currently used for config gui integration @@ -82,11 +77,6 @@ int main(int argc, char *argv[]) std::cerr << "No configuration for module '" << CHECKER_BUNDLE_NAME << "' found. Start with default params." << std::endl; } - else if (StringEndsWith(ToLower(strFilepath), "--defaultconfig")) - { - WriteEmptyReport(); - return 0; - } else if (strcmp(strFilepath.c_str(), "-h") == 0 || strcmp(strFilepath.c_str(), "--help") == 0) { ShowHelp(strToolpath); @@ -110,10 +100,7 @@ void ShowHelp(const std::string &toolPath) GetFileName(&applicationNameWithoutExt, true); std::cout << "\n\nUsage of " << applicationNameWithoutExt << ":" << std::endl; - std::cout << "\nRun the application with xodr file: \n" << applicationName << " sample.xodr" << std::endl; std::cout << "\nRun the application with dbqa configuration: \n" << applicationName << " config.xml" << std::endl; - std::cout << "\nRun the application and write empty report as default configuration: \n" - << applicationName << " --defaultconfig" << std::endl; std::cout << "\n\n"; } @@ -170,34 +157,41 @@ void RunChecks(const cParameterContainer &inputParams) pResultContainer.AddCheckerBundle(pExampleCheckerBundle); // Create a checker with a factory in the checker bundle - cChecker *pExampeChecker = pExampleCheckerBundle->CreateChecker("exampleChecker", "This is a description"); + cChecker *pExampleChecker = pExampleCheckerBundle->CreateChecker("exampleChecker", "This is a description"); + const std::string first_rule_uid = "asam.net:xodr:1.0.0:first_rule_name"; + pExampleChecker->AddRule(new cRule(first_rule_uid)); // Lets add now an issue - pExampeChecker->AddIssue(new cIssue("This is an information from the demo usecase", INFO_LVL)); + pExampleChecker->AddIssue(new cIssue("This is an information from the demo usecase", INFO_LVL, first_rule_uid)); // Create a test checker with an inertial location cChecker *pExampleInertialChecker = pExampleCheckerBundle->CreateChecker("exampleInertialChecker", "This is a description of inertial checker"); + const std::string second_rule_uid = "asam.net:xodr:1.0.0:second_rule_name"; + pExampleInertialChecker->AddRule(new cRule(second_rule_uid)); std::list listLoc; listLoc.push_back(new cLocationsContainer("inertial position", new cInertialLocation(1.0, 2.0, 3.0))); - pExampleInertialChecker->AddIssue(new cIssue("This is an information from the demo usecase", INFO_LVL, listLoc)); - - // Create a test checker with RuleUID and metadata - cChecker *pExampleRuleUIDChecker = - pExampleCheckerBundle->CreateChecker("exampleRuleUIDChecker", "This is a description of ruleUID checker"); - pExampleRuleUIDChecker->AddRule(new cRule("test.com::qwerty.qwerty")); - pExampleRuleUIDChecker->AddMetadata( + pExampleInertialChecker->AddIssue( + new cIssue("This is an information from the demo usecase", INFO_LVL, second_rule_uid, listLoc)); + + // Create a test checker with metadata + cChecker *pExampleMetadataChecker = + pExampleCheckerBundle->CreateChecker("exampleMetadataChecker", "This is a description of metadata checker"); + const std::string third_rule_uid = "asam.net:xodr:1.0.0:third_rule_name"; + pExampleMetadataChecker->AddRule(new cRule(third_rule_uid)); + pExampleMetadataChecker->AddMetadata( new cMetadata("run date", "2024/06/06", "Date in which the checker was executed")); - pExampleRuleUIDChecker->AddMetadata( + pExampleMetadataChecker->AddMetadata( new cMetadata("reference project", "project01", "Name of the project that created the checker")); // Create a test checker with Issue and RuleUID cChecker *pExampleIssueRuleChecker = pExampleCheckerBundle->CreateChecker( "exampleIssueRuleChecker", "This is a description of checker with issue and the involved ruleUID"); - + const std::string fourth_rule_uid = "asam.net:xodr:1.0.0:fourth_rule_name"; + pExampleIssueRuleChecker->AddRule(new cRule(fourth_rule_uid)); pExampleIssueRuleChecker->AddIssue( - new cIssue("This is an information from the demo usecase", ERROR_LVL, "test.com::qwerty.qwerty")); + new cIssue("This is an information from the demo usecase", ERROR_LVL, fourth_rule_uid)); - // Create a test checker with Issue and RuleUID + // Create a checker with skipped status cChecker *pSkippedChecker = pExampleCheckerBundle->CreateChecker( "exampleSkippedChecker", "This is a description of checker with skipped status", "Skipped execution", "skipped"); @@ -205,6 +199,8 @@ void RunChecks(const cParameterContainer &inputParams) // Create a test checker with an inertial location cChecker *pExampleDomainChecker = pExampleCheckerBundle->CreateChecker( "exampleDomainChecker", "This is a description of example domain info checker"); + const std::string fifth_rule_uid = "asam.net:xodr:1.0.0:fifth_rule_name"; + pExampleDomainChecker->AddRule(new cRule(fifth_rule_uid)); std::list listDomainSpecificInfo; std::string xmlString = @@ -212,7 +208,7 @@ void RunChecks(const cParameterContainer &inputParams) listDomainSpecificInfo.push_back(new cDomainSpecificInfo(getRootFromString(xmlString), "domain info test")); pExampleDomainChecker->AddIssue( - new cIssue("This is an information from the demo usecase", INFO_LVL, listDomainSpecificInfo)); + new cIssue("This is an information from the demo usecase", INFO_LVL, fifth_rule_uid, listDomainSpecificInfo)); // Lets add a summary for the checker bundle unsigned int issueCount = pExampleCheckerBundle->GetIssueCount(); @@ -228,26 +224,3 @@ void RunChecks(const cParameterContainer &inputParams) pResultContainer.Clear(); XMLPlatformUtils::Terminate(); } - -void WriteEmptyReport() -{ - cResultContainer emptyReport; - cCheckerBundle *pCheckerBundle = new cCheckerBundle(CHECKER_BUNDLE_NAME); - - emptyReport.AddCheckerBundle(pCheckerBundle); - - std::stringstream ssDefaultResultFile; - ssDefaultResultFile << CHECKER_BUNDLE_NAME << ".xqar"; - pCheckerBundle->SetParam("strResultFile", ssDefaultResultFile.str()); - - pCheckerBundle->CreateChecker("exampleChecker"); - - std::stringstream ssReportFile; - ssReportFile << CHECKER_BUNDLE_NAME << ".xqar"; - - std::cout << std::endl; - std::cout << "Write empty report: '" << ssReportFile.str() << "'" << std::endl << std::endl; - emptyReport.WriteResults(ssReportFile.str()); - - std::cout << "Finished." << std::endl; -} diff --git a/examples/checker_bundle_example/src/main.h b/examples/checker_bundle_example/src/main.h index d1e41783..1f45ff64 100644 --- a/examples/checker_bundle_example/src/main.h +++ b/examples/checker_bundle_example/src/main.h @@ -35,8 +35,3 @@ void ShowHelp(const std::string &applicationName); * Runs the checks */ void RunChecks(const cParameterContainer &inputParams); - -/* - * Writes an empty Report - */ -void WriteEmptyReport(); diff --git a/include/common/result_format/c_checker_bundle.h b/include/common/result_format/c_checker_bundle.h index 750fafb1..7ff8f34d 100644 --- a/include/common/result_format/c_checker_bundle.h +++ b/include/common/result_format/c_checker_bundle.h @@ -59,12 +59,6 @@ class cCheckerBundle cChecker *CreateChecker(const std::string &checkerId, const std::string &strDescription = "", const std::string &strSummary = "", const std::string &strStatus = "completed"); - /* - * Adds an amout of issues to the checker bundle - */ - cChecker *CreateCheckerWithIssues(const std::string &strCheckerId, const std::string &strDescription, - eIssueLevel issueLevel, std::map m_Issues); - /* * Returns a checker by its Id * \return Returns a checker instance or nullptr diff --git a/include/common/result_format/c_issue.h b/include/common/result_format/c_issue.h index 3dd455bb..df840b5f 100644 --- a/include/common/result_format/c_issue.h +++ b/include/common/result_format/c_issue.h @@ -51,16 +51,10 @@ class cIssue : public IResult * Creates a new Issue * */ - cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID = "", + cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID, cLocationsContainer *locationsContainer = nullptr, cDomainSpecificInfo *domainSpecificInfo = nullptr); - /* - * Creates a new Issue - * - */ - cIssue(const std::string &description, eIssueLevel infoLvl, std::list listLoc); - - cIssue(const std::string &description, eIssueLevel infoLvl, + cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID, std::list listDomainSpecificInfo); cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID, diff --git a/qc_framework/tests/test_data/3step_config.xml b/qc_framework/tests/test_data/3step_config.xml index 74c932d3..8741a6ec 100644 --- a/qc_framework/tests/test_data/3step_config.xml +++ b/qc_framework/tests/test_data/3step_config.xml @@ -6,6 +6,12 @@ + + + + + + diff --git a/src/common/src/result_format/c_checker_bundle.cpp b/src/common/src/result_format/c_checker_bundle.cpp index 5d356cde..e385fe95 100644 --- a/src/common/src/result_format/c_checker_bundle.cpp +++ b/src/common/src/result_format/c_checker_bundle.cpp @@ -157,26 +157,6 @@ cChecker *cCheckerBundle::CreateChecker(const std::string &checkerId, const std: return CreateChecker(new cChecker(checkerId, strDescription, strSummary, strStatus)); } -cChecker *cCheckerBundle::CreateCheckerWithIssues(const std::string &strCheckerId, const std::string &strDescription, - eIssueLevel issueLevel, std::map m_Issues) -{ - cChecker *pChecker = new cChecker(strCheckerId, strDescription, "", "completed"); - CreateChecker(pChecker); - - for (std::map::const_iterator it = m_Issues.cbegin(); it != m_Issues.cend(); it++) - { - std::stringstream ss_descriptionStream; - - ss_descriptionStream << it->first << " = " << it->second; - - pChecker->AddIssue(new cIssue(ss_descriptionStream.str(), issueLevel)); - } - - pChecker->UpdateSummary(); - - return pChecker; -} - // Deletes all checkers void cCheckerBundle::Clear() { diff --git a/src/common/src/result_format/c_issue.cpp b/src/common/src/result_format/c_issue.cpp index bc12fe0b..1764ce03 100644 --- a/src/common/src/result_format/c_issue.cpp +++ b/src/common/src/result_format/c_issue.cpp @@ -36,15 +36,9 @@ cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, const std::s AddDomainSpecificInfo(domainSpecificInfo); } -cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, std::list listLoc) - : cIssue(description, infoLvl) -{ - AddLocationsContainer(listLoc); -} - -cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, +cIssue::cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID, std::list listDomainSpecificInfo) - : cIssue(description, infoLvl) + : cIssue(description, infoLvl, ruleUID) { AddDomainSpecificInfo(listDomainSpecificInfo); } diff --git a/test/function/examples/example_checker_bundle/files/DemoCheckerBundle.xqar b/test/function/examples/example_checker_bundle/files/DemoCheckerBundle.xqar deleted file mode 100644 index 0e3eac79..00000000 --- a/test/function/examples/example_checker_bundle/files/DemoCheckerBundle.xqar +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/test/function/examples/example_checker_bundle/files/DemoCheckerBundle_config.xml b/test/function/examples/example_checker_bundle/files/DemoCheckerBundle_config.xml index fc533a59..8f7170ad 100644 --- a/test/function/examples/example_checker_bundle/files/DemoCheckerBundle_config.xml +++ b/test/function/examples/example_checker_bundle/files/DemoCheckerBundle_config.xml @@ -13,6 +13,12 @@ with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + + + + + + diff --git a/test/function/examples/example_checker_bundle/src/example_checker_bundle_tester.cpp b/test/function/examples/example_checker_bundle/src/example_checker_bundle_tester.cpp index c1c879cf..57478c75 100644 --- a/test/function/examples/example_checker_bundle/src/example_checker_bundle_tester.cpp +++ b/test/function/examples/example_checker_bundle/src/example_checker_bundle_tester.cpp @@ -27,19 +27,6 @@ TEST_F(cTesterExampleCheckerBundle, CmdBasic) ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); } -TEST_F(cTesterExampleCheckerBundle, CmdDefaultConfig) -{ - std::string strResultMessage; - - std::string strDefaultConfigFilePath = strWorkingDir + "/" + std::string(MODULE_NAME) + ".xqar"; - - TestResult nRes = ExecuteCommand(strResultMessage, MODULE_NAME, "--defaultconfig"); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); - - nRes |= CheckFileExists(strResultMessage, strDefaultConfigFilePath); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); -} - TEST_F(cTesterExampleCheckerBundle, CmdConfig) { std::string strResultMessage; @@ -77,26 +64,6 @@ TEST_F(cTesterExampleCheckerBundle, CmdConfigContainsIssue) fs::remove(strResultFilePath.c_str()); } -TEST_F(cTesterExampleCheckerBundle, CmdXodr) -{ - std::string strResultMessage; - - std::string strXodrFilePath = "../stimuli/xodr_examples/three_connected_roads_with_steps.xodr"; - std::string strResultFilePath = strWorkingDir + "/" + std::string(MODULE_NAME) + ".xqar"; - std::string strXsdFilePath = strTestFilesDir + "/../../../doc/schema/xqar_result_format.xsd"; - - TestResult nRes = ExecuteCommand(strResultMessage, MODULE_NAME, strXodrFilePath); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); - - nRes |= CheckFileExists(strResultMessage, strResultFilePath, false); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); - - nRes |= ValidateXmlSchema(strResultFilePath, strXsdFilePath); - ASSERT_TRUE_EXT(nRes == TestResult::ERR_NOERROR, strResultMessage.c_str()); - - fs::remove(strResultFilePath.c_str()); -} - TEST_F(cTesterExampleCheckerBundle, CmdConfigFileNotFound) { std::string strResultMessage;