Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify cpp checker bundle example and update cpp baselib #199

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 24 additions & 51 deletions examples/checker_bundle_example/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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";
}

Expand Down Expand Up @@ -170,49 +157,58 @@ 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<cLocationsContainer *> 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");

// 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<cDomainSpecificInfo *> listDomainSpecificInfo;

std::string xmlString =
"<DomainSpecificInfo name=\"test_domain\"><RoadLocation id=\"aa\" b=\"5.4\" c=\"0.0\"/></DomainSpecificInfo>";

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();
Expand All @@ -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;
}
5 changes: 0 additions & 5 deletions examples/checker_bundle_example/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@ void ShowHelp(const std::string &applicationName);
* Runs the checks
*/
void RunChecks(const cParameterContainer &inputParams);

/*
* Writes an empty Report
*/
void WriteEmptyReport();
6 changes: 0 additions & 6 deletions include/common/result_format/c_checker_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> m_Issues);

/*
* Returns a checker by its Id
* \return Returns a checker instance or nullptr
Expand Down
10 changes: 2 additions & 8 deletions include/common/result_format/c_issue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<cLocationsContainer *> listLoc);

cIssue(const std::string &description, eIssueLevel infoLvl,
cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID,
std::list<cDomainSpecificInfo *> listDomainSpecificInfo);

cIssue(const std::string &description, eIssueLevel infoLvl, const std::string &ruleUID,
Expand Down
6 changes: 6 additions & 0 deletions qc_framework/tests/test_data/3step_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<CheckerBundle application="DemoCheckerBundle">
<Param name="strResultFile" value="DemoCheckerBundle.xqar" />
<Checker checkerId="exampleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleInertialChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleMetadataChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleIssueRuleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleSkippedChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleDomainChecker" maxLevel="1" minLevel="3" />
</CheckerBundle>

<ReportModule application="TextReport">
Expand Down
20 changes: 0 additions & 20 deletions src/common/src/result_format/c_checker_bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string> m_Issues)
{
cChecker *pChecker = new cChecker(strCheckerId, strDescription, "", "completed");
CreateChecker(pChecker);

for (std::map<std::string, std::string>::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()
{
Expand Down
10 changes: 2 additions & 8 deletions src/common/src/result_format/c_issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cLocationsContainer *> 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<cDomainSpecificInfo *> listDomainSpecificInfo)
: cIssue(description, infoLvl)
: cIssue(description, infoLvl, ruleUID)
{
AddDomainSpecificInfo(listDomainSpecificInfo);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
<CheckerBundle application="DemoCheckerBundle">
<Param name="strResultFile" value="DemoCheckerBundle.xqar" />
<Checker checkerId="exampleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleInertialChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleMetadataChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleIssueRuleChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleSkippedChecker" maxLevel="1" minLevel="3" />
<Checker checkerId="exampleDomainChecker" maxLevel="1" minLevel="3" />
</CheckerBundle>

</Config>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading