diff --git a/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml b/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml index cdfd6d5d..27ffd17a 100644 --- a/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml +++ b/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml @@ -177,7 +177,7 @@ raw - makeError \( \S+ , \S+ , \S+ , 0 + makeError \( \S+ , 0 fatal_program_exit warning diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat index 52911241..fb812ddd 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat @@ -1,6 +1,4 @@ 00001,QualityGates does not run successfully !!! -00010,Assertion return error: $1 -00011,Assertion works: $1 00020,The function $1 is not implemented. 00021,Start quality gate $1. 00022,Calculate sources for quality gate $1. diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgCtrlppCheck.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgCtrlppCheck.cat index 0fd797b3..21d3fc0b 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgCtrlppCheck.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgCtrlppCheck.cat @@ -1,2 +1,26 @@ -assert.hasErr,$file -reason.hasErr,$errText +# an Ctrlppcheck error may contains following keys +# possible values +# id +# severity +# msg +# verbose +# path +# path0 +# line +# cwe +# special case for logging +# relPath - relative path in unix format + +#assertions are per severity (error, warning, style, performance, portability or information) +assert.has_error,ERROR in $relPath at line $line +reason.has_error,$msg ($id) +assert.has_warning,WARNING in $relPath at line $line +reason.has_warning,$msg ($id) +assert.has_style,STYLE in $relPath at line $line +reason.has_style,$msg ($id) +assert.has_performance,PERFORMANCE in $relPath at line $line +reason.has_performance,$msg ($id) +assert.has_portability,PORTABILITY in $relPath at line $line +reason.has_portability,$msg ($id) +assert.has_information,INFO in $relPath at line $line +reason.has_information,$msg ($id) diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgResult.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgResult.cat new file mode 100644 index 00000000..4faa5649 --- /dev/null +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgResult.cat @@ -0,0 +1,3 @@ +00001,Assertion return error: $1 +00002,Assertion works: $1 +00003,Assertion return an acceptable error (known bug): $1 \ No newline at end of file diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_OverloadedFiles.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_OverloadedFiles.cat index 3a023e3c..8a6871c5 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_OverloadedFiles.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_OverloadedFiles.cat @@ -1,6 +1,8 @@ -assert.isCheater,Check if file $location is overloaded. -reason.isCheater,It is not allowed to overwrite WinCCOA-license check files: $file.name -filesList,Files +filesList,Check files in $projectPath +# possible dollars +# location - checked file relative path in Linux format +# file.name - file name +# file.isOverloadedFrom - the overloaded file (form sub project or WinCC OA) assert.isOverloaded,Check if file $location is overloaded. reason.isOverloaded,The file '$file.name' is overloaded from '$file.isOverloadedFrom'. assert.isOverloadedAllowed,Check if file $location is overloaded (allowed overloads). diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgSyntaxCheck.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgSyntaxCheck.cat index ece4e6bd..63750f4a 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgSyntaxCheck.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgSyntaxCheck.cat @@ -1,3 +1,6 @@ + +syntaxMsgs + assert.missingFiles,Has files reason.missingFiles,Application doesn´t contain any scripts, libs or panels. syntaxMsgs,Details diff --git a/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat b/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat index 52911241..fb812ddd 100644 --- a/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat +++ b/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat @@ -1,6 +1,4 @@ 00001,QualityGates does not run successfully !!! -00010,Assertion return error: $1 -00011,Assertion works: $1 00020,The function $1 is not implemented. 00021,Start quality gate $1. 00022,Calculate sources for quality gate $1. diff --git a/WinCCOA_QualityChecks/msg/en_US.utf8/QgCtrlppCheck.cat b/WinCCOA_QualityChecks/msg/en_US.utf8/QgCtrlppCheck.cat index 0fd797b3..21d3fc0b 100644 --- a/WinCCOA_QualityChecks/msg/en_US.utf8/QgCtrlppCheck.cat +++ b/WinCCOA_QualityChecks/msg/en_US.utf8/QgCtrlppCheck.cat @@ -1,2 +1,26 @@ -assert.hasErr,$file -reason.hasErr,$errText +# an Ctrlppcheck error may contains following keys +# possible values +# id +# severity +# msg +# verbose +# path +# path0 +# line +# cwe +# special case for logging +# relPath - relative path in unix format + +#assertions are per severity (error, warning, style, performance, portability or information) +assert.has_error,ERROR in $relPath at line $line +reason.has_error,$msg ($id) +assert.has_warning,WARNING in $relPath at line $line +reason.has_warning,$msg ($id) +assert.has_style,STYLE in $relPath at line $line +reason.has_style,$msg ($id) +assert.has_performance,PERFORMANCE in $relPath at line $line +reason.has_performance,$msg ($id) +assert.has_portability,PORTABILITY in $relPath at line $line +reason.has_portability,$msg ($id) +assert.has_information,INFO in $relPath at line $line +reason.has_information,$msg ($id) diff --git a/WinCCOA_QualityChecks/msg/en_US.utf8/QgResult.cat b/WinCCOA_QualityChecks/msg/en_US.utf8/QgResult.cat new file mode 100644 index 00000000..4faa5649 --- /dev/null +++ b/WinCCOA_QualityChecks/msg/en_US.utf8/QgResult.cat @@ -0,0 +1,3 @@ +00001,Assertion return error: $1 +00002,Assertion works: $1 +00003,Assertion return an acceptable error (known bug): $1 \ No newline at end of file diff --git a/WinCCOA_QualityChecks/msg/en_US.utf8/QgStaticCheck_OverloadedFiles.cat b/WinCCOA_QualityChecks/msg/en_US.utf8/QgStaticCheck_OverloadedFiles.cat index 3a023e3c..8a6871c5 100644 --- a/WinCCOA_QualityChecks/msg/en_US.utf8/QgStaticCheck_OverloadedFiles.cat +++ b/WinCCOA_QualityChecks/msg/en_US.utf8/QgStaticCheck_OverloadedFiles.cat @@ -1,6 +1,8 @@ -assert.isCheater,Check if file $location is overloaded. -reason.isCheater,It is not allowed to overwrite WinCCOA-license check files: $file.name -filesList,Files +filesList,Check files in $projectPath +# possible dollars +# location - checked file relative path in Linux format +# file.name - file name +# file.isOverloadedFrom - the overloaded file (form sub project or WinCC OA) assert.isOverloaded,Check if file $location is overloaded. reason.isOverloaded,The file '$file.name' is overloaded from '$file.isOverloadedFrom'. assert.isOverloadedAllowed,Check if file $location is overloaded (allowed overloads). diff --git a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl b/WinCCOA_QualityChecks/scripts/QgTemplate.ctl deleted file mode 100644 index e24f476c..00000000 --- a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl +++ /dev/null @@ -1,57 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir" -#uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/QgBase" - -class QgTemplate : QgBase -{ - - public int setUp() - { - if (QgBase::setUp()) - return -1; - -// _sourceDir.create(); -// _pictures.setDir(_sourceDir.getDirPath + PICTURES_REL_PATH); - _pictures.setDir(WINCCOA_PATH + PICTURES_REL_PATH); - return 0; - } - - public int calculate() - { - return _pictures.calculate(); - } - - public int validate() - { - return _pictures.validate(); - } - - public mapping getStoreResult() - { - return _pictures.result.toMap(); - } - - public int tearDown() - { - _sourceDir.cleanUp(); - return QgBase::tearDown(); - } - - PicturesDir _pictures = PicturesDir(); -}; - -main() -{ - Qg::setId("QgTemplate"); - QgTemplate qg = QgTemplate(); - exit(qg.start()); -} diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl index e916847e..2c1d0fcc 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl @@ -12,6 +12,7 @@ #uses "classes/QualityGates/Qg" #uses "classes/QualityGates/QgBase" #uses "classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck" +#uses "classes/QualityGates/QgResult" //-------------------------------------------------------------------------------- // declare variables and constans @@ -32,7 +33,7 @@ class QgStaticCheck_OverloadedFiles : QgBase if (QgBase::setUp()) return -1; - QgVersionResult::showErrorsOnly = TRUE; + QgResult::showErrorsOnly = TRUE; return 0; } diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl index 19d88a13..f98d2658 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl @@ -44,7 +44,7 @@ class QgStaticPanelCheck : QgBase _panels.setDir(this.checkedPath + PANELS_REL_PATH); if (!_panels.exists()) - setMinValidScore("QgStaticCheck_Panels", "assert.missingPanels", "reason.missingPanels"); + this.setMinValidScore("QgStaticCheck_Panels", "missingPanels"); return 0; } diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl index 809ffbe5..d1461016 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl @@ -43,7 +43,7 @@ class QgStaticCheck_Pictures : QgBase _pictures.setDir(this.checkedPath); if (!_pictures.exists()) - setMinValidScore("QgStaticCheck_Pictures", "assert.missingPictures", "reason.missingPictures"); + this.setMinValidScore("QgStaticCheck_Pictures", "missingPictures"); return 0; } diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl index fe456a45..77d8a81e 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl @@ -44,6 +44,10 @@ class QgStaticCheck_Scripts : QgBase { this.checkedPath = PROJ_PATH + SCRIPTS_REL_PATH; } + else if (isdir(this.checkedPath + SCRIPTS_REL_PATH)) + { + this.checkedPath = this.checkedPath + SCRIPTS_REL_PATH; + } _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::scripts); @@ -54,13 +58,19 @@ class QgStaticCheck_Scripts : QgBase { this.checkedPath = PROJ_PATH + LIBS_REL_PATH; } + else if (isdir(this.checkedPath + LIBS_REL_PATH)) + { + this.checkedPath = this.checkedPath + LIBS_REL_PATH; + } _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::libs); } + ogger.info(0, "Path to check", this.checkedPath)); + if (!_scriptsData.exists()) - setMinValidScore(Qg::getId(), "assert.missingScripts", "reason.missingScripts"); + this.setMinValidScore(Qg::getId(), "missingScripts"); return 0; } @@ -81,7 +91,7 @@ class QgStaticCheck_Scripts : QgBase isdir(this.checkedPath + LIBS_REL_PATH) && (_scriptsData.getCountOfSubDirs() <= 0)) { // there are no scripts. Libs only and libs are checked in QgStaticCheck_Libs - setMinValidScore("QgStaticCheck_Scripts", "assert.missingScripts", "reason.missingScripts"); + this.setMinValidScore("QgStaticCheck_Scripts", "missingScripts"); return 0; } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl index 30b8c7da..6703c8cd 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl @@ -10,8 +10,7 @@ #uses "classes/FileSys/QgDir" #uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/QgApp" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir" +#uses "classes/QualityGates/QgTest" class QgAddOnResultsDir { @@ -100,18 +99,15 @@ class QgAddOnResultsDir public string getDirPath() { - if (_resultDir == "") + if (_resultDir != "") + return _resultDir; + + if (!QgTest::isStartedByTestFramework()) { - if (!Qg::isRunningOnJenkins()) - { - // projPath should be used, when Jenkins is not used - _resultDir = makeNativePath(PROJ_PATH + DATA_REL_PATH + "QualityGates/" + _qgId + "/" + _buildNo + "/"); - } - else - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _resultDir = makeNativePath(app.getSourcePath() + "QgResult/" + Qg::getId() + "/"); - } + // When you start some locale tests, proj path will be used + // the test-framework does not need it, because results are stored in + // test-framework comform format automatically. + _resultDir = makeNativePath(PROJ_PATH + DATA_REL_PATH + "QualityGates/" + _qgId + "/" + _buildNo + "/"); } return _resultDir; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl deleted file mode 100644 index 650765d9..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl +++ /dev/null @@ -1,32 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgApp" - - -class QgAddOnSourceDir -{ - public QgAddOnSourceDir() - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _dirPath = makeNativePath(app.getSourcePath() + "appData/" + app.getExtendedTechnicalName() + "/"); - } - - public string getDirPath() - { - return makeNativePath(_dirPath); - } - - public bool exists() - { - return (_dirPath != "" && isdir(_dirPath)); - } - - string _dirPath; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl deleted file mode 100644 index c801b340..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl +++ /dev/null @@ -1,70 +0,0 @@ - -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgApp" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir" - -class QgAddOnTmpSourceDir -{ - public QgAddOnTmpSourceDir() - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _tmpSourceDir = makeNativePath(app.getSourcePath() + "tmpSource/"); - } - - public bool exists() - { - return (_tmpSourceDir != "" && isdir(_tmpSourceDir)); - } - - public int create() - { - if (exists()) - cleanUp(); - - QgAddOnSourceDir source = QgAddOnSourceDir(); - - if (!source.exists()) - { - DebugFTN("QgAddOnTmpSourceDir", "Could not find source packet", source.getDirPath()); - return -1; - } - - if (!isdir(_tmpSourceDir)) - mkdir(_tmpSourceDir); - - copyAllFilesRecursive(source.getDirPath(), _tmpSourceDir); - - if (!exists()) - return -2; - - return 0; - } - - public int cleanUp() - { - if (exists()) - return rmdir(_tmpSourceDir, TRUE); - - return 0; - } - - public string getDirPath() - { - return makeNativePath(_tmpSourceDir); - } - - public string trimPath(const string &fullPath) - { - return substr(fullPath, strlen(getDirPath())); - } - - string _tmpSourceDir; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl deleted file mode 100644 index f7a58222..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl +++ /dev/null @@ -1,246 +0,0 @@ - -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/AddOn/Output/QgAddOnScore" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" - -enum QgAddOnResultState -{ - success, - warning, - failed, - error -}; - - -class QgAddOnResult -{ - //-------------------------------------------------------------------------------- -//@public members -//-------------------------------------------------------------------------------- - public static const float MIN_VALID_SCORE = 1.0; - public static const float NOT_VALID_SCORE = 0.0; - public static const string KEY_SCORE_REASON = "Reason"; - public static const string KEY_SCORE_PERCENT = "%"; - public static const string KEY_SCORE_TOTAL_POINTS = "Total points"; - public static const string KEY_SCORE_ERROR_POINTS = "Error points"; - - public static const string KEY_QG_RESULT_TESTVERSION = "qgTestVersionResults"; - public static const string KEY_QG_RESULT_SUM = "qgSummary"; - public static const string KEY_QG_RESULT_SCORE = "score"; - - - public QgAddOnResult() - { - } - - public void setData(const mapping &data) - { - _data = data; - } - - public void setErr(int prio, int code, string note = "") - { - if (prio == PRIO_FATAL) - prio = PRIO_SEVERE; - - errClass err; - - if (note == "") - err = makeError("QgAddOnResultErr", prio, ERR_CONTROL, code, Qg::getId()); - else - err = makeError("QgAddOnResultErr", prio, ERR_CONTROL, code, Qg::getId(), note); - - throwError(err); - DebugFTN("QgAddOnResult", getStackTrace()); - - switch (prio) - { - case PRIO_INFO: - setState(QgAddOnResultState::success); - break; - - case PRIO_WARNING: - setState(QgAddOnResultState::warning); - break; - - case PRIO_SEVERE: - setState(QgAddOnResultState::failed); - break; - - default: - setState(QgAddOnResultState::error); - break; - } - - _hasErr = TRUE; - } - - public int calculate() - { - DebugFTN("QgAddOnResult", __FUNCTION__); - setState(QgAddOnResultState::success); - return 0; - } - - public void addScore(int score) - { - - if (mappingHasKey(_data, "score")) - score = _data["score"]; - - QgAddOnScore scoreFile = QgAddOnScore(); - scoreFile.addScore(score); - _score = score; - } - - public void setState(QgAddOnResultState state) - { - _state = state; - } - - public string stateToString() - { - switch (_state) - { - case QgAddOnResultState::success: - return "success"; - - case QgAddOnResultState::warning: - return "warning"; - - case QgAddOnResultState::error: - return "error"; - - case QgAddOnResultState::failed: - { - ///@todo 05.06.2018 lschopp: remove the option QgAddOnResultState::failed - DebugFTN("QgAddOnResult", __FUNCTION__, "obsolete option"); - return "error"; - } - } - - DebugFTN("QgAddOnResult", __FUNCTION__, "internall error, this state does not exists", _state); - return ""; - } - - public int publish() - { - if (!_resDir.exists()) - _resDir.create(); - - if (!_hasErr && calculate()) - { - DebugFTN("QgAddOnResult", __FUNCTION__, "calculate does not work"); - return -3; - } - - file f = fopen(_resDir.getDirPath() + "_state", "wb+"); - - if (ferror(f)) - { - return -2; - } - - fputs(stateToString(), f); - fclose(f); - - f = fopen(_resDir.getDirPath() + "_data", "wb+"); - - string json; - - if (mappingHasKey(_data, "qgSummary")) - json = jsonEncode(_data["qgSummary"]); - else - json = jsonEncode(_data); - -// strreplace(json, "&", ""); - fputs(json, f); - fclose(f); - - // due to the current state, the score and exitCode are updated - int exitCode; - - switch (_state) - { - case QgAddOnResultState::success: - addScore(2); - exitCode = 0; - break; - - case QgAddOnResultState::warning: - addScore(1); - exitCode = 0; - break; - - case QgAddOnResultState::failed: - addScore(-1); - exitCode = 0; - break; - - case QgAddOnResultState::error: - addScore(-1); - exitCode = 0; - break; - - default: - DebugFTN("QgAddOnResult", __FUNCTION__, "internall error, this state does not exists", _state); - addScore(0); - exitCode = 0; - } - - if (mappingHasKey(_data, "qgTestVersionResults")) - { - string path = _resDir.getDirPath() + "QgTestVersion/"; - - mkdir(path); - - int testId = Qg::idToNum(); - - if (testId <= 0) - { - DebugFTN("QgAddOnResult", __FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); - return -4; - } - - f = fopen(path + "_Id", "wb+"); - fputs((string)testId, f); - fclose(f); - - f = fopen(path + "_Results", "wb+"); - json = jsonEncode(_data["qgTestVersionResults"]); - -// strreplace(json, "&", ""); - - fputs(json, f); - fclose(f); - - f = fopen(path + "_Score", "wb+"); - fputs((string)_score, f); - fclose(f); - } - - - - return exitCode; - } - - public string getResultDirPath() - { - return _resDir.getDirPath(); - } - - QgAddOnResultsDir _resDir = QgAddOnResultsDir(); - protected mapping _data; - QgAddOnResultState _state; - bool _hasErr; - int _score; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl deleted file mode 100644 index cfb61e4a..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl +++ /dev/null @@ -1,31 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" - - -class QgAddOnScore -{ - public QgAddOnScore() - { - } - - /** - - @deprecated since 06.05.2018 +lSchopp dismiss score per version - @param score - @return errcode - */ - public int addScore(int score) - { - return 0; - } - - QgAddOnResultsDir _resDir = QgAddOnResultsDir(); -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl index 5c27f905..dff15ae6 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl @@ -8,15 +8,9 @@ // //-------------------------------------------------------------------------------- -// used libraries (#uses) - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -/*! @brief Quality-Gate base utils. +/*! Quality-Gate base utils. * - * @details Base utilitys to handle with QualityGate. + * @details Base utilities to handle with QualityGate. * @author lschopp */ class Qg @@ -25,7 +19,7 @@ class Qg //@public members //-------------------------------------------------------------------------------- //------------------------------------------------------------------------------ - /** @brief Function returns id for current QualityGate. + /** Function returns id for current QualityGate. @return ID of QualityGate. @exception 0 when ID are not setted. */ @@ -35,48 +29,17 @@ class Qg } //------------------------------------------------------------------------------ - /** @brief Function set id for current QualityGate. + /** Function set id for current QualityGate. @details Each QualityGate must have unique ID to handle with result files. @warning This ID is loaded "global" in the manager. It can not be quered by other manager at the same time. @param id QualityGate ID. */ - public static void setId(const string id) + public static void setId(const string &id) { _id = id; } - //------------------------------------------------------------------------------ - /** @brief Function returns all defined QualityGate IDs. - @warning This list muss be equal to store-DB. in other case can not be results - imported in store-DB. - @return List with all QG-IDs. - */ - public static dyn_string getAllIds() - { - return makeDynString("QgStaticCheck_Pictures", "QgStaticCheck_Scripts", "QgStaticCheck_Panels", - "QgSyntaxCheck", - "QgStaticCheck_OverloadedFiles", "Documentation", - "UnitTests", "CtrlCoverage", "QgCtrlppCheck", - "QgStaticCheck_Libs"); - } - - //------------------------------------------------------------------------------ - /** @brief Function converts current QG-ID to int variable. - @details We need this convert for backend (store). - @return - */ - public static int idToNum() - { - return dynContains(getAllIds(), getId()); - } - - //------------------------------------------------------------------------------ - public static bool isRunningOnJenkins() - { - return (getenv("WORKSPACE") != ""); - } - //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl deleted file mode 100644 index 29776d74..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl +++ /dev/null @@ -1,406 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2023 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "CtrlPv2Admin" - -//--------------------------------------------------------------------------------------------------------------------------------------- -class QgApp -{ - //------------------------------------------------------------------------------------------------------------------------------------- - public QgApp(string id = "") - { - _isValid = FALSE; - - if (id == "") - { - /// @todo I think we can remove this class, because always ends here. - DebugFTN("QgApp", "!!! Parameter #1 (id) is missing"); - return; - } - - _id = id; - string optsPath = _getPath() + "opts.json"; - DebugFTN("QgApp", __FUNCTION__, optsPath); - - if (!isfile(optsPath)) - { - DebugFTN("QgApp", "!!! options file does not exists:", optsPath); - return; - } - - string json; - fileToString(optsPath, json); - _options = jsonDecode(json); - - string resDir = _getResultsDir(); - - if (isdir(resDir)) - mkdir(resDir); - - _isValid = TRUE; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public static QgApp getAppFromProjName(const string projName = PROJ) - { - // parse WinCCOA_FinalyApi_22 to app id - dyn_string items = strsplit(projName, "_"); - - if (dynlen(items) < 3) - { - QgApp app = QgApp(); - return app; - } - - QgApp app = QgApp(items[3]); - return app; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - /** - Function creates new not runnable project. - - @return error code. Succes == 0 - */ - public int makeProj() - { - const string appName = getExtendedTechnicalName(); - // const string appName = getAppName(); - string sourcePath = _getPath() + "appData/" + appName; - const string projName = _getProjName(); - const string destPath = _getProjPath(); - - int rc; - dyn_string names, versions, paths; - - if (!isdir(sourcePath)) - { - DebugFTN("QgApp", __FUNCTION__, "source dir does not exist", sourcePath, _id); - return -2; - } - - paGetProjs(names, versions, paths); - - if (dynContains(names, projName) > 0) //Project is registered - paDelProj(projName, TRUE); - else if (isdir(destPath)) - rmdir(destPath, TRUE); - - dyn_string langs; - - if (dynlen(langs) <= 0) - { - for (int i = 0 ; i < getNoOfLangs(); i++) - langs[i + 1] = getLocale(i); - } - - // proj without DB - DebugFTN("QgApp", __FUNCTION__, "crete new project", _getProjName(), dirName(_getProjPath()), langs); - rc = paCreateProj(_getProjName(), dirName(_getProjPath()), - langs, - 1, "System1", // system num / name - 2, // without DB - "" // no ascii list - ); - - if (rc) - { - DebugFTN("QgApp", "!!! could not create new project", rc); - return -3; - } - - // set proj NOT runnable - paSetProjRunnable(projName, FALSE); - - sourcePath = sourcePath + "/"; - // copy content to the project - const string destPath = _getProjPath(); - const dyn_string simpleDirs = makeDynString(SCRIPTS_REL_PATH, PANELS_REL_PATH, MSG_REL_PATH, - COLORDB_REL_PATH, DATA_REL_PATH, DPLIST_REL_PATH, - HELP_REL_PATH, PICTURES_REL_PATH, SOURCE_REL_PATH, - BIN_REL_PATH, IMAGES_REL_PATH, CONFIG_REL_PATH); - - for (int i = 1; i <= dynlen(simpleDirs); i++) - { - string sourceDir = makeNativePath(sourcePath + simpleDirs[i]); - string destDir = makeNativePath(destPath + simpleDirs[i]); - - if ((CONFIG_REL_PATH != simpleDirs[i]) && isdir(destDir)) - { - // clean up WinCC OA dir, that we have only correct dirs / files form version (addOn) - rmdir(destDir, TRUE); - } - else if ((CONFIG_REL_PATH == simpleDirs[i])) - { - DebugFTN("QgApp", sourceDir, isfile(sourceDir + "config"), sourceDir + "config"); - - // remove config file, otherwise you destrou the add on project - //! @todo 06.05.2018: must not be possible - if (isfile(sourceDir + "config")) - remove(sourceDir + "config"); - } - else if ((BIN_REL_PATH == simpleDirs[i]) && !isdir(sourceDir)) - { - // use bin_ - if (isdir(sourceDir + "_" + VERSION)) - sourceDir = sourceDir + "_" + VERSION; - - const int minMinorVersion = 15; - - // copy all bin directories, really hack. - /// @todo remove this code, when multipe pipeline ( per oa version ) are running - /// @warning this works only for WinCC OA major version == 3 - for (int j = 0; j <= 100; j++) - { - int version = minMinorVersion + j; - string sDir = sourceDir + "_3." + version; - string dDir = destDir + "_3." + version; - - if (!isdir(sDir)) - continue; - - if (!copyAllFilesRecursive(sDir, dDir)) - { - DebugFTN("QgApp", "!!! could not copy dir", sDir, dDir); - return -4; - } - } - } - - DebugFTN("QgApp", "try copy", isdir(sourceDir), sourceDir); - - if (!isdir(sourceDir)) - continue; // nothing to do - - DebugFTN("QgApp", "to", destDir); - - if (!copyAllFilesRecursive(sourceDir, destDir)) - { - DebugFTN("QgApp", "!!! could not copy dir", sourceDir, destDir); - return -4; - } - } - - // create AddonInformation.json file - rc = _makeAddOnInfoFile(); - - if (rc) - { - DebugFTN("QgApp", "!!! could not create AddonInformation.json file", rc); - return -5; - } - - // add this project as subProject, so be sure we have intgrated all scripts libs ... - rc = paSetSubProjs(_getProjName(), makeDynString(PROJ)); - - if (rc) - { - DebugFTN("QgApp", "!!! could not set sub projects", rc, _getProjName(), makeDynString(PROJ)); - return -6; - } - - return 0; - } - - public string getExtendedTechnicalName() - { - return getenv("EXTENDED_TECHNICAL_NAME"); - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public string getAppName() - { - if (!mappingHasKey(_options, "data") || - !mappingHasKey(_options["data"], "filename")) - { - return ""; - } - - string filename = _options["data"]["filename"]; - filename = delExt(filename); - - return filename; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public string getVersionProperty(const string &property) - { - if (mappingHasKey(_options, "data") && mappingHasKey(_options["data"], property)) - { - return _options["data"][property]; - } - - return ""; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public bool isValid() - { - return _isValid; - } - - int _makeAddOnInfoFile() - { - // see also https://www.dropbox.com/s/xkc6pasizej2ui2/Auto%20Generierung%20AddonInformation.docx?dl=0 - - const string destPath = _getProjPath(); - const string addOnInfoPath = destPath + DATA_REL_PATH + "AddonInformation.json"; - - - if (!isdir(destPath + DATA_REL_PATH)) - mkdir(destPath + DATA_REL_PATH); // make dir for AddonInformation.json file - - if (isfile(addOnInfoPath)) - moveFile(addOnInfoPath, addOnInfoPath + ".copy"); // make copy of original file (+lShopp) - - if (!mappingHasKey(_options, "data") || !mappingHasKey(_options["data"], "product_id")) - { - DebugFTN("QgApp", __FUNCTION__, "missing product_id", _options); - return -1; - } - - const string productId = _options["data"]["product_id"]; - - string serverUrl = getenv("SERVER_HOST_NAME"); - string token = getenv("WinCCOA_TOKEN"); - - if (serverUrl == "") - serverUrl = "WinCCOA.com"; - - string url = "https://" + token + - serverUrl + - "/rest/products?expand=contractor&filter=%5B%7B++%22property%22%3A+%22id%22%2C++%22value%22%3A+" + - productId + - "%2C++%22operator%22%3A+%22%3D%22%7D%5D"; - mapping result; - int rc = netGet(url, result); - - if (rc || result["httpStatusCode"] != 200) - { - DebugFTN("QgApp", __FUNCTION__, "could not get data from store", url); - DebugFN("QgApp", __FUNCTION__, rc, result); - return -2; - } - - string json; - - if (mappingHasKey(result, "content")) - { - json = result["content"]; - } - - mapping addOnInfo; - mapping data = jsonDecode(json); - - try - { - addOnInfo["addon_extended_technical_name"] = (string)getenv("EXTENDED_TECHNICAL_NAME"); - - addOnInfo["addon_name"] = (string)data["data"][1]["name"]; - addOnInfo["addon_description"] = (string)data["data"][1]["description"]; - addOnInfo["addon_item_number"] = (string)data["data"][1]["item_number"]; - addOnInfo["addon_provider_name"] = (string)data["data"][1]["contractor"]["name"]; - - addOnInfo["version_name"] = (string)_options["data"]["name"]; - addOnInfo["version_internal_id"] = (string)_options["data"]["internal_number"]; - addOnInfo["version_description"] = (string)_options["data"]["description"]; - - } - catch - { - DebugFTN("QgApp", getLastException()); - DebugFTN("QgApp", __FUNCTION__, "mising key ???", "check this url", url, data, _options); - return -3; - } - - - file f = fopen(addOnInfoPath, "wb+"); - fputs(jsonEncode(addOnInfo, FALSE), f); - fclose(f); - - if (!isfile(addOnInfoPath)) - DebugFTN("QgApp", __FUNCTION__, "Check te file", addOnInfoPath); - - return 0; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - string _getResultsDir() - { - return makeNativePath(_getPath() + "_results/"); - } - - public string getSourcePath() - { - return _getPath(); - } - //------------------------------------------------------------------------------------------------------------------------------------- - string _getPath() - { - string dir = getenv("WORKSPACE"); - - if ((dir != "") && isdir(dir)) - return makeNativePath(dir + "/"); - - if (_id == "") - return ""; - - if (_WIN32) - { - string tmpDir = dirName(tmpnam()); - return makeNativePath(tmpDir + "WinCCOA/apps/" + _id + "/"); - } - else if (_UNIX) - return makeNativePath("/tmp/WinCCOA/apps/" + _id + "/"); - else - return ""; - } - - public string getProjName() - { - return _getProjName(); - } - //------------------------------------------------------------------------------------------------------------------------------------- - string _getProjName() - { - return "WinCCOA_FinalyApi_" + _id; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - string _getProjPath(const string relPath = "") - { - return makeNativePath(_getPath() + _getProjName() + "/" + relPath); - } - - //------------------------------------------------------------------------------------------------------------------------------------- - // members - string _id; - bool _isValid; - - /* - { - "id":22, - "product_id":6, - "name":"2", - "filename":"Shift_Calender.zip", - "created_at":"2017-08-29 09:08:48", - "created_by":5, - "updated_by":4, - "updated_at":"2017-12-09 08:12:09", - "is_feature":0, - "is_bugfix":1, - "release_date":"1970-01-01", - "description":"Update for new version​ 3.16!", - "internal_number":2, - "internal_filename":"22", - "active":null - } - */ - mapping _options; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl index 66f4becc..6179ae38 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl @@ -10,12 +10,12 @@ //-------------------------------------------------------------------------------- // used libraries (#uses) #uses "classes/ErrorHdl/OaLogger" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir" +#uses "classes/QualityGates/QgBaseError" #uses "classes/QualityGates/QgResultPublisher" #uses "classes/oaTest/OaTest" #uses "classes/QualityGates/Qg" #uses "classes/QualityGates/QgMsgCat" -#uses "classes/QualityGates/QgVersionResult" +#uses "classes/QualityGates/QgResult" //-------------------------------------------------------------------------------- // declare variables and constans @@ -23,7 +23,6 @@ QgMsgCat myQgMsgCat = QgMsgCat(); OaTest myTest = OaTest(); - //-------------------------------------------------------------------------------- /** Error codes used in QgBase.cat */ @@ -119,7 +118,7 @@ class QgBase } //------------------------------------------------------------------------------ - public static QgResultState calculateState(const shared_ptr result) + public static QgResultState calculateState(const shared_ptr result) { if (result.hasError) return QgResultState::warning; @@ -153,25 +152,22 @@ class QgBase //------------------------------------------------------------------------------ public void setMinValidScore(const string &msgCatName, - const string &keyText, const string &keyReason, + const string &key, const mapping dollars = makeMapping()) { _setMinScore = TRUE; - _minScoreResult = new QgVersionResult(); - _minScoreResult.setMsgCatName(msgCatName); - _minScoreResult.setMinValidScore(keyText, keyReason, dollars); + _minScoreResult = new QgResult(msgCatName, key, dollars); } //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - protected QgAddOnTmpSourceDir _sourceDir = QgAddOnTmpSourceDir(); protected QgResultPublisher _publisher = QgResultPublisher(); - protected shared_ptr _result; + protected shared_ptr _result; protected bool _setMinScore = FALSE; - protected shared_ptr _minScoreResult; + protected shared_ptr _minScoreResult; //------------------------------------------------------------------------------ protected int _start() diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl new file mode 100644 index 00000000..14ca2c8a --- /dev/null +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl @@ -0,0 +1,20 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +//-------------------------------------------------------------------------------- +/** Error codes used in QgBase.cat +*/ +enum QgBaseError +{ + Exception = 1, + /// Assertion return error: $1 + NotImplemented = 20, + Start, + Calculate, + Validate, + Done +}; \ No newline at end of file diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl index ad37b120..aea2eec8 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl @@ -7,11 +7,12 @@ // SPDX-License-Identifier: GPL-3.0-only // -#uses "classes/QualityGates/Tools/CppCheck/CppCheckError" #uses "classes/FileSys/QgFile" -#uses "classes/QualityGates/Tools/CppCheck/CppCheck" #uses "classes/QualityGates/Qg" #uses "classes/QualityGates/QgBase" +#uses "classes/QualityGates/QgResult" +#uses "classes/QualityGates/Tools/CppCheck/CppCheck" +#uses "classes/QualityGates/Tools/CppCheck/CppCheckError" //-------------------------------------------------------------------------------- @@ -38,8 +39,8 @@ class QgCtrlppCheck : QgBase } //------------------------------------------------------------------------------ - /** @brief Function validates this quality-check. - @details Validate all all errors from ctrlppcheck. + /** Validate all errors from ctrlppcheck. + Errors are filtered by function isErrorFiltered(). @todo calculate somehow the score. @@ -48,11 +49,7 @@ class QgCtrlppCheck : QgBase */ public int validate() { - QgVersionResult::lastErr = ""; - _result = new QgVersionResult(); - - _result.setMsgCatName("QgCtrlppCheck"); - _result.setAssertionText("checks"); + _result = new QgResult("QgCtrlppCheck", "checks"); if (dpExists("_CtrlppCheck")) { @@ -75,16 +72,16 @@ class QgCtrlppCheck : QgBase if (isErrorFiltered(error)) continue; + mapping dollars = error.toMapping(); + QgFile f = QgFile(error.path); string relPath = f.getRelPath(SCRIPTS_REL_PATH); + dollars["relPath"] = makeUnixPath(relPath); - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgCtrlppCheck"); - assertion.setAssertionText(makeUnixPath(relPath)); - assertion.setReasonText(error.msg + " (" + error.id + ")"); + shared_ptr assertion = new QgResult("QgCtrlppCheck", "has_" + severity, dollars); + // simulate fail assertion.assertEqual(error.severity, ""); _result.addChild(assertion); - } return 0; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl index 7c7158eb..6b0332ea 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl @@ -9,15 +9,16 @@ #uses "classes/ErrorHdl/OaLogger" #uses "classes/QualityGates/QgBase" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" #uses "fileSys" - class QgOverloadedFilesCheck { //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- + public string projPathToCheck = PROJ_PATH; /** List with allowed files. */ @@ -86,16 +87,26 @@ class QgOverloadedFilesCheck public int calculate() { OaLogger logger; - dyn_string files = getFileNamesRecursive(PROJ_PATH); + if (projPathToCheck.isEmpty() || !isdir(projPathToCheck)) + { + logger.warning(0, Qg::getId(), "Directory does not exists", projPathToCheck); + return -1; + } + + projPathToCheck = makeNativePath(projPathToCheck); + logger.info(0, Qg::getId(), "Check files in the project directory", projPathToCheck); + dyn_string files = getFileNamesRecursive(projPathToCheck); dynSort(files); + DebugTN(__FUNCTION__, projPathToCheck, files); // + const int projPathLen = strlen(projPathToCheck); for (int i = 1; i <= dynlen(files); i++) { - string path = files[i]; + string path = makeNativePath(files[i]); logger.info(0, Qg::getId(), "Check file", path); - const string relPath = substr(path, strlen(PROJ_PATH)); + const string relPath = substr(path, projPathLen); if (strpos(relPath, makeNativePath(CONFIG_REL_PATH)) == 0 || strpos(relPath, makeNativePath(DB_REL_PATH)) == 0 || @@ -118,56 +129,39 @@ class QgOverloadedFilesCheck */ public int validate() { - QgVersionResult::lastErr = ""; - result = new QgVersionResult(); - - + result = new QgResult("QgStaticCheck_OverloadedFiles", "filesList", makeMapping("projectPath", projPathToCheck)); +DebugTN(__FUNCTION__, _relPaths); if (dynlen(_relPaths) > 0) { - result.setMsgCatName("QgStaticCheck_OverloadedFiles"); - result.setAssertionText("filesList"); - result.setLocation(PROJ_PATH); - for (int i = 1; i <= dynlen(_relPaths); i++) { const string relPath = _relPaths[i]; const string overloadedFrom = findSourceProj(relPath); + DebugTN(__FUNCTION__, relPath, overloadedFrom); shared_ptr settings = new QgSettings("OverloadedFilesCheck.isOverloadedAllowed"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); + shared_ptr assertion = new QgResult("QgStaticCheck_OverloadedFiles", "", makeMapping("file.name", relPath, "file.isOverloadedFrom", overloadedFrom)); assertion.setLocation(relPath); - assertion.setMsgCatName("QgStaticCheck_OverloadedFiles"); if (isAllowed(relPath)) { - assertion.setAssertionText("assert.isOverloadedAllowed", makeMapping("file.name", relPath)); - assertion.setReasonText("reason.isOverloadedAllowed", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); + assertion.setKey("isOverloadedAllowed"); assertion.allowNextErr(TRUE); - assertion.assertFalse(overloadedFrom != "", settings.getScorePoints()); // negative logic, for better look in store - assertion.referenceValue = (overloadedFrom != ""); // reference value faken, for better look in store + assertion.assertTrue(overloadedFrom.isEmpty(), settings.getScorePoints()); } else { - assertion.setAssertionText("assert.isOverloaded", makeMapping("file.name", relPath)); - assertion.setReasonText("reason.isOverloaded", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); - assertion.assertFalse(overloadedFrom != "", settings.getScorePoints()); // negative logic, for better look in store - + assertion.setKey("isOverloaded"); + assertion.assertTrue(overloadedFrom.isEmpty(), settings.getScorePoints()); } - shared_ptr fileChildData = new QgVersionResult(); - fileChildData.text = relPath; - fileChildData.addChild(assertion); - // add child to results - result.addChild(fileChildData); + result.addChild(assertion); } } - } return 0; @@ -212,7 +206,7 @@ class QgOverloadedFilesCheck } //------------------------------------------------------------------------------ - public shared_ptr result; //!< Overloaded file check result + public shared_ptr result; //!< Overloaded file check result //-------------------------------------------------------------------------------- //@private members diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResult.ctl similarity index 50% rename from WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl rename to WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResult.ctl index d1571892..d2a124e1 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResult.ctl @@ -7,108 +7,98 @@ // SPDX-License-Identifier: GPL-3.0-only // -#uses "csv" +#uses "classes/ErrorHdl/OaLogger" #uses "classes/QualityGates/QgMsgCat" #uses "classes/QualityGates/Qg" +#uses "classes/QualityGates/QgTest" #uses "classes/Variables/Float" +#uses "csv" -enum QgVersionResultType -{ - TableView, - TreeView, - SimpleTreeView -}; - -enum QgVersionResultJsonFormat +enum QgResultJsonFormat { Indented, //!< Defines human readable output Compact //!< Defines a compact output. More performant for parsing. }; +enum QgResultError +{ + AssertionError = 1, + AssertionOK, + AssertionErrorAccepted +}; -QgVersionResultType qgVersionResultType = QgVersionResultType::TableView; - -struct QgVersionResult +class QgResult { //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - static bool showErrorsOnly = FALSE; - string lowerBound; - string upperBound; - string value; - string referenceValue; + /// enable OaTest checks. It may be disabled for testing purpouse + public static bool selfTest = false; + public static bool showErrorsOnly = FALSE; + public string lowerBound; + public string upperBound; + public string value; + public string referenceValue; + public bool hasError; + /// getTotalPoints() shall be used + public int totalPoints; + /// getTotalPoints() shall be used + public int errorPoints; - bool hasError; - dyn_anytype children; - static string lastErr; - QgMsgCat msgCat = QgMsgCat(); - - int totalPoints; - int errorPoints; - - - string text; - string assertKey; - mapping assertDollars; - - string reason; - string reasonKey; - mapping reasonDollars; - string location; - - static const float NOT_VALID_SCORE = 0.0; - float score = NOT_VALID_SCORE; + //------------------------------------------------------------------------------ + public QgResult(const string &catalog, const string &key, const mapping &dollars) + { + this.setMsgCatName(catalog); + this.setKey(key); + this.setDollars(dollars); + } - static const float MIN_VALID_SCORE = 1.0; + //------------------------------------------------------------------------------ + public void setKey(const string &key) + { + this.key = key; + } //------------------------------------------------------------------------------ - QgVersionResult() + public void setDollars(const mapping &dollars) { + this.dollars = dollars; } //------------------------------------------------------------------------------ - void setLocation(const string &location) + public void setLocation(const string &location) { this.location = location; } //------------------------------------------------------------------------------ - string getLocation() + public string getLocation() { return this.location; } //------------------------------------------------------------------------------ - void setMsgCatName(const string &name) + public void setMsgCatName(const string &name) { msgCat.setName(name); } //------------------------------------------------------------------------------ - string getLastErr() + public static dyn_string getLastErrors() { return lastErr; } //------------------------------------------------------------------------------ - public void setAssertionText(const string &key, const mapping dollars = makeMapping()) - { - assertKey = key; - assertDollars = dollars; - } - - //------------------------------------------------------------------------------ - public void setReasonText(const string &key, const mapping dollars = makeMapping()) + public static void clearLastErr() { - reasonKey = key; - reasonDollars = dollars; + dynClear(lastErr); } //------------------------------------------------------------------------------ - mapping sumToMap() + public mapping sumToMap() { return makeMapping("totalPoints", totalPoints, "errorPoints", errorPoints, @@ -121,41 +111,24 @@ struct QgVersionResult Float f = Float(score); mapping map; - switch (qgVersionResultType) - { - case QgVersionResultType::TableView: - { - map["children"] = makeDynMapping(); - - map["children"][1] = makeMapping("value", totalPoints, - "text", KEY_SCORE_TOTAL_POINTS, - "leaf", TRUE, - "goodRange", "> 0"); - map["children"][2] = makeMapping("value", errorPoints, - "text", KEY_SCORE_ERROR_POINTS, - "leaf", TRUE, - "goodRange", "0"); - map["children"][3] = makeMapping("value", f.round(), - "text", KEY_SCORE_PERCENT, - "leaf", TRUE, - "goodRange", "1 - 100"); - - map["leaf"] = FALSE; - map["expanded"] = TRUE; - map["text"] = "Score"; - break; - } - - case QgVersionResultType::SimpleTreeView: - case QgVersionResultType::TreeView: - { - map[KEY_SCORE_TOTAL_POINTS] = totalPoints; - map[KEY_SCORE_ERROR_POINTS] = errorPoints; - map[KEY_SCORE_PERCENT] = f.round(2); - break; - } - - } + map["children"] = makeDynMapping(); + + map["children"][1] = makeMapping("value", totalPoints, + "text", KEY_SCORE_TOTAL_POINTS, + "leaf", TRUE, + "goodRange", "> 0"); + map["children"][2] = makeMapping("value", errorPoints, + "text", KEY_SCORE_ERROR_POINTS, + "leaf", TRUE, + "goodRange", "0"); + map["children"][3] = makeMapping("value", f.round(), + "text", KEY_SCORE_PERCENT, + "leaf", TRUE, + "goodRange", "1 - 100"); + + map["leaf"] = FALSE; + map["expanded"] = TRUE; + map["text"] = "Score"; return map; } @@ -187,7 +160,7 @@ struct QgVersionResult /** @brief Function returns count of all points. @return Count of all points. */ - public int getTotalPoints() + private int getTotalPoints() { return totalPoints; } @@ -196,19 +169,19 @@ struct QgVersionResult /** @brief Function returns count of error points. @return Count of errors. */ - public int getErrorPoints() + private int getErrorPoints() { return errorPoints; } //------------------------------------------------------------------------------ - public void toStdOut() + private void toStdOut() { - DebugN(__FUNCTION__, text, assertKey, dynlen(children), lowerBound, upperBound, referenceValue); + DebugN(__FUNCTION__, text, this.key, dynlen(children), lowerBound, upperBound, referenceValue); } //------------------------------------------------------------------------------ - anytype toMap(const bool clearObjectOnReturn = TRUE) + public mapping toMap() { mapping map; string goodRange; @@ -218,137 +191,51 @@ struct QgVersionResult else if (referenceValue != "") goodRange = referenceValue; - switch (qgVersionResultType) - { - case QgVersionResultType::TableView: - { - if (text != "") - map["text"] = text; - else if (assertKey != "") - map["text"] = msgCat.getText(assertKey, assertDollars); - - - if (value != "") - map["value"] = value; - - map["leaf"] = (dynlen(children) <= 0); - - if (goodRange != "") - map["goodRange"] = goodRange; + if (!this.text.isEmpty()) + map["text"] = this.text; - if (dynlen(children) > 0) - { - map["children"] = makeDynMapping(); + if (!this.value.isEmpty()) + map["value"] = value; - for (int i = 1; i <= dynlen(children); i++) - { - if (showErrorsOnly && !children[i].hasError) - continue; + map["leaf"] = (dynlen(children) <= 0); - dynAppend(map["children"], children[i].toMap()); - } - } + if (!this.goodRange.isEmpty()) + map["goodRange"] = goodRange; - if (hasError) - map["expanded"] = hasError; - - if (errorPoints > 0) - { - map["totalPoints"] = totalPoints; - map["errorPoints"] = errorPoints; - } - else if (totalPoints > 0) - map["totalPoints"] = totalPoints; - - if (hasError) - { - if (reason != "") - map["reason"] = reason; - else if (reasonKey != "") - map["reason"] = msgCat.getText(reasonKey, reasonDollars); - } - - break; - } + if (dynlen(children) > 0) + { + map["children"] = makeDynMapping(); - case QgVersionResultType::TreeView: + for (int i = 1; i <= dynlen(children); i++) { - if (goodRange != "") - map["goodRange"] = goodRange; - - if (value != "") - map["value"] = value; - - if (errorPoints > 0) - { - map["totalPoints"] = totalPoints; - map["errorPoints"] = errorPoints; - } - else if (totalPoints > 0) - map["totalPoints"] = totalPoints; + if (showErrorsOnly && !children[i].hasError) + continue; - if (hasError && reason != "") - map["reason"] = reason; - - - if (dynlen(children)) - { - for (int i = 1; i <= dynlen(children); i++) - { - map[children[i].text] = children[i].toMap(); - } - } - - break; + dynAppend(map["children"], children[i].toMap()); } + } - case QgVersionResultType::SimpleTreeView: - { - dyn_string ret; - - if (goodRange != "") - dynAppend(ret, "goodRange: " + goodRange); - - if (value != "") - dynAppend(ret, "value: " + value); - - if (errorPoints > 0) - { - dynAppend(ret, "errorPoints: " + errorPoints); - } - - if (hasError && reason != "") - dynAppend(ret, "reason: " + reason); - - - if (dynlen(children)) - { - for (int i = 1; i <= dynlen(children); i++) - { - map[children[i].text] = children[i].toMap(); - } - - if (clearObjectOnReturn) - clear(); - - return map; - } - - if (clearObjectOnReturn) - clear(); + if (hasError) + map["expanded"] = hasError; - return strjoin(ret, ", "); - } + if (errorPoints > 0) + { + map["totalPoints"] = totalPoints; + map["errorPoints"] = errorPoints; } + else if (totalPoints > 0) + map["totalPoints"] = totalPoints; - if (clearObjectOnReturn) - clear(); + if (hasError) + { + map["reason"] = this.reason; + } return map; } //------------------------------------------------------------------------------ - bool assertGreatherEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) + public bool assertGreatherEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) { value = (string)_castToString(currentValue); upperBound = (string)_castToString(refValue); @@ -360,7 +247,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertLessEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) + public bool assertLessEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) { value = (string)_castToString(currentValue); upperBound = (string)_castToString(refValue); @@ -372,7 +259,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) + public bool assertEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) { value = (string)_castToString(currentValue); upperBound = (string)_castToString(refValue); @@ -384,7 +271,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertFalse(const bool condition, int points = 1) + public bool assertFalse(const bool condition, int points = 1) { value = (string)condition; referenceValue = (string)FALSE; @@ -394,7 +281,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertTrue(const bool condition, int points = 1) + public bool assertTrue(const bool condition, int points = 1) { value = (string)condition; referenceValue = (string)TRUE; @@ -404,7 +291,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertDynContains(const dyn_anytype &list, const anytype &refValue, int points = 1) + public bool assertDynContains(const dyn_anytype &list, const anytype &refValue, int points = 1) { value = (string)refValue; referenceValue = strjoin(list, ", "); @@ -414,7 +301,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool assertBetween(const anytype ¤tValue, const anytype &lowerLimit, const anytype &upperLimit, int points = 1) + public bool assertBetween(const anytype ¤tValue, const anytype &lowerLimit, const anytype &upperLimit, int points = 1) { value = (string)_castToString(currentValue); upperBound = (string)_castToString(upperLimit); @@ -425,7 +312,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - bool info(const anytype ¤tValue, int points = 1) + public bool info(const anytype ¤tValue, int points = 1) { value = (string)_castToString(currentValue); referenceValue = (string)"-"; @@ -437,11 +324,8 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - public void setMinValidScore(const string &keyText, const string &keyReason, - const mapping dollars = makeMapping()) + public void setMinValidScore() { - setAssertionText(keyText, dollars); - setReasonText(keyReason, dollars); hasError = TRUE; _addScorePoints(); @@ -452,28 +336,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - public void setNotValidScore(const string &keyText, const string &keyReason, - const mapping dollars = makeMapping()) - { - shared_ptr child = new QgVersionResult(); - child.setAssertionText(keyText, dollars); - child.setReasonText(keyReason, dollars); - child.hasError = TRUE; - child.totalPoints = 0; - child.errorPoints = 0; - addChild(child); - - hasError = TRUE; - - _addScorePoints(); - - // non-valid (null) score must probably set - totalPoints = 0; - errorPoints = 0; - } - - //------------------------------------------------------------------------------ - void addChild(shared_ptr child, const int pos = -1) + public void addChild(shared_ptr child, const int pos = -1) { if (pos <= 0) dynAppend(children, child); @@ -488,23 +351,22 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - void clear() + private void clear() { - lowerBound = ""; - upperBound = ""; - value = ""; - referenceValue = ""; - text = ""; - reason = ""; - hasError = FALSE; - dynClear(children); - _operand = "-"; - totalPoints = 0; - errorPoints = 0; + this.lowerBound = ""; + this.upperBound = ""; + this.value = ""; + this.referenceValue = ""; + this.text = ""; + this.hasError = FALSE; + dynClear(this.children); + this._operand = "-"; + this.totalPoints = 0; + this.errorPoints = 0; } //------------------------------------------------------------------------------ - void allowNextErr(bool flag) + public void allowNextErr(bool flag) { _allowNextErr = flag; } @@ -512,54 +374,126 @@ struct QgVersionResult //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------- +//@private members +//-------------------------------------------------------------------------------- + + private OaLogger logger = OaLogger("QgResult"); + private string key; + private mapping dollars; + + // cached assertion text and reason + private string text; + private string reason; + + + private dyn_anytype children; + private static dyn_string lastErr; + private QgMsgCat msgCat = QgMsgCat(); + + private string location; + + private static const float NOT_VALID_SCORE = 0.0; + private float score = NOT_VALID_SCORE; + + private static const float MIN_VALID_SCORE = 1.0; + + private string _operand = "-"; + + /// @todo mPunk 30.10.2018: remove this contans and replace it by msg-cat, there shall be obsolete + private static const string KEY_SCORE_PERCENT = "%"; + private static const string KEY_SCORE_TOTAL_POINTS = "Total points"; + private static const string KEY_SCORE_ERROR_POINTS = "Error points"; + private static dyn_dyn_string knownBugs; + //------------------------------------------------------------------------------ - protected bool _allowNextErr; + private bool _allowNextErr; //------------------------------------------------------------------------------ - protected _addScorePoints(int points = 1) + private _addScorePoints(int points = 1) { mapping userData; if (location != "") { - assertDollars["location"] = location; + this.dollars["location"] = location; userData["Location"] = location; } - userData["Note"] = msgCat.getText(assertKey, assertDollars); + this.text = msgCat.getText(this.getAssertKey(), this.dollars); + this.reason = msgCat.getText(this.getReasonKey(), this.dollars); + // clear dollars to free memory + mappingClear(this.dollars); + + userData["Note"] = this.text; - userData["Method"] = assertKey; - userData["ErrMsg"] = msgCat.getText(reasonKey, reasonDollars); + userData["Method"] = this.getAssertKey(); + userData["ErrMsg"] = this.reason; userData["StackTrace"] = makeDynString(); getKnownBugId(userData); totalPoints += points; + // store last errors (only for internal testing) + if (hasError && selfTest) + this.lastErr.append(this.key); + if (hasError && !_allowNextErr) { errorPoints += points; - lastErr = reason; - - const int prio = mappingHasKey(userData, "KnownBug") ? PRIO_INFO : PRIO_WARNING; - throwError(makeError("QgBase", prio, ERR_CONTROL, 10, msgCat.getText(reasonKey, reasonDollars))); if (_enableOaTestOutput()) - oaUnitFail(assertKey, userData); + oaUnitFail(this.key, userData); + else + { + const int prio = mappingHasKey(userData, "KnownBug") ? PRIO_INFO : PRIO_WARNING; + + if (mappingHasKey(userData, "KnownBug")) + logger.info(QgResultError::AssertionErrorAccepted, this.reason, userData["Note"]); + else + logger.warning(QgResultError::AssertionError, this.reason, userData["Note"]); + } } else { if (_enableOaTestOutput()) - oaUnitPass(assertKey, userData); + { + oaUnitPass(this.key, userData); + } else - throwError(makeError("QgBase", PRIO_INFO, ERR_CONTROL, 11, msgCat.getText(assertKey, assertDollars))); + { + logger.info(QgResultError::AssertionOK, this.key, userData); + } } _allowNextErr = FALSE; + + } + + //------------------------------------------------------------------------------ + private string getAssertKey() + { + if (this.key.isEmpty()) + return ""; + + return "assert." + this.key; + } + + + //------------------------------------------------------------------------------ + private string getReasonKey() + { + if (this.key.isEmpty()) + return ""; + + return "reason." + this.key; } //------------------------------------------------------------------------------ - protected getKnownBugId(mapping &userData) + /// @todo replace this code by OaTest-knownBug-handler + private getKnownBugId(mapping &userData) { if (dynlen(knownBugs) <= 0) readKnownBugList(); @@ -575,7 +509,7 @@ struct QgVersionResult string tcId = knownBugs[i][2]; string pattern = knownBugs[i][3]; - if ((tcId == assertKey) && patternMatch(pattern, msg)) + if ((tcId == this.key) && patternMatch(pattern, msg)) { userData["KnownBug"] = bugId; break; @@ -596,17 +530,15 @@ struct QgVersionResult //------------------------------------------------------------------------------ /** @brief enabled or disabled oaUnitResults - @todo mPunk 30.10.2018: make it configureable, otherwise does not work in jenkins - @return TRUE hen are oaUnit results enabled + @return TRUE when are oaUnit results enabled */ - protected static bool _enableOaTestOutput() + private static bool _enableOaTestOutput() { - return true; - return Qg::isRunningOnJenkins(); + return QgTest::isStartedByTestFramework() && !selfTest; } //------------------------------------------------------------------------------ - protected static string _castToString(const anytype &expr) + private static string _castToString(const anytype &expr) { string str; @@ -622,17 +554,4 @@ struct QgVersionResult return str; } - - -//-------------------------------------------------------------------------------- -//@private members -//-------------------------------------------------------------------------------- - private string _operand = "-"; - - /// @todo mPunk 30.10.2018: remove this contans and replace it by msg-cat, there shall be obsolete - static const string KEY_SCORE_REASON = "Reason"; - static const string KEY_SCORE_PERCENT = "%"; - static const string KEY_SCORE_TOTAL_POINTS = "Total points"; - static const string KEY_SCORE_ERROR_POINTS = "Error points"; - static dyn_dyn_string knownBugs; }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl index 714ad045..23fa91fa 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl @@ -7,9 +7,11 @@ // SPDX-License-Identifier: GPL-3.0-only // +#uses "classes/json/JsonFile" #uses "classes/QualityGates/Qg" +#uses "classes/QualityGates/QgTest" #uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" -#uses "classes/QualityGates/QgVersionResult" +#uses "classes/QualityGates/QgResult" //-------------------------------------------------------------------------------- enum QgResultState @@ -27,34 +29,15 @@ class QgResultPublisher //------------------------------------------------------------------------------ public QgResultState state; - public shared_ptr result; + public shared_ptr result; public dyn_string fields; - public static QgVersionResultJsonFormat jsonFormat = QgVersionResultJsonFormat::Compact; + public static QgResultJsonFormat jsonFormat = QgResultJsonFormat::Compact; //------------------------------------------------------------------------------ public QgResultPublisher() { } - //------------------------------------------------------------------------------ - public static string stateToString(const QgResultState &state) - { - switch (state) - { - case QgResultState::success: - return "success"; - - case QgResultState::warning: - return "warning"; - - case QgResultState::error: - return "error"; - } - - DebugFTN("QgBase", __FUNCTION__, "internall error, this state does not exists", state); - return ""; - } - //------------------------------------------------------------------------------ public int publish() { @@ -65,9 +48,6 @@ class QgResultPublisher if (!resDir.exists()) resDir.create(); - if (_publishState(resDir)) - return sendNotification(-1); - if (_publishSummary(resDir)) return sendNotification(-2); @@ -79,10 +59,14 @@ class QgResultPublisher //-------------------------------------------------------------------------------- //@protected members +//-------------------------------------------------------------------------------- + +//-------------------------------------------------------------------------------- +//@private members //-------------------------------------------------------------------------------- //------------------------------------------------------------------------------ - protected int sendNotification(const int errCode) + private int sendNotification(const int errCode) { if (isEvConnOpen() && (Qg::getId() != "")) dpSet("_WinCCOA_qgCmd.Command", Qg::getId() + ":DONE:" + errCode); @@ -91,58 +75,22 @@ class QgResultPublisher } //------------------------------------------------------------------------------ - protected int _publishState(const QgAddOnResultsDir &resDir) + private int _publishSummary(const QgAddOnResultsDir &resDir) { - string resPath; - - if (Qg::isRunningOnJenkins()) - resPath = resDir.getDirPath() + "_state"; - else - resPath = resDir.getDirPath() + "State"; - - file f = fopen(resPath, "wb+"); - - if (ferror(f)) - return -1; - - fputs(stateToString(state), f); - fclose(f); - return 0; + JsonFile jsonFile = JsonFile(resDir.getDirPath() + "sum.json"); + jsonFile.create(); + return jsonFile.write(result.sumToMap(), jsonFormat == QgResultJsonFormat::Compact); } //------------------------------------------------------------------------------ - protected int _publishSummary(const QgAddOnResultsDir &resDir) + private int _publishFull(const QgAddOnResultsDir &resDir) { - string resPath; - - if (Qg::isRunningOnJenkins()) - resPath = resDir.getDirPath() + "_data"; - else - resPath = resDir.getDirPath() + "sum.json"; - - file f = fopen(resPath, "wb+"); - - if (ferror(f)) - return -1; + if (!QgTest::isStartedByTestFramework()) + return _publishFullLocale(resDir); - fputs(jsonEncode(result.sumToMap(), jsonFormat == QgVersionResultJsonFormat::Compact), f); - fclose(f); return 0; } - //------------------------------------------------------------------------------ - protected int _publishFull(const QgAddOnResultsDir &resDir) - { - if (Qg::isRunningOnJenkins()) - return _publishFullOnJenkins(resDir); - else - return _publishFullLocale(resDir); - } - -//-------------------------------------------------------------------------------- -//@private members -//-------------------------------------------------------------------------------- - //------------------------------------------------------------------------------ private int _publishFullLocale(const QgAddOnResultsDir &resDir) { @@ -162,9 +110,8 @@ class QgResultPublisher map["root"]["children"] = makeDynMapping(); map["root"]["children"][1] = result.scoreToMap(); map["root"]["children"][2] = result.toMap(); -// result.clear(); - fputs(jsonEncode(map, jsonFormat == QgVersionResultJsonFormat::Compact), f); + fputs(jsonEncode(map, jsonFormat == QgResultJsonFormat::Compact), f); fclose(f); f = fopen(path + "Score", "wb+"); @@ -172,77 +119,4 @@ class QgResultPublisher fclose(f); return 0; } - - //------------------------------------------------------------------------------ - private int _publishFullOnJenkins(const QgAddOnResultsDir &resDir) - { - string path = resDir.getDirPath() + "QgTestVersion/"; - - mkdir(path); - - int testId = Qg::idToNum(); - - if (testId <= 0) - { - DebugFTN("QgBase", __FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); - return -1; - } - - file f = fopen(path + "_Id", "wb+"); - - if (ferror(f)) - { - DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "_Id"); - return -2; - } - - fputs((string)testId, f); - fclose(f); - - DebugFN("QgBase", __FUNCTION__, path); - f = fopen(path + "_Results", "wb+"); - - if (ferror(f)) - { - DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "_Results"); - return -3; - } - - mapping map; - - switch (qgVersionResultType) - { - case QgVersionResultType::TableView: - { - map["fields"] = fields; - map["root"] = makeMapping(); - map["root"]["children"] = makeDynMapping(); - map["root"]["children"][1] = result.scoreToMap(); - map["root"]["children"][2] = result.toMap(); -// result.clear(); - break; - } - - case QgVersionResultType::SimpleTreeView: - case QgVersionResultType::TreeView: - { - map["score"] = result.scoreToMap(); - map["details"] = result.toMap(); -// result.clear(); - break; - } - } - -// [result.text] = result.toMap(); - DebugFTN("QgBase", __FUNCTION__, "write QgVersionResultJsonFormat to json file"); - fputs(jsonEncode(map, jsonFormat == QgVersionResultJsonFormat::Compact), f); - fclose(f); - - DebugFTN("QgBase", __FUNCTION__, "write " + path + "_Score file"); - f = fopen(path + "_Score", "wb+"); - fputs((string)result.score, f); - fclose(f); - return 0; - } - }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl index 383752c4..a0917ecf 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl @@ -8,23 +8,24 @@ // #uses "classes/QualityGates/Tools/Lizard/ToolLizard" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" class FunctionData { -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //@public members -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- - //------------------------------------------------------------------------------ - public shared_ptr result; //!< Quality gate result + //--------------------------------------------------------------------------- + public shared_ptr result; //!< Quality gate result - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public FunctionData() { } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public int fillFromCsv(const dyn_string &line) { if (dynlen(line) < (int)LizardCsvIndx::PARAMS) @@ -55,62 +56,62 @@ class FunctionData return 0; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /// cyclomatic complex. number public int getCCN() { return _ccn; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- // lines of comment public int getLOC() { return getLinesCount() - getNLOC(); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- // no. lines of code public int getNLOC() { return _nloc; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public int getParamCount() { return _paramCount; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public int getLinesCount() { return _linesCount; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public string getSynopsis() { return _synopsis; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public string getName() { return _name; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public string isCtor() { return _isCtor; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public int validate() { - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("function.name", getName()); + result = new QgResult("QgStaticCheck_FunctionData", "function", dollars); validateCCN(); validateNLOC(); @@ -119,23 +120,19 @@ class FunctionData return 0; } -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //@protected members -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- protected validateCCN() { shared_ptr settings = new QgSettings("FunctionData.function.CCN"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_FunctionData"); - - assertion.setAssertionText("assert.function.CCN"); - assertion.setReasonText("reason.function.CCN", makeMapping("function.name", getName(), - "function.CCN", getCCN())); + const mapping dollars = makeMapping("function.name", getName(), "function.CCN", getCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_FunctionData", "function.CCN", dollars); assertion.assertLessEqual(getCCN(), settings.getHighLimit(DEFAULT_CNN_HIGH), settings.getScorePoints()); @@ -143,7 +140,7 @@ class FunctionData } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- protected validateNLOC() { string path = isCtor() ? "FunctionData.function.NLOC.ctor" : "FunctionData.function.NLOC"; @@ -151,13 +148,8 @@ class FunctionData if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_FunctionData"); - - assertion.setAssertionText("assert.function.NLOC"); - assertion.setReasonText("reason.function.NLOC", makeMapping("function.name", getName(), - "function.NLOC", getNLOC())); - + const mapping dollars = makeMapping("function.name", getName(), "function.NLOC", getNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_FunctionData", "function.NLOC", dollars); assertion.assertBetween(getNLOC(), settings.getLowLimit(DEFAULT_NLOC_LOW), settings.getHighLimit(DEFAULT_NLOC_HIGH), @@ -166,19 +158,15 @@ class FunctionData } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- protected validateParamCount() { shared_ptr settings = new QgSettings("FunctionData.function.paramCount"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_FunctionData"); - - assertion.setAssertionText("assert.function.paramCount"); - assertion.setReasonText("reason.function.paramCount", makeMapping("function.name", getName(), - "function.paramCount", getNLOC())); + const mapping dollars = makeMapping("function.name", getName(), "function.paramCount", getParamCount()); + shared_ptr assertion = new QgResult("QgStaticCheck_FunctionData", "function.paramCount", dollars); assertion.assertLessEqual(getParamCount(), settings.getHighLimit(10), settings.getScorePoints()); @@ -186,27 +174,23 @@ class FunctionData } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- protected validateCountOfLines() { shared_ptr settings = new QgSettings("FunctionData.function.countOfLines"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_FunctionData"); - - assertion.setAssertionText("assert.function.countOfLines"); - assertion.setReasonText("reason.function.countOfLines", makeMapping("function.name", getName(), - "function.countOfLines", getLinesCount())); + const mapping dollars = makeMapping("function.name", getName(), "function.countOfLines", getLinesCount()); + shared_ptr assertion = new QgResult("QgStaticCheck_FunctionData", "function.countOfLines", dollars); assertion.info(getLinesCount(), settings.getScorePoints()); result.addChild(assertion); } } -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //@private members -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- int _nloc, _ccn, _paramCount, _linesCount; string _synopsis, _name; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl index bee3399a..facedf24 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl @@ -7,15 +7,15 @@ // SPDX-License-Identifier: GPL-3.0-only // -#uses "classes/QualityGates/Tools/Python/Python" -#uses "classes/FileSys/QgFile" #uses "csv" -#uses "classes/QualityGates/Tools/Lizard/ToolLizard" +#uses "classes/FileSys/QgFile" +#uses "classes/QualityGates/QgAddOnResultErr" #uses "classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData" -#uses "classes/Variables/Float" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" - -#uses "classes/QualityGates/QgAddOnResultErr" +#uses "classes/QualityGates/Tools/Lizard/ToolLizard" +#uses "classes/QualityGates/Tools/Python/Python" +#uses "classes/Variables/Float" /** Checks for static script data. @@ -35,10 +35,10 @@ class ScriptData //@public members //-------------------------------------------------------------------------------- - //------------------------------------------------------------------------------ - public shared_ptr result; //!< Quality gate result + //--------------------------------------------------------------------------- + public shared_ptr result; //!< Quality gate result - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Default c-tor @param filePath Full native path to file there shall be checked. @@ -48,7 +48,7 @@ class ScriptData setPath(filePath); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Set path to the checked file. It shall be used before calculation. @@ -59,7 +59,7 @@ class ScriptData _filePath = filePath; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Return the checked file name with extension. @note Not full path only the file name. @@ -69,7 +69,7 @@ class ScriptData return baseName(_filePath); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns TRUE when file is calcualted, otherwise false. */ @@ -78,7 +78,7 @@ class ScriptData return _isCalculated; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns count of function located in file. */ @@ -87,7 +87,7 @@ class ScriptData return dynlen(_functions); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns clount of lines in the script. Count of all lines (code, comments, empty ...) @@ -97,7 +97,7 @@ class ScriptData return _linesCount; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns CCN (cyclomatic complexicity) of script. CCN of all functions. @@ -107,7 +107,7 @@ class ScriptData return _ccn; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns NLOC (NumberLinesOfCode) of script. Pure code lines count (without comments, empty lines) @@ -117,7 +117,7 @@ class ScriptData return _nloc; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns average CCN of script. Seel also function getCCN() . @@ -133,7 +133,7 @@ class ScriptData return f.round(); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns average NLOC of script. Seel also function getNLOC() . @@ -149,8 +149,8 @@ class ScriptData return f.round(); } - //------------------------------------------------------------------------------ - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- /** Returns average count of lines per function in script. */ @@ -159,7 +159,7 @@ class ScriptData return _avgLines; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns maximum enabled count of functions, there can be located in script. Quality limit. @@ -170,7 +170,7 @@ class ScriptData return (int)settings.getHighLimit(DEFAULT_FUNCCOUNT_HIGH); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns minimun enabled count of functions, there can be located in script. Quality limit. @@ -181,7 +181,7 @@ class ScriptData return (int)settings.getLowLimit(DEFAULT_FUNCCOUNT_LOW); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns maximum enabled NLOC. Quality limit. @@ -193,7 +193,7 @@ class ScriptData return (int)settings.getHighLimit(DEFAULT_NLOC_HIGH); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns minimum enabled NLOC. Quality limit. @@ -205,7 +205,7 @@ class ScriptData return (int)settings.getLowLimit(DEFAULT_NLOC_LOW); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns maximum enabled average CCN. Quality limit. @@ -217,7 +217,7 @@ class ScriptData return (float)settings.getHighLimit(DEFAULT_AVGCCN_HIGH); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Returns everage count of functions parameters. Quality limit. @@ -227,7 +227,7 @@ class ScriptData return _avgParamCount; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Function calculate script data. @@ -312,15 +312,15 @@ class ScriptData return 0; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate script data. @return Return 0 when successfull. */ public int validate() { - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("script.name", getName()); + result = new QgResult("QgStaticCheck_ScriptData", "function", dollars); if (!validateIsCalucalted()) return 0; @@ -337,11 +337,11 @@ class ScriptData //@protected members //-------------------------------------------------------------------------------- - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- protected dyn_anytype _functions; //!< list with functions data. protected string _filePath = ""; //!< Full native path to the script. - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate calculation state of the script. @detals There are more reasons, why the script is not calculated @@ -359,10 +359,8 @@ class ScriptData { // check if file is calculated. // ognore all not calculated files (crypted, empty files ...) - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.isCalculated"); - assertion.setReasonText("reason.script.isCalculated", makeMapping("script.name", getName())); + const mapping dollars = makeMapping("script.name", getName()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "script.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { @@ -375,7 +373,7 @@ class ScriptData return 1; } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate count of function in the script. Enabled count of functions are depend of the script type. For example scope of panel @@ -394,17 +392,14 @@ class ScriptData if (settings.isEnabled()) { // check count of functions. - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.countOfFunctions"); - assertion.setReasonText("reason.script.countOfFunctions", makeMapping("script.name", getName(), - "countOfFunctions", getCountOfFunctions())); + const mapping dollars = makeMapping("script.name", getName(), "script.countOfFunctions", getCountOfFunctions()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "script.countOfFunctions", dollars); assertion.assertBetween(getCountOfFunctions(), getMinCountOfFunctions(), getMaxCountOfFunctions(), settings.getScorePoints()); result.addChild(assertion); } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate average CCN of the script. Check average CCN (Cyclomatic complexicity -McCabe) @@ -417,18 +412,15 @@ class ScriptData if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.avgCCN"); - assertion.setReasonText("reason.script.avgCCN", makeMapping("script.name", getName(), - "avgCCN", getAvgCCN())); + const mapping dollars = makeMapping("script.name", getName(), "script.avgCCN", getAvgCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "script.avgCCN", dollars); assertion.assertLessEqual(getAvgCCN(), getMaxAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate NLOC of the script. Check NLOC - Noumber Line Of Code @@ -439,17 +431,14 @@ class ScriptData if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.NLOC"); - assertion.setReasonText("reason.script.NLOC", makeMapping("script.name", getName(), - "NLOC", getNLOC())); + const mapping dollars = makeMapping("script.name", getName(), "script.NLOC", getNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "script.NLOC", dollars); assertion.assertBetween(getNLOC(), getMinNLOC(), getMaxNLOC(), settings.getScorePoints()); result.addChild(assertion); } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate average NLOC. Check average NLOC - Noumber Line Of Code @@ -462,11 +451,8 @@ class ScriptData if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.avgNLOC"); - assertion.setReasonText("reason.script.avgNLOC", makeMapping("script.name", getName(), - "avgNLOC", getAvgNLOC())); + const mapping dollars = makeMapping("script.name", getName(), "script.avgNLOC", getAvgNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "script.avgNLOC", dollars); assertion.info(getAvgNLOC(), settings.getScorePoints()); // does not check it, only information character // assertion.assertLessEqual(getAvgNLOC(), getMaxAvgCCN()); result.addChild(assertion); @@ -474,7 +460,7 @@ class ScriptData } } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** Validate functions in script. Check each functions located in script. @@ -484,9 +470,8 @@ class ScriptData // check all functions too. if (getCountOfFunctions() > 0) { - shared_ptr functions = new QgVersionResult(); - functions.setMsgCatName("QgStaticCheck_ScriptData"); - functions.setAssertionText("functionsList"); + const mapping dollars = makeMapping("script.name", getName(), "functionsList", getAvgNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptData", "functionsList", dollars); for (int i = 1; i <= dynlen(_functions); i++) { diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl index e5245a27..08e47d52 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl @@ -7,17 +7,18 @@ // SPDX-License-Identifier: GPL-3.0-only // -#uses "classes/QualityGates/QgBase" -#uses "classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData" #uses "classes/FileSys/QgFile" +#uses "classes/QualityGates/QgBase" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" +#uses "classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData" class ScriptFile : QgFile { -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //@public members -//-------------------------------------------------------------------------------- - //------------------------------------------------------------------------------ +//----------------------------------------------------------------------------- + //--------------------------------------------------------------------------- /** @brief Default c-tor. @param dirPath Full path to directory. */ @@ -28,13 +29,13 @@ class ScriptFile : QgFile _enabledExtensions = makeDynString("ctl", "ctc"); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public static bool isCrypted(const string &s) { return (strpos(s, "PVSS_CRYPTED_PANEL") == 0); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- public bool isFileCrypted() { string s; @@ -46,12 +47,13 @@ class ScriptFile : QgFile return isCrypted(s); } + //--------------------------------------------------------------------------- public bool isCalculated() { return _isCalculated; } - + //--------------------------------------------------------------------------- public int calculate() { _isCalculated = FALSE; @@ -89,10 +91,11 @@ class ScriptFile : QgFile return 0; } + //--------------------------------------------------------------------------- public int validate() { - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("file.name", getName()); + result = new QgResult("QgStaticCheck_ScriptFile", "file", dollars); { shared_ptr settings = new QgSettings("ScriptFile.file.isExampleFile"); @@ -101,10 +104,8 @@ class ScriptFile : QgFile { // check if the file is example. // ignore all example files, the example are terrible scripts - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.isExampleFile"); - assertion.setReasonText("reason.file.isExampleFile", makeMapping("file.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "file.isExampleFile", this.isExample()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptFile", "file.isExampleFile", dollars); assertion.allowNextErr(TRUE); if (!assertion.assertFalse(this.isExample(), settings.getScorePoints())) @@ -123,11 +124,8 @@ class ScriptFile : QgFile if (settings.isEnabled()) { // check for valid extensions - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.extension"); - assertion.setReasonText("reason.file.extension", makeMapping("file.name", getName(), - "file.extension", _extension)); + const mapping dollars = makeMapping("function.name", getName(), "file.extension", _extension); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptFile", "file.extension", dollars); if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { @@ -146,10 +144,8 @@ class ScriptFile : QgFile { // check if file is calculated. // ognore all not calculated files (crypted, empty files ...) - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.isCalculated"); - assertion.setReasonText("reason.file.isCalculated", makeMapping("file.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "file.isCalculated", isCalculated()); + shared_ptr assertion = new QgResult("QgStaticCheck_ScriptFile", "file.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { @@ -169,33 +165,41 @@ class ScriptFile : QgFile return 0; } + //--------------------------------------------------------------------------- public int getCCN() { return _scriptData.getCCN(); } + //--------------------------------------------------------------------------- public int getNLOC() { return _scriptData.getNLOC(); } + //--------------------------------------------------------------------------- public float getAvgCCN() { return _scriptData.getAvgCCN(); } + //--------------------------------------------------------------------------- public float getAvgNLOC() { return _scriptData.getAvgNLOC(); } + //--------------------------------------------------------------------------- + public shared_ptr result; //!< Quality gate result - - //------------------------------------------------------------------------------ - public shared_ptr result; //!< Quality gate result - +//----------------------------------------------------------------------------- +//@protected members +//----------------------------------------------------------------------------- protected ScriptData _scriptData = ScriptData(); +//----------------------------------------------------------------------------- +//@private members +//----------------------------------------------------------------------------- static dyn_string _enabledExtensions = makeDynString(); string _extension; bool _isCalculated; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl index 82230c8e..09a2d1d7 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl @@ -7,7 +7,7 @@ // SPDX-License-Identifier: GPL-3.0-only // -#uses "classes/QualityGates/QgVersionResult" +#uses "classes/QualityGates/QgResult" #uses "classes/FileSys/QgFile" #uses "classes/QualityGates/QgAddOnResultErr" #uses "classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFile" @@ -26,7 +26,7 @@ class PanelCheck : QgFile //-------------------------------------------------------------------------------- //------------------------------------------------------------------------------ - public shared_ptr result; //!< Quality gate result + public shared_ptr result; //!< Quality gate result //------------------------------------------------------------------------------ /** Default c-tor @@ -229,9 +229,8 @@ class PanelCheck : QgFile //------------------------------------------------------------------------------ public int validate() { - QgVersionResult::lastErr = ""; - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("file.name", getName()); + result = new QgResult("QgStaticCheck_Panels", "file", dollars); if (validateIsExample() || validateIsBackUp() || @@ -267,10 +266,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isExampleFile"); - assertion.setReasonText("reason.panel.isExampleFile", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "panel.isExampleFile", this.isExample()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.isExampleFile", dollars); assertion.allowNextErr(TRUE); if (!assertion.assertFalse(isExample(), settings.getScorePoints())) @@ -292,10 +289,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isBackUp"); - assertion.setReasonText("reason.panel.isBackUp", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "panel.isBackUp", this.isBackUp()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.isBackUp", dollars); if (!assertion.assertFalse(isBackUp(), settings.getScorePoints())) { @@ -316,11 +311,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.extension"); - assertion.setReasonText("reason.panel.extension", makeMapping("panel.name", getName(), - "panel.extension", _extension)); + const mapping dollars = makeMapping("function.name", getName(), "panel.extension", _extension); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.extension", dollars); if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { @@ -341,10 +333,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isCrypted"); - assertion.setReasonText("reason.panel.isCrypted", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "panel.isCrypted", _pnl.isCrypted()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.isCrypted", dollars); if (!assertion.assertFalse(_pnl.isCrypted(), settings.getScorePoints())) { @@ -365,10 +355,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isCalculated"); - assertion.setReasonText("reason.panel.isCalculated", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("function.name", getName(), "panel.isCalculated", this.isCalculated()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { @@ -387,11 +375,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.countOfProperties"); - assertion.setReasonText("reason.panel.countOfProperties", makeMapping("panel.name", getName(), - "panel.countOfProperties", _pnl.getCountOfProperties())); + const mapping dollars = makeMapping("function.name", getName(), "panel.countOfProperties", _pnl.getCountOfProperties()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.countOfProperties", dollars); assertion.info(_pnl.getCountOfProperties(), settings.getScorePoints()); result.addChild(assertion); } @@ -404,11 +389,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.countOfEvents"); - assertion.setReasonText("reason.panel.countOfEvents", makeMapping("panel.name", getName(), - "panel.countOfEvents", _pnl.getCountOfEvents())); + const mapping dollars = makeMapping("function.name", getName(), "panel.countOfEvents", _pnl.getCountOfEvents()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.countOfEvents", dollars); assertion.assertLessEqual(_pnl.getCountOfEvents(), settings.getHighLimit(DEFAULT_EVENTCOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } @@ -420,12 +402,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - // countOfShapes - assertion.setAssertionText("assert.panel.countOfShapes"); - assertion.setReasonText("reason.panel.countOfShapes", makeMapping("panel.name", getName(), - "panel.countOfShapes", _pnl.getCountOfShapes())); + const mapping dollars = makeMapping("function.name", getName(), "panel.countOfShapes", _pnl.getCountOfShapes()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.countOfShapes", dollars); assertion.assertLessEqual(_pnl.getCountOfShapes(), settings.getHighLimit(DEFAULT_SHAPECOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } @@ -439,12 +417,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - // info only, dont check the values - assertion.setAssertionText("assert.panel.CCN"); - assertion.setReasonText("reason.panel.CCN", makeMapping("panel.name", getName(), - "panel.CCN", getCCN())); + const mapping dollars = makeMapping("function.name", getName(), "panel.CCN", this.getCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.CCN", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -456,11 +430,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.avgCCN"); - assertion.setReasonText("reason.panel.avgCCN", makeMapping("panel.name", getName(), - "panel.avgCCN", getAvgCCN())); + const mapping dollars = makeMapping("function.name", getName(), "panel.avgCCN", this.getAvgCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.avgCCN", dollars); assertion.info(getAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -472,11 +443,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.NLOC"); - assertion.setReasonText("reason.panel.NLOC", makeMapping("panel.name", getName(), - "panel.NLOC", getNLOC())); + const mapping dollars = makeMapping("function.name", getName(), "panel.NLOC", this.getNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.NLOC", dollars); assertion.info(getNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -488,11 +456,8 @@ class PanelCheck : QgFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.avgNLOC"); - assertion.setReasonText("reason.panel.avgNLOC", makeMapping("panel.name", getName(), - "panel.avgNLOC", getAvgNLOC())); + const mapping dollars = makeMapping("function.name", getName(), "panel.avgNLOC", this.getAvgNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.avgNLOC", dollars); assertion.info(getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -500,15 +465,12 @@ class PanelCheck : QgFile protected validateEvents() { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - //---------------------------------------------------------------------------- // validate events if (_pnl.getCountOfEvents() > 0) { - shared_ptr ev = new QgVersionResult(); - ev.setAssertionText("panel.events"); + const mapping dollars = makeMapping("function.name", getName(), "panel.events.count", _pnl.getCountOfEvents()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "panel.events", dollars); while (_pnl.getCountOfEvents() > 0) { @@ -528,8 +490,8 @@ class PanelCheck : QgFile // validate shapes if (_pnl.getCountOfShapes() > 0) { - shared_ptr sh = new QgVersionResult(); - sh.setAssertionText("panel.shapes"); + const mapping dollars = makeMapping("function.name", getName(), "panel.shapes.count", _pnl.getCountOfShapes()); + shared_ptr sh = new QgResult("QgStaticCheck_Panels", "panel.shapes", dollars); while (_pnl.getCountOfShapes() > 0) { @@ -546,20 +508,17 @@ class PanelCheck : QgFile // validate properties protected validateProperties() { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - if (_pnl.getCountOfProperties() > 0) { - shared_ptr prop = new QgVersionResult(); - prop.setAssertionText("panel.properties"); + const mapping dollars = makeMapping("function.name", getName(), "panel.properties.count", _pnl.getCountOfProperties()); + shared_ptr prop = new QgResult("QgStaticCheck_Panels", "panel.properties", dollars); while (_pnl.getCountOfProperties() > 0) { ///@todo probably place for checking properties string key = mappingGetKey(_pnl.properties, 1); - shared_ptr property = new QgVersionResult(); - property.setAssertionText(key); + const mapping dollars = makeMapping("function.name", getName(), "panel.properties.key", key); + shared_ptr property = new QgResult("QgStaticCheck_Panels", "property", dollars); property.info(_pnl.properties[key]); mappingRemove(_pnl.properties, key); prop.addChild(property); diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileShape.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileShape.ctl index db643d5d..958ec1f6 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileShape.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileShape.ctl @@ -7,43 +7,55 @@ // SPDX-License-Identifier: GPL-3.0-only // +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileScript" #uses "classes/QualityGates/QgSettings" class PanelFileShape { - //------------------------------------------------------------------------------ - public shared_ptr result;//!< Quality gate result +//----------------------------------------------------------------------------- +//@public members +//----------------------------------------------------------------------------- + //--------------------------------------------------------------------------- + public shared_ptr result;//!< Quality gate result + + //--------------------------------------------------------------------------- public PanelFileShape() { } + //--------------------------------------------------------------------------- public void initFromMap(const mapping &map) { _firstLevelProps = map; } + //--------------------------------------------------------------------------- public void setProperties(const mapping &properties) { _properties = properties; } + //--------------------------------------------------------------------------- public mapping getProperties() { return _properties; } + //--------------------------------------------------------------------------- public int getCountOfProperties() { return mappinglen(_properties); } + //--------------------------------------------------------------------------- public int getCountOfEvents() { return mappinglen(_events); } + //--------------------------------------------------------------------------- public int getCountOfShapes() { //TODO @@ -51,16 +63,19 @@ class PanelFileShape return 0; } + //--------------------------------------------------------------------------- public mapping getEvents() { return _events; } + //--------------------------------------------------------------------------- public void setEvents(mapping &scripts) { _events = scripts; } + //--------------------------------------------------------------------------- public PanelFileScript getEvent(string name) { if (mappingHasKey(_events, name)) @@ -70,7 +85,7 @@ class PanelFileShape return foo; } - + //--------------------------------------------------------------------------- public string getName() { if (mappingHasKey(_firstLevelProps, "Name")) @@ -79,14 +94,13 @@ class PanelFileShape return ""; } - + //--------------------------------------------------------------------------- public static int getMaxCountOfEvents() { return 100; } - - + //--------------------------------------------------------------------------- public int calculate() { int count = mappinglen(_events); @@ -111,32 +125,35 @@ class PanelFileShape return 0; } + //--------------------------------------------------------------------------- public int getCCN() { return _ccn; } + //--------------------------------------------------------------------------- public float getAvgCCN() { return _avgCcn; } + //--------------------------------------------------------------------------- public int getNLOC() { return _nloc; } + //--------------------------------------------------------------------------- public float getAvgNLOC() { return _avgNloc; } - + //--------------------------------------------------------------------------- public int validate() { - QgVersionResult::lastErr = ""; - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("shape.name", getName()); + result = new QgResult("QgStaticCheck_Panels", "shape", dollars); validateCountOfProperties(); validateCountOfEvents(); @@ -150,6 +167,11 @@ class PanelFileShape return 0; } +//----------------------------------------------------------------------------- +//@protected members +//----------------------------------------------------------------------------- + + //--------------------------------------------------------------------------- // countOfProperties protected int validateCountOfProperties() { @@ -157,16 +179,14 @@ class PanelFileShape if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.shape.countOfProperties"); - assertion.setReasonText("reason.shape.countOfProperties", makeMapping("shape.name", getName(), - "shape.countOfProperties", getCountOfProperties())); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.countOfProperties", this.getCountOfProperties()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.countOfProperties", dollars); assertion.info(getCountOfProperties(), settings.getScorePoints()); result.addChild(assertion); } } + //--------------------------------------------------------------------------- // getCountOfEvents protected int validateCountOfEvents() { @@ -174,90 +194,77 @@ class PanelFileShape if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.shape.countOfEvents"); - assertion.setReasonText("reason.shape.countOfEvents", makeMapping("shape.name", getName(), - "shape.countOfEvents", getCountOfEvents())); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.countOfEvents", this.getCountOfEvents()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.countOfEvents", dollars); assertion.assertLessEqual(getCountOfEvents(), settings.getHighLimit(DEFAULT_EVENTCOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } } - //---------------------------------------------------------------------------- + //--------------------------------------------------------------------------- protected int validateCCN() { shared_ptr settings = new QgSettings("PanelFileShape.shape.CCN"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - // info only, dont check the values - assertion.setAssertionText("assert.shape.CCN"); - assertion.setReasonText("reason.shape.CCN", makeMapping("shape.name", getName(), - "shape.CCN", getCCN())); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.CCN", this.getCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.CCN", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } + //--------------------------------------------------------------------------- protected int validateAvgCCN() { shared_ptr settings = new QgSettings("PanelFileShape.shape.avgCCN"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.shape.avgCCN"); - assertion.setReasonText("reason.shape.avgCCN", makeMapping("shape.name", getName(), - "shape.avgCCN", getAvgCCN())); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.avgCCN", this.getAvgCCN()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.CCN", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } + //--------------------------------------------------------------------------- protected int validateNLOC() { shared_ptr settings = new QgSettings("PanelFileShape.shape.NLOC"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.shape.NLOC"); - assertion.setReasonText("reason.shape.NLOC", makeMapping("shape.name", getName(), - "shape.NLOC", getNLOC())); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.NLOC", this.getNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.NLOC", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } + //--------------------------------------------------------------------------- protected int validateAvgNLOC() { shared_ptr settings = new QgSettings("PanelFileShape.shape.avgNLOC"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.shape.avgNLOC"); - assertion.setReasonText("reason.shape.avgNLOC", makeMapping("shape.name", getName(), - "shape.avgNLOC", getAvgNLOC())); - assertion.info(getCCN(), settings.getScorePoints()); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.avgNLOC", this.getAvgNLOC()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.avgNLOC", dollars); + assertion.info(this.getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } } - //---------------------------------------------------------------------------- + //--------------------------------------------------------------------------- // validate events protected int validateEvents() { if (mappinglen(_events) > 0) { - shared_ptr ev = new QgVersionResult(); - ev.setAssertionText("shape.events"); + const mapping dollars = makeMapping("shape.name", this.getName()); + shared_ptr assertion = new QgResult("QgStaticCheck_Panels", "shape.events", dollars); for (int i = 1; i <= mappinglen(_events); i++) { @@ -270,24 +277,22 @@ class PanelFileShape } } - //---------------------------------------------------------------------------- + //--------------------------------------------------------------------------- // validate properties protected int validateProperties() { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); if (mappinglen(_properties) > 0) { - shared_ptr prop = new QgVersionResult(); - prop.setAssertionText("shape.properties"); + const mapping dollars = makeMapping("shape.name", this.getName()); + shared_ptr prop = new QgResult("QgStaticCheck_Panels", "shape.properties", dollars); for (int i = 1; i <= mappinglen(_properties); i++) { ///@todo probably place for checking properties string key = mappingGetKey(_properties, i); - shared_ptr property = new QgVersionResult(); - property.setAssertionText(key); + const mapping dollars = makeMapping("shape.name", this.getName(), "shape.properties.key", key); + shared_ptr prop = new QgResult("QgStaticCheck_Panels", "shape.properties", dollars); property.info(_properties[key]); prop.addChild(property); @@ -297,6 +302,10 @@ class PanelFileShape } } +//----------------------------------------------------------------------------- +//@private members +//----------------------------------------------------------------------------- + mapping _events; mapping _properties; mapping _firstLevelProps; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl index a7b9933c..ec23dbee 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl @@ -7,16 +7,24 @@ #uses "std" #uses "spaceCheck" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" class PicturesFile { +//----------------------------------------------------------------------------- +//@public members +//----------------------------------------------------------------------------- + public shared_ptr result; + + //--------------------------------------------------------------------------- public PicturesFile(const string &path) { _path = path; // !! extension must be written lowercase, that NonCaseSensitive works } + //--------------------------------------------------------------------------- public int calculate() { if (!isfile(_path)) @@ -28,27 +36,26 @@ class PicturesFile return 0; } + //--------------------------------------------------------------------------- public uint getMaxSize() { // 1MB in == 1048576 bytes return (uint)1048576; } + //--------------------------------------------------------------------------- public int validate() { - result = new QgVersionResult(); - result.text = getName(); + const mapping dollars = makeMapping("file.name", getName()); + result = new QgResult("QgStaticCheck_Pictures", "file", dollars); { shared_ptr settings = new QgSettings("PicturesFile.file.size"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Pictures"); - assertion.setAssertionText("assert.file.size"); - assertion.setReasonText("reason.file.size", makeMapping("file.name", getName(), - "file.size", byteSizeToString(_size))); + const mapping dollars = makeMapping("file.name", getName(), "file.size", byteSizeToString(_size)); + shared_ptr assertion = new QgResult("QgStaticCheck_Pictures", "file.size", dollars); assertion.assertLessEqual(_size, settings.getHighLimit(getMaxSize()), settings.getScorePoints()); assertion.value = byteSizeToString(_size); // to see it with unit assertion.upperBound = byteSizeToString(settings.getHighLimit(getMaxSize())); // to see it with unit @@ -61,12 +68,8 @@ class PicturesFile if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Pictures"); - assertion.setAssertionText("assert.file.extension"); - assertion.setReasonText("reason.file.extension", makeMapping("file.name", getName(), - "file.extension", _extension, - "allowedValues", settings.getReferenceValues())); + const mapping dollars = makeMapping("file.name", getName(), "file.extension", _extension); + shared_ptr assertion = new QgResult("QgStaticCheck_Pictures", "file.extension", dollars); assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints()); result.addChild(assertion); } @@ -74,14 +77,15 @@ class PicturesFile return 0; } + //--------------------------------------------------------------------------- public string getName() { return baseName(_path); } - - public shared_ptr result; - +//----------------------------------------------------------------------------- +//@private members +//----------------------------------------------------------------------------- string _extension; uint _size; string _path; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl index a677a9d4..f1d340d9 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl @@ -9,6 +9,7 @@ #uses "classes/ErrorHdl/OaLogger" #uses "classes/QualityGates/QgBase" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgStaticCheck/StaticDir" #uses "classes/QualityGates/QgSettings" #uses "stdVar" @@ -156,18 +157,21 @@ class StaticCodeDir : StaticDir if (rc == 0) { + const mapping dollars = makeMapping("dir.name", getName(), + "dir.avgNLOC", getAvgNLOC(), + "dir.avgNLOC", getAvgNLOC(), + "dir.CCN", getCCN(), + "dir.CCN", getAvgCCN() + ); + { shared_ptr settings = new QgSettings("StaticCodeDir.dir.NLOC"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticCodeDir", "dir.NLOC", dollars); // NLOC in dir - assertion.setAssertionText("assert.dir.NLOC"); - assertion.setReasonText("reason.dir.NLOC", makeMapping("dir.name", getName(), - "dir.NLOC", getNLOC())); assertion.info(getNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -176,17 +180,12 @@ class StaticCodeDir : StaticDir // average NLOC in dir if (getAvgNLOC() > 0) { - shared_ptr settings = new QgSettings("StaticCodeDir.dir.avgNLOC"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticCodeDir", "dir.avgNLOC", dollars); - assertion.setAssertionText("assert.dir.avgNLOC"); - assertion.setReasonText("reason.dir.avgNLOC", makeMapping("dir.name", getName(), - "dir.avgNLOC", getAvgNLOC())); assertion.info(getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -198,12 +197,7 @@ class StaticCodeDir : StaticDir if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); - - assertion.setAssertionText("assert.dir.CCN"); - assertion.setReasonText("reason.dir.CCN", makeMapping("dir.name", getName(), - "dir.CCN", getCCN())); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticCodeDir", "dir.CCN", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -216,12 +210,7 @@ class StaticCodeDir : StaticDir if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); - - assertion.setAssertionText("assert.dir.avgCCN"); - assertion.setReasonText("reason.dir.avgCCN", makeMapping("dir.name", getName(), - "dir.CCN", getAvgCCN())); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticCodeDir", "dir.avgCCN", dollars); assertion.info(getAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl index 1db7e30d..00e5b762 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl @@ -8,25 +8,29 @@ // #uses "classes/ErrorHdl/OaLogger" -#uses "classes/QualityGates/QgBase" #uses "classes/FileSys/QgDir" +#uses "classes/QualityGates/QgBase" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" class StaticDir : QgDir { + //--------------------------------------------------------------------------- public setDir(string dirPath) { dynClear(_files); dynClear(_childs); - if (!dirPath.endsWith("/") && !dirPath.endsWith("\\")) - dirPath += makeNativePath("/"); // ensure trailing path delimiter + dirPath = makeUnixPath(dirPath); + + if (!dirPath.isEmpty() && !dirPath.endsWith("/")) + dirPath += "/"; // ensure trailing path delimiter - QgDir::setDirPath(dirPath); + QgDir::setDirPath(makeNativePath(dirPath)); } - //------------------------------------------------------------------------------ + //--------------------------------------------------------------------------- /** @brief Function calculates statistic data from panels, scripts, libs dirs. @details It works for oa panels, scripts, libs directories. @@ -47,10 +51,11 @@ class StaticDir : QgDir dynClear(_files); dynClear(_childs); + _allFilesCount = 0; if (!exists()) { - logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist", getDirPath()); + logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist: " + getDirPath()); return -1; } @@ -94,31 +99,30 @@ class StaticDir : QgDir return 0; } + //--------------------------------------------------------------------------- public int validate() { const int filesCount = getCountOfFiles(); const int subDirCount = getCountOfSubDirs(); const bool isEmpty = (filesCount + subDirCount) == 0; + const mapping dollars = makeMapping("dir.name", getName(), + "dir.filesCountRecursive", getCountOfFilesRecursive(), + "dir.isEmpty", isEmpty, + "dir.subDirCount", subDirCount, + "dir.filesCount", filesCount + ); - QgVersionResult::lastErr = ""; - - result = new QgVersionResult(); - result.text = getName(); + result = new QgResult("QgStaticCheck_StaticDir", "directory", dollars); { - shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.hasFilesRecursive"); + shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.isEmpty"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.hasFilesRecursive"); - assertion.setReasonText("reason.dir.hasFilesRecursive", makeMapping("dir.name", getName())); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticDir", "dir.isEmpty", dollars); - if (!assertion.assertGreatherEqual(getCountOfFilesRecursive(), - settings.getLowLimit(DEFAULT_FILESREC_LOW), - settings.getScorePoints())) + if (!assertion.assertFalse(isEmpty, settings.getScorePoints())) { result.addChild(assertion); return 1; @@ -129,16 +133,15 @@ class StaticDir : QgDir } { - shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.isEmpty"); + shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.hasFilesRecursive"); if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.isEmpty"); - assertion.setReasonText("reason.dir.isEmpty", makeMapping("dir.name", getName())); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticDir", "dir.hasFilesRecursive", dollars); - if (!assertion.assertFalse(isEmpty, settings.getScorePoints())) + if (!assertion.assertGreatherEqual(getCountOfFilesRecursive(), + settings.getLowLimit(DEFAULT_FILESREC_LOW), + settings.getScorePoints())) { result.addChild(assertion); return 1; @@ -153,11 +156,7 @@ class StaticDir : QgDir if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.subDirCount"); - assertion.setReasonText("reason.dir.subDirCount", makeMapping("dir.name", getName(), - "dir.subDirCount", subDirCount)); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticDir", "dir.subDirCount", dollars); assertion.assertLessEqual(subDirCount, settings.getHighLimit(DEFAULT_SUBDIRCOUNT_HIGH), settings.getScorePoints()); @@ -171,11 +170,10 @@ class StaticDir : QgDir if (settings.isEnabled()) { - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.filesCount"); - assertion.setReasonText("reason.dir.filesCount", makeMapping("dir.name", getName(), - "dir.filesCount", filesCount)); + shared_ptr assertion = new QgResult("QgStaticCheck_StaticDir", "dir.filesCount", dollars); + DebugTN(__FUNCTION__, filesCount, + settings.getHighLimit(DEFAULT_FILESCOUNT_HIGH), + settings.getScorePoints(), dollars); assertion.assertLessEqual(filesCount, settings.getHighLimit(DEFAULT_FILESCOUNT_HIGH), settings.getScorePoints()); @@ -186,13 +184,13 @@ class StaticDir : QgDir return 0; } + //--------------------------------------------------------------------------- public int validateSubDirs() { if (dynlen(_childs) > 0) { - shared_ptr subDirs = new QgVersionResult(); - subDirs.setMsgCatName("QgStaticCheck_StaticDir"); - subDirs.setAssertionText("subDirsList"); + const mapping dollars = makeMapping("dir.name", getName()); + shared_ptr subDirs = new QgResult("QgStaticCheck_StaticDir", "subDirsList", dollars); while (dynlen(_childs) > 0) { @@ -207,13 +205,13 @@ class StaticDir : QgDir return 0; } + //--------------------------------------------------------------------------- public int validateFiles() { if (dynlen(_files) > 0) { - shared_ptr files = new QgVersionResult(); - files.setMsgCatName("QgStaticCheck_StaticDir"); - files.setAssertionText("filesList"); + const mapping dollars = makeMapping("dir.name", getName()); + shared_ptr files = new QgResult("QgStaticCheck_StaticDir", "filesList", dollars); while (dynlen(_files) > 0) { @@ -228,32 +226,37 @@ class StaticDir : QgDir return 0; } + //--------------------------------------------------------------------------- public dyn_anytype getSubDirs() { return _childs; } + //--------------------------------------------------------------------------- public dyn_anytype getFiles() { return _files; } - + //--------------------------------------------------------------------------- public int getCountOfFiles() { return dynlen(_files); } + //--------------------------------------------------------------------------- public int getCountOfFilesRecursive() { return _allFilesCount; } + //--------------------------------------------------------------------------- public int getCountOfSubDirs() { return dynlen(_childs); } + //--------------------------------------------------------------------------- public void clear() { dynClear(_files); @@ -261,18 +264,18 @@ class StaticDir : QgDir // result = nullptr; } + //--------------------------------------------------------------------------- public string getSettingsRoot() { return "StaticDir"; } - //------------------------------------------------------------------------------ -// public QgVersionResult result = QgVersionResult(); //!< Quality gate result - public shared_ptr result; + //--------------------------------------------------------------------------- + public shared_ptr result; -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- //@protected members -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- protected dyn_anytype _files; protected dyn_anytype _childs; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl index 8f41d19d..1b13747a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl @@ -12,6 +12,7 @@ #uses "classes/QualityGates/Qg" #uses "classes/QualityGates/QgBase" #uses "classes/Variables/String" +#uses "classes/QualityGates/QgResult" #uses "classes/QualityGates/QgSettings" //-------------------------------------------------------------------------------- @@ -47,13 +48,13 @@ class QgSyntaxCheck : QgBase if (QgBase::setUp()) return -1; - QgVersionResult::showErrorsOnly = TRUE; + QgResult::showErrorsOnly = TRUE; QgDir panelsDir = QgDir(PROJ_PATH + PANELS_REL_PATH); QgDir scriptsDir = QgDir(PROJ_PATH + SCRIPTS_REL_PATH); if (!panelsDir.exists() && !scriptsDir.exists()) - setMinValidScore("QgSyntaxCheck", "assert.missingFiles", "reason.missingFiles"); + this.setMinValidScore("QgSyntaxCheck", "missingFiles"); return 0; } @@ -79,14 +80,17 @@ class QgSyntaxCheck : QgBase @return 0 when successfull, otherwise -1. @attention override from QgBase::validate() + + @todo many code might be eliminated by using WinCC OA LogAnalyzer. But this feature + exists in versions >= 3.19. That means after refactoring it will no more works with + WinCC OA version <= 3.18 + The value is to eliminate code here. + + is parsed in weir way and no body can grant, that it works "for ever" + + performance */ public int validate() { - QgVersionResult::lastErr = ""; - _result = new QgVersionResult(); - - _result.setMsgCatName("QgSyntaxCheck"); - _result.setAssertionText("syntaxMsgs"); + _result = new QgResult("QgSyntaxCheck", "syntaxMsgs"); dyn_string msgs; _oaSyntaxCheck.stdErrToMessages(msgs); @@ -126,10 +130,7 @@ class QgSyntaxCheck : QgBase msg = makeUnixPath(msg); strreplace(msg, makeUnixPath(PROJ_PATH), ""); - shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgSyntaxCheck"); - assertion.setAssertionText("assert.isSyntaxValid"); - assertion.setReasonText("reason.isSyntaxValid", makeMapping("msg", msg)); + shared_ptr assertion = new QgResult("QgSyntaxCheck", ("isSyntaxValid", makeMapping("msg", msg)); if (prio == "INFO") { @@ -144,23 +145,6 @@ class QgSyntaxCheck : QgBase DebugFN("QgSyntaxCheck", __FUNCTION__, "Skip checks for info message"); continue; // ignore info messages } - else if (errCode == "117") - { - /// @todo remove this check when are WinCCOALicenseCtrlExt implemented - if (strpos(msg, "WinCCOALicenseCtrlExt") > 0) - continue; // ignore missing extension, this is added by IL - } - else if (errCode == "61") - { - /// 61, Cannot open file, /.../WinCCOA_FinalyApi_234/scripts/ - String str = String(makeUnixPath(msg)); - - if (str.endsWith(makeUnixPath(SCRIPTS_REL_PATH)) || str.endsWith(makeUnixPath(PANELS_REL_PATH))) - { - DebugFTN("QgSyntaxCheck", "oa bug, ignore this message", msg); - continue; // ignore missing extension, this is added by IL - } - } DebugFTN("QgSyntaxCheck", __FUNCTION__, "add message to bad-list"); diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl index 12c0567c..0bf28e91 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl @@ -29,6 +29,19 @@ class QgTest : OaTest //@public members //-------------------------------------------------------------------------------- + //------------------------------------------------------------------------------ + /** Function check if the quality gate has been started by WinCC OA TestFramework + @return true when started by WinCC OA TestFramework, false otherwise. + */ + public static bool isStartedByTestFramework() + { + // this file is generated by WinCC OA Testframework, before test manager has + // been started. Therefore we "know" it is started by the testframework. + // see also OaTestBase::isStartedByTF() + // yes it will be better to use origin function, but it is private ;-( + return isfile(PROJ_PATH + "fullResult.json"); + } + //------------------------------------------------------------------------------ /** @brief Function calculates QG score. @details Calculates the QG-score depended of test-results. Calculate how many @@ -59,6 +72,7 @@ class QgTest : OaTest return perc; } + //------------------------------------------------------------------------------ public void addScoreDetail(const mapping &info) { try diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl index 3432f33c..2d1e2e38 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl @@ -6,7 +6,7 @@ */ -//-------------------------------------------------------------------------------- +//----------------------------------------------------------------------------- struct CppCheckError { string id; @@ -19,6 +19,7 @@ struct CppCheckError int cwe; string knownBug; // for internal use (tests) + //--------------------------------------------------------------------------- string toStdErrString() { string s = "ID: " + id + "\n" + @@ -39,4 +40,19 @@ struct CppCheckError return s; } + + //--------------------------------------------------------------------------- + public mapping toMapping() + { + return makeMapping( + "id", id, + "severity", severity, + "msg", msg, + "verbose", verbose, + "path", path, + "path0", path0, + "line", line, + "cwe", cwe + ); + } }; diff --git a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl index 14592d89..2507f3e1 100644 --- a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl @@ -154,12 +154,6 @@ void tool_QualityGates_QgOverloadedFilesCheck() _startCtrlMan("QualityGates/StaticTests/QgOverloadedFilesCheck"); } -void tool_QualityGates_UnitTests() -{ - tool_QualityGates_showBusy("UnitTests"); - _startCtrlMan("QualityGates/QgTestRunner"); -} - void tool_QualityGates_OpenResult() { ModuleOnWithPanel("QgResult-1", -1, -1, 400, 400, 1, 1, "Scale", "vision/QualityChecks/QG_Main.pnl", "QG Result Overview", makeDynString("")); diff --git a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl index ad6000ba..5f2ffc52 100644 --- a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl @@ -127,7 +127,7 @@ void ctrlPPCheck() res["countOfParams.avg"] = script.getAvgParamCount(); - map["script"] = res;//script.result.toMap(); + map["script"] = res; } diff --git a/WinCC_OA_Test/Projects/Global/scripts/libs/classes/oaTest/OaTest.ctl b/WinCC_OA_Test/Projects/Global/scripts/libs/classes/oaTest/OaTest.ctl new file mode 100644 index 00000000..2b32296a --- /dev/null +++ b/WinCC_OA_Test/Projects/Global/scripts/libs/classes/oaTest/OaTest.ctl @@ -0,0 +1,47 @@ +// $License: NOLICENSE +/** + @file $relPath + @brief OaTest basic class + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only + @author mPokorny +*/ + +//Libraries used(#uses) +#uses "classes/oaTest/OaTestBase" + +//-------------------------------------------------------------------------------- +/** + @brief Overloaded OaTestBase class +*/ +class OaTest : OaTestBase +{ + + //------------------------------------------------------------------------------ + /** + @brief The function checks, if the *value* contains *refValue* + @param value The value that is tested. + @param refValue Value to find. + @param note Optional parameter. Test case-specific data can be set for the test case. + It can be used to track an assertion message for a better bug analysis. + @return oaUnitAssertTrue The function returns the error code. See also oaUnitAssertTrue() + */ + protected int assertDynContains(const anytype &value, const anytype &refValue, const string note = "") + { + _fillTcData(note); + tcData.setErrMsg("The value '" + value + "' does not contains " + refValue); + tcData.setCurrentValue(value); + tcData.setReferenceValue(refValue); + tcData.setMethod(__FUNCTION__); + + int rc = oaUnitAssertTrue(getCurrentTestCaseId(), value.contains(refValue), getTestCaseData()); + + if ((rc != 0) && hasKnownBugHandler()) + { + oaTestKnownBugLoader.newBugFound(tcData); + } + + return rc; + } + +}; diff --git a/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl new file mode 100644 index 00000000..4e5cc95b --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl @@ -0,0 +1,123 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck"/*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgOverloadedFilesCheck : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("QgOverloadedFilesCheck::ctor", + "QgOverloadedFilesCheck::calculate", + "QgOverloadedFilesCheck::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "QgOverloadedFilesCheck::ctor": + { + QgOverloadedFilesCheck check = QgOverloadedFilesCheck(); + assertEqual(check.projPathToCheck, PROJ_PATH); + return 0; + } + + case "QgOverloadedFilesCheck::calculate": + { + QgOverloadedFilesCheck check = QgOverloadedFilesCheck(); + check.projPathToCheck = "oijas0dij0adji"; + + // not existing + assertEqual(check.calculate(), -1); + + check.projPathToCheck = PROJ_PATH; + assertEqual(check.calculate(), 0); + + return 0; + } + + case "QgOverloadedFilesCheck::validate": + { + QgOverloadedFilesCheck check = QgOverloadedFilesCheck(); + check.projPathToCheck = PROJ_PATH + "_EMPTY__/"; + mkdir(check.projPathToCheck); + mkdir(check.projPathToCheck + SCRIPTS_REL_PATH); + + check.calculate(); + assertEqual(check.validate(), 0); + assertEqual(check.result.errorPoints, 0); + QgResult::clearLastErr(); + + fclose(fopen(check.projPathToCheck + SCRIPTS_REL_PATH + "some-one-script.ctl", "wb+")); + assertTrue(isfile(check.projPathToCheck + SCRIPTS_REL_PATH + "some-one-script.ctl")); + check.calculate(); + assertEqual(check.validate(), 0); + assertEqual(check.result.errorPoints, 0); + QgResult::clearLastErr(); + + // copy some one file from WinCC OA + copyFile(WINCCOA_PATH + SCRIPTS_REL_PATH + "userPara.ctl", check.projPathToCheck + SCRIPTS_REL_PATH); + assertTrue(isfile(check.projPathToCheck + SCRIPTS_REL_PATH + "userPara.ctl")); + check.calculate(); + assertEqual(check.validate(), 0); + assertEqual(check.result.errorPoints, 0); // warning only + assertDynContains(QgResult::getLastErrors(), "isOverloadedAllowed"); + QgResult::clearLastErr(); + remove(check.projPathToCheck + SCRIPTS_REL_PATH + "about.ctl"); + + + copyFile(WINCCOA_PATH + SCRIPTS_REL_PATH + "about.ctl", check.projPathToCheck + SCRIPTS_REL_PATH); + assertTrue(isfile(check.projPathToCheck + SCRIPTS_REL_PATH + "about.ctl")); + check.calculate(); + assertEqual(check.validate(), 0); + assertEqual(check.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "isOverloaded"); + QgResult::clearLastErr(); + remove(check.projPathToCheck + SCRIPTS_REL_PATH + "about.ctl"); + + return 0; + } + } + + return -1; + } + +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgOverloadedFilesCheck test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testProj.unit.config new file mode 100644 index 00000000..574152be --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testProj.unit.config @@ -0,0 +1,13 @@ +{ + "FILE_VERSION":"1.0", + "ID":"QgOverloadedFilesCheck", + "NAME":"Unit tests for QgOverloadedFilesCheck", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl -n" } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testSuite.config b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testSuite.config new file mode 100644 index 00000000..b41abebe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgOverloadedFilesCheck/testSuite.config @@ -0,0 +1,7 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for general ctrl code", + "TEST_PROJECTS": [ + "unit" + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl new file mode 100644 index 00000000..ca9c1abe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl @@ -0,0 +1,285 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir"/*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgPicturesDir : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("PicturesDir::ctor", + "PicturesDir::exists", + "PicturesDir::calculate", + "PicturesDir::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "PicturesDir::ctor": + { + PicturesDir dir = PicturesDir(); + assertEqual(dir.getName(), ""); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + dir.setDir(PROJ_PATH); + assertEqual(dir.getName(), PROJ); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + return 0; + } + + case "PicturesDir::exists": + { + PicturesDir dir = PicturesDir(); + assertFalse(dir.exists()); + dir.setDir(PROJ_PATH); + assertTrue(dir.exists()); + dir.setDir(PROJ_PATH + "abc"); + assertFalse(dir.exists()); + return 0; + } + + case "PicturesDir::calculate": + { + PicturesDir dir = PicturesDir(); + + // not existing + assertEqual(dir.calculate(), -1); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + // existing, but empty + string tmpDir = _makeTmpDir(); + dir.setDir(tmpDir); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + // existing with 2 sub dirs and 1 file + mkdir(tmpDir + "subDir1"); + mkdir(tmpDir + "subDir2"); + fclose(fopen(tmpDir + "file.png", "wb+")); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 1); + assertEqual(dir.getCountOfSubDirs(), 2); + + + // existing witth 3 files in defirent sub dirs + fclose(fopen(tmpDir + "subDir1/file.PNG", "wb+")); + fclose(fopen(tmpDir + "subDir1/file.txt", "wb+")); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 3); + assertEqual(dir.getCountOfSubDirs(), 2); + + dyn_anytype childs = dir.getSubDirs(); + assertEqual(dynlen(childs), 2); + assertEqual(childs[1].getName(), "subDir1"); + + + dir.setDir(PROJ_PATH); + assertTrue(dir.exists()); + dir.setDir(PROJ_PATH + "abc"); + assertFalse(dir.exists()); + + rmdir(tmpDir, TRUE); + return 0; + } + + case "PicturesDir::validate": + { + PicturesDir dir = PicturesDir(); + string tmpDir = _makeTmpDir(); + + dir.setDir(tmpDir); + + // *** check empty + dir.calculate(); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(dir.result.totalPoints, 1); + assertDynContains(QgResult::getLastErrors(), "dir.isEmpty"); + QgResult::clearLastErr(); + + // *** check direcotry with 1 sub-dir without any files + mkdir(tmpDir + "one-empty"); + assertTrue(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); + dir.calculate(); + assertEqual(dir.validate(), 0); + // dir (2 cheks) + sub dir (1 check) + assertEqual(dir.result.errorPoints, 2); + assertEqual(dir.result.totalPoints, 3); + assertDynContains(QgResult::getLastErrors(), "dir.hasFilesRecursive"); + assertDynContains(QgResult::getLastErrors(),"dir.isEmpty"); + rmdir(tmpDir + "one-empty", true); + assertFalse(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); + QgResult::clearLastErr(); + + // *** check with 10 files, try it with different extentions + mkdir(tmpDir + "10-files"); + dir.setDir(tmpDir + "10-files"); + fclose(fopen(dir.getDirPath() + "file1.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file2.PNG", "wb+")); + fclose(fopen(dir.getDirPath() + "file3.jPg", "wb+")); + fclose(fopen(dir.getDirPath() + "file4.JpG", "wb+")); + fclose(fopen(dir.getDirPath() + "file5.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file6.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file7.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file8.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file9.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file10.png", "wb+")); + dir.calculate(); + + assertEqual(dir.getCountOfFiles(), 10); + assertEqual(dir.getCountOfFilesRecursive(), 10); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 24); + // ! after validations are the file objects removed (to spare memory) + // therefor you will have count 0 + assertEqual(dir.getCountOfFiles(), 0); + rmdir(tmpDir + "10-files", true); + + // *** too mutch files + mkdir(tmpDir + "too-much-files"); + dir.setDir(tmpDir + "too-much-files"); + shared_ptr settings = new QgSettings("PicturesDir.dir.filesCount"); + int limit = settings.getHighLimit(-1); + this.info("Create " + limit + " files"); + + for(int i = 1; i <= limit; i++) + { + fclose(fopen(dir.getDirPath() + "file" + i + ".png", "wb+")); + } + + this.info("Create one-extra-file file"); + fclose(fopen(dir.getDirPath() + "one-extra-file.png", "wb+")); + + dir.calculate(); + + assertEqual(dir.getCountOfFiles(), limit + 1); + assertEqual(dir.getCountOfFilesRecursive(), limit + 1); + + assertEqual(dir.validate(), 0); + // assertEqual(dir.result.errorPoints, 1); + // assertEqual(dir.result.totalPoints, 25); + assertDynContains(QgResult::getLastErrors(), "dir.filesCount"); + QgResult::clearLastErr(); + rmdir(tmpDir, true); + assertFalse(isdir(tmpDir), tmpDir); + + // *** try with 5 sub dirs + mkdir(tmpDir + "5-sub-dirs"); + dir.setDir(tmpDir + "5-sub-dirs"); + mkdir(dir.getDirPath() + "subDir1"); + fclose(fopen(dir.getDirPath() + "subDir1/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir2"); + fclose(fopen(dir.getDirPath() + "subDir2/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir3"); + fclose(fopen(dir.getDirPath() + "subDir3/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir4"); + fclose(fopen(dir.getDirPath() + "subDir4/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir5"); + fclose(fopen(dir.getDirPath() + "subDir5/file1.png", "wb+")); + dir.calculate(); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 34); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 5); + QgResult::clearLastErr(); + rmdir(tmpDir + "5-sub-dirs", true); + + // *** too mutch sub dirs + mkdir(tmpDir + "too-mutch-sub-dirs"); + dir.setDir(tmpDir + "too-mutch-sub-dirs"); + limit = settings.getHighLimit(-1); + this.info("Create " + limit + " sub directories"); + + for(int i = 1; i <= limit; i++) + { + mkdir(dir.getDirPath() + "subDir" + i); + fclose(fopen(dir.getDirPath() + "subDir" + i + "/file1.png", "wb+")); + } + + this.info("Create extra-subDir"); + mkdir(dir.getDirPath() + "extra-subDir"); + fclose(fopen(dir.getDirPath() + "extra-subDir/file1.png", "wb+")); + dir.calculate(); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "dir.subDirCount"); + QgResult::clearLastErr(); + rmdir(tmpDir + "too-mutch-sub-dirs", true); + + return 0; + } + } + + return -1; + } + + //------------------------------------------------------------------------------ + string _makeTmpDir() + { + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; + + // create tmp-dir for this test + if (isdir(tmpDir)) + rmdir(tmpDir, TRUE); + + mkdir(tmpDir); + + return tmpDir; + } +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgPicturesDir test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl new file mode 100644 index 00000000..b28673a3 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl @@ -0,0 +1,96 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesFile" /*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgPicturesFile : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("PicturesFile::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "PicturesFile::validate": + { + string tmpDir = _makeTmpDir(); + PicturesFile picture = PicturesFile(tmpDir + "file1.thhhhxt"); + + // *** invalid extension + fclose(fopen(tmpDir + "file1.thhhhxt", "wb+")); + picture.calculate(); + + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "file.extension"); + QgResult::clearLastErr(); + remove(tmpDir + "file1.thhhhxt"); + + // *** valid file + picture = PicturesFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png")); + // copyFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png"), tmpDir); + picture.calculate(); + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 0); + + return 0; + } + } + + return -1; + } + + //------------------------------------------------------------------------------ + string _makeTmpDir() + { + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; + + // create tmp-dir for this test + if (isdir(tmpDir)) + rmdir(tmpDir, TRUE); + + mkdir(tmpDir); + + return tmpDir; + } +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgPicturesFile test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testProj.unit.config new file mode 100644 index 00000000..d954476d --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testProj.unit.config @@ -0,0 +1,14 @@ +{ + "FILE_VERSION":"1.0", + "ID":"QgPicturesCheck", + "NAME":"Unit tests for QgPicturesCheck", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl -n" } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testSuite.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testSuite.config new file mode 100644 index 00000000..b41abebe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 2/testSuite.config @@ -0,0 +1,7 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for general ctrl code", + "TEST_PROJECTS": [ + "unit" + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl new file mode 100644 index 00000000..ca9c1abe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl @@ -0,0 +1,285 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir"/*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgPicturesDir : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("PicturesDir::ctor", + "PicturesDir::exists", + "PicturesDir::calculate", + "PicturesDir::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "PicturesDir::ctor": + { + PicturesDir dir = PicturesDir(); + assertEqual(dir.getName(), ""); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + dir.setDir(PROJ_PATH); + assertEqual(dir.getName(), PROJ); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + return 0; + } + + case "PicturesDir::exists": + { + PicturesDir dir = PicturesDir(); + assertFalse(dir.exists()); + dir.setDir(PROJ_PATH); + assertTrue(dir.exists()); + dir.setDir(PROJ_PATH + "abc"); + assertFalse(dir.exists()); + return 0; + } + + case "PicturesDir::calculate": + { + PicturesDir dir = PicturesDir(); + + // not existing + assertEqual(dir.calculate(), -1); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + // existing, but empty + string tmpDir = _makeTmpDir(); + dir.setDir(tmpDir); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); + + // existing with 2 sub dirs and 1 file + mkdir(tmpDir + "subDir1"); + mkdir(tmpDir + "subDir2"); + fclose(fopen(tmpDir + "file.png", "wb+")); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 1); + assertEqual(dir.getCountOfSubDirs(), 2); + + + // existing witth 3 files in defirent sub dirs + fclose(fopen(tmpDir + "subDir1/file.PNG", "wb+")); + fclose(fopen(tmpDir + "subDir1/file.txt", "wb+")); + + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 3); + assertEqual(dir.getCountOfSubDirs(), 2); + + dyn_anytype childs = dir.getSubDirs(); + assertEqual(dynlen(childs), 2); + assertEqual(childs[1].getName(), "subDir1"); + + + dir.setDir(PROJ_PATH); + assertTrue(dir.exists()); + dir.setDir(PROJ_PATH + "abc"); + assertFalse(dir.exists()); + + rmdir(tmpDir, TRUE); + return 0; + } + + case "PicturesDir::validate": + { + PicturesDir dir = PicturesDir(); + string tmpDir = _makeTmpDir(); + + dir.setDir(tmpDir); + + // *** check empty + dir.calculate(); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(dir.result.totalPoints, 1); + assertDynContains(QgResult::getLastErrors(), "dir.isEmpty"); + QgResult::clearLastErr(); + + // *** check direcotry with 1 sub-dir without any files + mkdir(tmpDir + "one-empty"); + assertTrue(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); + dir.calculate(); + assertEqual(dir.validate(), 0); + // dir (2 cheks) + sub dir (1 check) + assertEqual(dir.result.errorPoints, 2); + assertEqual(dir.result.totalPoints, 3); + assertDynContains(QgResult::getLastErrors(), "dir.hasFilesRecursive"); + assertDynContains(QgResult::getLastErrors(),"dir.isEmpty"); + rmdir(tmpDir + "one-empty", true); + assertFalse(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); + QgResult::clearLastErr(); + + // *** check with 10 files, try it with different extentions + mkdir(tmpDir + "10-files"); + dir.setDir(tmpDir + "10-files"); + fclose(fopen(dir.getDirPath() + "file1.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file2.PNG", "wb+")); + fclose(fopen(dir.getDirPath() + "file3.jPg", "wb+")); + fclose(fopen(dir.getDirPath() + "file4.JpG", "wb+")); + fclose(fopen(dir.getDirPath() + "file5.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file6.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file7.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file8.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file9.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file10.png", "wb+")); + dir.calculate(); + + assertEqual(dir.getCountOfFiles(), 10); + assertEqual(dir.getCountOfFilesRecursive(), 10); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 24); + // ! after validations are the file objects removed (to spare memory) + // therefor you will have count 0 + assertEqual(dir.getCountOfFiles(), 0); + rmdir(tmpDir + "10-files", true); + + // *** too mutch files + mkdir(tmpDir + "too-much-files"); + dir.setDir(tmpDir + "too-much-files"); + shared_ptr settings = new QgSettings("PicturesDir.dir.filesCount"); + int limit = settings.getHighLimit(-1); + this.info("Create " + limit + " files"); + + for(int i = 1; i <= limit; i++) + { + fclose(fopen(dir.getDirPath() + "file" + i + ".png", "wb+")); + } + + this.info("Create one-extra-file file"); + fclose(fopen(dir.getDirPath() + "one-extra-file.png", "wb+")); + + dir.calculate(); + + assertEqual(dir.getCountOfFiles(), limit + 1); + assertEqual(dir.getCountOfFilesRecursive(), limit + 1); + + assertEqual(dir.validate(), 0); + // assertEqual(dir.result.errorPoints, 1); + // assertEqual(dir.result.totalPoints, 25); + assertDynContains(QgResult::getLastErrors(), "dir.filesCount"); + QgResult::clearLastErr(); + rmdir(tmpDir, true); + assertFalse(isdir(tmpDir), tmpDir); + + // *** try with 5 sub dirs + mkdir(tmpDir + "5-sub-dirs"); + dir.setDir(tmpDir + "5-sub-dirs"); + mkdir(dir.getDirPath() + "subDir1"); + fclose(fopen(dir.getDirPath() + "subDir1/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir2"); + fclose(fopen(dir.getDirPath() + "subDir2/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir3"); + fclose(fopen(dir.getDirPath() + "subDir3/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir4"); + fclose(fopen(dir.getDirPath() + "subDir4/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir5"); + fclose(fopen(dir.getDirPath() + "subDir5/file1.png", "wb+")); + dir.calculate(); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 34); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 5); + QgResult::clearLastErr(); + rmdir(tmpDir + "5-sub-dirs", true); + + // *** too mutch sub dirs + mkdir(tmpDir + "too-mutch-sub-dirs"); + dir.setDir(tmpDir + "too-mutch-sub-dirs"); + limit = settings.getHighLimit(-1); + this.info("Create " + limit + " sub directories"); + + for(int i = 1; i <= limit; i++) + { + mkdir(dir.getDirPath() + "subDir" + i); + fclose(fopen(dir.getDirPath() + "subDir" + i + "/file1.png", "wb+")); + } + + this.info("Create extra-subDir"); + mkdir(dir.getDirPath() + "extra-subDir"); + fclose(fopen(dir.getDirPath() + "extra-subDir/file1.png", "wb+")); + dir.calculate(); + + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "dir.subDirCount"); + QgResult::clearLastErr(); + rmdir(tmpDir + "too-mutch-sub-dirs", true); + + return 0; + } + } + + return -1; + } + + //------------------------------------------------------------------------------ + string _makeTmpDir() + { + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; + + // create tmp-dir for this test + if (isdir(tmpDir)) + rmdir(tmpDir, TRUE); + + mkdir(tmpDir); + + return tmpDir; + } +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgPicturesDir test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl new file mode 100644 index 00000000..b28673a3 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl @@ -0,0 +1,96 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesFile" /*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgPicturesFile : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("PicturesFile::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "PicturesFile::validate": + { + string tmpDir = _makeTmpDir(); + PicturesFile picture = PicturesFile(tmpDir + "file1.thhhhxt"); + + // *** invalid extension + fclose(fopen(tmpDir + "file1.thhhhxt", "wb+")); + picture.calculate(); + + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "file.extension"); + QgResult::clearLastErr(); + remove(tmpDir + "file1.thhhhxt"); + + // *** valid file + picture = PicturesFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png")); + // copyFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png"), tmpDir); + picture.calculate(); + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 0); + + return 0; + } + } + + return -1; + } + + //------------------------------------------------------------------------------ + string _makeTmpDir() + { + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; + + // create tmp-dir for this test + if (isdir(tmpDir)) + rmdir(tmpDir, TRUE); + + mkdir(tmpDir); + + return tmpDir; + } +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgPicturesFile test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testProj.unit.config new file mode 100644 index 00000000..d954476d --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testProj.unit.config @@ -0,0 +1,14 @@ +{ + "FILE_VERSION":"1.0", + "ID":"QgPicturesCheck", + "NAME":"Unit tests for QgPicturesCheck", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl -n" } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testSuite.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testSuite.config new file mode 100644 index 00000000..b41abebe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck copy 3/testSuite.config @@ -0,0 +1,7 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for general ctrl code", + "TEST_PROJECTS": [ + "unit" + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl index 24d6bace..ca9c1abe 100644 --- a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl @@ -15,10 +15,10 @@ // used libraries (#uses) #uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir"/*!< tested object */ #uses "classes/oaTest/OaTest" -#uses "classes/QualityGates/QgVersionResult" +#uses "classes/QualityGates/QgResult" //-------------------------------------------------------------------------------- -class TstQg : OaTest +class TstQgPicturesDir : OaTest { //------------------------------------------------------------------------------ @@ -38,7 +38,7 @@ class TstQg : OaTest return -1; // eliminate false positives - QgVersionResult::enableOaTestCheck = false; + QgResult::selfTest = true; return 0; } @@ -76,7 +76,6 @@ class TstQg : OaTest case "PicturesDir::calculate": { PicturesDir dir = PicturesDir(); - string tmpDir = _makeTmpDir(); // not existing assertEqual(dir.calculate(), -1); @@ -85,6 +84,7 @@ class TstQg : OaTest assertEqual(dir.getCountOfSubDirs(), 0); // existing, but empty + string tmpDir = _makeTmpDir(); dir.setDir(tmpDir); assertEqual(dir.calculate(), 0); @@ -133,83 +133,128 @@ class TstQg : OaTest dir.setDir(tmpDir); - // check empty + // *** check empty dir.calculate(); assertEqual(dir.validate(), 0); assertEqual(dir.result.errorPoints, 1); assertEqual(dir.result.totalPoints, 1); - assertEqual(QgVersionResult::lastErr, "reason.dir.isEmpty"); -// return ; - - // check with 10 files, try it with different extentions - fclose(fopen(tmpDir + "file1.png", "wb+")); - fclose(fopen(tmpDir + "file2.PNG", "wb+")); - fclose(fopen(tmpDir + "file3.jPg", "wb+")); - fclose(fopen(tmpDir + "file4.JpG", "wb+")); - fclose(fopen(tmpDir + "file5.png", "wb+")); - fclose(fopen(tmpDir + "file6.png", "wb+")); - fclose(fopen(tmpDir + "file7.png", "wb+")); - fclose(fopen(tmpDir + "file8.png", "wb+")); - fclose(fopen(tmpDir + "file9.png", "wb+")); - fclose(fopen(tmpDir + "file10.png", "wb+")); - dir.calculate(); + assertDynContains(QgResult::getLastErrors(), "dir.isEmpty"); + QgResult::clearLastErr(); - assertEqual(dir.validate(), 0); - assertEqual(dir.result.errorPoints, 0); - assertEqual(dir.result.totalPoints, 23); - assertEqual(dir.getCountOfFiles(), 10); - - // to mutch files - fclose(fopen(tmpDir + "file11.png", "wb+")); + // *** check direcotry with 1 sub-dir without any files + mkdir(tmpDir + "one-empty"); + assertTrue(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); dir.calculate(); - assertEqual(dir.validate(), 0); - assertEqual(dir.result.errorPoints, 1); - assertEqual(dir.result.totalPoints, 25); - assertEqual(QgVersionResult::lastErr, "reason.dir.filesCount"); - assertEqual(dir.getCountOfFiles(), 11); -// DebugN(dir.result.children); - remove(tmpDir + "file11.png"); - - // try with 5 sub dirs - mkdir(tmpDir + "subDir1"); - fclose(fopen(tmpDir + "subDir1/file1.png", "wb+")); - mkdir(tmpDir + "subDir2"); - fclose(fopen(tmpDir + "subDir2/file1.png", "wb+")); - mkdir(tmpDir + "subDir3"); - fclose(fopen(tmpDir + "subDir3/file1.png", "wb+")); - mkdir(tmpDir + "subDir4"); - fclose(fopen(tmpDir + "subDir4/file1.png", "wb+")); - mkdir(tmpDir + "subDir5"); - fclose(fopen(tmpDir + "subDir5/file1.png", "wb+")); + // dir (2 cheks) + sub dir (1 check) + assertEqual(dir.result.errorPoints, 2); + assertEqual(dir.result.totalPoints, 3); + assertDynContains(QgResult::getLastErrors(), "dir.hasFilesRecursive"); + assertDynContains(QgResult::getLastErrors(),"dir.isEmpty"); + rmdir(tmpDir + "one-empty", true); + assertFalse(isdir(tmpDir + "one-empty"), tmpDir + "one-empty"); + QgResult::clearLastErr(); + + // *** check with 10 files, try it with different extentions + mkdir(tmpDir + "10-files"); + dir.setDir(tmpDir + "10-files"); + fclose(fopen(dir.getDirPath() + "file1.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file2.PNG", "wb+")); + fclose(fopen(dir.getDirPath() + "file3.jPg", "wb+")); + fclose(fopen(dir.getDirPath() + "file4.JpG", "wb+")); + fclose(fopen(dir.getDirPath() + "file5.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file6.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file7.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file8.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file9.png", "wb+")); + fclose(fopen(dir.getDirPath() + "file10.png", "wb+")); dir.calculate(); + assertEqual(dir.getCountOfFiles(), 10); + assertEqual(dir.getCountOfFilesRecursive(), 10); + assertEqual(dir.validate(), 0); assertEqual(dir.result.errorPoints, 0); - assertEqual(dir.result.totalPoints, 48); + assertEqual(dir.result.totalPoints, 24); + // ! after validations are the file objects removed (to spare memory) + // therefor you will have count 0 + assertEqual(dir.getCountOfFiles(), 0); + rmdir(tmpDir + "10-files", true); + + // *** too mutch files + mkdir(tmpDir + "too-much-files"); + dir.setDir(tmpDir + "too-much-files"); + shared_ptr settings = new QgSettings("PicturesDir.dir.filesCount"); + int limit = settings.getHighLimit(-1); + this.info("Create " + limit + " files"); + + for(int i = 1; i <= limit; i++) + { + fclose(fopen(dir.getDirPath() + "file" + i + ".png", "wb+")); + } + + this.info("Create one-extra-file file"); + fclose(fopen(dir.getDirPath() + "one-extra-file.png", "wb+")); - // to mutch sub dirs - mkdir(tmpDir + "subDir6"); - fclose(fopen(tmpDir + "subDir6/file1.png", "wb+")); dir.calculate(); + assertEqual(dir.getCountOfFiles(), limit + 1); + assertEqual(dir.getCountOfFilesRecursive(), limit + 1); + assertEqual(dir.validate(), 0); - assertEqual(dir.result.errorPoints, 1); - assertEqual(QgVersionResult::lastErr, "reason.dir.subDirCount"); -// DebugN(dir); - rmdir(tmpDir + "subDir6", TRUE); + // assertEqual(dir.result.errorPoints, 1); + // assertEqual(dir.result.totalPoints, 25); + assertDynContains(QgResult::getLastErrors(), "dir.filesCount"); + QgResult::clearLastErr(); + rmdir(tmpDir, true); + assertFalse(isdir(tmpDir), tmpDir); + + // *** try with 5 sub dirs + mkdir(tmpDir + "5-sub-dirs"); + dir.setDir(tmpDir + "5-sub-dirs"); + mkdir(dir.getDirPath() + "subDir1"); + fclose(fopen(dir.getDirPath() + "subDir1/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir2"); + fclose(fopen(dir.getDirPath() + "subDir2/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir3"); + fclose(fopen(dir.getDirPath() + "subDir3/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir4"); + fclose(fopen(dir.getDirPath() + "subDir4/file1.png", "wb+")); + mkdir(dir.getDirPath() + "subDir5"); + fclose(fopen(dir.getDirPath() + "subDir5/file1.png", "wb+")); + dir.calculate(); - // invalid extention, is a indirect test fi pictureFile. So it is tested that file errors are added - fclose(fopen(tmpDir + "subDir5/file1.txt", "wb+")); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 34); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 5); + QgResult::clearLastErr(); + rmdir(tmpDir + "5-sub-dirs", true); + + // *** too mutch sub dirs + mkdir(tmpDir + "too-mutch-sub-dirs"); + dir.setDir(tmpDir + "too-mutch-sub-dirs"); + limit = settings.getHighLimit(-1); + this.info("Create " + limit + " sub directories"); + + for(int i = 1; i <= limit; i++) + { + mkdir(dir.getDirPath() + "subDir" + i); + fclose(fopen(dir.getDirPath() + "subDir" + i + "/file1.png", "wb+")); + } + + this.info("Create extra-subDir"); + mkdir(dir.getDirPath() + "extra-subDir"); + fclose(fopen(dir.getDirPath() + "extra-subDir/file1.png", "wb+")); dir.calculate(); assertEqual(dir.validate(), 0); assertEqual(dir.result.errorPoints, 1); - assertEqual(QgVersionResult::lastErr, "reason.file.extention"); -// DebugN(dir); + assertDynContains(QgResult::getLastErrors(), "dir.subDirCount"); + QgResult::clearLastErr(); + rmdir(tmpDir + "too-mutch-sub-dirs", true); - // claen up after test -// rmdir(tmpDir, TRUE); return 0; } } @@ -220,7 +265,7 @@ class TstQg : OaTest //------------------------------------------------------------------------------ string _makeTmpDir() { - string tmpDir = dirName(tmpnam()) + "QgPictureDir/"; + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; // create tmp-dir for this test if (isdir(tmpDir)) @@ -235,6 +280,6 @@ class TstQg : OaTest //-------------------------------------------------------------------------------- void main() { - TstQg test; + TstQgPicturesDir test; test.startAll(); } diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl new file mode 100644 index 00000000..b28673a3 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl @@ -0,0 +1,96 @@ +//-------------------------------------------------------------------------------- +/** + @file $relPath + @copyright Copyright 2023 SIEMENS AG + SPDX-License-Identifier: GPL-3.0-only +*/ + +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesFile" /*!< tested object */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgResult" + +//-------------------------------------------------------------------------------- +class TstQgPicturesFile : OaTest +{ + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("PicturesFile::validate"); + } + + //------------------------------------------------------------------------------ + public int setUp() + { + if (OaTest::setUp()) + return -1; + + // eliminate false positives + QgResult::selfTest = true; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { + switch (tcId) + { + case "PicturesFile::validate": + { + string tmpDir = _makeTmpDir(); + PicturesFile picture = PicturesFile(tmpDir + "file1.thhhhxt"); + + // *** invalid extension + fclose(fopen(tmpDir + "file1.thhhhxt", "wb+")); + picture.calculate(); + + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 1); + assertDynContains(QgResult::getLastErrors(), "file.extension"); + QgResult::clearLastErr(); + remove(tmpDir + "file1.thhhhxt"); + + // *** valid file + picture = PicturesFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png")); + // copyFile(getPath(PICTURES_REL_PATH, "WinCCOA_QualityChecks/WinCCOA_QualityChecks.png"), tmpDir); + picture.calculate(); + assertEqual(picture.validate(), 0); + assertEqual(picture.result.errorPoints, 0); + + return 0; + } + } + + return -1; + } + + //------------------------------------------------------------------------------ + string _makeTmpDir() + { + string tmpDir = PROJ_PATH + PICTURES_REL_PATH + "QgPictureDir/"; + + // create tmp-dir for this test + if (isdir(tmpDir)) + rmdir(tmpDir, TRUE); + + mkdir(tmpDir); + + return tmpDir; + } +}; + +//-------------------------------------------------------------------------------- +void main() +{ + TstQgPicturesFile test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config index 8346f4e3..d954476d 100644 --- a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config @@ -8,6 +8,7 @@ # no database needed "PACK_SEL" : 2, "TEST_MANAGERS":[ - { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl -n" } + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl -n" } ] } \ No newline at end of file diff --git a/WinCC_OA_Test/testRuns.config b/WinCC_OA_Test/testRuns.config index 5d12db5a..db3dea3b 100644 --- a/WinCC_OA_Test/testRuns.config +++ b/WinCC_OA_Test/testRuns.config @@ -5,10 +5,11 @@ "NAME":"Regression tests", "TEST_RUNS":[ "Common", - "CtrlppCheck" -# There are still too many failuers -# Need to be analyzed and fixed. You are welcome to do that ;-) -# "QgPicturesCheck" + "CtrlppCheck", + "QgPicturesCheck", + "QgPanelsCheck", + "QgOverloadedFilesCheck", + "QgScriptsCheck" ] }, "Common":{ @@ -34,6 +35,30 @@ "CONFIG":"testSuite.config", "ID":"suite_QgPicturesCheck" } + }, + "QgPanelsCheck":{ + "DESCRIPTION":"QgPanelsCheck tests", + "NAME":"QgPanelsCheck tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_QgPanelsCheck" + } + }, + "QgOverloadedFilesCheck":{ + "DESCRIPTION":"QgOverloadedFilesCheck tests", + "NAME":"QgOverloadedFilesCheck tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_QgOverloadedFilesCheck" + } + }, + "QgScriptsCheck":{ + "DESCRIPTION":"QgScriptsCheck tests", + "NAME":"QgScriptsCheck tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_QgScriptsCheck" + } } } } \ No newline at end of file