diff --git a/.gitignore b/.gitignore index 129733e..e946c6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ WinCCOA_QualityChecks/bin/ctrlppcheck/ ctrlppcheck/build/ +# astyle backup files +*.ctl.orig diff --git a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl b/WinCCOA_QualityChecks/scripts/QgTemplate.ctl index feeef37..1adc66b 100644 --- a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl +++ b/WinCCOA_QualityChecks/scripts/QgTemplate.ctl @@ -16,7 +16,7 @@ class QgTemplate : QgBase public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) return -1; // _sourceDir.create(); diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/BuildAddOn/QgSyntaxCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/BuildAddOn/QgSyntaxCheck.ctl index d624e4a..dc56caf 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/BuildAddOn/QgSyntaxCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/BuildAddOn/QgSyntaxCheck.ctl @@ -16,7 +16,7 @@ //-------------------------------------------------------------------------------- -/** +/** @breif main rutine to start QualityGate QgStaticCheck-OASyntaxCheck */ void main() diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl index 82ea405..c4082a0 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgOverloadedFilesCheck.ctl @@ -25,17 +25,17 @@ class QgStaticCheck_OverloadedFiles : QgBase //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) return -1; - + QgVersionResult::showErrorsOnly = TRUE; return 0; } - + //------------------------------------------------------------------------------ /** @brief Calculates pictures directory. @details Calculates pictures directory recursive. @@ -45,7 +45,7 @@ class QgStaticCheck_OverloadedFiles : QgBase { return _files.calculate(); } - + //------------------------------------------------------------------------------ /** @brief Function validates calculated pictures dircetory. @warning Call function calculate() before. Otherwise validation does not work. @@ -70,12 +70,12 @@ class QgStaticCheck_OverloadedFiles : QgBase //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + QgOverloadedFilesCheck _files = QgOverloadedFilesCheck(); //!< Pictures directory }; //-------------------------------------------------------------------------------- -/** +/** @breif main rutine to start QualityGate QgStaticCheck-Pictures */ void main() diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl index ee3c120..18371c5 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPanelsCheck.ctl @@ -27,7 +27,7 @@ class QgStaticPanelCheck : QgBase //@public members //-------------------------------------------------------------------------------- public string checkedPath = PROJ_PATH; - + //------------------------------------------------------------------------------ /** @brief Function setups panels tests. @details Creates temp-source dir. @@ -35,17 +35,17 @@ class QgStaticPanelCheck : QgBase */ public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) return -1; PanelCheck::setSourceDirPath(this.checkedPath); PanelFile::setSourceDirPath(this.checkedPath); _panels.setDir(this.checkedPath + PANELS_REL_PATH); - - if ( !_panels.exists() ) + + if (!_panels.exists()) setMinValidScore("QgStaticCheck_Panels", "assert.missingPanels", "reason.missingPanels"); - + return 0; } @@ -56,12 +56,12 @@ class QgStaticPanelCheck : QgBase */ public int calculate() { - if ( _panels.exists() ) + if (_panels.exists()) return _panels.calculate(); else return 0; } - + //------------------------------------------------------------------------------ /** @brief Function validates calculated panels dircetory. @warning Call function calculate() before. Otherwise validation does not work. @@ -86,12 +86,12 @@ class QgStaticPanelCheck : QgBase //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + PanelsDir _panels = PanelsDir(); //!< panels directory }; //-------------------------------------------------------------------------------- -/** +/** @breif main rutine to start QualityGate QgStaticCheck-panels */ void main(string path = PROJ_PATH) diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl index ff525fb..0aecd9b 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgPicturesCheck.ctl @@ -28,7 +28,7 @@ class QgStaticCheck_Pictures : QgBase //@public members //-------------------------------------------------------------------------------- public string checkedPath = PROJ_PATH + PICTURES_REL_PATH; - + //------------------------------------------------------------------------------ /** @brief Function setups pictures tests. @details Creates temp-source dir. @@ -36,15 +36,15 @@ class QgStaticCheck_Pictures : QgBase */ public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) return -1; throwError(makeError("", PRIO_INFO, ERR_CONTROL, 0, Qg::getId() + " will check " + this.checkedPath + PICTURES_REL_PATH)); _pictures.setDir(this.checkedPath); - - if ( !_pictures.exists() ) + + if (!_pictures.exists()) setMinValidScore("QgStaticCheck_Pictures", "assert.missingPictures", "reason.missingPictures"); - + return 0; } @@ -55,12 +55,12 @@ class QgStaticCheck_Pictures : QgBase */ public int calculate() { - if ( _pictures.exists() ) + if (_pictures.exists()) return _pictures.calculate(); - + return 0; } - + //------------------------------------------------------------------------------ /** @brief Function validates calculated pictures dircetory. @warning Call function calculate() before. Otherwise validation does not work. @@ -85,12 +85,12 @@ class QgStaticCheck_Pictures : QgBase //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + PicturesDir _pictures = PicturesDir(); //!< Pictures directory }; //-------------------------------------------------------------------------------- -/** +/** @breif main rutine to start QualityGate QgStaticCheck-Pictures */ void main(string path = PROJ_PATH + PICTURES_REL_PATH) diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl index b196943..62a53c5 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl @@ -32,32 +32,34 @@ class QgStaticCheck_Scripts : QgBase //--------------------------------------------------------------------------- public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) { throwError(makeError("", PRIO_SEVERE, ERR_CONTROL, 0, "QgBase::setUp fails")); return -1; } - if ( Qg::getId() == "QgStaticCheck_Scripts" ) + if (Qg::getId() == "QgStaticCheck_Scripts") { if (this.checkedPath.isEmpty()) { this.checkedPath = PROJ_PATH + SCRIPTS_REL_PATH; } + _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::scripts); } - else if ( Qg::getId() == "QgStaticCheck_Libs" ) + else if (Qg::getId() == "QgStaticCheck_Libs") { if (this.checkedPath.isEmpty()) { this.checkedPath = PROJ_PATH + LIBS_REL_PATH; } + _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::libs); } - if ( !_scriptsData.exists() ) + if (!_scriptsData.exists()) setMinValidScore(Qg::getId(), "assert.missingScripts", "reason.missingScripts"); return 0; @@ -66,7 +68,7 @@ class QgStaticCheck_Scripts : QgBase //--------------------------------------------------------------------------- public int calculate() { - if ( _scriptsData.exists() ) + if (_scriptsData.exists()) return _scriptsData.calculate(); else return 0; @@ -75,8 +77,8 @@ class QgStaticCheck_Scripts : QgBase //--------------------------------------------------------------------------- public int validate() { - if ( (Qg::getId() == "QgStaticCheck_Scripts") && (_scriptsData.getCountOfFilesRecursive() <= 0) && - isdir(this.checkedPath + LIBS_REL_PATH) && (_scriptsData.getCountOfSubDirs() <= 0) ) + if ((Qg::getId() == "QgStaticCheck_Scripts") && (_scriptsData.getCountOfFilesRecursive() <= 0) && + 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"); @@ -111,11 +113,11 @@ class QgStaticCheck_Scripts : QgBase */ void main(string testType, string path = "") { - if ( testType == "scripts" ) + if (testType == "scripts") { Qg::setId("QgStaticCheck_Scripts"); } - else if ( testType == "libs" ) + else if (testType == "libs") { Qg::setId("QgStaticCheck_Libs"); } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/ErrorHdl/OaLogger.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/ErrorHdl/OaLogger.ctl index ae4df4c..c49004b 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/ErrorHdl/OaLogger.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/ErrorHdl/OaLogger.ctl @@ -84,7 +84,7 @@ class OaLogger { err = makeError(msgCatalog, prio, ERR_CONTROL, 0, codeOrError); } - if (isA(codeOrError, ERRCLASS_VAR) || isA(codeOrError, DYN_ERRCLASS_VAR)) + else if (isA(codeOrError, ERRCLASS_VAR) || isA(codeOrError, DYN_ERRCLASS_VAR)) { err = codeOrError; } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgDir.ctl index e60b884..d1d31b3 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgDir.ctl @@ -32,7 +32,7 @@ class QgDir { setDirPath(dirPath); } - + //------------------------------------------------------------------------------ /** @brief Function set the directory path @param dirPath Full path to directory. @@ -41,7 +41,7 @@ class QgDir { _dirPath = dirPath; } - + //------------------------------------------------------------------------------ /** @brief Function returns full native path to directory. @return Full native path to directory. @@ -51,42 +51,42 @@ class QgDir { return makeNativePath(_dirPath); } - + public string getName() { return baseName(_dirPath); } - - + //------------------------------------------------------------------------------ /** @brief Function creates new directory. @return Error code. Returns 0 when successfull created, otherwise -1. */ public int mk() { - if ( exists() ) + if (exists()) return 0; - + const string delim = makeNativePath("/"); dyn_string items = strsplit(makeNativePath(_dirPath), delim); - + string dirPath = ""; - for(int i = 1; i <= dynlen(items); i++) + + for (int i = 1; i <= dynlen(items); i++) { dirPath += items[i]; - - if ( !isdir(dirPath) ) + + if (!isdir(dirPath)) mkdir(dirPath); - + dirPath += delim; } - - if ( !exists() ) + + if (!exists()) return -1; - + return 0; } - + //------------------------------------------------------------------------------ /** @brief Function checks if directory exists. @return Returns TRUE when directory exists, otherwise FALSE. @@ -96,7 +96,7 @@ class QgDir { return (_dirPath != "" && isdir(_dirPath)); } - + //------------------------------------------------------------------------------ /** @brief Function removes directory. @details Function remove direcotry recursive. @@ -105,36 +105,38 @@ class QgDir */ public int rm() { - if ( _dirPath == "" ) + if (_dirPath == "") return -1; - - if ( rmdir(_dirPath, TRUE) ) + + if (rmdir(_dirPath, TRUE)) return 0; - + return -1; } - + //------------------------------------------------------------------------------ public dyn_string getSubDirNames() { - if ( !exists() ) + if (!exists()) return makeDynString(); - + dyn_string dirs = getFileNames(getDirPath(), "*", FILTER_DIRS); - for(int i = dynlen(dirs); i > 0; i--) + + for (int i = dynlen(dirs); i > 0; i--) { const string dir = dirs[i]; const string exPattern = _excludePattern; - - if ( (dir == "") || (dir == ".") || - (dir == "..") || patternMatch(exPattern, dir) ) + + if ((dir == "") || (dir == ".") || + (dir == "..") || patternMatch(exPattern, dir)) { dynRemove(dirs, i); } } + return dirs; } - + public void setExcludePattern(const string &pattern) { _excludePattern = pattern; @@ -142,7 +144,7 @@ class QgDir //-------------------------------------------------------------------------------- //@private members -//-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- string _dirPath; string _excludePattern; }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgFile.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgFile.ctl index 1733861..6780f48 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/FileSys/QgFile.ctl @@ -32,7 +32,7 @@ class QgFile { setFilePath(filePath); } - + //------------------------------------------------------------------------------ /** @brief Function set the file path @param dirPath Full path to file. @@ -41,7 +41,7 @@ class QgFile { _filePath = filePath; } - + //------------------------------------------------------------------------------ /** @brief Function returns full native path to file. @return Full native path to file. @@ -51,29 +51,29 @@ class QgFile { return makeNativePath(_filePath); } - + public string getName() { return baseName(_filePath); - } - + } + //------------------------------------------------------------------------------ /** @brief Function creates new empty file. @return Error code. Returns 0 when successfull created, otherwise -1. */ public int mk() { - if ( exists() ) + if (exists()) return 0; - + fclose(fopen(getFilePath(), "wb+")); - - if ( !exists() ) + + if (!exists()) return -1; - + return 0; } - + //------------------------------------------------------------------------------ /** @brief Function checks if file exist. @return Returns TRUE when file exist, otherwise FALSE. @@ -82,7 +82,7 @@ class QgFile { return isfile(_filePath); } - + //------------------------------------------------------------------------------ /** @brief Function removes file. @details Function remove file. @@ -90,76 +90,78 @@ class QgFile */ public int rm() { - if ( !exists() ) + if (!exists()) return 0; - - if ( !remove(getFilePath()) ) + + if (!remove(getFilePath())) return 0; - + return -1; } - + //------------------------------------------------------------------------------ public bool isExample() { return (strpos(getFilePath(), makeNativePath("examples/")) > 0); } - + //------------------------------------------------------------------------------ public bool isTest() { return (strpos(getFilePath(), makeNativePath("tests/")) > 0); } - + //------------------------------------------------------------------------------ public string getRelPath(string key = "") { string absPath = getFilePath(); - - if ( absPath == "" ) + + if (absPath == "") return ""; - + absPath = makeNativePath(absPath); dyn_string dsProjs; + for (int i = 1; i <= SEARCH_PATH_LEN ; i++) { - dsProjs[i] = makeNativePath(getPath("", "", "", i)); + dsProjs[i] = makeNativePath(getPath("", "", "", i)); } - + // check if absPath start with some proj paths for (int i = 1; i <= dynlen(dsProjs) ; i++) { - if ( strpos(absPath, dsProjs[i]) == 0 ) + if (strpos(absPath, dsProjs[i]) == 0) return substr(absPath, strlen(dsProjs[i])); } - + // in remote-ui must be proj pahts not equal dyn_string keys = makeDynString(key); - - if ( key == "" ) + + if (key == "") keys = makeDynString(PANELS_REL_PATH, SCRIPTS_REL_PATH, CONFIG_REL_PATH);// ... for (int i = 1; i <= dynlen(keys) ; i++) { string key = makeNativePath(keys[i]); int keyPos = strpos(absPath, key); - if ( keyPos == 0 ) + + if (keyPos == 0) return absPath; - else if ( keyPos > 0 ) + else if (keyPos > 0) return substr(absPath, keyPos); } - + return ""; } - + //------------------------------------------------------------------------------ public bool isPatternMatch(const string &pattern) { return patternMatch(pattern, makeUnixPath(_filePath)); } - + //-------------------------------------------------------------------------------- //@private members -//-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- string _filePath; }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/Math/Math.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/Math/Math.ctl index 97aa5e9..6286065 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/Math/Math.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/Math/Math.ctl @@ -44,7 +44,7 @@ class Math */ public static float getPercent(const float &f1, const float &f2) { - if( (f1 == 0.0) || (f2 == 0) ) + if ((f1 == 0.0) || (f2 == 0)) return 0.0; float f = f1 / f2; 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 b93410d..0f9f602 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl @@ -17,9 +17,10 @@ class QgAddOnResultsDir { public QgAddOnResultsDir() { - if ( _buildNo <= 0 ) + if (_buildNo <= 0) _buildNo = (long)getCurrentTime(); - if ( Qg::getId() != "" ) + + if (Qg::getId() != "") setQgId(Qg::getId()); } @@ -31,7 +32,8 @@ class QgAddOnResultsDir public string getLastDirPath() { dyn_string histDirs = getHistoryDirs(); - if ( dynlen(histDirs) > 0 ) + + if (dynlen(histDirs) > 0) return histDirs[1]; else return ""; @@ -42,11 +44,11 @@ class QgAddOnResultsDir QgDir dir = QgDir(PROJ_PATH + DATA_REL_PATH + "QualityGates/"); dyn_string subdirs = dir.getSubDirNames(); - for(int i = dynlen(subdirs); i >= 1; i--) + for (int i = dynlen(subdirs); i >= 1; i--) { //settings folder must be ignored, //otherwise a tab will be created in the result panel - if ( subdirs[i] == "settings" ) + if (subdirs[i] == "settings") { dynRemove(subdirs, i); } @@ -61,10 +63,12 @@ class QgAddOnResultsDir QgDir dir = QgDir(qgResDir); dyn_string histDirs = dir.getSubDirNames(); dynSort(histDirs, FALSE); - for(int i = 1; i <= dynlen(histDirs); i++) + + for (int i = 1; i <= dynlen(histDirs); i++) { histDirs[i] = makeNativePath(qgResDir + histDirs[i] + "/"); } + return histDirs; } @@ -75,11 +79,12 @@ class QgAddOnResultsDir public int create() { - if ( exists() ) + if (exists()) cleanUp(); QgDir dir = QgDir(getDirPath()); - if ( dir.mk() ) + + if (dir.mk()) return -2; return 0; @@ -87,19 +92,17 @@ class QgAddOnResultsDir public int cleanUp() { - if ( exists() ) + if (exists()) return rmdir(getDirPath(), TRUE); return 0; } - - public string getDirPath() { - if ( _resultDir == "" ) + if (_resultDir == "") { - if ( !Qg::isRunningOnJenkins() ) + if (!Qg::isRunningOnJenkins()) { // projPath should be used, when Jenkins is not used _resultDir = makeNativePath(PROJ_PATH + DATA_REL_PATH + "QualityGates/" + _qgId + "/" + _buildNo + "/"); diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl index c9b6e90..43eab52 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl @@ -17,16 +17,16 @@ class 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 index 1b0738f..8e69aaf 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl @@ -18,53 +18,53 @@ class QgAddOnTmpSourceDir QgApp app = QgApp::getAppFromProjName(PROJ); _tmpSourceDir = makeNativePath(app.getSourcePath() + "tmpSource/"); } - + public bool exists() { return (_tmpSourceDir != "" && isdir(_tmpSourceDir)); } - + public int create() { - if ( exists() ) + if (exists()) cleanUp(); - + QgAddOnSourceDir source = QgAddOnSourceDir(); - - if ( !source.exists() ) + + if (!source.exists()) { DebugFTN("QgAddOnTmpSourceDir", "Could not find source packet", source.getDirPath()); return -1; } - - if ( !isdir(_tmpSourceDir) ) + + if (!isdir(_tmpSourceDir)) mkdir(_tmpSourceDir); - + copyAllFilesRecursive(source.getDirPath(), _tmpSourceDir); - - if ( !exists() ) + + if (!exists()) return -2; - + return 0; } - + public int cleanUp() { - if ( exists() ) + 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 index 1baf404..ba8e62c 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl @@ -30,202 +30,214 @@ class QgAddOnResult 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_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 ) + if (prio == PRIO_FATAL) prio = PRIO_SEVERE; - + errClass err; - if ( note == "" ) + + 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) + + 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") ) + + 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) + 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 + ///@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() ) + if (!_resDir.exists()) _resDir.create(); - - if ( !_hasErr && calculate() ) + + if (!_hasErr && calculate()) { DebugFTN("QgAddOnResult", __FUNCTION__, "calculate does not work"); return -3; } - - file f = fopen(_resDir.getDirPath() + "_state", "wb+"); - if ( ferror(f) ) + + 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") ) + + 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) + + 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") ) + + if (mappingHasKey(_data, "qgTestVersionResults")) { string path = _resDir.getDirPath() + "QgTestVersion/"; - + mkdir(path); - + int testId = Qg::idToNum(); - - if ( testId <= 0 ) + + if (testId <= 0) { - DebugFTN("QgAddOnResult",__FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); + DebugFTN("QgAddOnResult", __FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); return -4; } - f = fopen(path + "_Id", "wb+"); + 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+"); + + 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; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl index 8e25569..fe40d73 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl @@ -15,17 +15,17 @@ class QgAddOnScore public QgAddOnScore() { } - - /** - + + /** + @deprecated since 06.05.2018 +lSchopp dismiss score per version - @param score + @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 df9e3e2..9258097 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl @@ -33,7 +33,7 @@ class Qg { return _id; } - + //------------------------------------------------------------------------------ /** @brief Function set id for current QualityGate. @details Each QualityGate must have unique ID to handle with result files. @@ -45,7 +45,7 @@ class Qg { _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 @@ -55,28 +55,28 @@ class Qg public static dyn_string getAllIds() { return makeDynString("QgStaticCheck_Pictures", "QgStaticCheck_Scripts", "QgStaticCheck_Panels", - "QgSyntaxCheck", + "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 + @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/QgAddOnResultErr.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl index b39fe74..121be86 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl @@ -60,40 +60,41 @@ class QgAddOnResultErr { return getErrorText(_err); } - + public int getPriority() { return getErrorPriority(_err); } - + public string getPriorityAsText() { - switch(getPriority()) + switch (getPriority()) { case PRIO_INFO: - return "Info"; + return "Info"; + case PRIO_WARNING: - return "Warning"; + return "Warning"; + case PRIO_SEVERE: - return "Error"; + return "Error"; + default: - return "Unkwon"; + return "Unkwon"; } } - + public void fillMap(mapping &map) { map[getPriorityAsText()] = getText(); } - + public mapping toMap() { mapping map; fillMap(map); return map; } - - //-------------------------------------------------------------------------------- //@private members diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl index 815888c..b0726bb 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl @@ -16,54 +16,56 @@ class QgApp public QgApp(string id = "") { _isValid = FALSE; - if ( id == "" ) + + if (id == "") { /// @todo I think we can remove this class, because always ends here. - DebugFTN("QgApp", "!!! Parameter #1 (id) is missing" ); + DebugFTN("QgApp", "!!! Parameter #1 (id) is missing"); return; } _id = id; string optsPath = _getPath() + "opts.json"; DebugFTN("QgApp", __FUNCTION__, optsPath); - if ( !isfile(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) ) + + if (isdir(resDir)) mkdir(resDir); - + _isValid = TRUE; } - + //------------------------------------------------------------------------------------------------------------------------------------- public static QgApp getAppFromProjName(const string projName = PROJ) { - // parse WinCCOA_FinalyApi_22 to app id + // parse WinCCOA_FinalyApi_22 to app id dyn_string items = strsplit(projName, "_"); - if ( dynlen(items) < 3 ) + + 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() @@ -73,232 +75,242 @@ class QgApp string sourcePath = _getPath() + "appData/" + appName; const string projName = _getProjName(); const string destPath = _getProjPath(); - - int rc; + + int rc; dyn_string names, versions, paths; - - if ( !isdir(sourcePath) ) + + 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 + + if (dynContains(names, projName) > 0) //Project is registered paDelProj(projName, TRUE); - else if ( isdir(destPath) ) + else if (isdir(destPath)) rmdir(destPath, TRUE); - - dyn_string langs; - if ( dynlen(langs) <= 0 ) + + dyn_string langs; + + if (dynlen(langs) <= 0) { for (int i = 0 ; i < getNoOfLangs(); i++) - langs[i+1] = getLocale(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, + rc = paCreateProj(_getProjName(), dirName(_getProjPath()), + langs, 1, "System1", // system num / name 2, // without DB "" // no ascii list - ); - - if ( rc ) + ); + + 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++) + 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) ) - { + + 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]) ) - { + 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") ) + if (isfile(sourceDir + "config")) remove(sourceDir + "config"); } - else if ( (BIN_REL_PATH == simpleDirs[i]) && !isdir(sourceDir) ) + else if ((BIN_REL_PATH == simpleDirs[i]) && !isdir(sourceDir)) { - // use bin_ - if ( isdir(sourceDir + "_" + VERSION) ) + // 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++) + for (int j = 0; j <= 100; j++) { int version = minMinorVersion + j; string sDir = sourceDir + "_3." + version; string dDir = destDir + "_3." + version; - - if ( !isdir(sDir) ) + + if (!isdir(sDir)) continue; - - if ( !copyAllFilesRecursive(sDir, dDir) ) + + if (!copyAllFilesRecursive(sDir, dDir)) { DebugFTN("QgApp", "!!! could not copy dir", sDir, dDir); return -4; } } } - + DebugFTN("QgApp", "try copy", isdir(sourceDir), sourceDir); - if ( !isdir(sourceDir) ) + + if (!isdir(sourceDir)) continue; // nothing to do - + DebugFTN("QgApp", "to", destDir); - if ( !copyAllFilesRecursive(sourceDir, destDir) ) + + if (!copyAllFilesRecursive(sourceDir, destDir)) { DebugFTN("QgApp", "!!! could not copy dir", sourceDir, destDir); return -4; } } - + // create AddonInformation.json file rc = _makeAddOnInfoFile(); - if ( rc ) + + 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 ) + + 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") ) + 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) ) + 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) ) + + + if (!isdir(destPath + DATA_REL_PATH)) mkdir(destPath + DATA_REL_PATH); // make dir for AddonInformation.json file - - - if ( isfile(addOnInfoPath) ) + + if (isfile(addOnInfoPath)) moveFile(addOnInfoPath, addOnInfoPath + ".copy"); // make copy of original file (+lShopp) - - if ( !mappingHasKey(_options, "data") || !mappingHasKey(_options["data"], "product_id") ) + + 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 == "" ) + + 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+" + + + 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 ) + 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") ) + + if (mappingHasKey(result, "content")) { json = result["content"]; } - + mapping addOnInfo; - mapping data = jsonDecode(json); - + 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 { @@ -306,25 +318,24 @@ class QgApp 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) ) + + if (!isfile(addOnInfoPath)) DebugFTN("QgApp", __FUNCTION__, "Check te file", addOnInfoPath); - - + return 0; } - + //------------------------------------------------------------------------------------------------------------------------------------- string _getResultsDir() { return makeNativePath(_getPath() + "_results/"); } - + public string getSourcePath() { return _getPath(); @@ -333,23 +344,24 @@ class QgApp string _getPath() { string dir = getenv("WORKSPACE"); - if ( (dir != "") && isdir(dir) ) + + if ((dir != "") && isdir(dir)) return makeNativePath(dir + "/"); - - if ( _id == "" ) + + if (_id == "") return ""; - - if ( _WIN32 ) + + if (_WIN32) { string tmpDir = dirName(tmpnam()); return makeNativePath(tmpDir + "WinCCOA/apps/" + _id + "/"); } - else if ( _UNIX ) + else if (_UNIX) return makeNativePath("/tmp/WinCCOA/apps/" + _id + "/"); else return ""; } - + public string getProjName() { return _getProjName(); @@ -359,18 +371,18 @@ class QgApp { return "WinCCOA_FinalyApi_" + _id; } - + //------------------------------------------------------------------------------------------------------------------------------------- string _getProjPath(const string relPath = "") { return makeNativePath(_getPath() + _getProjName() + "/" + relPath); } - + //------------------------------------------------------------------------------------------------------------------------------------- // members string _id; bool _isValid; - + /* { "id":22, @@ -388,7 +400,7 @@ class QgApp "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 2ff2f5f..f346821 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl @@ -65,8 +65,9 @@ class QgBase myTest.setUp(); myQgMsgCat.setName(Qg::getId()); - if (isEvConnOpen() && ( Qg::getId() != "" ) ) + if (isEvConnOpen() && (Qg::getId() != "")) dpSet("_WinCCOA_qgCmd.Command", Qg::getId() + ":START"); + return 0; } @@ -81,12 +82,12 @@ class QgBase */ public int start() { - if (isEvConnOpen() && ( Qg::getId() != "" ) ) + if (isEvConnOpen() && (Qg::getId() != "")) dpSet("_WinCCOA_qgCmd.Command", Qg::getId() + ":START"); int rc = _start(); - if (isEvConnOpen() && ( Qg::getId() != "" ) ) + if (isEvConnOpen() && (Qg::getId() != "")) dpSet("_WinCCOA_qgCmd.Command", Qg::getId() + ":DONE:" + rc); return rc; @@ -110,15 +111,17 @@ class QgBase public int tearDown() { myTest.tearDown(); - if ( publish() ) + + if (publish()) return -1; + return 0; } //------------------------------------------------------------------------------ public static QgResultState calculateState(const shared_ptr result) { - if ( result.hasError ) + if (result.hasError) return QgResultState::warning; return QgResultState::success; @@ -129,14 +132,14 @@ class QgBase { _publisher.fields = getStoreFields(); - if ( _setMinScore ) + if (_setMinScore) _publisher.result = _minScoreResult; else _publisher.result = _result; _publisher.state = calculateState(_publisher.result); - if ( _publisher.publish() ) + if (_publisher.publish()) return -1; return 0; @@ -175,22 +178,25 @@ class QgBase { const time startTime = getCurrentTime(); logger.info(QgBaseError::Start, Qg::getId()); + try // exceptions happen here more often, so it should be sure to stop the QG properly { _setMinScore = FALSE; int rc = setUp(); - if ( rc ) + + if (rc) { logger.severe(QgBaseError::NotImplemented, __FUNCTION__, Qg::getId()); return -1; } - if ( !_setMinScore ) + if (!_setMinScore) { logger.info(QgBaseError::Calculate, Qg::getId()); rc = calculate(); + // ctrlppcheck-suppress knownConditionTrueFalse // the variable rc can be changed in the function calculate() in the derived class. - if ( rc ) + if (rc) { DebugFTN("QgBase", __FUNCTION__, "calculate returns some error", rc); return -2; @@ -198,11 +204,12 @@ class QgBase } // ctrlppcheck-suppress duplicateCondition // The variable _setMinScore can be changed in the function calculate() in the derived class. - if ( !_setMinScore ) + if (!_setMinScore) { logger.info(QgBaseError::Validate, Qg::getId()); rc = validate(); - if ( rc ) + + if (rc) { DebugFTN("QgBase", __FUNCTION__, "validate returns some error", rc); return -3; @@ -210,7 +217,8 @@ class QgBase } rc = tearDown(); - if ( rc ) + + if (rc) { DebugFTN("QgBase", __FUNCTION__, "tearDown returns some error", rc); return -4; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl index 61e4e2f..6f332ed 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgCtrlppCheck/QgCtrlppCheck.ctl @@ -54,8 +54,7 @@ class QgCtrlppCheck : QgBase _result.setMsgCatName("QgCtrlppCheck"); _result.setAssertionText("checks"); - - if ( dpExists("_CtrlppCheck") ) + if (dpExists("_CtrlppCheck")) { dpGet("_CtrlppCheck.filter.id", disabledIds, "_CtrlppCheck.filter.severity", disabledSeverities); @@ -69,11 +68,11 @@ class QgCtrlppCheck : QgBase includeFilesPattern = "*"; } - for(int i = 1; i <= dynlen(check.errList); i++) + for (int i = 1; i <= dynlen(check.errList); i++) { CppCheckError error = check.errList[i]; - if ( isErrorFiltered(error) ) + if (isErrorFiltered(error)) continue; QgFile f = QgFile(error.path); @@ -87,6 +86,7 @@ class QgCtrlppCheck : QgBase _result.addChild(assertion); } + return 0; } @@ -106,7 +106,7 @@ class QgCtrlppCheck : QgBase { dirPath = path; - if ( dpExists("_CtrlppCheck") ) + if (dpExists("_CtrlppCheck")) { dpGet("_CtrlppCheck.settings.enableLibCheck", check.settings.enableLibCheck, //"_CtrlppCheck.settings.enableHeadersCheck", check.settings.enableHeadersCheck, // currently disabled @@ -161,19 +161,21 @@ class QgCtrlppCheck : QgBase } QgFile f = QgFile(error.path); + if (f.isExample() || f.isTest() || !f.isPatternMatch(includeFilesPattern)) return true; - if ( error.msg == "" ) + if (error.msg == "") return TRUE; const string id = error.id; - if ( dynContains(disabledIds, id) ) + if (dynContains(disabledIds, id)) return TRUE; const string severity = error.severity; - if ( dynContains(disabledSeverities, severity) ) + + if (dynContains(disabledSeverities, severity)) return TRUE; @@ -187,7 +189,6 @@ class QgCtrlppCheck : QgBase CppCheck check; }; - /// Start Qg ctrlppcheck. /// Simple old ctrl style. public int start_QgCtrlppCheck(string path = PROJ_PATH + SCRIPTS_REL_PATH) diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgMsgCat.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgMsgCat.ctl index 675fc29..30e07f8 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgMsgCat.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgMsgCat.ctl @@ -24,81 +24,87 @@ class QgMsgCat { setName(msgCat); } - + public setPrio(QgMsgCatErrPrio prio) { _prio = prio; } - + public setName(const string &msgCatName) { _msgCat = msgCatName; } - + public string getName() { return _msgCat; } - + public string getText(const string &catKey, const mapping dollars = makeMapping()) { - if ( catKey == "" ) + if (catKey == "") DebugFTN("QgMsgCat", __FUNCTION__, "msg cat is empty", getStackTrace(), dollars, _msgCat); - + // get string from msg catalog string text = _getMsgCatText(catKey); - - for (int i=1; i<= mappinglen(dollars); i++) + + for (int i = 1; i <= mappinglen(dollars); i++) { string key = mappingGetKey(dollars, i); string value = _formatValue(dollars[key]); strreplace(text, "$" + key, value); } - + strreplace(text, "$prio", getPriorityAsText(_prio)); strreplace(text, "$QgId", Qg::getId()); - + return text; } - + public string getPriorityAsText(const QgMsgCatErrPrio &prio) { - switch(prio) + switch (prio) { case QgMsgCatErrPrio::Info: - return "Info"; + return "Info"; + case QgMsgCatErrPrio::Warning: - return "Warning"; + return "Warning"; + case QgMsgCatErrPrio::Error: - return "Error"; + return "Error"; + default: - return "Unkwon"; + return "Unkwon"; } } - + protected string _getMsgCatText(const string &catKey) { - if ( !mappingHasKey(_cache, _msgCat) ) + if (!mappingHasKey(_cache, _msgCat)) _cache[_msgCat] = makeMapping(); - - if ( !mappingHasKey(_cache[_msgCat], catKey) ) + + if (!mappingHasKey(_cache[_msgCat], catKey)) { string text = getCatStr(_msgCat, catKey); - if ( dynlen(getLastError()) > 0 ) // string founded + + if (dynlen(getLastError()) > 0) // string founded { // DebugN(__FUNCTION__, "not found", catKey, _msgCat); text = catKey; } + _cache[_msgCat][catKey] = text; } - + return _cache[_msgCat][catKey];; } - + string _formatValue(const anytype &value) { string str; - if ( getType(value) == FLOAT_VAR ) + + if (getType(value) == FLOAT_VAR) { Float f = Float(value); str = (string)f.round(2); // round float @@ -107,15 +113,12 @@ class QgMsgCat { str = (string)value; } - + return str; } - - - + QgMsgCatErrPrio _prio; string _msgCat; - + static protected mapping _cache; - }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl index fdcfefa..7459554 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl @@ -21,60 +21,62 @@ class QgOverloadedFilesCheck /** List with allowed files. */ - public dyn_string allowedFiles = makeDynString(CONFIG_REL_PATH + "powerconfig", - DATA_REL_PATH + "RDBSetup/ora/RDB_config_template.sql", - DATA_REL_PATH + "Reporting/Reporting.wsdl", - DATA_REL_PATH + "Reporting/Reporting_document_literal.wsdl", - DATA_REL_PATH + "Reporting/Templates/BIRT/alertGetPeriod_1DPE_Table.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_1DPE_Line_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_2DPE_Bar_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_2DPE_Bar_3D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_4DPE_Bar_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_alarms_Timerange_Table.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_AlertsCount_Bar_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Bar_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Pie_2D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Pie_3D.rptdesign", - DATA_REL_PATH + "Reporting/Templates/BIRT/localization.properties", - DATA_REL_PATH + "Reporting/Templates/BIRT/localization_de_AT.properties", - DATA_REL_PATH + "Reporting/Templates/InformationServer/WinCC_OA_AlarmTable.rdl", - DATA_REL_PATH + "Reporting/Templates/InformationServer/WinCC_OA_LineChart.rdl", - DATA_REL_PATH + "iec104/PKI/certs/iec.crt", - DATA_REL_PATH + "iec104/PKI/certs/iecRoot.crt", - DATA_REL_PATH + "iec104/PKI/crl/empty.del", - DATA_REL_PATH + "iec104/PKI/private/iec.key", - DATA_REL_PATH + "iec104/PKI/private/iecRoot.key", - DATA_REL_PATH + "opcua/client/PKI/CA/certs/WinCC_OA_UA_Client.der", - DATA_REL_PATH + "opcua/client/PKI/CA/certs/WinCC_OA_UA_Server.der", - DATA_REL_PATH + "opcua/client/PKI/CA/crl/empty.del", - DATA_REL_PATH + "opcua/client/PKI/CA/private/WinCC_OA_UA_Client.pem", - DATA_REL_PATH + "opcua/client/PKI/CA/rejected/empty.del", - DATA_REL_PATH + "opcua/client/PKI/issuers/certs/empty.del", - DATA_REL_PATH + "opcua/client/PKI/issuers/crl/empty.del", - DATA_REL_PATH + "opcua/server/PKI/CA/certs/WinCC_OA_UA_Client.der", - DATA_REL_PATH + "opcua/server/PKI/CA/certs/WinCC_OA_UA_Server.der", - DATA_REL_PATH + "opcua/server/PKI/CA/crl/empty.del", - DATA_REL_PATH + "opcua/server/PKI/CA/private/WinCC_OA_UA_Server.pem", - DATA_REL_PATH + "opcua/server/PKI/CA/rejected/empty.del", - DATA_REL_PATH + "opcua/server/PKI/issuers/certs/empty.del", - DATA_REL_PATH + "opcua/server/PKI/issuers/crl/empty.del", - DATA_REL_PATH + "xls_report/ATVTemplate.xltm", - DATA_REL_PATH + "xls_report/CstTemplate.xltm", - DATA_REL_PATH + "xls_report/OprTemplate.xltm", - DATA_REL_PATH + "xls_report/Report.cmd", - DATA_REL_PATH + "xls_report/Report.mdb", - DATA_REL_PATH + "xls_report/Report.xls", - DATA_REL_PATH + "xls_report/SQLTemplate.xltm", - DATA_REL_PATH + "xls_report/StdTemplate.xltm", - SCRIPTS_REL_PATH + "userDrivers.ctl", - SCRIPTS_REL_PATH + "userPara.ctl", - LIBS_REL_PATH + "aesuser.ctl", - LIBS_REL_PATH + "asModifyDisplay.ctl", - LIBS_REL_PATH + "classes/oaTest/OaTest.ctl", - // (officially not part of product) - LIBS_REL_PATH + "driverSettings_HOOK.ctl", - PANELS_REL_PATH + "vision/aes/_AS_propFilterExtended.pnl", - PANELS_REL_PATH + "vision/aes/_ES_propFilterExtended.pnl"); + public dyn_string allowedFiles = makeDynString( + CONFIG_REL_PATH + "powerconfig", + DATA_REL_PATH + "RDBSetup/ora/RDB_config_template.sql", + DATA_REL_PATH + "Reporting/Reporting.wsdl", + DATA_REL_PATH + "Reporting/Reporting_document_literal.wsdl", + DATA_REL_PATH + "Reporting/Templates/BIRT/alertGetPeriod_1DPE_Table.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_1DPE_Line_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_2DPE_Bar_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_2DPE_Bar_3D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpGetPeriod_4DPE_Bar_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_alarms_Timerange_Table.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_AlertsCount_Bar_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Bar_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Pie_2D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/dpQuery_Value_Pie_3D.rptdesign", + DATA_REL_PATH + "Reporting/Templates/BIRT/localization.properties", + DATA_REL_PATH + "Reporting/Templates/BIRT/localization_de_AT.properties", + DATA_REL_PATH + "Reporting/Templates/InformationServer/WinCC_OA_AlarmTable.rdl", + DATA_REL_PATH + "Reporting/Templates/InformationServer/WinCC_OA_LineChart.rdl", + DATA_REL_PATH + "iec104/PKI/certs/iec.crt", + DATA_REL_PATH + "iec104/PKI/certs/iecRoot.crt", + DATA_REL_PATH + "iec104/PKI/crl/empty.del", + DATA_REL_PATH + "iec104/PKI/private/iec.key", + DATA_REL_PATH + "iec104/PKI/private/iecRoot.key", + DATA_REL_PATH + "opcua/client/PKI/CA/certs/WinCC_OA_UA_Client.der", + DATA_REL_PATH + "opcua/client/PKI/CA/certs/WinCC_OA_UA_Server.der", + DATA_REL_PATH + "opcua/client/PKI/CA/crl/empty.del", + DATA_REL_PATH + "opcua/client/PKI/CA/private/WinCC_OA_UA_Client.pem", + DATA_REL_PATH + "opcua/client/PKI/CA/rejected/empty.del", + DATA_REL_PATH + "opcua/client/PKI/issuers/certs/empty.del", + DATA_REL_PATH + "opcua/client/PKI/issuers/crl/empty.del", + DATA_REL_PATH + "opcua/server/PKI/CA/certs/WinCC_OA_UA_Client.der", + DATA_REL_PATH + "opcua/server/PKI/CA/certs/WinCC_OA_UA_Server.der", + DATA_REL_PATH + "opcua/server/PKI/CA/crl/empty.del", + DATA_REL_PATH + "opcua/server/PKI/CA/private/WinCC_OA_UA_Server.pem", + DATA_REL_PATH + "opcua/server/PKI/CA/rejected/empty.del", + DATA_REL_PATH + "opcua/server/PKI/issuers/certs/empty.del", + DATA_REL_PATH + "opcua/server/PKI/issuers/crl/empty.del", + DATA_REL_PATH + "xls_report/ATVTemplate.xltm", + DATA_REL_PATH + "xls_report/CstTemplate.xltm", + DATA_REL_PATH + "xls_report/OprTemplate.xltm", + DATA_REL_PATH + "xls_report/Report.cmd", + DATA_REL_PATH + "xls_report/Report.mdb", + DATA_REL_PATH + "xls_report/Report.xls", + DATA_REL_PATH + "xls_report/SQLTemplate.xltm", + DATA_REL_PATH + "xls_report/StdTemplate.xltm", + SCRIPTS_REL_PATH + "userDrivers.ctl", + SCRIPTS_REL_PATH + "userPara.ctl", + LIBS_REL_PATH + "aesuser.ctl", + LIBS_REL_PATH + "asModifyDisplay.ctl", + LIBS_REL_PATH + "classes/oaTest/OaTest.ctl", + // (officially not part of product) + LIBS_REL_PATH + "driverSettings_HOOK.ctl", + PANELS_REL_PATH + "vision/aes/_AS_propFilterExtended.pnl", + PANELS_REL_PATH + "vision/aes/_ES_propFilterExtended.pnl" + ); //------------------------------------------------------------------------------ /** @brief claculate projects files. @@ -86,18 +88,19 @@ class QgOverloadedFilesCheck OaLogger logger; dyn_string files = getFileNamesRecursive(PROJ_PATH); dynSort(files); + // - for(int i = 1; i <= dynlen(files); i++) + for (int i = 1; i <= dynlen(files); i++) { string path = files[i]; logger.info(0, Qg::getId(), "Check file", path); const string relPath = substr(path, strlen(PROJ_PATH)); - if ( strpos(relPath, makeNativePath(CONFIG_REL_PATH)) == 0 || - strpos(relPath, makeNativePath(DB_REL_PATH)) == 0 || - strpos(relPath, makeNativePath(LOG_REL_PATH)) == 0 || - relPath == makeNativePath("data/AddonInformation.json") ) + if (strpos(relPath, makeNativePath(CONFIG_REL_PATH)) == 0 || + strpos(relPath, makeNativePath(DB_REL_PATH)) == 0 || + strpos(relPath, makeNativePath(LOG_REL_PATH)) == 0 || + relPath == makeNativePath("data/AddonInformation.json")) { continue; } @@ -119,30 +122,30 @@ class QgOverloadedFilesCheck result = new QgVersionResult(); - if ( dynlen(_relPaths) > 0 ) + if (dynlen(_relPaths) > 0) { result.setMsgCatName("QgStaticCheck_OverloadedFiles"); result.setAssertionText("filesList"); result.setLocation(PROJ_PATH); - for(int i = 1; i <= dynlen(_relPaths); i++) + for (int i = 1; i <= dynlen(_relPaths); i++) { const string relPath = _relPaths[i]; const string overloadedFrom = findSourceProj(relPath); shared_ptr settings = new QgSettings("OverloadedFilesCheck.isOverloadedAllowed"); - if ( settings.isEnabled() ) + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); assertion.setLocation(relPath); assertion.setMsgCatName("QgStaticCheck_OverloadedFiles"); - - if ( isAllowed(relPath) ) + + if (isAllowed(relPath)) { assertion.setAssertionText("assert.isOverloadedAllowed", makeMapping("file.name", relPath)); assertion.setReasonText("reason.isOverloadedAllowed", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); + "file.isOverloadedFrom", overloadedFrom)); 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 @@ -151,11 +154,11 @@ class QgOverloadedFilesCheck { assertion.setAssertionText("assert.isOverloaded", makeMapping("file.name", relPath)); assertion.setReasonText("reason.isOverloaded", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); + "file.isOverloadedFrom", overloadedFrom)); assertion.assertFalse(overloadedFrom != "", settings.getScorePoints()); // negative logic, for better look in store } - + shared_ptr fileChildData = new QgVersionResult(); fileChildData.text = relPath; fileChildData.addChild(assertion); @@ -191,13 +194,15 @@ class QgOverloadedFilesCheck public static string findSourceProj(const string &relPath) { bool isOverload = FALSE; - for(int i = 2; i <= SEARCH_PATH_LEN; i++) + + for (int i = 2; i <= SEARCH_PATH_LEN; i++) { string subProjPath = getPath("", "", -1, i); - if ( !isfile(subProjPath + relPath) ) + + if (!isfile(subProjPath + relPath)) continue; - if ( i == SEARCH_PATH_LEN ) + if (i == SEARCH_PATH_LEN) return "WinCC OA " + baseName(subProjPath); else return "Sub-project: " + baseName(subProjPath); diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl index 2744840..357f015 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl @@ -24,13 +24,13 @@ class QgResultPublisher //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ public QgResultState state; public shared_ptr result; public dyn_string fields; public static QgVersionResultJsonFormat jsonFormat = QgVersionResultJsonFormat::Compact; - + //------------------------------------------------------------------------------ public QgResultPublisher() { @@ -39,12 +39,14 @@ class QgResultPublisher //------------------------------------------------------------------------------ public static string stateToString(const QgResultState &state) { - switch(state) + switch (state) { case QgResultState::success: return "success"; + case QgResultState::warning: return "warning"; + case QgResultState::error: return "error"; } @@ -60,31 +62,31 @@ class QgResultPublisher result.score = f.round(2); QgAddOnResultsDir resDir = QgAddOnResultsDir(); - if ( !resDir.exists() ) + if (!resDir.exists()) resDir.create(); - if ( _publishState(resDir) ) + if (_publishState(resDir)) return sendNotification(-1); - - if ( _publishSummary(resDir) ) + + if (_publishSummary(resDir)) return sendNotification(-2); - - if ( _publishFull(resDir) ) + + if (_publishFull(resDir)) return sendNotification(-3); - + return sendNotification(0); } - + //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ protected int sendNotification(const int errCode) { - if (isEvConnOpen() && ( Qg::getId() != "" ) ) + if (isEvConnOpen() && (Qg::getId() != "")) dpSet("_WinCCOA_qgCmd.Command", Qg::getId() + ":DONE:" + errCode); - + return errCode; } @@ -92,13 +94,15 @@ class QgResultPublisher protected int _publishState(const QgAddOnResultsDir &resDir) { string resPath; - if ( Qg::isRunningOnJenkins() ) + + if (Qg::isRunningOnJenkins()) resPath = resDir.getDirPath() + "_state"; else resPath = resDir.getDirPath() + "State"; - - file f = fopen(resPath, "wb+"); - if ( ferror(f) ) + + file f = fopen(resPath, "wb+"); + + if (ferror(f)) return -1; fputs(stateToString(state), f); @@ -110,13 +114,15 @@ class QgResultPublisher protected int _publishSummary(const QgAddOnResultsDir &resDir) { string resPath; - if ( Qg::isRunningOnJenkins() ) + + if (Qg::isRunningOnJenkins()) resPath = resDir.getDirPath() + "_data"; else resPath = resDir.getDirPath() + "sum.json"; file f = fopen(resPath, "wb+"); - if ( ferror(f) ) + + if (ferror(f)) return -1; fputs(jsonEncode(result.sumToMap(), jsonFormat == QgVersionResultJsonFormat::Compact), f); @@ -127,24 +133,24 @@ class QgResultPublisher //------------------------------------------------------------------------------ protected int _publishFull(const QgAddOnResultsDir &resDir) { - if ( Qg::isRunningOnJenkins() || true ) + if (Qg::isRunningOnJenkins() || true) return _publishFullOnJenkins(resDir); else return _publishFullLocale(resDir); } - //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ private int _publishFullLocale(const QgAddOnResultsDir &resDir) { string path = resDir.getDirPath(); file f = fopen(path + "Result", "wb+"); - if ( ferror(f) ) + + if (ferror(f)) { DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "Result"); return -3; @@ -152,16 +158,16 @@ class QgResultPublisher mapping map; map["fields"] = fields; - map["root"]= makeMapping(); + map["root"] = makeMapping(); 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); fclose(f); - - f = fopen(path + "Score", "wb+"); + + f = fopen(path + "Score", "wb+"); fputs((string)result.score, f); fclose(f); return 0; @@ -176,36 +182,40 @@ class QgResultPublisher int testId = Qg::idToNum(); - if ( testId <= 0 ) + 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) ) + + 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) ) + + if (ferror(f)) { DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "_Results"); return -3; } mapping map; - switch(qgVersionResultType) + + switch (qgVersionResultType) { case QgVersionResultType::TableView: { map["fields"] = fields; - map["root"]= makeMapping(); + map["root"] = makeMapping(); map["root"]["children"] = makeDynMapping(); map["root"]["children"][1] = result.scoreToMap(); map["root"]["children"][2] = result.toMap(); @@ -222,12 +232,13 @@ class QgResultPublisher 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" ); + DebugFTN("QgBase", __FUNCTION__, "write " + path + "_Score file"); f = fopen(path + "_Score", "wb+"); fputs((string)result.score, f); fclose(f); diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSettings.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSettings.ctl index 39a452f..a661a52 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSettings.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSettings.ctl @@ -29,12 +29,12 @@ class QgSettings private dyn_string excluded_ = ""; private static mapping jsonFiles_ ; private const string IDPATH_DELIMITER = "."; - + //=========================================================================== //@public methods //=========================================================================== - - /** + + /** Generates a QgSettings class using the specified id. The information required for this is read from the Settings Json Files under the path ".../data/qualityGates/settings/". Example id: "FunctionData.function.CCN" @@ -44,11 +44,11 @@ class QgSettings { readSettingsFromFile(id); } - + //--------------------------------------------------------------------------- - - /** - @return Returns the Settings Id + + /** + @return Returns the Settings Id */ public string getId() { @@ -57,17 +57,17 @@ class QgSettings //--------------------------------------------------------------------------- - /** + /** @param id Specifies the id of the setting */ public void setId(const string &id) { - id_ = id; + id_ = id; } - + //--------------------------------------------------------------------------- - /** - @return Returns the description of the retrieved setting + /** + @return Returns the description of the retrieved setting */ public langString getDescription() { @@ -75,26 +75,26 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param description Sets the description for the specified check */ public void setDescription(const langString &description) { - description_ = description; + description_ = description; } - + //--------------------------------------------------------------------------- - - /** - @param def The value to be returned in the event that this preference node + + /** + @param def The value to be returned in the event that this preference node has no value associated with key. - @return The low Limit from the retrieved settings + @return The low Limit from the retrieved settings @author ataker */ public anytype getLowLimit(const anytype &def) { - if ( getType(low_limit_) != MIXED_VAR && low_limit_ < high_limit_) + if (getType(low_limit_) != MIXED_VAR && low_limit_ < high_limit_) { return low_limit_; } @@ -105,26 +105,26 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param high_limit Value for the lower limit at the check */ public void setLowLimit(const anytype &low_limit) { low_limit_ = low_limit; } - + //--------------------------------------------------------------------------- - - /** - @param def The value to be returned in the event that this preference node + + /** + @param def The value to be returned in the event that this preference node has no value associated with key. - @return The high Limit from the retrieved settings + @return The high Limit from the retrieved settings @author ataker */ public anytype getHighLimit(const anytype &def) { - if ( getType(high_limit_) != MIXED_VAR && high_limit_ > low_limit_) + if (getType(high_limit_) != MIXED_VAR && high_limit_ > low_limit_) { return high_limit_; } @@ -135,19 +135,19 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param high_limit Value for the high limit at the check */ public void setHighLimit(const anytype &high_limit) { high_limit_ = high_limit; } - + //--------------------------------------------------------------------------- - - /** - @return Returns the score points of the retrieved setting + + /** + @return Returns the score points of the retrieved setting */ public int getScorePoints() { @@ -155,41 +155,41 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param score_points Sets how many points can be reached at the check */ public void setScorePoints(const int &score_points) { if (score_points > 0) { - score_points_ = score_points; + score_points_ = score_points; } } //--------------------------------------------------------------------------- - /** + /** @return If the check should be executed */ public bool isEnabled() { return enabled_; } - + //--------------------------------------------------------------------------- - /** + /** @param enabled FALSE to disable the test and TRUE to enable the test. */ public void setEnabled(bool enabled) { enabled_ = enabled; } - + //--------------------------------------------------------------------------- - - /** + + /** @return Returns the values that should excluded for the specifed check */ public dyn_string getExcluded() @@ -198,19 +198,19 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param excluded Set a list of regular expression that can be used in the specified test. */ public void setExcluded(const dyn_string &excluded) { excluded_ = excluded; } - + //--------------------------------------------------------------------------- - - /** - @return Returns the reference values of the retrieved setting + + /** + @return Returns the reference values of the retrieved setting */ public dyn_mixed getReferenceValues() { @@ -218,8 +218,8 @@ class QgSettings } //--------------------------------------------------------------------------- - - /** + + /** @param reference_values Values that could be used in the specified check. How these values are used depends on the test */ @@ -227,72 +227,73 @@ class QgSettings { reference_values_ = reference_values; } - + public static dyn_mapping getAllSettingsAsMapping(bool defaultValues = false) { dyn_mapping settings; dyn_string SETTING_FILES = getSettingFiles(); - - for ( int i = 1; i <= dynlen(SETTING_FILES); i++ ) + + for (int i = 1; i <= dynlen(SETTING_FILES); i++) { string file_name = SETTING_FILES[i] + ".json"; - string file_path = ""; - + string file_path = ""; + if (!defaultValues) { file_path = getPath(DATA_REL_PATH, "qualityGates/settings/" + file_name); } else { - for ( int j = 2; j < SEARCH_PATH_LEN; j++ ) + for (int j = 2; j < SEARCH_PATH_LEN; j++) { string path = getPath(DATA_REL_PATH, "", getActiveLang(), j); - if ( strpos(path, "WinCCOA_QualityChecks") >= 0) + + if (strpos(path, "WinCCOA_QualityChecks") >= 0) { file_path = getPath(DATA_REL_PATH, "qualityGates/settings/" + file_name, getActiveLang(), j); - - if ( file_path != "" ) + + if (file_path != "") { break; } } - } - } - - if ( file_path == "" ) + } + } + + if (file_path == "") { continue; - } - + } + JsonFile json_file = JsonFile(file_path); - - anytype json_data; - int ret_val = json_file.read(json_data); - + + anytype json_data; + int ret_val = json_file.read(json_data); + if (ret_val < 0) { continue; } else { - if ( !mappingHasKey(jsonFiles_, file_name) ) + if (!mappingHasKey(jsonFiles_, file_name)) { shared_ptr json_data_pointer = new mapping(json_data); - jsonFiles_[file_name] = json_data_pointer; - } - + jsonFiles_[file_name] = json_data_pointer; + } + dynAppend(settings, json_data); } } - + return settings; } - + //=========================================================================== //@private methods //=========================================================================== - - //workaround for private static dyn_string + + //workaround for private static dyn_string private static dyn_string getSettingFiles() { return makeDynString("FunctionData", "PanelCheck", @@ -300,54 +301,55 @@ class QgSettings "InternalCheck", "OverloadedFilesCheck", "SyntaxCheck", "ScriptData", "ScriptFile", "StaticCodeDir", - "StaticDir"); - } - + "StaticDir"); + } + private void readSettingsFromFile(const string &id) { string file_name = getBasePart(id); - - if ( file_name == "" ) + + if (file_name == "") { - throw(makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 1)); + throw (makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 1)); return; } - - file_name += ".json"; - if ( mappingHasKey(jsonFiles_, file_name) ) + file_name += ".json"; + + if (mappingHasKey(jsonFiles_, file_name)) { - createQgSettingsFromJsonData(jsonFiles_[file_name], id); + createQgSettingsFromJsonData(jsonFiles_[file_name], id); return; } - string file_path = getPath(DATA_REL_PATH, "qualityGates/settings/" + file_name); - if ( file_path == "" ) + string file_path = getPath(DATA_REL_PATH, "qualityGates/settings/" + file_name); + + if (file_path == "") { - throw(makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 2)); + throw (makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 2)); return; - } - + } + JsonFile json_file = JsonFile(file_path); - - anytype json_data; + + anytype json_data; int ret_val = json_file.read(json_data); shared_ptr json_data_pointer = new mapping(json_data); - + if (ret_val < 0) { - throw(makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 3)); + throw (makeError("QgSettings_Exceptions", PRIO_WARNING, ERR_PARAM, 3)); return; } else { jsonFiles_[file_name] = json_data_pointer; } - - createQgSettingsFromJsonData(json_data_pointer, id); + + createQgSettingsFromJsonData(json_data_pointer, id); } - /** + /** @param id The idpath where the base part should be returned @return Returns the basepart of the specified id */ @@ -355,31 +357,31 @@ class QgSettings { return substr(id, 0, strpos(id, IDPATH_DELIMITER)); } - + //--------------------------------------------------------------------------- - /** + /** @param id The idpath where the last part should be removed @return Returns the Id without the last idpath */ private string removeLastPart(const string &id) { int len; - - for ( len = strlen(id); len > 0; len--) + + for (len = strlen(id); len > 0; len--) { - if ( id[len] == IDPATH_DELIMITER ) + if (id[len] == IDPATH_DELIMITER) { break; } } - + return substr(id, 0, len); } //--------------------------------------------------------------------------- - - /** + + /** Fills the class members with the values from the json_data with the specified id @param json_data The retrieved mapping from the settings file @param id The complete id from the setting @@ -387,53 +389,54 @@ class QgSettings private void createQgSettingsFromJsonData(shared_ptr json_data, const string &id) { if (mappingHasKey(json_data, "settingsVersion") == false || - mappingHasKey(json_data, "checks") == false ) + mappingHasKey(json_data, "checks") == false) { return; } - + //determine machting check for id dyn_mapping checks = json_data["checks"]; mapping check; string id_iteration = id; - + for (int j = dynlen(strsplit(id, ".")); j >= 2; j--) - { + { for (int i = 1; i <= dynlen(checks); i++) { - if ( mappingHasKey(checks[i], "id") ) + if (mappingHasKey(checks[i], "id")) { - if ( id_iteration == checks[i]["id"] ) + if (id_iteration == checks[i]["id"]) { check = checks[i]; break; } } } - - if ( mappinglen(check) > 0 ) + + if (mappinglen(check) > 0) { break; } else { id_iteration = removeLastPart(id_iteration); - } + } } - - if ( mappinglen(check) < 1 ) + + if (mappinglen(check) < 1) { return; - } - + } + Mapping map = Mapping(check); + //read settings depeding on the version - switch(json_data["settingsVersion"]) + switch (json_data["settingsVersion"]) { case 0: default: - + this.setId(map.getAt("id")); this.setDescription(map.getAt("description")); this.setLowLimit(map.getAt("lowLimit")); @@ -444,6 +447,4 @@ class QgSettings this.setExcluded(map.getAt("excluded")); } } - - //--------------------------------------------------------------------------- }; 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 bc8edd3..4f2d66a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl @@ -15,23 +15,23 @@ class FunctionData //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ public shared_ptr result; //!< Quality gate result - + //------------------------------------------------------------------------------ public FunctionData() { } - + //------------------------------------------------------------------------------ public int fillFromCsv(const dyn_string &line) { - if ( dynlen(line) < (int)LizardCsvIndx::PARAMS ) + if (dynlen(line) < (int)LizardCsvIndx::PARAMS) { return -1; // there might be an fault - lizard format not valid possibly } - + _nloc = (int)line[(int)LizardCsvIndx::NLOC]; _ccn = (int)line[(int)LizardCsvIndx::CCN]; // func["TOKENS"] = (int)line[(int)LizardCsvIndx::TOKEN_COUNT]; // doesn't work ??? Lizard error ??? @@ -39,175 +39,175 @@ class FunctionData _linesCount = (int)line[(int)LizardCsvIndx::LINES]; _synopsis = line[(int)LizardCsvIndx::PARAMS]; _name = line[(int)LizardCsvIndx::FUNCTION_NAME]; - + // check c-tor // trimm :: from function name like FunctionData::FunctionData() // and compare 1. with 3. item. _isCtor = FALSE; dyn_string items = strsplit(_name, "::"); + // strsplit returns 3 items "FunctionData", "", "FunctionData" --> (oa-Bug) - if ( dynlen(items) == 3 ) + if (dynlen(items) == 3) { - _isCtor = (items[1] == items[3]); + _isCtor = (items[1] == items[3]); } - + 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(); - + validateCCN(); validateNLOC(); validateParamCount(); validateCountOfLines(); - return 0; + return 0; } - + //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - - + //------------------------------------------------------------------------------ protected validateCCN() { shared_ptr settings = new QgSettings("FunctionData.function.CCN"); - - if ( settings.isEnabled() ) + + 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())); + "function.CCN", getCCN())); assertion.assertLessEqual(getCCN(), - settings.getHighLimit(DEFAULT_CNN_HIGH), - settings.getScorePoints()); + settings.getHighLimit(DEFAULT_CNN_HIGH), + settings.getScorePoints()); result.addChild(assertion); } } - + //------------------------------------------------------------------------------ protected validateNLOC() { - string path = isCtor() ? "FunctionData.function.NLOC.ctor" : "FunctionData.function.NLOC"; + string path = isCtor() ? "FunctionData.function.NLOC.ctor" : "FunctionData.function.NLOC"; shared_ptr settings = new QgSettings(path); - - if ( settings.isEnabled() ) + + 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())); - + "function.NLOC", getNLOC())); + assertion.assertBetween(getNLOC(), - settings.getLowLimit(DEFAULT_NLOC_LOW), - settings.getHighLimit(DEFAULT_NLOC_HIGH), - settings.getScorePoints()); + settings.getLowLimit(DEFAULT_NLOC_LOW), + settings.getHighLimit(DEFAULT_NLOC_HIGH), + settings.getScorePoints()); result.addChild(assertion); } } - + //------------------------------------------------------------------------------ protected validateParamCount() { shared_ptr settings = new QgSettings("FunctionData.function.paramCount"); - - if ( settings.isEnabled() ) + + 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())); + "function.paramCount", getNLOC())); assertion.assertLessEqual(getParamCount(), - settings.getHighLimit(10), - settings.getScorePoints()); + settings.getHighLimit(10), + settings.getScorePoints()); result.addChild(assertion); } } - + //------------------------------------------------------------------------------ protected validateCountOfLines() { shared_ptr settings = new QgSettings("FunctionData.function.countOfLines"); - - if ( settings.isEnabled() ) + + 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())); + "function.countOfLines", getLinesCount())); assertion.info(getLinesCount(), settings.getScorePoints()); result.addChild(assertion); } } - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + int _nloc, _ccn, _paramCount, _linesCount; string _synopsis, _name; bool _isCtor; 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 5d1f961..5f219e7 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl @@ -25,7 +25,7 @@ - Functions list - CountOfLines - Average values - + @note Call function calculate() before you want acces some file information. C-tor does not read the file to eliminate performacne. */ @@ -34,10 +34,10 @@ class ScriptData //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ public shared_ptr result; //!< Quality gate result - + //------------------------------------------------------------------------------ /** Default c-tor @@ -47,7 +47,7 @@ class ScriptData { setPath(filePath); } - + //------------------------------------------------------------------------------ /** Set path to the checked file. @@ -56,9 +56,9 @@ class ScriptData */ public void setPath(const string &filePath) { - _filePath = filePath; + _filePath = filePath; } - + //------------------------------------------------------------------------------ /** Return the checked file name with extension. @@ -68,7 +68,7 @@ class ScriptData { return baseName(_filePath); } - + //------------------------------------------------------------------------------ /** Returns TRUE when file is calcualted, otherwise false. @@ -77,7 +77,7 @@ class ScriptData { return _isCalculated; } - + //------------------------------------------------------------------------------ /** Returns count of function located in file. @@ -86,7 +86,7 @@ class ScriptData { return dynlen(_functions); } - + //------------------------------------------------------------------------------ /** Returns clount of lines in the script. @@ -96,7 +96,7 @@ class ScriptData { return _linesCount; } - + //------------------------------------------------------------------------------ /** Returns CCN (cyclomatic complexicity) of script. @@ -106,7 +106,7 @@ class ScriptData { return _ccn; } - + //------------------------------------------------------------------------------ /** Returns NLOC (NumberLinesOfCode) of script. @@ -116,7 +116,7 @@ class ScriptData { return _nloc; } - + //------------------------------------------------------------------------------ /** Returns average CCN of script. @@ -125,13 +125,14 @@ class ScriptData public float getAvgCCN() { float count = getCountOfFunctions(); - if ( count <= 0 ) + + if (count <= 0) return 0.0; - + Float f = Float((float)_ccn / count); return f.round(); } - + //------------------------------------------------------------------------------ /** Returns average NLOC of script. @@ -140,13 +141,14 @@ class ScriptData public float getAvgNLOC() { float count = getCountOfFunctions(); - if ( count <= 0 ) + + if (count <= 0) return 0.0; - + Float f = Float((float)_nloc / count); return f.round(); } - + //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ /** @@ -156,7 +158,7 @@ class ScriptData { return _avgLines; } - + //------------------------------------------------------------------------------ /** Returns maximum enabled count of functions, there can be located in script. @@ -167,7 +169,7 @@ class ScriptData shared_ptr settings = new QgSettings("ScriptData.script.countOfFunctions"); return (int)settings.getHighLimit(DEFAULT_FUNCCOUNT_HIGH); } - + //------------------------------------------------------------------------------ /** Returns minimun enabled count of functions, there can be located in script. @@ -178,7 +180,7 @@ class ScriptData shared_ptr settings = new QgSettings("ScriptData.script.countOfFunctions"); return (int)settings.getLowLimit(DEFAULT_FUNCCOUNT_LOW); } - + //------------------------------------------------------------------------------ /** Returns maximum enabled NLOC. @@ -190,7 +192,7 @@ class ScriptData shared_ptr settings = new QgSettings("ScriptData.script.NLOC"); return (int)settings.getHighLimit(DEFAULT_NLOC_HIGH); } - + //------------------------------------------------------------------------------ /** Returns minimum enabled NLOC. @@ -202,7 +204,7 @@ class ScriptData shared_ptr settings = new QgSettings("ScriptData.script.NLOC"); return (int)settings.getLowLimit(DEFAULT_NLOC_LOW); } - + //------------------------------------------------------------------------------ /** Returns maximum enabled average CCN. @@ -214,7 +216,7 @@ class ScriptData shared_ptr settings = new QgSettings("ScriptData.script.avgCCN"); return (float)settings.getHighLimit(DEFAULT_AVGCCN_HIGH); } - + //------------------------------------------------------------------------------ /** Returns everage count of functions parameters. @@ -224,17 +226,17 @@ class ScriptData { return _avgParamCount; } - + //------------------------------------------------------------------------------ /** Function calculate script data. - + @details Script data are calculated by lizard. See also class ToolLizard. @note Lizard need python @warning We have modified the lizard, that the csv output returns also file summary. Default csv output returns only functions data. Summary is located in first line in format NLOC,CCN - + @return Return 0 when successfull. */ public int calculate() @@ -243,69 +245,73 @@ class ScriptData _nloc = 0; _ccn = 0; _isCalculated = FALSE; - - if ( !isfile(_filePath) ) + + if (!isfile(_filePath)) return -1; - + string cmd; cmd = Python::getExecutable() + " " + ToolLizard::getBinDir() + "lizard.py --csv " + makeUnixPath(_filePath); string stdOut, stdErr; int rc = system(cmd, stdOut, stdErr); - if ( rc != 0 ) + + if (rc != 0) { DebugFTN("ScriptData", __FUNCTION__, "!!! check if lizard is installed", rc, cmd, stdErr); return -2; } - + dyn_dyn_string data; csvParseContent(stdOut, data, ","); stdOut = ""; - + uint allFuncParams, allFuncLines; - if ( dynlen(data) > 0 ) + + if (dynlen(data) > 0) { // the first line contains only summary for file in format: NLOC,CCN - if ( dynlen(data[1]) >= 2 ) + if (dynlen(data[1]) >= 2) { _nloc = data[1][1]; _ccn = data[1][2]; } - - for(int i = 2; i <= dynlen(data); i++) + + for (int i = 2; i <= dynlen(data); i++) { dyn_string line = data[i]; - + FunctionData func = FunctionData(); - if ( func.fillFromCsv(line) ) + + if (func.fillFromCsv(line)) { continue; // shouldn't be possible / probably a fault in lizard format } - + allFuncParams += func.getParamCount(); allFuncLines += func.getLinesCount(); dynAppend(_functions, func); } } - - if ( dynlen(data) > 0 ) + + if (dynlen(data) > 0) { _avgLines = (float)allFuncLines / (float)dynlen(data); _avgParamCount = (float)allFuncParams / (float)dynlen(data); } - + { string str; fileToString(_filePath, str); - if ( str != "" ) + + if (str != "") str += " "; // otherwise last line could be ignored - + _linesCount = dynlen(strsplit(str, "\n")); } - + _isCalculated = TRUE; return 0; } - + //------------------------------------------------------------------------------ /** Validate script data. @@ -315,10 +321,10 @@ class ScriptData { result = new QgVersionResult(); result.text = getName(); - - if ( !validateIsCalucalted() ) + + if (!validateIsCalucalted()) return 0; - + validateCountOfFunctions(); validateAvgCCN(); validateNLOC(); @@ -326,15 +332,15 @@ class ScriptData validateFunctions(); return 0; } - + //-------------------------------------------------------------------------------- //@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. @@ -348,25 +354,27 @@ class ScriptData protected int validateIsCalucalted() { shared_ptr settings = new QgSettings("ScriptData.script.isCalculated"); - - if ( settings.isEnabled() ) + + if (settings.isEnabled()) { - // check if file is calculated. - // ognore all not calculated files (crypted, empty files ...) + // 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())); - if ( !assertion.assertTrue(isCalculated(), settings.getScorePoints()) ) + + if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { - result.addChild(assertion); + result.addChild(assertion); return 0; } } + // result.addChild(assertion); // sonnst doppelt drinnen ist return 1; } - + //------------------------------------------------------------------------------ /** Validate count of function in the script. @@ -382,15 +390,15 @@ class ScriptData protected validateCountOfFunctions() { shared_ptr settings = new QgSettings("ScriptData.script.countOfFunctions"); - - if ( settings.isEnabled() ) + + 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())); + "countOfFunctions", getCountOfFunctions())); assertion.assertBetween(getCountOfFunctions(), getMinCountOfFunctions(), getMaxCountOfFunctions(), settings.getScorePoints()); result.addChild(assertion); } @@ -403,17 +411,17 @@ class ScriptData */ protected validateAvgCCN() { - if ( getCountOfFunctions() > 1 ) // only when has more then 1 function + if (getCountOfFunctions() > 1) // only when has more then 1 function { shared_ptr settings = new QgSettings("ScriptData.script.avgCCN"); - - if ( settings.isEnabled() ) - { + + 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())); + "avgCCN", getAvgCCN())); assertion.assertLessEqual(getAvgCCN(), getMaxAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -423,71 +431,73 @@ class ScriptData //------------------------------------------------------------------------------ /** Validate NLOC of the script. - Check NLOC - Noumber Line Of Code + Check NLOC - Noumber Line Of Code */ protected validateNLOC() - { + { shared_ptr settings = new QgSettings("ScriptData.script.NLOC"); - - if ( settings.isEnabled() ) + + 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())); + "NLOC", getNLOC())); assertion.assertBetween(getNLOC(), getMinNLOC(), getMaxNLOC(), settings.getScorePoints()); result.addChild(assertion); } } - + //------------------------------------------------------------------------------ - /** + /** Validate average NLOC. Check average NLOC - Noumber Line Of Code */ protected validateAvgNLOC() { - if ( getCountOfFunctions() > 1 ) // only when has more then 1 function + if (getCountOfFunctions() > 1) // only when has more then 1 function { shared_ptr settings = new QgSettings("ScriptData.script.avgNLOC"); - - if ( settings.isEnabled() ) + + 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())); + "avgNLOC", getAvgNLOC())); assertion.info(getAvgNLOC(), settings.getScorePoints()); // does not check it, only information character - // assertion.assertLessEqual(getAvgNLOC(), getMaxAvgCCN()); + // assertion.assertLessEqual(getAvgNLOC(), getMaxAvgCCN()); result.addChild(assertion); } } } - + //------------------------------------------------------------------------------ - /** + /** Validate functions in script. Check each functions located in script. */ protected validateFunctions() { // check all functions too. - if ( getCountOfFunctions() > 0 ) - { + if (getCountOfFunctions() > 0) + { shared_ptr functions = new QgVersionResult(); functions.setMsgCatName("QgStaticCheck_ScriptData"); functions.setAssertionText("functionsList"); - for(int i = 1; i <= dynlen(_functions); i++) + + for (int i = 1; i <= dynlen(_functions); i++) { _functions[i].validate(); functions.addChild(_functions[i].result); } + result.addChild(functions); } } - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- 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 353393b..c53e466 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl @@ -27,173 +27,176 @@ class ScriptFile : QgFile // !! extension must be written lowercase, that NonCaseSensitive works _enabledExtensions = makeDynString("ctl", "ctc"); } - + //------------------------------------------------------------------------------ public static bool isCrypted(const string &s) { - return ( strpos(s, "PVSS_CRYPTED_PANEL") == 0); + return (strpos(s, "PVSS_CRYPTED_PANEL") == 0); } - + //------------------------------------------------------------------------------ public bool isFileCrypted() - { + { string s; fileToString(getFilePath(), s); - - if ( (s == "") && (strpos(getFilePath(), ".ctc") > 0) ) + + if ((s == "") && (strpos(getFilePath(), ".ctc") > 0)) return TRUE; - + return isCrypted(s); } - - + public bool isCalculated() { return _isCalculated; } - - + + public int calculate() { _isCalculated = FALSE; _extension = getExt(getFilePath()); - - if ( !isfile(getFilePath()) ) + + if (!isfile(getFilePath())) { DebugFTN("ScriptFile", __FUNCTION__, "file does not exists", getFilePath()); return -1; } - - if ( isFileCrypted() ) + + if (isFileCrypted()) { DebugFTN("ScriptFile", __FUNCTION__, "!!! file is encrypted", getFilePath()); return 0; } - - if ( this.isExample() ) + + if (this.isExample()) { // do calculate example, aprove performance DebugFTN("ScriptFile", __FUNCTION__, "!!! Dont calculate example file", getFilePath()); return 0; } - + _scriptData.setPath(getFilePath()); - if ( _scriptData.calculate() ) + + if (_scriptData.calculate()) { DebugFTN("ScriptFile", __FUNCTION__, "can not calculate script data"); return -2; } - + _isCalculated = TRUE; - + return 0; } - - + public int validate() { result = new QgVersionResult(); result.text = getName(); - - { - shared_ptr settings = new QgSettings("ScriptFile.file.isExampleFile"); - - if ( settings.isEnabled() ) - { - // check if the file is example. - // ignore all example files, the example are terrible scripts + + { + shared_ptr settings = new QgSettings("ScriptFile.file.isExampleFile"); + + if (settings.isEnabled()) + { + // 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())); assertion.allowNextErr(TRUE); - if ( !assertion.assertFalse(this.isExample(), settings.getScorePoints()) ) + + if (!assertion.assertFalse(this.isExample(), settings.getScorePoints())) { - result.addChild(assertion); + result.addChild(assertion); return 0; } + result.addChild(assertion); } } - + { - shared_ptr settings = new QgSettings("ScriptFile.file.extension"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("ScriptFile.file.extension"); + + if (settings.isEnabled()) { - // check for valid extensions + // 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)); - if ( !assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints()) ) + "file.extension", _extension)); + + if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { result.addChild(assertion); return 0; } + result.addChild(assertion); } } - + { - shared_ptr settings = new QgSettings("ScriptFile.file.isCalculated"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("ScriptFile.file.isCalculated"); + + if (settings.isEnabled()) { - // check if file is calculated. - // ognore all not calculated files (crypted, empty files ...) + // 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())); - if ( !assertion.assertTrue(isCalculated(), settings.getScorePoints()) ) + + if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { - result.addChild(assertion); + result.addChild(assertion); return 0; } + result.addChild(assertion); } } - - if ( _scriptData.validate() ) + + if (_scriptData.validate()) return -1; - + result.addChild(_scriptData.result); - + 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 - + protected ScriptData _scriptData = ScriptData(); - - static dyn_string _enabledExtensions = makeDynString(); + + static dyn_string _enabledExtensions = makeDynString(); string _extension; - bool _isCalculated; - }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptsDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptsDir.ctl index 5d0dd2c..7bb540c 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptsDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptsDir.ctl @@ -28,53 +28,53 @@ class ScriptsDir : StaticCodeDir { setDir(dirPath); } - + public setType(const ScriptsDataType &type) { _type = type; - if ( _type == ScriptsDataType::scripts ) + + if (_type == ScriptsDataType::scripts) setExcludePattern("libs"); } - + public ScriptsDataType getType() { return _type; } - + //------------------------------------------------------------------------------ public ScriptFile makeCheckFile(const string &fullPath) { ScriptFile p = ScriptFile(fullPath); return p; } - + public ScriptsDir makeCheckSubDir(const string &fullPath) { ScriptsDir dir = ScriptsDir(fullPath); return dir; } - + public int calculate() { - if ( this.getType() == ScriptsDataType::scripts ) + if (this.getType() == ScriptsDataType::scripts) { - if ( strpos(makeUnixPath(getDirPath()), LIBS_REL_PATH) >= 0 ) + if (strpos(makeUnixPath(getDirPath()), LIBS_REL_PATH) >= 0) { return 1; } } - - if ( StaticCodeDir::calculate() ) + + if (StaticCodeDir::calculate()) { DebugFTN("ScriptsDir", __FUNCTION__, "Function StaticCodeDir::calculate return error"); return -2; } - + return 0; } - - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- 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 14978b5..241448e 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl @@ -27,7 +27,7 @@ class PanelCheck : QgFile //------------------------------------------------------------------------------ public shared_ptr result; //!< Quality gate result - + //------------------------------------------------------------------------------ /** Default c-tor * @param filePath Full path to the oa-panel. @@ -134,30 +134,30 @@ class PanelCheck : QgFile _pnl.setPath(getRelPath()); _isBackUp = _pnl.isBackUp(); - if( _isBackUp ) + if (_isBackUp) { return 0; } - - if ( isExample() ) + + if (isExample()) { // do not calculate example, improve performance return 0; } - + _extension = getExt(getFilePath()); - + _pnl.read(); - if( _pnl.isCrypted() ) + if (_pnl.isCrypted()) { return 0; } - if( _pnl.isXmlFormat() ) + if (_pnl.isXmlFormat()) { // xml panel can be directly loaded - if( _pnl.load() ) + if (_pnl.load()) { DebugFTN("PanelCheck", __FUNCTION__, "can not load XML panel", getRelPath()); _pnl.strContent = ""; @@ -170,7 +170,7 @@ class PanelCheck : QgFile // _pnl.strContent = ""; string oldRelPath = _pnl.getRelPath(); const string originFullPath = _pnl.getFullPath(); - + string uuId = createUuid(); strreplace(uuId, "{", ""); strreplace(uuId, "}", ""); @@ -198,10 +198,10 @@ class PanelCheck : QgFile return -1; } - + remove(newPath); - if( isfile(newPath + ".bak") ) + if (isfile(newPath + ".bak")) remove(newPath + ".bak"); // on converting generate the ui back up panel, so delete the waste. _pnl.setPath(oldRelPath); @@ -210,7 +210,7 @@ class PanelCheck : QgFile _pnl.calculate(); _pnl.strContent = ""; - + _isCalculated = TRUE; return 0; } @@ -225,23 +225,23 @@ class PanelCheck : QgFile { return _isBackUp; } - + //------------------------------------------------------------------------------ public int validate() { QgVersionResult::lastErr = ""; result = new QgVersionResult(); result.text = getName(); - - if ( validateIsExample() || - validateIsBackUp() || - validateExtension() || - validateIsCrypted() || - validateIsCalculated() ) + + if (validateIsExample() || + validateIsBackUp() || + validateExtension() || + validateIsCrypted() || + validateIsCalculated()) { return 0; } - + validateCountOfProperties(); validateCountOfEvents(); validateCountOfShapes(); @@ -254,255 +254,270 @@ class PanelCheck : QgFile validateProperties(); return 0; } - + //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - + // check if the file is example. - // ignore all example files, the example are terrible panels + // ignore all example files, the example are terrible panels protected int validateIsExample() { - shared_ptr settings = new QgSettings("PanelCheck.panel.isExampleFile"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.isExampleFile"); + + 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())); assertion.allowNextErr(TRUE); - if ( !assertion.assertFalse(isExample(), settings.getScorePoints()) ) + + if (!assertion.assertFalse(isExample(), settings.getScorePoints())) { - result.addChild(assertion); + result.addChild(assertion); return 1; } + result.addChild(assertion); } + return 0; } - - // is backup + + // is backup protected int validateIsBackUp() { - shared_ptr settings = new QgSettings("PanelCheck.panel.isBackUp"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.isBackUp"); + + 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())); - if ( !assertion.assertFalse(isBackUp(), settings.getScorePoints()) ) + + if (!assertion.assertFalse(isBackUp(), settings.getScorePoints())) { result.addChild(assertion); return 1; } + result.addChild(assertion); } + return 0; } - - // check for valid extensions + + // check for valid extensions protected int validateExtension() { - shared_ptr settings = new QgSettings("PanelCheck.panel.extension"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.extension"); + + 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)); - if ( !assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints()) ) + "panel.extension", _extension)); + + if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { result.addChild(assertion); return 1; } + result.addChild(assertion); } + return 0; } - - // is crypted + + // is crypted protected int validateIsCrypted() { - shared_ptr settings = new QgSettings("PanelCheck.panel.isCrypted"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.isCrypted"); + + 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())); - if ( !assertion.assertFalse(_pnl.isCrypted(), settings.getScorePoints()) ) + + if (!assertion.assertFalse(_pnl.isCrypted(), settings.getScorePoints())) { result.addChild(assertion); return 1; } + result.addChild(assertion); } + return 0; } - - // is calculated + + // is calculated protected int validateIsCalculated() { - shared_ptr settings = new QgSettings("PanelCheck.panel.isCalculated"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.isCalculated"); + + 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())); - if ( !assertion.assertTrue(isCalculated(), settings.getScorePoints()) ) + + if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { result.addChild(assertion); return 1; } - } + } + return 0; } - - // countOfProperties + + // countOfProperties protected validateCountOfProperties() { - shared_ptr settings = new QgSettings("PanelCheck.panel.countOfProperties"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.countOfProperties"); + + 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())); + "panel.countOfProperties", _pnl.getCountOfProperties())); assertion.info(_pnl.getCountOfProperties(), settings.getScorePoints()); result.addChild(assertion); } } - - // getCountOfEvents + + // getCountOfEvents protected validateCountOfEvents() { - shared_ptr settings = new QgSettings("PanelCheck.panel.countOfEvents"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.countOfEvents"); + + 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())); + "panel.countOfEvents", _pnl.getCountOfEvents())); assertion.assertLessEqual(_pnl.getCountOfEvents(), settings.getHighLimit(DEFAULT_EVENTCOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } } - + protected validateCountOfShapes() { - shared_ptr settings = new QgSettings("PanelCheck.panel.countOfShapes"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.countOfShapes"); + + 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())); + "panel.countOfShapes", _pnl.getCountOfShapes())); assertion.assertLessEqual(_pnl.getCountOfShapes(), settings.getHighLimit(DEFAULT_SHAPECOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } } - - - //---------------------------------------------------------------------------- + + + //---------------------------------------------------------------------------- protected validateCCN() { - shared_ptr settings = new QgSettings("PanelCheck.panel.panel.CCN"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.panel.CCN"); + + 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())); + "panel.CCN", getCCN())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } - + protected validateAvgCCN() { - shared_ptr settings = new QgSettings("PanelCheck.panel.avgCCN"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.avgCCN"); + + 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())); + "panel.avgCCN", getAvgCCN())); assertion.info(getAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } } - + protected validateNLOC() { - shared_ptr settings = new QgSettings("PanelCheck.panel.NLOC"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.NLOC"); + + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_Panels"); + assertion.setMsgCatName("QgStaticCheck_Panels"); assertion.setAssertionText("assert.panel.NLOC"); assertion.setReasonText("reason.panel.NLOC", makeMapping("panel.name", getName(), - "panel.NLOC", getNLOC())); + "panel.NLOC", getNLOC())); assertion.info(getNLOC(), settings.getScorePoints()); result.addChild(assertion); } } - + protected validateAvgNLOC() { - shared_ptr settings = new QgSettings("PanelCheck.panel.avgNLOC"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelCheck.panel.avgNLOC"); + + 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())); + "panel.avgNLOC", getAvgNLOC())); assertion.info(getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } } - + protected validateEvents() { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); + //---------------------------------------------------------------------------- // validate events - if ( _pnl.getCountOfEvents() > 0 ) - { + if (_pnl.getCountOfEvents() > 0) + { shared_ptr ev = new QgVersionResult(); - ev.setAssertionText("panel.events"); - - while( _pnl.getCountOfEvents() > 0 ) + ev.setAssertionText("panel.events"); + + while (_pnl.getCountOfEvents() > 0) { const anytype key = mappingGetKey(_pnl.events, 1); _pnl.events[key].validate(); ev.addChild(_pnl.events[key].result); mappingRemove(_pnl.events, key); } - + result.addChild(ev); } } @@ -511,34 +526,36 @@ class PanelCheck : QgFile { //---------------------------------------------------------------------------- // validate shapes - if ( _pnl.getCountOfShapes() > 0 ) - { + if (_pnl.getCountOfShapes() > 0) + { shared_ptr sh = new QgVersionResult(); sh.setAssertionText("panel.shapes"); - - while(_pnl.getCountOfShapes() > 0 ) - { + + while (_pnl.getCountOfShapes() > 0) + { _pnl.shapes[1].validate(); sh.addChild(_pnl.shapes[1].result); dynRemove(_pnl.shapes, 1); } + result.addChild(sh); } } - //---------------------------------------------------------------------------- - // validate properties + //---------------------------------------------------------------------------- + // validate properties protected validateProperties() { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - if ( _pnl.getCountOfProperties() > 0 ) + + if (_pnl.getCountOfProperties() > 0) { shared_ptr prop = new QgVersionResult(); prop.setAssertionText("panel.properties"); - - while ( _pnl.getCountOfProperties() > 0 ) - { + + while (_pnl.getCountOfProperties() > 0) + { ///@todo probably place for checking properties string key = mappingGetKey(_pnl.properties, 1); shared_ptr property = new QgVersionResult(); @@ -547,21 +564,21 @@ class PanelCheck : QgFile mappingRemove(_pnl.properties, key); prop.addChild(property); } - + result.addChild(prop); } } - - - + + + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - - static string _sourceDir = PROJ_PATH; - static dyn_string _enabledExtensions = makeDynString(); + + static string _sourceDir = PROJ_PATH; + static dyn_string _enabledExtensions = makeDynString(); string _extension; - + PanelFile _pnl = PanelFile(); bool _isBackUp; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFile.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFile.ctl index 566be1f..22426d5 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFile.ctl @@ -26,268 +26,274 @@ class PanelFile //------------------------------------------------------------------------------ public PanelFile(const string relPath = "") { - setPath(relPath); + setPath(relPath); } - + //------------------------------------------------------------------------------ public void setPath(const string &relPath) { - _relPath = relPath; + _relPath = relPath; } - + //------------------------------------------------------------------------------ static public void setSourceDirPath(const string &path) { _sourceDir = path; } - + //------------------------------------------------------------------------------ public bool exists() { - return (_relPath != "" && isfile(getFullPath()) ); + return (_relPath != "" && isfile(getFullPath())); } - + //------------------------------------------------------------------------------ public int toXml() { string cmd; - - if ( _WIN32 ) + + if (_WIN32) cmd = getPath(BIN_REL_PATH, getComponentName(UI_COMPONENT) + ".exe"); else cmd = getPath(BIN_REL_PATH, getComponentName(UI_COMPONENT)) + " -platform offscreen"; - - if ( cmd == "" ) + + if (cmd == "") return -1; - - cmd += " -p " + makeNativePath(_relPath) + " -xmlConvert=XML -proj "+ PROJ; - + + cmd += " -p " + makeNativePath(_relPath) + " -xmlConvert=XML -proj " + PROJ; + int rc = system(cmd); - if ( rc ) + + if (rc) { logger.warning("Can not convert panel into xml format: " + cmd); return -2; } - + return 0; } - + //------------------------------------------------------------------------------ public bool isBackUp() { return (strpos(getExt(_relPath), "bak") == 0); } - + //------------------------------------------------------------------------------ public string getFullPath() { return _sourceDir + PANELS_REL_PATH + _relPath; } - + //------------------------------------------------------------------------------ public string getRelPath() { return _relPath; } - + //------------------------------------------------------------------------------ public int read() { File panelFile = File(getFullPath()); - + panelFile.read(this.strContent); - - if ( this.strContent != "" ) - { + + if (this.strContent != "") + { _isXml = this.strContent.startsWith("= 0 ) + + while (node >= 0) { nodeName = xmlNodeName(_xmlDoc, node);; - - switch ( nodeName ) + + switch (nodeName) { case "properties": _readProps(xmlFirstChild(_xmlDoc, node), properties); break; + case "events": - _readEvents(node, events); + _readEvents(node, events); break; + case "shapes": _readShapes(node, shapes); - break; - + break; + default: logger.warning("InternFailure: undefined nodeName, " + nodeName + ", " + getFullPath()); } node = xmlNextSibling(_xmlDoc, node); } - + return 0; } - + //------------------------------------------------------------------------------ public int calculate() { int count = 0; - for(int i = 1; i <= dynlen(shapes); i++) + + for (int i = 1; i <= dynlen(shapes); i++) { shapes[i].calculate(); - + _ccn += shapes[i].getCCN(); _nloc += shapes[i].getNLOC(); _avgCcn += shapes[i].getAvgCCN(); _avgNloc += shapes[i].getAvgNLOC(); count++; } - - for(int i = 1; i <= mappinglen(events); i++) + + for (int i = 1; i <= mappinglen(events); i++) { const string key = mappingGetKey(events, i); events[key].calculate(); - + _ccn += events[key].getCCN(); _nloc += events[key].getNLOC(); _avgCcn += events[key].getAvgCCN(); _avgNloc += events[key].getAvgNLOC(); count++; } - + // avarege per dir ??? not sure if is correct so - if ( count > 0 ) + if (count > 0) { _avgCcn = _avgCcn / count; _avgNloc = _avgNloc / count; } } - + //------------------------------------------------------------------------------ public int getCCN() { return _ccn; } - + //------------------------------------------------------------------------------ public float getAvgCCN() { return _avgCcn; } - + //------------------------------------------------------------------------------ public int getNLOC() { return _nloc; } - + //------------------------------------------------------------------------------ public float getAvgNLOC() { return _avgNloc; } - + //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- @@ -296,65 +302,69 @@ class PanelFile //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ int _readShapes(int node, dyn_anytype &shapes) { - if ( node < 0 ) + if (node < 0) return -1; - + int shNode = xmlFirstChild(_xmlDoc, node); PanelFileShape sh = PanelFileShape(); - while ( !_readShape(shNode, sh) ) + + while (!_readShape(shNode, sh)) { dynAppend(shapes, sh); shNode = xmlNextSibling(_xmlDoc, shNode); } - + return 0; } - + //------------------------------------------------------------------------------ int _readShape(int node, PanelFileShape &sh) { - if ( node < 0 ) + if (node < 0) return -1; - + string nodeName = xmlNodeName(_xmlDoc, node); - mapping map = xmlElementAttributes(_xmlDoc, node); - - if ( (nodeName == "reference") && !mappingHasKey(map, "shapeType") ) + mapping map = xmlElementAttributes(_xmlDoc, node); + + if ((nodeName == "reference") && !mappingHasKey(map, "shapeType")) { map["shapeType"] = "PANEL_REFERENCE"; // refernec does not contains the type. So push it here. } - - if ( (nodeName == "shape") || (nodeName == "reference") ) + + if ((nodeName == "shape") || (nodeName == "reference")) { mapping props; mapping events; int scNode = xmlFirstChild(_xmlDoc, node); - - while ( scNode >= 0 ) - { + + while (scNode >= 0) + { nodeName = xmlNodeName(_xmlDoc, scNode); - switch ( nodeName ) + + switch (nodeName) { case "properties": - _readProps(xmlFirstChild(_xmlDoc, scNode), props); + _readProps(xmlFirstChild(_xmlDoc, scNode), props); break; + case "events": - _readEvents(scNode, events); + _readEvents(scNode, events); break; - + default: logger.warning("InternFailure: undefined nodeName, " + nodeName + ", " + getFullPath()); - + } + scNode = xmlNextSibling(_xmlDoc, scNode); } - + sh.initFromMap(map); - sh.setProperties(props); + sh.setProperties(props); sh.setEvents(events); return 0; } @@ -362,81 +372,83 @@ class PanelFile logger.warning("Unknown shape type, " + nodeName + ", " + getFullPath()); return -2; } - + //------------------------------------------------------------------------------ int _readEvents(int node, mapping &events) { - if ( node < 0 ) + if (node < 0) return -1; - + string name = xmlNodeName(_xmlDoc, node); - if ( name != "events" ) + + if (name != "events") return -1; - - int evNode = xmlFirstChild(_xmlDoc, node); - while ( !_readEvent(evNode, events) ) + + int evNode = xmlFirstChild(_xmlDoc, node); + + while (!_readEvent(evNode, events)) evNode = xmlNextSibling(_xmlDoc, evNode); - + return 0; } - + //------------------------------------------------------------------------------ int _readEvent(int node, mapping &events) { - if ( node < 0 ) + if (node < 0) return -1; - + string name = xmlNodeName(_xmlDoc, node); mapping map = xmlElementAttributes(_xmlDoc, node); - - if ( name == "script" ) + + if (name == "script") { name = map["name"]; PanelFileScript script = PanelFileScript(name); int scNode = xmlFirstChild(_xmlDoc, node); - + script.setScript(xmlNodeValue(_xmlDoc, scNode)); - - events[name] = script; + + events[name] = script; } - + return 0; } - + //------------------------------------------------------------------------------ int _readProps(int node, anytype &result) { - if ( node < 0 ) + if (node < 0) return -1; - - if ( xmlNodeType(_xmlDoc, node) == XML_TEXT_NODE ) + + if (xmlNodeType(_xmlDoc, node) == XML_TEXT_NODE) { string value = xmlNodeValue(_xmlDoc, node); result = value; return 0; } - else if ( xmlNodeType(_xmlDoc, node) == XML_ELEMENT_NODE ) + else if (xmlNodeType(_xmlDoc, node) == XML_ELEMENT_NODE) { mapping map = xmlElementAttributes(_xmlDoc, node); - - if ( mappingHasKey(map, "name") ) + + if (mappingHasKey(map, "name")) { - if ( getType(result) == ANYTYPE_VAR ) + if (getType(result) == ANYTYPE_VAR) result = makeMapping(); - + string key = map["name"]; anytype a; - if ( !_readProps(xmlFirstChild(_xmlDoc, node), a) ) + + if (!_readProps(xmlFirstChild(_xmlDoc, node), a)) result[key] = a; } - + } - + _readProps(xmlNextSibling(_xmlDoc, node), result); return 0; } - - + //------------------------------------------------------------------------------ bool _isXml; bool _isCrypted; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileScript.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileScript.ctl index e364807..aad1abf 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileScript.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelFile/PanelFileScript.ctl @@ -15,72 +15,71 @@ class PanelFileScript : ScriptData { _name = name; } - + public void setScript(const string &script) { _script = script; strreplace(_script, """, "\""); strreplace(_script, "&", "&"); } - - public string getName() + + public string getName() { return _name; } - + public string getScript() { return _script; - } - - + } + public int getMaxCountOfFunctions() { - if ( "ScopeLib" == _name ) + if ("ScopeLib" == _name) return 30; - + return 5; } - + public int getMinCountOfFunctions() - { - if ( "ScopeLib" == _name ) + { + if ("ScopeLib" == _name) return 0; // scope is allowed to be empty - + return 1; } - + public int getMinNLOC() { - if ( "ScopeLib" == _name ) + if ("ScopeLib" == _name) return 0; // scope is allowed to be empty - + return 4; } - - + + public float getMaxAvgCCN() { return 10; } - + public int calculate() { _filePath = tmpnam() + ".ctl"; - + file f = fopen(_filePath, "wb+"); fputs(getScript(), f); fclose(f); - - if ( ScriptData::calculate() ) + + if (ScriptData::calculate()) return -1; - + remove(_filePath); return 0; } - + string _name; string _script; - + }; 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 9ab4346..d853f8c 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 @@ -14,7 +14,7 @@ class PanelFileShape { //------------------------------------------------------------------------------ public shared_ptr result;//!< Quality gate result - + public PanelFileShape() { } @@ -23,120 +23,121 @@ class PanelFileShape { _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 //return dynlen(_shapes); return 0; } - + public mapping getEvents() { return _events; } - + public void setEvents(mapping &scripts) { _events = scripts; } - + public PanelFileScript getEvent(string name) { - if ( mappingHasKey(_events, name) ) + if (mappingHasKey(_events, name)) return _events[name]; - + PanelFileScript foo = PanelFileScript(); return foo; } - - + + public string getName() { - if ( mappingHasKey(_firstLevelProps, "Name") ) + if (mappingHasKey(_firstLevelProps, "Name")) return _firstLevelProps["Name"]; - + return ""; } - - + + public static int getMaxCountOfEvents() { return 100; } - - - + + + public int calculate() { int count = mappinglen(_events); - for(int i = 1; i <= count; i++) + + for (int i = 1; i <= count; i++) { const string key = mappingGetKey(_events, i); _events[key].calculate(); - + _ccn += _events[key].getCCN(); _nloc += _events[key].getNLOC(); _avgCcn += _events[key].getAvgCCN(); _avgNloc += _events[key].getAvgNLOC(); } - - if ( count > 0 ) + + if (count > 0) { _avgCcn = _avgCcn / count; _avgNloc = _avgNloc / count; } - + 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(); - + validateCountOfProperties(); validateCountOfEvents(); validateCCN(); @@ -145,159 +146,161 @@ class PanelFileShape validateAvgNLOC(); validateEvents(); validateProperties(); - - return 0; + + return 0; } - - // countOfProperties + + // countOfProperties protected int validateCountOfProperties() { shared_ptr settings = new QgSettings("PanelFileShape.shape.countOfProperties"); - - if ( settings.isEnabled() ) + + 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())); + "shape.countOfProperties", getCountOfProperties())); assertion.info(getCountOfProperties(), settings.getScorePoints()); result.addChild(assertion); } } - - // getCountOfEvents + + // getCountOfEvents protected int validateCountOfEvents() { - shared_ptr settings = new QgSettings("PanelFileShape.shape.countOfEvents"); - - if ( settings.isEnabled() ) + shared_ptr settings = new QgSettings("PanelFileShape.shape.countOfEvents"); + + 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())); + "shape.countOfEvents", getCountOfEvents())); 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 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())); + "shape.CCN", getCCN())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } - + protected int validateAvgCCN() { - shared_ptr settings = new QgSettings("PanelFileShape.shape.avgCCN"); - - if ( settings.isEnabled() ) + 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())); + "shape.avgCCN", getAvgCCN())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } - + protected int validateNLOC() { - shared_ptr settings = new QgSettings("PanelFileShape.shape.NLOC"); - - if ( settings.isEnabled() ) + 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())); + "shape.NLOC", getNLOC())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } - + protected int validateAvgNLOC() { - shared_ptr settings = new QgSettings("PanelFileShape.shape.avgNLOC"); - - if ( settings.isEnabled() ) + 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())); + "shape.avgNLOC", getAvgNLOC())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } - - //---------------------------------------------------------------------------- - // validate events + + //---------------------------------------------------------------------------- + // validate events protected int validateEvents() { - if ( mappinglen(_events) > 0 ) + if (mappinglen(_events) > 0) { shared_ptr ev = new QgVersionResult(); ev.setAssertionText("shape.events"); - - for( int i = 1; i <= mappinglen(_events); i++ ) - { + + for (int i = 1; i <= mappinglen(_events); i++) + { anytype event = mappingGetValue(_events, i); event.validate(); ev.addChild(event.result); } + result.addChild(ev); } } - //---------------------------------------------------------------------------- - // validate properties + //---------------------------------------------------------------------------- + // validate properties protected int validateProperties() { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - if ( mappinglen(_properties) > 0 ) + + if (mappinglen(_properties) > 0) { shared_ptr prop = new QgVersionResult(); prop.setAssertionText("shape.properties"); - - for( int i = 1; i <= mappinglen(_properties); i++ ) - { + + 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); property.info(_properties[key]); - + prop.addChild(property); } - + result.addChild(prop); } } - + mapping _events; mapping _properties; mapping _firstLevelProps; - + int _nloc, _ccn; float _avgCcn, _avgNloc; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelsDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelsDir.ctl index 2e46df6..7417c54 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelsDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelsDir.ctl @@ -21,7 +21,7 @@ class PanelsDir : StaticCodeDir { setDir(dirPath); } - + //------------------------------------------------------------------------------ public PanelCheck makeCheckFile(const string &fullPath) { @@ -35,8 +35,7 @@ class PanelsDir : StaticCodeDir PanelsDir dir = PanelsDir(fullPath); return dir; } - - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl index 952e003..651ddfb 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl @@ -9,52 +9,52 @@ class PicturesDir : StaticDir -{ +{ //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + //------------------------------------------------------------------------------ public PicturesDir(const string dir = "") { setDir(dir); } - + //------------------------------------------------------------------------------ public PicturesFile makeCheckFile(const string &fullPath) { PicturesFile pict = PicturesFile(fullPath); return pict; } - + //------------------------------------------------------------------------------ public PicturesDir makeCheckSubDir(const string &fullPath) { PicturesDir dir = PicturesDir(fullPath); return dir; } - + //------------------------------------------------------------------------------ public int validate() { StaticDir::validate(); - + // validate subdirs and files StaticDir::validateSubDirs(); StaticDir::validateFiles(); - + return 0; } - + //------------------------------------------------------------------------------ public string getSettingsRoot() { return "PicturesDir"; } - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- - + }; 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 5fc30b8..9573ff0 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesFile.ctl @@ -7,74 +7,74 @@ class PicturesFile public PicturesFile(const string &path) { _path = path; - // !! extension must be written lowercase, that NonCaseSensitive works + // !! extension must be written lowercase, that NonCaseSensitive works } - + public int calculate() { - if ( !isfile(_path) ) + if (!isfile(_path)) return -1; - + _size = getFileSize(_path); _extension = getExt(_path); - + return 0; } - + public uint getMaxSize() { // 1MB in == 1048576 bytes return (uint)1048576; } - + public int validate() { result = new QgVersionResult(); result.text = getName(); - + { shared_ptr settings = new QgSettings("PicturesFile.file.size"); - - if ( settings.isEnabled() ) + + 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))); + "file.size", byteSizeToString(_size))); 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 result.addChild(assertion); } } - - { - shared_ptr settings = new QgSettings("PicturesFile.file.extension"); - - if ( settings.isEnabled() ) + + { + shared_ptr settings = new QgSettings("PicturesFile.file.extension"); + + 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())); + "file.extension", _extension, + "allowedValues", settings.getReferenceValues())); assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints()); result.addChild(assertion); } } return 0; } - + public string getName() { return baseName(_path); } - - + + public shared_ptr result; - + 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 39d4275..dc143e1 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl @@ -12,7 +12,7 @@ #uses "classes/QualityGates/QgStaticCheck/StaticDir" #uses "classes/QualityGates/QgSettings" -class StaticCodeDir :StaticDir +class StaticCodeDir : StaticDir { public StaticCodeDir(const string dirPath = "") { @@ -50,7 +50,7 @@ class StaticCodeDir :StaticDir dynClear(_files); dynClear(_childs); - if ( !exists() ) + if (!exists()) { logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist", getDirPath()); return -1; @@ -61,7 +61,7 @@ class StaticCodeDir :StaticDir // check all files dyn_string fileNames = getFileNames(getDirPath()); - for(int i = 1; i <= dynlen(fileNames); i++) + for (int i = 1; i <= dynlen(fileNames); i++) { const string fullPath = makeNativePath(getDirPath() + fileNames[i]); logger.info(0, Qg::getId(), "Check file", fullPath); @@ -72,7 +72,7 @@ class StaticCodeDir :StaticDir checkFile.calculate(); - if ( checkFile.isCalculated() ) + if (checkFile.isCalculated()) { // it is not possible to calculate file (non panel/script file, crypted ...), so dont updatet the statistic data. _ccn += checkFile.getCCN(); @@ -80,7 +80,8 @@ class StaticCodeDir :StaticDir _avgCcn += checkFile.getAvgCCN(); _avgNloc += checkFile.getAvgNLOC(); - if ( checkFile.getAvgCCN() > 0.99 ) + + if (checkFile.getAvgCCN() > 0.99) { // average CCN can no be < 1. It looks like empty file count ++; @@ -93,7 +94,7 @@ class StaticCodeDir :StaticDir // check all directories dyn_string childs = getSubDirNames(); - for(int i = 1; i <= dynlen(childs); i++) + for (int i = 1; i <= dynlen(childs); i++) { const string subDirPath = makeNativePath(getDirPath() + childs[i] + "/"); anytype child = makeCheckSubDir(subDirPath); @@ -106,7 +107,8 @@ class StaticCodeDir :StaticDir _avgCcn += child.getAvgCCN(); _avgNloc += child.getAvgNLOC(); - if ( child.getAvgCCN() > 0.99 ) + + if (child.getAvgCCN() > 0.99) { // average CCN can no be < 1. It looks like empty dir count ++; @@ -116,7 +118,7 @@ class StaticCodeDir :StaticDir } // average per dir ??? not sure if is correct so - if ( count > 0 ) + if (count > 0) { _avgCcn = _avgCcn / count; _avgNloc = _avgNloc / count; @@ -150,12 +152,13 @@ class StaticCodeDir :StaticDir public int validate() { int rc = StaticDir::validate(); - if ( rc == 0 ) + + if (rc == 0) { { shared_ptr settings = new QgSettings("StaticCodeDir.dir.NLOC"); - if ( settings.isEnabled() ) + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); @@ -163,25 +166,26 @@ class StaticCodeDir :StaticDir // NLOC in dir assertion.setAssertionText("assert.dir.NLOC"); assertion.setReasonText("reason.dir.NLOC", makeMapping("dir.name", getName(), - "dir.NLOC", getNLOC())); + "dir.NLOC", getNLOC())); assertion.info(getNLOC(), settings.getScorePoints()); result.addChild(assertion); } } + // average NLOC in dir - if ( getAvgNLOC() > 0 ) + if (getAvgNLOC() > 0) { shared_ptr settings = new QgSettings("StaticCodeDir.dir.avgNLOC"); - if ( settings.isEnabled() ) + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); assertion.setAssertionText("assert.dir.avgNLOC"); assertion.setReasonText("reason.dir.avgNLOC", makeMapping("dir.name", getName(), - "dir.avgNLOC", getAvgNLOC())); + "dir.avgNLOC", getAvgNLOC())); assertion.info(getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -191,31 +195,32 @@ class StaticCodeDir :StaticDir { shared_ptr settings = new QgSettings("StaticCodeDir.dir.CC"); - if ( settings.isEnabled() ) + 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())); + "dir.CCN", getCCN())); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } } + // average CCN in dir - if ( getAvgCCN() > 0 ) + if (getAvgCCN() > 0) { shared_ptr settings = new QgSettings("StaticCodeDir.dir.avgCCN"); - if ( settings.isEnabled() ) + 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())); + "dir.CCN", getAvgCCN())); 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 2fe85cc..f175604 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl @@ -14,30 +14,31 @@ class StaticDir : QgDir { - + public setDir(string dirPath) { dynClear(_files); dynClear(_childs); + if (!dirPath.endsWith("/") && !dirPath.endsWith("\\")) dirPath += makeNativePath("/"); // ensure trailing path delimiter QgDir::setDirPath(dirPath); } - + //------------------------------------------------------------------------------ /** @brief Function calculates statistic data from panels, scripts, libs dirs. @details It works for oa panels, scripts, libs directories. - + @warning Empty files or directories are ignored for average values. @warning Not calculated files or directories are ignored for average values. - - @return Error code. + + @return Error code. value | description ------|------------ 0 | Success -1 | Internal error. Directory does not exists. - + */ public int calculate() { @@ -46,180 +47,187 @@ class StaticDir : QgDir dynClear(_files); dynClear(_childs); - - if ( !exists() ) + + if (!exists()) { logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist", getDirPath()); return -1; } - + float count = 0; - // check all files + // check all files dyn_string fileNames = getFileNames(getDirPath()); - for(int i = 1; i <= dynlen(fileNames); i++) + for (int i = 1; i <= dynlen(fileNames); i++) { const string fullPath = makeNativePath(getDirPath() + fileNames[i]); logger.info(0, Qg::getId(), "Check file", fullPath); anytype checkFile = makeCheckFile(fullPath); - + _allFilesCount++; - - if ( checkFile.calculate() ) + + if (checkFile.calculate()) { continue; } - + dynAppend(_files, checkFile); } - + // check all directories dyn_string childs = getSubDirNames(); - for(int i = 1; i <= dynlen(childs); i++) + for (int i = 1; i <= dynlen(childs); i++) { const string subDirPath = makeNativePath(getDirPath() + childs[i] + "/"); anytype child = makeCheckSubDir(subDirPath); - if ( child.calculate() ) + + if (child.calculate()) continue; // only for safety (should never occur) - + _allFilesCount += child.getCountOfFilesRecursive(); - + dynAppend(_childs, child); } - + return 0; } - + public int validate() { const int filesCount = getCountOfFiles(); const int subDirCount = getCountOfSubDirs(); const bool isEmpty = (filesCount + subDirCount) == 0; - + QgVersionResult::lastErr = ""; result = new QgVersionResult(); result.text = getName(); - + { shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.hasFilesRecursive"); - - if ( settings.isEnabled() ) + + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); + assertion.setMsgCatName("QgStaticCheck_StaticDir"); assertion.setAssertionText("assert.dir.hasFilesRecursive"); assertion.setReasonText("reason.dir.hasFilesRecursive", makeMapping("dir.name", getName())); - if ( !assertion.assertGreatherEqual(getCountOfFilesRecursive(), - settings.getLowLimit(DEFAULT_FILESREC_LOW), - settings.getScorePoints()) ) + + if (!assertion.assertGreatherEqual(getCountOfFilesRecursive(), + settings.getLowLimit(DEFAULT_FILESREC_LOW), + settings.getScorePoints())) { result.addChild(assertion); return 1; } + result.addChild(assertion); } } - - + { shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.isEmpty"); - - if ( settings.isEnabled() ) + + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); + assertion.setMsgCatName("QgStaticCheck_StaticDir"); assertion.setAssertionText("assert.dir.isEmpty"); assertion.setReasonText("reason.dir.isEmpty", makeMapping("dir.name", getName())); - if ( !assertion.assertFalse(isEmpty, settings.getScorePoints()) ) + + if (!assertion.assertFalse(isEmpty, settings.getScorePoints())) { result.addChild(assertion); return 1; } + result.addChild(assertion); } } { shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.subDirCount"); - - if ( settings.isEnabled() ) + + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); + assertion.setMsgCatName("QgStaticCheck_StaticDir"); assertion.setAssertionText("assert.dir.subDirCount"); assertion.setReasonText("reason.dir.subDirCount", makeMapping("dir.name", getName(), - "dir.subDirCount", subDirCount)); + "dir.subDirCount", subDirCount)); assertion.assertLessEqual(subDirCount, - settings.getHighLimit(DEFAULT_SUBDIRCOUNT_HIGH), - settings.getScorePoints()); + settings.getHighLimit(DEFAULT_SUBDIRCOUNT_HIGH), + settings.getScorePoints()); result.addChild(assertion); } } - - + + { shared_ptr settings = new QgSettings(getSettingsRoot() + ".dir.filesCount"); - - if ( settings.isEnabled() ) + + if (settings.isEnabled()) { shared_ptr assertion = new QgVersionResult(); - assertion.setMsgCatName("QgStaticCheck_StaticDir"); + assertion.setMsgCatName("QgStaticCheck_StaticDir"); assertion.setAssertionText("assert.dir.filesCount"); assertion.setReasonText("reason.dir.filesCount", makeMapping("dir.name", getName(), - "dir.filesCount", filesCount)); + "dir.filesCount", filesCount)); assertion.assertLessEqual(filesCount, - settings.getHighLimit(DEFAULT_FILESCOUNT_HIGH), - settings.getScorePoints()); + settings.getHighLimit(DEFAULT_FILESCOUNT_HIGH), + settings.getScorePoints()); result.addChild(assertion); } } return 0; } - + public int validateSubDirs() - { - if ( dynlen(_childs) > 0 ) + { + if (dynlen(_childs) > 0) { shared_ptr subDirs = new QgVersionResult(); subDirs.setMsgCatName("QgStaticCheck_StaticDir"); subDirs.setAssertionText("subDirsList"); - while(dynlen(_childs) > 0) + + while (dynlen(_childs) > 0) { _childs[1].validate(); subDirs.addChild(_childs[1].result); dynRemove(_childs, 1); } + result.addChild(subDirs); } - + return 0; } - + public int validateFiles() { - if ( dynlen(_files) > 0 ) + if (dynlen(_files) > 0) { shared_ptr files = new QgVersionResult(); files.setMsgCatName("QgStaticCheck_StaticDir"); files.setAssertionText("filesList"); - while(dynlen(_files) > 0) + + while (dynlen(_files) > 0) { _files[1].validate(); files.addChild(_files[1].result); dynRemove(_files, 1); } - + result.addChild(files); } - + return 0; } - + public dyn_anytype getSubDirs() { return _childs; @@ -228,48 +236,47 @@ class StaticDir : QgDir 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); dynClear(_childs); // result = nullptr; } - + public string getSettingsRoot() { return "StaticDir"; } - - + //------------------------------------------------------------------------------ // public QgVersionResult result = QgVersionResult(); //!< Quality gate result public shared_ptr result; - + //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - + protected dyn_anytype _files; protected dyn_anytype _childs; - + protected int _allFilesCount; const int DEFAULT_FILESREC_LOW = 1; const int DEFAULT_SUBDIRCOUNT_HIGH = 5; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl index d9bfdca..cbaef35 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgSyntaxCheck/QgSyntaxCheck.ctl @@ -44,7 +44,7 @@ class QgSyntaxCheck : QgBase */ public int setUp() { - if ( QgBase::setUp() ) + if (QgBase::setUp()) return -1; QgVersionResult::showErrorsOnly = TRUE; @@ -52,7 +52,7 @@ class QgSyntaxCheck : QgBase QgDir panelsDir = QgDir(PROJ_PATH + PANELS_REL_PATH); QgDir scriptsDir = QgDir(PROJ_PATH + SCRIPTS_REL_PATH); - if ( !panelsDir.exists() && !scriptsDir.exists() ) + if (!panelsDir.exists() && !scriptsDir.exists()) setMinValidScore("QgSyntaxCheck", "assert.missingFiles", "reason.missingFiles"); return 0; @@ -93,29 +93,30 @@ class QgSyntaxCheck : QgBase _oaSyntaxCheck.stdErr = ""; // free memory _oaSyntaxCheck.stdOut = ""; // free memory - for(int i = 1; i <= dynlen(msgs); i++) + for (int i = 1; i <= dynlen(msgs); i++) { string msg = msgs[i]; - if ( strpos(msg, "is Qt installed correctly") > 0 ) + + if (strpos(msg, "is Qt installed correctly") > 0) { continue; // this message is not relevant } shared_ptr settings = new QgSettings("SyntaxCheck.isSyntaxValid"); - if ( settings.isEnabled() ) + if (settings.isEnabled()) { DebugFTN("QgSyntaxCheck", __FUNCTION__, "check message", msg); dyn_string items = strsplit(msg, ","); - if ( dynlen(items) < 4 ) + if (dynlen(items) < 4) continue; // ignore something like 'This plugin does not support createPlatformOpenGLContext!' const string type = strltrim(items[3], " "); const string prio = strltrim(items[4], " "); string errCode; - if ( dynlen(items) >= 5 ) + if (dynlen(items) >= 5) errCode = strltrim(items[5], " "); dynRemove(items, 1); @@ -130,30 +131,31 @@ class QgSyntaxCheck : QgBase assertion.setAssertionText("assert.isSyntaxValid"); assertion.setReasonText("reason.isSyntaxValid", makeMapping("msg", msg)); - if ( prio == "INFO" ) + if (prio == "INFO") { - if ( errCode == "0" ) + if (errCode == "0") { - DebugFN("QgSyntaxCheck", __FUNCTION__, "this will works, syntax check does not returns errors"); - assertion.assertTrue(TRUE, settings.getScorePoints()); + DebugFN("QgSyntaxCheck", __FUNCTION__, "this will works, syntax check does not returns errors"); + assertion.assertTrue(TRUE, settings.getScorePoints()); assertion.referenceValue = msg; _result.addChild(assertion); } + DebugFN("QgSyntaxCheck", __FUNCTION__, "Skip checks for info message"); continue; // ignore info messages } - else if ( errCode == "117" ) + else if (errCode == "117") { /// @todo remove this check when are WinCCOALicenseCtrlExt implemented - if ( strpos(msg, "WinCCOALicenseCtrlExt") > 0 ) + if (strpos(msg, "WinCCOALicenseCtrlExt") > 0) continue; // ignore missing extension, this is added by IL } - else if ( errCode == "61" ) + 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)) ) + 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 diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl index d7cea5d..7ab0de2 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl @@ -28,11 +28,10 @@ class QgTest : OaTest //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - - + //------------------------------------------------------------------------------ /** @brief Function calculates QG score. - @details Calculates the QG-score depended of test-results. Calculate how many + @details Calculates the QG-score depended of test-results. Calculate how many percente of test-cases are OK. @return Percentil of passed testcases. @todo lschopp 23.05.2018: return result in float format. But we need to check what @@ -43,15 +42,15 @@ class QgTest : OaTest float error = getErrorCount(); float all = getAllCount(); float perc; - - if ( all != 0 ) + + if (all != 0) perc = (error / all) * 100.0; - + perc = 100.0 - perc; - + Float f = Float(perc); perc = f.round(); - + mapping map = makeMapping("Total points", all, "Error points", error, "%", perc); @@ -59,13 +58,13 @@ class QgTest : OaTest return perc; } - + public void addScoreDetail(const mapping &info) { try { // try-catch necessary / no guarantee that variable "_data" exists - if ( mappingHasKey(_data, "qgTestVersionResults") ) + if (mappingHasKey(_data, "qgTestVersionResults")) { _data["qgTestVersionResults"]["Score"] = info; } @@ -73,10 +72,10 @@ class QgTest : OaTest catch { } - + DebugTN("QgTest", __FUNCTION__, info); } - + //------------------------------------------------------------------------------ /** @brief Function returns count of all errors. @details Returns count of all NOT passed test cases executed in this QG. @@ -86,7 +85,7 @@ class QgTest : OaTest { return _errCount; } - + //------------------------------------------------------------------------------ /** @brief Function returns count of all testcases. @details Returns count of all test cases executed in this QG. @@ -96,7 +95,7 @@ class QgTest : OaTest { return _all; } - + //------------------------------------------------------------------------------ /** @brief Function returns error priority of current error. @return Error priority. @@ -105,7 +104,7 @@ class QgTest : OaTest { return _errPrio; } - + //------------------------------------------------------------------------------ /** @brief Function returns error code of current error. @return Error code. @@ -114,7 +113,7 @@ class QgTest : OaTest { return _errCode; } - + //------------------------------------------------------------------------------ /** @brief Function returns error note of current error. @return Error note. @@ -129,13 +128,13 @@ class QgTest : OaTest //-------------------------------------------------------------------------------- //@protected members -//-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- protected string _errNote = ""; //!< Error note. protected int _errPrio = PRIO_SEVERE; //!< Error priority. protected int _errCode = 1; //!< Error code. //-------------------------------------------------------------------------------- //@private members -//-------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------- const int RESULT_FILE_FORMAT = 3; //!< Default result output. }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl index 31ada5d..ccb4c98 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl @@ -121,7 +121,7 @@ struct QgVersionResult Float f = Float(score); mapping map; - switch(qgVersionResultType) + switch (qgVersionResultType) { case QgVersionResultType::TableView: { @@ -172,9 +172,9 @@ struct QgVersionResult float all = getTotalPoints(); float perc; - if ( all < 0 ) + if (all < 0) return NOT_VALID_SCORE; - else if ( all != 0 ) + else if (all != 0) { perc = (error / all) * 100.0; perc = 100.0 - perc; @@ -206,63 +206,65 @@ struct QgVersionResult { DebugN(__FUNCTION__, text, assertKey, dynlen(children), lowerBound, upperBound, referenceValue); } - + //------------------------------------------------------------------------------ anytype toMap(const bool clearObjectOnReturn = TRUE) { mapping map; string goodRange; - if ( (lowerBound != "") || (upperBound != "") ) + + if ((lowerBound != "") || (upperBound != "")) goodRange = lowerBound + " " + _operand + " " + upperBound; - else if ( referenceValue != "" ) + else if (referenceValue != "") goodRange = referenceValue; - switch(qgVersionResultType) + switch (qgVersionResultType) { case QgVersionResultType::TableView: { - if ( text != "" ) + if (text != "") map["text"] = text; - else if ( assertKey != "" ) + else if (assertKey != "") map["text"] = msgCat.getText(assertKey, assertDollars); - if ( value != "" ) + if (value != "") map["value"] = value; map["leaf"] = (dynlen(children) <= 0); - if ( goodRange != "" ) + if (goodRange != "") map["goodRange"] = goodRange; - if ( dynlen(children) > 0 ) + if (dynlen(children) > 0) { map["children"] = makeDynMapping(); - for(int i = 1; i <= dynlen(children); i++) + + for (int i = 1; i <= dynlen(children); i++) { - if ( showErrorsOnly && !children[i].hasError ) + if (showErrorsOnly && !children[i].hasError) continue; + dynAppend(map["children"], children[i].toMap()); } } - if ( hasError ) + if (hasError) map["expanded"] = hasError; - - if ( errorPoints > 0 ) + if (errorPoints > 0) { map["totalPoints"] = totalPoints; map["errorPoints"] = errorPoints; } - else if ( totalPoints > 0 ) + else if (totalPoints > 0) map["totalPoints"] = totalPoints; - if ( hasError ) + if (hasError) { - if ( reason != "" ) + if (reason != "") map["reason"] = reason; - else if ( reasonKey != "" ) + else if (reasonKey != "") map["reason"] = msgCat.getText(reasonKey, reasonDollars); } @@ -271,27 +273,27 @@ struct QgVersionResult case QgVersionResultType::TreeView: { - if ( goodRange != "" ) + if (goodRange != "") map["goodRange"] = goodRange; - if ( value != "" ) + if (value != "") map["value"] = value; - if ( errorPoints > 0 ) + if (errorPoints > 0) { map["totalPoints"] = totalPoints; map["errorPoints"] = errorPoints; } - else if ( totalPoints > 0 ) + else if (totalPoints > 0) map["totalPoints"] = totalPoints; - if ( hasError && reason != "" ) + if (hasError && reason != "") map["reason"] = reason; - if ( dynlen(children) ) + if (dynlen(children)) { - for(int i = 1; i <= dynlen(children); i++) + for (int i = 1; i <= dynlen(children); i++) { map[children[i].text] = children[i].toMap(); } @@ -303,47 +305,48 @@ struct QgVersionResult case QgVersionResultType::SimpleTreeView: { dyn_string ret; - if ( goodRange != "" ) + + if (goodRange != "") dynAppend(ret, "goodRange: " + goodRange); - if ( value != "" ) + if (value != "") dynAppend(ret, "value: " + value); - if ( errorPoints > 0 ) + if (errorPoints > 0) { dynAppend(ret, "errorPoints: " + errorPoints); } - if ( hasError && reason != "" ) + if (hasError && reason != "") dynAppend(ret, "reason: " + reason); - if ( dynlen(children) ) + if (dynlen(children)) { - for(int i = 1; i <= dynlen(children); i++) + for (int i = 1; i <= dynlen(children); i++) { map[children[i].text] = children[i].toMap(); } - if ( clearObjectOnReturn ) + if (clearObjectOnReturn) clear(); + return map; } - if ( clearObjectOnReturn ) + if (clearObjectOnReturn) clear(); return strjoin(ret, ", "); } } - if ( clearObjectOnReturn ) + if (clearObjectOnReturn) clear(); return map; } - //------------------------------------------------------------------------------ bool assertGreatherEqual(const anytype ¤tValue, const anytype &refValue, int points = 1) { @@ -472,12 +475,12 @@ struct QgVersionResult //------------------------------------------------------------------------------ void addChild(shared_ptr child, const int pos = -1) { - if ( pos <= 0 ) + if (pos <= 0) dynAppend(children, child); else dynInsertAt(children, child, pos); - if ( child.hasError ) + if (child.hasError) hasError = TRUE; errorPoints += child.errorPoints; @@ -506,7 +509,6 @@ struct QgVersionResult _allowNextErr = flag; } - //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- @@ -517,6 +519,7 @@ struct QgVersionResult protected _addScorePoints(int points = 1) { mapping userData; + if (location != "") { assertDollars["location"] = location; @@ -524,15 +527,16 @@ struct QgVersionResult } userData["Note"] = msgCat.getText(assertKey, assertDollars); - + userData["Method"] = assertKey; userData["ErrMsg"] = msgCat.getText(reasonKey, reasonDollars); userData["StackTrace"] = makeDynString(); - + getKnownBugId(userData); totalPoints += points; - if ( hasError && !_allowNextErr ) + + if (hasError && !_allowNextErr) { errorPoints += points; lastErr = reason; @@ -540,12 +544,12 @@ struct QgVersionResult const int prio = mappingHasKey(userData, "KnownBug") ? PRIO_INFO : PRIO_WARNING; throwError(makeError("QgBase", prio, ERR_CONTROL, 10, msgCat.getText(reasonKey, reasonDollars))); - if ( _enableOaTestOutput() ) + if (_enableOaTestOutput()) oaUnitFail(assertKey, userData); } else { - if ( _enableOaTestOutput() ) + if (_enableOaTestOutput()) oaUnitPass(assertKey, userData); else throwError(makeError("QgBase", PRIO_INFO, ERR_CONTROL, 11, msgCat.getText(assertKey, assertDollars))); @@ -553,41 +557,43 @@ struct QgVersionResult _allowNextErr = FALSE; } - + //------------------------------------------------------------------------------ protected getKnownBugId(mapping &userData) { - if ( dynlen(knownBugs) <= 0 ) + if (dynlen(knownBugs) <= 0) readKnownBugList(); - + string msg = userData["ErrMsg"]; + for (int i = 2; i <= dynlen(knownBugs); i++) { - if ( dynlen(knownBugs[i]) < 2 ) + if (dynlen(knownBugs[i]) < 2) continue; + string bugId = knownBugs[i][1]; string tcId = knownBugs[i][2]; string pattern = knownBugs[i][3]; - - if ( (tcId == assertKey) && patternMatch(pattern, msg) ) + + if ((tcId == assertKey) && patternMatch(pattern, msg)) { userData["KnownBug"] = bugId; break; } } } - + //------------------------------------------------------------------------------ private readKnownBugList() { string path = getPath(DATA_REL_PATH, "knownBugList.csv"); - - if ( path != "" ) + + if (path != "") csvFileRead(path, knownBugs, ";"); else knownBugs[1] = makeDynString("BUG_ID", "TC_ID", "PATTERN", "COMMENT"); } - + //------------------------------------------------------------------------------ /** @brief enabled or disabled oaUnitResults @todo mPunk 30.10.2018: make it configureable, otherwise does not work in jenkins @@ -603,7 +609,8 @@ struct QgVersionResult protected static string _castToString(const anytype &expr) { string str; - if ( getType(expr) == FLOAT_VAR ) + + if (getType(expr) == FLOAT_VAR) { Float f = Float(expr); str = (string)f.round(2); // round float @@ -625,7 +632,7 @@ struct QgVersionResult /// @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_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/Tools/CppCheck/CppCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheck.ctl index 97278cb..c687b70 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheck.ctl @@ -24,20 +24,21 @@ class CppCheck //------------------------------------------------------------------------------ public static synchronized string getExecutable() { - if ( !initialized ) + if (!initialized) { paCfgReadValue(getPath(CONFIG_REL_PATH, "config"), "qualityChecks", "ctrlppcheckPath", path); - if ( path == "" ) + if (path == "") { - if ( _UNIX ) + if (_UNIX) path = getPath(BIN_REL_PATH, "ctrlppcheck/ctrlppcheck"); - else if ( _WIN32 ) + else if (_WIN32) path = getPath(BIN_REL_PATH, "ctrlppcheck/ctrlppcheck.exe"); } + initialized = TRUE; - if ( path != "" ) + if (path != "") path = "\"" + path + "\""; } @@ -48,7 +49,8 @@ class CppCheck public int start(const string addOptions = "") { string cmd = getExecutable(); - if ( cmd == "" ) + + if (cmd == "") { stdErr = __FUNCTION__ + " can not find executable"; rc = -1; @@ -56,11 +58,12 @@ class CppCheck } cmd += " " + addOptions + " " + settings.toCmdLine(); - + DebugFTN("ctrlppcheck", __FUNCTION__, cmd); rc = system(cmd, stdOut, stdErr); DebugFN("ctrlppcheck_dtl", __FUNCTION__, stdOut, stdErr); - if ( settings.verbose ) + + if (settings.verbose) DebugN(stdOut); return rc; @@ -91,7 +94,8 @@ class CppCheck public dyn_anytype getAllPossibleErrors() { string cmd = getExecutable(); - if ( cmd == "" ) + + if (cmd == "") { stdErr = __FUNCTION__ + " can not find executable"; return makeDynAnytype(); @@ -126,15 +130,17 @@ class CppCheck docNum = xmlDocumentFromString(str, errMsg, errLine, errColumn); DebugFTN("ctrlppcheck", __FUNCTION__, - "docNum", docNum, - "errMsg", errMsg, - "errLine", errLine, - "errColumn", errColumn); - if ( docNum < 0 ) + "docNum", docNum, + "errMsg", errMsg, + "errLine", errLine, + "errColumn", errColumn); + + if (docNum < 0) { DebugFTN("ctrlppcheck", __FUNCTION__, str); return; } + xmlRec(xmlFirstChild(docNum)); str = ""; } @@ -142,7 +148,7 @@ class CppCheck //------------------------------------------------------------------------------ protected stdErrToErrList() { - if ( !settings.isXmlOutEnabled() ) + if (!settings.isXmlOutEnabled()) return; // make a copy of result in log @@ -169,17 +175,19 @@ class CppCheck //------------------------------------------------------------------------------ void xmlRec(int node) { - if ( node < 0 ) + if (node < 0) return; - if ( xmlNodeType(docNum, node) == XML_ELEMENT_NODE ) + if (xmlNodeType(docNum, node) == XML_ELEMENT_NODE) { string nodeName = xmlNodeName(docNum, node); - if ( nodeName == "errors" ) + + if (nodeName == "errors") { dyn_uint nodes; xmlChildNodes(docNum, node, nodes); - for(int i = 1; i <= dynlen(nodes); i++) + + for (int i = 1; i <= dynlen(nodes); i++) { CppCheckError err; xnmlNextErr(nodes[i], err); @@ -197,29 +205,32 @@ class CppCheck //------------------------------------------------------------------------------ void xnmlNextErr(uint node, CppCheckError &err) { - if ( (xmlNodeType(docNum, node) == XML_ELEMENT_NODE) && (xmlNodeName(docNum, node) == "error") ) + if ((xmlNodeType(docNum, node) == XML_ELEMENT_NODE) && (xmlNodeName(docNum, node) == "error")) { mapping map = xmlElementAttributes(docNum, node); err.id = map["id"]; err.severity = map["severity"]; err.msg = map["msg"]; - if ( mappingHasKey(map, "verbose") ) + + if (mappingHasKey(map, "verbose")) { string msg = map["verbose"]; strreplace(msg, FF, "\n"); err.verbose = msg; } - if ( mappingHasKey(map, "cwe") ) + + if (mappingHasKey(map, "cwe")) err.cwe = map["cwe"]; - if ( mappingHasKey(map, "knownBug") ) + if (mappingHasKey(map, "knownBug")) err.knownBug = map["knownBug"]; dyn_uint nodes; xmlChildNodes(docNum, node, nodes); - for(int i = 1; i <= dynlen(nodes); i++) + + for (int i = 1; i <= dynlen(nodes); i++) { - if ( !xmlErrLocation(nodes[i], err) ) + if (!xmlErrLocation(nodes[i], err)) break; } } @@ -228,7 +239,7 @@ class CppCheck //------------------------------------------------------------------------------ int xmlErrLocation(uint node, CppCheckError &err) { - if ( (xmlNodeType(docNum, node) == XML_ELEMENT_NODE) && (xmlNodeName(docNum, node) == "location") ) + if ((xmlNodeType(docNum, node) == XML_ELEMENT_NODE) && (xmlNodeName(docNum, node) == "location")) { mapping map = xmlElementAttributes(docNum, node); err.line = (int)map["line"]; @@ -239,6 +250,7 @@ class CppCheck return 0; } + return -1; } }; 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 c4ec71f..6ef4aa1 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckError.ctl @@ -11,25 +11,25 @@ struct CppCheckError int line; int cwe; string knownBug; // for internal use (tests) - + string toStdErrString() { string s = "ID: " + id + "\n" + "Severity: " + severity + "\n"; - - if ( msg != "" ) + + if (msg != "") s += "Msg: " + msg + "\n"; - - if ( verbose != "" ) + + if (verbose != "") s += "Verbose: " + verbose + "\n"; - - if ( path != "" ) + + if (path != "") s += "Path: " + path + "\n"; - - + + s += "Line: " + line + "\n" + "CWE: " + cwe; - + return s; } }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckSettings.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckSettings.ctl index 88f8e3e..346208e 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckSettings.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/CppCheck/CppCheckSettings.ctl @@ -39,7 +39,7 @@ class CppCheckSettings //------------------------------------------------------------------------------ public addEnabled(const string &str) { - if ( enabled != "" ) + if (enabled != "") enabled += "," + str; else enabled = str; @@ -54,7 +54,7 @@ class CppCheckSettings //------------------------------------------------------------------------------ public enableXmlFormat(bool enable) { - if ( enable ) + if (enable) xml = "--xml"; else xml = ""; @@ -69,7 +69,7 @@ class CppCheckSettings //------------------------------------------------------------------------------ public addRuleFile(const string &path) { - if ( path == "" ) + if (path == "") return; dynAppend(ruleFiles, path); @@ -83,7 +83,8 @@ class CppCheckSettings public unloadRule(const string &path) { int idx = dynContains(ruleFiles, path); - if ( idx <= 0 ) + + if (idx <= 0) return; dynRemove(ruleFiles, idx); @@ -95,7 +96,7 @@ class CppCheckSettings // ctrlppcheck-suppress unusedFunction public addIncludeDir(const string &path) { - if ( path == "" ) + if (path == "") return; dynAppend(includedSubProjDirs, path); @@ -109,7 +110,8 @@ class CppCheckSettings public unloadIncludeDir(const string &path) { int idx = dynContains(includedSubProjDirs, path); - if ( idx <= 0 ) + + if (idx <= 0) return; dynRemove(includedSubProjDirs, idx); @@ -118,7 +120,7 @@ class CppCheckSettings //------------------------------------------------------------------------------ public addLibraryFile(const string &path) { - if ( path == "" ) + if (path == "") return; dynAppend(libraryFiles, path); @@ -132,7 +134,8 @@ class CppCheckSettings public unloadLibrary(const string &path) { int idx = dynContains(libraryFiles, path); - if ( idx <= 0 ) + + if (idx <= 0) return; dynRemove(libraryFiles, idx); @@ -143,49 +146,51 @@ class CppCheckSettings { string opts; - if ( enabled != "" ) + if (enabled != "") opts += " --enable=" + enabled; - if ( xml != "" ) + + if (xml != "") opts += " " + xml; - if ( inconclusive ) + if (inconclusive) opts += " --inconclusive"; - for(int i = 1; i <= dynlen(ruleFiles); i++) + for (int i = 1; i <= dynlen(ruleFiles); i++) opts += " --rule-file=" + makeNativePath(ruleFiles[i]); - if ( enableLibCheck ) + if (enableLibCheck) opts += " --check-library"; // disable header check for perfomance reason //if ( !enableHeadersCheck ) // opts += " --check-headers=no"; - if ( includeSubProjects ) + if (includeSubProjects) { // add all subproject to check includes via option -I - if ( dynlen(includedSubProjDirs) <= 0 ) + if (dynlen(includedSubProjDirs) <= 0) { includedSubProjDirs = getSubProjPathes(); dynAppend(includedSubProjDirs, WINCCOA_PATH); } + for (int i = 1; i <= dynlen(includedSubProjDirs); i++) opts += " -I " + includedSubProjDirs[i]; } - for(int i = 1; i <= dynlen(libraryFiles); i++) + for (int i = 1; i <= dynlen(libraryFiles); i++) opts += " --library=" + makeNativePath(libraryFiles[i]); opts += " --winccoa-projectName=" + winccoaProjectName; - if ( verbose ) + if (verbose) opts += " -v"; - if ( inlineSuppressions ) + if (inlineSuppressions) opts += " --inline-suppr"; - if ( errorList ) + if (errorList) opts += " --errorlist"; return opts; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Lizard/ToolLizard.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Lizard/ToolLizard.ctl index 3d6acfb..0ef5f5a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Lizard/ToolLizard.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Lizard/ToolLizard.ctl @@ -20,7 +20,7 @@ enum LizardCsvIndx //-------------------------------------------------------------------------------- /** Lizard tool. - + Lizard is Cyclomatic Complexity Analyzer. Lizard is used to calculate ctrl scripts and get the NLOC, Functions list, Function argument list, CCN and count of lines in function. @@ -34,32 +34,35 @@ class ToolLizard public ToolLizard() { } - + //------------------------------------------------------------------------------ public static synchronized string getBinDir() { - if ( !initialized ) + if (!initialized) { paCfgReadValue(getPath(CONFIG_REL_PATH, "config"), "qualityChecks", "lizardPath", binDir); - if ( binDir == "" ) + + if (binDir == "") binDir = getPath(DATA_REL_PATH, "lizard/"); - - if ( binDir != "" ) + + if (binDir != "") { binDir = makeNativePath(binDir + "/"); // add / on the end of path strreplace(binDir, makeNativePath("//"), makeNativePath("/")); // remove duplicated // } + initialized = TRUE; } + return binDir; } - + //------------------------------------------------------------------------------ public static bool isInstalled() { return isfile(getBinDir() + "lizard.py"); } - + //@private //------------------------------------------------------------------------------ static bool initialized; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/OaSyntaxCheck/OaSyntaxCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/OaSyntaxCheck/OaSyntaxCheck.ctl index 1765d6e..380e59c 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/OaSyntaxCheck/OaSyntaxCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/OaSyntaxCheck/OaSyntaxCheck.ctl @@ -1,9 +1,9 @@ /** @brief Simple WinCC OA syntax check. - + @details Classic WinCC OA syntax check. - + ## Debug flags + OaSyntaxCheck - enable all debugs specific to this tool. */ @@ -12,14 +12,14 @@ class OaSyntaxCheck //-------------------------------------------------------------------------------- //@public members //-------------------------------------------------------------------------------- - + /// std output public string stdOut; /// std error output public string stdErr; /// return code from syntax check public int rc = -1; - + /** @brief Start syntax check for all WinnCC OA scripts, libs and panels. @warning Works only with current project. @@ -34,9 +34,10 @@ class OaSyntaxCheck stdOut = ""; stdErr = ""; string cmd; - if ( _WIN32 ) + + if (_WIN32) cmd = getPath(BIN_REL_PATH, getComponentName(UI_COMPONENT) + ".exe"); - else if ( _UNIX ) + else if (_UNIX) cmd = getPath(BIN_REL_PATH, getComponentName(UI_COMPONENT)); else { @@ -44,22 +45,23 @@ class OaSyntaxCheck DebugFTN("OaSyntaxCheck", __FUNCTION__, stdErr); return -1; } - + cmd += " -syntax all -n -proj " + PROJ + " -log +stderr"; - - if ( _UNIX ) + + if (_UNIX) cmd += " -platform offscreen"; // because at centos gui is not opened - + rc = system(cmd, stdOut, stdErr); - if ( rc ) + + if (rc) { DebugFTN("OaSyntaxCheck", __FUNCTION__, "command exited with rc = " + rc, cmd, stdOut, stdErr); return -2; } - + return 0; } - + /// convert std error output from syntax check to list of messages. public stdErrToMessages(dyn_string &msgs) { @@ -68,20 +70,22 @@ class OaSyntaxCheck dyn_string lines = strsplit(stdErr, "\n"); DebugFTN("OaSyntaxCheck", "parse stderr", dynlen(lines)); string line; - for(int i = 1; i <= dynlen(lines); i++) + + for (int i = 1; i <= dynlen(lines); i++) { - if ( strpos(lines[i], getComponentName(UI_COMPONENT)) >= 0 ) + if (strpos(lines[i], getComponentName(UI_COMPONENT)) >= 0) { - if ( line != "" ) + if (line != "") dynAppend(msgs, line); - + line = lines[i]; continue; } - + line += "\n" + lines[i]; } + dynAppend(msgs, line); } - + }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Python/Python.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Python/Python.ctl index b67d409..d0c91ef 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Python/Python.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Tools/Python/Python.ctl @@ -3,7 +3,7 @@ //-------------------------------------------------------------------------------- /** Interface for python. - + We need python for ToolLizard. @warning It is external dependency. */ @@ -19,11 +19,13 @@ class Python public static bool isInstalled() { string execPath = getExecutable(); - if ( (execPath != "") && isfile(execPath) ) + + if ((execPath != "") && isfile(execPath)) return TRUE; - + string stdOut; - if ( _WIN32 ) + + if (_WIN32) { system("assoc .py", stdOut); strreplace(stdOut, "\n", ""); @@ -36,31 +38,12 @@ class Python return (strpos(stdOut, "Python ") == 0); } } - + //------------------------------------------------------------------------------ public static synchronized string getExecutable() -{ - return findExecutable("python"); -} - //------------------------------------------------------------------------------ - // public static synchronized string getExecutable() - // { - // if ( !initialized ) - // { - // paCfgReadValue(getPath(CONFIG_REL_PATH, "config"), "qualityChecks", "pythonPath", path); - - // if ( path == "" ) - // { - // if ( _UNIX ) - // path = "python"; - // else if ( _WIN32 ) - // path = getPath(DATA_REL_PATH, "python/python.exe"); - // } - // initialized = TRUE; - // } - - // return path; - // } + { + return findExecutable("python"); + } //@private //------------------------------------------------------------------------------ diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Float.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Float.ctl index 9a301ec..d3eb246 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Float.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Float.ctl @@ -32,7 +32,7 @@ class Float { _f = f; } - + //------------------------------------------------------------------------------ /** @brief Function returns value of float variable. @return value of variable. @@ -41,7 +41,7 @@ class Float { return _f; } - + //------------------------------------------------------------------------------ /** @brief Function sets new content to variable. @param f New float value. @@ -50,7 +50,7 @@ class Float { _f = f; } - + //------------------------------------------------------------------------------ /** @brief Function rounds the float variable with given precision. @param precision Round precision. @@ -58,13 +58,13 @@ class Float */ public float round(int precision = 2) { - if ( precision < 0 ) + if (precision < 0) precision = 0; - + float precisionFactor = pow(10.0, precision); return floor(_f * precisionFactor + 0.5) / precisionFactor; } - + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Mapping.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Mapping.ctl index 7587349..92f41aa 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Mapping.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/Mapping.ctl @@ -31,7 +31,7 @@ class Mapping * @warning The c-tor make a copy of variable and that cost some memory-usage.. * In case of big mappings it is better to use function set(), instead of c-tor. */ - public Mapping(mapping map = makeMapping() ) + public Mapping(mapping map = makeMapping()) { _var = map; } @@ -60,7 +60,7 @@ class Mapping */ public anytype getAt(const anytype &key, const anytype def = NULL) { - if( mappingHasKey(_var, key) ) + if (mappingHasKey(_var, key)) return _var[ key ]; return def; @@ -76,11 +76,11 @@ class Mapping // mapping map = var.get(); - for( int i = 1; i <= mappinglen(map); i++ ) + for (int i = 1; i <= mappinglen(map); i++) { const anytype key = mappingGetKey(map, i); anytype value = map[key]; - + _var[key] = value; } } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/String.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/String.ctl index 47b67fa..b67808a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/Variables/String.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/Variables/String.ctl @@ -32,7 +32,7 @@ class String { _s = s; } - + //------------------------------------------------------------------------------ /** @brief Function returns value of string variable. @return value of variable. @@ -41,7 +41,7 @@ class String { return _s; } - + //------------------------------------------------------------------------------ /** @brief Function sets new content to variable. @param f New string value. @@ -50,7 +50,7 @@ class String { _s = s; } - + public bool endsWith(const string &str) { return substr(_s, strlen(_s) - strlen(str)) == str; diff --git a/WinCCOA_QualityChecks/scripts/libs/fileSys.ctl b/WinCCOA_QualityChecks/scripts/libs/fileSys.ctl index 7e00a03..032f042 100644 --- a/WinCCOA_QualityChecks/scripts/libs/fileSys.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/fileSys.ctl @@ -20,39 +20,45 @@ */ dyn_string getFileNamesRecursive(string dir, string pattern = "*", int filter = FILTER_FILES) { - if ( (dir == "") || !isdir(dir) ) + if ((dir == "") || !isdir(dir)) return makeDynString(); - + dyn_string dirs = getFileNames(dir, "*", FILTER_DIRS); dyn_string filtered = getFileNames(dir, pattern, filter); dyn_string result; int len = dynlen(filtered); - for(int i = 1; i <= len; i++) + + for (int i = 1; i <= len; i++) { string subDir = filtered[i]; - if ( !_isValidDirName(subDir) ) + + if (!_isValidDirName(subDir)) continue; dynAppend(result, makeNativePath(dir + "/" + subDir)); } len = dynlen(dirs); - for(int i = 1; i <= len; i++) + + for (int i = 1; i <= len; i++) { string subDir = dirs[i]; - if ( !_isValidDirName(subDir) ) + + if (!_isValidDirName(subDir)) continue; + dynAppend(result, getFileNamesRecursive(makeNativePath(dir + "/" + subDir), pattern, filter)); } - + string delims = makeNativePath("//"); string delim = makeNativePath("/"); - for(int i = 1; i <= dynlen(result); i++) + + for (int i = 1; i <= dynlen(result); i++) { strreplace(result[i], delims, delim); } - + dynUnique(result); dynSort(result); @@ -63,19 +69,20 @@ dyn_string getFileNamesRecursive(string dir, string pattern = "*", int filter = dyn_string getSubProjPathes() { dyn_string pathes; + for (int i = 2; i < SEARCH_PATH_LEN; i++) { dynAppend(pathes, getPath("", "", -1, i)); } - + return pathes; } //--------------------------------------------------------------------------------------------------------------------------------------- private bool _isValidDirName(const string name) { - if ( (name == "..") || (name == "") || (name == ".") ) + if ((name == "..") || (name == "") || (name == ".")) return FALSE; - + return TRUE; } diff --git a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl index fafebc4..c13bf11 100644 --- a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl @@ -61,11 +61,9 @@ void makeGediToolbar() action = moduleAddAction("", "", "", id, -1, ""); moduleSetAction(action, "separator", TRUE); - // moduleAddAction(getCatStr("WinCCOA_gedi_ext", "tool_QualityGates_BuildDocu"), "", "", id, -1, "tool_QualityGates_BuildDocu"); moduleAddAction(getCatStr("WinCCOA_gedi_ext", "open_Docu"), "", "", id, -1, "open_Docu"); -// moduleAddDockModule("WinCCOA_test", "vision/gedi/tests/testStarter.pnl"); - openDockModule(); + openDockModule(); } private int _startCtrlMan(string script, const string scriptOptions = "") @@ -74,9 +72,9 @@ private int _startCtrlMan(string script, const string scriptOptions = "") string stdErr = ""; string cmd; - if ( _WIN32 ) + if (_WIN32) cmd = getPath(BIN_REL_PATH, getComponentName(CTRL_COMPONENT) + ".exe"); - else if ( _UNIX ) + else if (_UNIX) cmd = getPath(BIN_REL_PATH, getComponentName(CTRL_COMPONENT)); else { @@ -85,9 +83,9 @@ private int _startCtrlMan(string script, const string scriptOptions = "") return -1; } - if ( getPath(SCRIPTS_REL_PATH, script + ".ctl") != "" ) + if (getPath(SCRIPTS_REL_PATH, script + ".ctl") != "") script += ".ctl"; - else if ( getPath(SCRIPTS_REL_PATH, script + ".ctc") != "" ) + else if (getPath(SCRIPTS_REL_PATH, script + ".ctc") != "") script += ".ctc"; else DebugFTN("qualityCheck_ext", "Sorry, the script " + script + " was not found."); @@ -95,7 +93,8 @@ private int _startCtrlMan(string script, const string scriptOptions = "") cmd += " " + script + " " + scriptOptions + " -proj " + PROJ;// + " -log +stderr"; int rc = system(cmd, stdOut, stdErr); - if ( rc ) + + if (rc) { DebugFTN("qualityCheck_ext", __FUNCTION__, "command exited with rc = " + rc, cmd, stdOut, stdErr); return rc; @@ -112,7 +111,8 @@ private tool_QualityGates_showBusy(const string &qgId) void tool_QualityGates_QgStaticCheck_CtrlppCheck() { tool_QualityGates_showBusy("QgCtrlppCheck"); - if ( useGediScope ) + + if (useGediScope) start_QgCtrlppCheck(); else _startCtrlMan("QualityGates/StaticTests/QgCtrlppCheck"); @@ -162,7 +162,7 @@ void tool_QualityGates_UnitTests() void tool_QualityGates_OpenResult() { - ModuleOnWithPanel("QgResult-1",-1,-1,400,400,1,1,"Scale","vision/QualityChecks/QG_Main.pnl","QG Result Overview",makeDynString("")); + ModuleOnWithPanel("QgResult-1", -1, -1, 400, 400, 1, 1, "Scale", "vision/QualityChecks/QG_Main.pnl", "QG Result Overview", makeDynString("")); } void open_Docu() diff --git a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl index bf9a13b..ce7c125 100644 --- a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl @@ -34,7 +34,7 @@ void makeScriptEditorToolbar() /// @todo translate label by msgCat actionId = moduleAddAction("CtrlppCheck", "", "", -1, tbID, "ctrlPPCheck"); - while( !dpExists("_CtrlCommandInterface_StaticTests") ) + while (!dpExists("_CtrlCommandInterface_StaticTests")) { // ctrlppcheck-suppress badPerformanceInLoops // wait till created by update script delay(1); @@ -54,47 +54,52 @@ void ctrlPPCheck() mapping map; // mapping with checked data // get current script path; - if ( isFunctionDefined("seGetFileName") ) - path = seGetFileName(); + if (isFunctionDefined("seGetFileName")) + path = seGetFileName(); // store path; map["path"] = path; bool tmpFileUsed = FALSE; - if ( path == "" ) // panel or version < 3.16 + + if (path == "") // panel or version < 3.16 { - /* - When we want to check panel, we need to skip the script delimiter. - The delimiter is ASCII-char 226 (something like --). This is of cores wrong code (parse problem) - So it is fine when we commented the lines out. In that case can ctrlppcheck parse the code - again. I want to delete the lines, but there are some helpfully informations, there - can be used in ctrlppcheck in future. - - That means we need to read the code here now, and comment out all bad lines. - */ + /* + When we want to check panel, we need to skip the script delimiter. + The delimiter is ASCII-char 226 (something like --). This is of cores wrong code (parse problem) + So it is fine when we commented the lines out. In that case can ctrlppcheck parse the code + again. I want to delete the lines, but there are some helpfully informations, there + can be used in ctrlppcheck in future. + + That means we need to read the code here now, and comment out all bad lines. + */ path = tmpnam() + ".ctl"; file f = fopen(path, "wb+"); string script = getScript(); dyn_string lines = strsplit(script, "\n"); - for(int i = 1; i <= dynlen(lines) ; i++) + + for (int i = 1; i <= dynlen(lines) ; i++) { - if ( lines[i] == "" ) + if (lines[i] == "") continue; char firstChar = lines[i][0]; bool isDelim = firstChar == (char)226; - if ( isDelim ) + + if (isDelim) lines[i] = "//" + lines[i]; } + script = strjoin(lines, "\n"); fputs(script, f); fclose(f); tmpFileUsed = TRUE; } - { // in new scope to eliminate memory usage + { + // in new scope to eliminate memory usage ScriptData script; script.setPath(path); script.calculate(); @@ -126,7 +131,8 @@ void ctrlPPCheck() } - { // in new scope to eliminate memory usage + { + // in new scope to eliminate memory usage CppCheck ctrlPpCheck; dpGet("_CtrlppCheck.settings.enableLibCheck", ctrlPpCheck.settings.enableLibCheck, @@ -153,7 +159,7 @@ void ctrlPPCheck() map["ctrlPpCheck"] = ctrlPpCheck.errList; } - if ( tmpFileUsed ) + if (tmpFileUsed) remove(path); // remove temp file @@ -173,10 +179,10 @@ void ctrlPPCheck() /// @warning The panel functions needs active connection to event. Dont try it to start with -n option. void showResult(const mapping &result) { - if ( isModuleOpen("CtrlppCheck") ) + if (isModuleOpen("CtrlppCheck")) moduleOff("CtrlppCheck"); - while ( isModuleOpen("CtrlppCheck") ) + while (isModuleOpen("CtrlppCheck")) { // ctrlppcheck-suppress badPerformanceInLoops delay(0, 20); @@ -186,7 +192,7 @@ void showResult(const mapping &result) ModuleOnWithPanel("CtrlppCheck", -2, -2, 100, 200, 1, 1, "", "vision/scriptEditor/staticTests.pnl", "staticTests", makeDynString()); - while ( !isPanelOpen("staticTests", "CtrlppCheck") ) + while (!isPanelOpen("staticTests", "CtrlppCheck")) { // ctrlppcheck-suppress badPerformanceInLoops delay(0, 100); @@ -201,11 +207,11 @@ void showResult(const mapping &result) /// @todo make some identifier, that can be this action simple used for every lib void update_cb(const string dpe, const string cmd) { - if ( strpos(cmd, "line:") != 0 ) + if (strpos(cmd, "line:") != 0) return; string line = substr(cmd, strlen("line:")); - seSetCursorPos((int)line -1, 0); + seSetCursorPos((int)line - 1, 0); }