diff --git a/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md b/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md index 4e8f88b2..7660aeff 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull-request-template.md @@ -37,6 +37,8 @@ If the issue is not fully described in Github, add more information here (justif Provide a clear description of how this change was tested. At minimum this should include proof that a computer has executed the changed lines. Ideally this should include an automated test or an explanation as to why this change has no tests. +To execute all automated regressions tests start the script /WinCC_OA_Test/executeTests.cmd + Note that automated test coverage is less than complete, so a successful PR build does not necessarily imply that a computer has executed the changed lines. If automated test coverage does not exist for the lines you are changing, **you must describe** the scenario(s) in which you manually tested the change. Currently is not possible to start automatic tests on every PR. Therefore provide the tests manually and paste the result (screenshot) here. @@ -44,6 +46,7 @@ Currently is not possible to start automatic tests on every PR. Therefore provid For frontend changes, include screenshots of the relevant page(s) before and after the change. For refactoring and code cleanup changes, exercise the code before and after the change and verify the behavior remains the same. + --> ### Proposed upgrade guidelines @@ -70,6 +73,7 @@ N/A - [ ] There is automated testing or an explanation that explains why this change has no tests. - [ ] For dependency updates, there are links to external changelogs and, if possible, full differentials. - [ ] Any localizations are transferred to /msg/ files. +- [ ] Automated tests has been executed and valid diff --git a/.gitignore b/.gitignore index e946c6fa..c115ae57 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,10 @@ WinCCOA_QualityChecks/bin/ctrlppcheck/ ctrlppcheck/build/ # astyle backup files *.ctl.orig + +# WinCC OA Tests +WinCC_OA_Test/Projects/Stored/ +WinCC_OA_Test/Results/ +WinCC_OA_Test/Projects/TfCustomizedQG/log/ +WinCC_OA_Test/Projects/TfCustomizedQG/config/config +*.dump diff --git a/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml b/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml index cdfd6d5d..27ffd17a 100644 --- a/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml +++ b/WinCCOA_QualityChecks/data/ctrlPpCheck/rule/ctrl.xml @@ -177,7 +177,7 @@ raw - makeError \( \S+ , \S+ , \S+ , 0 + makeError \( \S+ , 0 fatal_program_exit warning diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat index 52911241..d1f37ad9 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgBase.cat @@ -1,6 +1,7 @@ 00001,QualityGates does not run successfully !!! 00010,Assertion return error: $1 00011,Assertion works: $1 +00012,Assertion return an acceptable error (known bug): $1 00020,The function $1 is not implemented. 00021,Start quality gate $1. 00022,Calculate sources for quality gate $1. diff --git a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_FunctionData.cat b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_FunctionData.cat index 9b01c013..6957356a 100644 --- a/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_FunctionData.cat +++ b/WinCCOA_QualityChecks/msg/de_AT.utf8/QgStaticCheck_FunctionData.cat @@ -4,5 +4,5 @@ assert.function.NLOC,NLOC (No. Lines Of Code) reason.function.NLOC,The function '$function.name()' has invalid lines of code ($function.NLOC) assert.function.countOfLines,Count of lines reason.function.countOfLines,The function '$function.name()' has invalid count of lines ($function.countOfLines) -assert.function.paramCount,Count of parameters +assert.function.paramCount,The function '$function.name()' has $function.paramCount parameter(s) reason.function.paramCount,The function '$function.name()' has too much parameters ($function.paramCount) diff --git a/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat b/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat index 52911241..c8bcf124 100644 --- a/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat +++ b/WinCCOA_QualityChecks/msg/en_US.utf8/QgBase.cat @@ -1,6 +1,7 @@ 00001,QualityGates does not run successfully !!! 00010,Assertion return error: $1 00011,Assertion works: $1 +00012,Assertion returns an acceptable error (known bug): $1 00020,The function $1 is not implemented. 00021,Start quality gate $1. 00022,Calculate sources for quality gate $1. diff --git a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl b/WinCCOA_QualityChecks/scripts/QgTemplate.ctl deleted file mode 100644 index 1adc66b3..00000000 --- a/WinCCOA_QualityChecks/scripts/QgTemplate.ctl +++ /dev/null @@ -1,57 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir" -#uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/QgBase" - -class QgTemplate : QgBase -{ - - public int setUp() - { - if (QgBase::setUp()) - return -1; - -// _sourceDir.create(); -// _pictures.setDir(_sourceDir.getDirPath + PICTURES_REL_PATH); - _pictures.setDir(WINCCOA_PATH + PICTURES_REL_PATH); - return 0; - } - - public int calculate() - { - return _pictures.calculate(); - } - - public int validate() - { - return _pictures.validate(); - } - - public mapping getStoreResult() - { - return _pictures.result.toMap(); - } - - public int tearDown() - { - _sourceDir.cleanUp(); - return QgBase::tearDown(); - } - - PicturesDir _pictures = PicturesDir(); -}; - -main() -{ - Qg::setId("QgTemplate"); - QgTemplate qg = QgTemplate(); - exit(qg.start()); -} diff --git a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl index 62a53c52..3dea5fef 100644 --- a/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/QualityGates/StaticTests/QgScriptsCheck.ctl @@ -44,6 +44,10 @@ class QgStaticCheck_Scripts : QgBase { this.checkedPath = PROJ_PATH + SCRIPTS_REL_PATH; } + else if (isdir(this.checkedPath + SCRIPTS_REL_PATH)) + { + this.checkedPath = this.checkedPath + SCRIPTS_REL_PATH; + } _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::scripts); @@ -54,11 +58,17 @@ class QgStaticCheck_Scripts : QgBase { this.checkedPath = PROJ_PATH + LIBS_REL_PATH; } + else if (isdir(this.checkedPath + LIBS_REL_PATH)) + { + this.checkedPath = this.checkedPath + LIBS_REL_PATH; + } _scriptsData.setDir(this.checkedPath); _scriptsData.setType(ScriptsDataType::libs); } + throwError(makeError("", PRIO_INFO, ERR_CONTROL, 0, "Path to check", this.checkedPath)); + if (!_scriptsData.exists()) setMinValidScore(Qg::getId(), "assert.missingScripts", "reason.missingScripts"); 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 0f9f602a..2f509fba 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir.ctl @@ -10,8 +10,7 @@ #uses "classes/FileSys/QgDir" #uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/QgApp" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir" +#uses "classes/QualityGates/QgTest" class QgAddOnResultsDir { @@ -100,20 +99,17 @@ class QgAddOnResultsDir public string getDirPath() { - if (_resultDir == "") + if (_resultDir != "") + return _resultDir; + + if (!QgTest::isStartedByTestFramework()) { - if (!Qg::isRunningOnJenkins()) - { - // projPath should be used, when Jenkins is not used - _resultDir = makeNativePath(PROJ_PATH + DATA_REL_PATH + "QualityGates/" + _qgId + "/" + _buildNo + "/"); - } - else - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _resultDir = makeNativePath(app.getSourcePath() + "QgResult/" + Qg::getId() + "/"); - } + // When you start some locale tests, proj path will be used + // the test-framework does not need it, because results are stored in + // test-framework comform format automatically. + _resultDir = makeNativePath(PROJ_PATH + DATA_REL_PATH + "QualityGates/" + _qgId + "/" + _buildNo + "/"); } - + return _resultDir; } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl deleted file mode 100644 index 43eab52e..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir.ctl +++ /dev/null @@ -1,32 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgApp" - - -class QgAddOnSourceDir -{ - public QgAddOnSourceDir() - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _dirPath = makeNativePath(app.getSourcePath() + "appData/" + app.getExtendedTechnicalName() + "/"); - } - - public string getDirPath() - { - return makeNativePath(_dirPath); - } - - public bool exists() - { - return (_dirPath != "" && isdir(_dirPath)); - } - - string _dirPath; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl deleted file mode 100644 index 8e69aaf6..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir.ctl +++ /dev/null @@ -1,70 +0,0 @@ - -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/QgApp" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnSourceDir" - -class QgAddOnTmpSourceDir -{ - public QgAddOnTmpSourceDir() - { - QgApp app = QgApp::getAppFromProjName(PROJ); - _tmpSourceDir = makeNativePath(app.getSourcePath() + "tmpSource/"); - } - - public bool exists() - { - return (_tmpSourceDir != "" && isdir(_tmpSourceDir)); - } - - public int create() - { - if (exists()) - cleanUp(); - - QgAddOnSourceDir source = QgAddOnSourceDir(); - - if (!source.exists()) - { - DebugFTN("QgAddOnTmpSourceDir", "Could not find source packet", source.getDirPath()); - return -1; - } - - if (!isdir(_tmpSourceDir)) - mkdir(_tmpSourceDir); - - copyAllFilesRecursive(source.getDirPath(), _tmpSourceDir); - - if (!exists()) - return -2; - - return 0; - } - - public int cleanUp() - { - if (exists()) - return rmdir(_tmpSourceDir, TRUE); - - return 0; - } - - public string getDirPath() - { - return makeNativePath(_tmpSourceDir); - } - - public string trimPath(const string &fullPath) - { - return substr(fullPath, strlen(getDirPath())); - } - - string _tmpSourceDir; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl deleted file mode 100644 index ba8e62c6..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnResult.ctl +++ /dev/null @@ -1,246 +0,0 @@ - -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/Qg" -#uses "classes/QualityGates/AddOn/Output/QgAddOnScore" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" - -enum QgAddOnResultState -{ - success, - warning, - failed, - error -}; - - -class QgAddOnResult -{ - //-------------------------------------------------------------------------------- -//@public members -//-------------------------------------------------------------------------------- - public static const float MIN_VALID_SCORE = 1.0; - public static const float NOT_VALID_SCORE = 0.0; - public static const string KEY_SCORE_REASON = "Reason"; - public static const string KEY_SCORE_PERCENT = "%"; - public static const string KEY_SCORE_TOTAL_POINTS = "Total points"; - public static const string KEY_SCORE_ERROR_POINTS = "Error points"; - - public static const string KEY_QG_RESULT_TESTVERSION = "qgTestVersionResults"; - public static const string KEY_QG_RESULT_SUM = "qgSummary"; - public static const string KEY_QG_RESULT_SCORE = "score"; - - - public QgAddOnResult() - { - } - - public void setData(const mapping &data) - { - _data = data; - } - - public void setErr(int prio, int code, string note = "") - { - if (prio == PRIO_FATAL) - prio = PRIO_SEVERE; - - errClass err; - - if (note == "") - err = makeError("QgAddOnResultErr", prio, ERR_CONTROL, code, Qg::getId()); - else - err = makeError("QgAddOnResultErr", prio, ERR_CONTROL, code, Qg::getId(), note); - - throwError(err); - DebugFTN("QgAddOnResult", getStackTrace()); - - switch (prio) - { - case PRIO_INFO: - setState(QgAddOnResultState::success); - break; - - case PRIO_WARNING: - setState(QgAddOnResultState::warning); - break; - - case PRIO_SEVERE: - setState(QgAddOnResultState::failed); - break; - - default: - setState(QgAddOnResultState::error); - break; - } - - _hasErr = TRUE; - } - - public int calculate() - { - DebugFTN("QgAddOnResult", __FUNCTION__); - setState(QgAddOnResultState::success); - return 0; - } - - public void addScore(int score) - { - - if (mappingHasKey(_data, "score")) - score = _data["score"]; - - QgAddOnScore scoreFile = QgAddOnScore(); - scoreFile.addScore(score); - _score = score; - } - - public void setState(QgAddOnResultState state) - { - _state = state; - } - - public string stateToString() - { - switch (_state) - { - case QgAddOnResultState::success: - return "success"; - - case QgAddOnResultState::warning: - return "warning"; - - case QgAddOnResultState::error: - return "error"; - - case QgAddOnResultState::failed: - { - ///@todo 05.06.2018 lschopp: remove the option QgAddOnResultState::failed - DebugFTN("QgAddOnResult", __FUNCTION__, "obsolete option"); - return "error"; - } - } - - DebugFTN("QgAddOnResult", __FUNCTION__, "internall error, this state does not exists", _state); - return ""; - } - - public int publish() - { - if (!_resDir.exists()) - _resDir.create(); - - if (!_hasErr && calculate()) - { - DebugFTN("QgAddOnResult", __FUNCTION__, "calculate does not work"); - return -3; - } - - file f = fopen(_resDir.getDirPath() + "_state", "wb+"); - - if (ferror(f)) - { - return -2; - } - - fputs(stateToString(), f); - fclose(f); - - f = fopen(_resDir.getDirPath() + "_data", "wb+"); - - string json; - - if (mappingHasKey(_data, "qgSummary")) - json = jsonEncode(_data["qgSummary"]); - else - json = jsonEncode(_data); - -// strreplace(json, "&", ""); - fputs(json, f); - fclose(f); - - // due to the current state, the score and exitCode are updated - int exitCode; - - switch (_state) - { - case QgAddOnResultState::success: - addScore(2); - exitCode = 0; - break; - - case QgAddOnResultState::warning: - addScore(1); - exitCode = 0; - break; - - case QgAddOnResultState::failed: - addScore(-1); - exitCode = 0; - break; - - case QgAddOnResultState::error: - addScore(-1); - exitCode = 0; - break; - - default: - DebugFTN("QgAddOnResult", __FUNCTION__, "internall error, this state does not exists", _state); - addScore(0); - exitCode = 0; - } - - if (mappingHasKey(_data, "qgTestVersionResults")) - { - string path = _resDir.getDirPath() + "QgTestVersion/"; - - mkdir(path); - - int testId = Qg::idToNum(); - - if (testId <= 0) - { - DebugFTN("QgAddOnResult", __FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); - return -4; - } - - f = fopen(path + "_Id", "wb+"); - fputs((string)testId, f); - fclose(f); - - f = fopen(path + "_Results", "wb+"); - json = jsonEncode(_data["qgTestVersionResults"]); - -// strreplace(json, "&", ""); - - fputs(json, f); - fclose(f); - - f = fopen(path + "_Score", "wb+"); - fputs((string)_score, f); - fclose(f); - } - - - - return exitCode; - } - - public string getResultDirPath() - { - return _resDir.getDirPath(); - } - - QgAddOnResultsDir _resDir = QgAddOnResultsDir(); - protected mapping _data; - QgAddOnResultState _state; - bool _hasErr; - int _score; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl deleted file mode 100644 index fe40d730..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/AddOn/Output/QgAddOnScore.ctl +++ /dev/null @@ -1,31 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" - - -class QgAddOnScore -{ - public QgAddOnScore() - { - } - - /** - - @deprecated since 06.05.2018 +lSchopp dismiss score per version - @param score - @return errcode - */ - public int addScore(int score) - { - return 0; - } - - QgAddOnResultsDir _resDir = QgAddOnResultsDir(); -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl index 92580977..875c84dc 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/Qg.ctl @@ -8,15 +8,9 @@ // //-------------------------------------------------------------------------------- -// used libraries (#uses) - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -/*! @brief Quality-Gate base utils. +/*! Quality-Gate base utils. * - * @details Base utilitys to handle with QualityGate. + * @details Base utilities to handle with QualityGate. * @author lschopp */ class Qg @@ -25,7 +19,7 @@ class Qg //@public members //-------------------------------------------------------------------------------- //------------------------------------------------------------------------------ - /** @brief Function returns id for current QualityGate. + /** Function returns id for current QualityGate. @return ID of QualityGate. @exception 0 when ID are not setted. */ @@ -35,48 +29,17 @@ class Qg } //------------------------------------------------------------------------------ - /** @brief Function set id for current QualityGate. + /** Function set id for current QualityGate. @details Each QualityGate must have unique ID to handle with result files. @warning This ID is loaded "global" in the manager. It can not be quered by other manager at the same time. @param id QualityGate ID. */ - public static void setId(const string id) + public static void setId(const string &id) { _id = id; } - //------------------------------------------------------------------------------ - /** @brief Function returns all defined QualityGate IDs. - @warning This list muss be equal to store-DB. in other case can not be results - imported in store-DB. - @return List with all QG-IDs. - */ - public static dyn_string getAllIds() - { - return makeDynString("QgStaticCheck_Pictures", "QgStaticCheck_Scripts", "QgStaticCheck_Panels", - "QgSyntaxCheck", - "QgStaticCheck_OverloadedFiles", "Documentation", - "UnitTests", "CtrlCoverage", "QgCtrlppCheck", - "QgStaticCheck_Libs"); - } - - //------------------------------------------------------------------------------ - /** @brief Function converts current QG-ID to int variable. - @details We need this convert for backend (store). - @return - */ - public static int idToNum() - { - return dynContains(getAllIds(), getId()); - } - - //------------------------------------------------------------------------------ - public static bool isRunningOnJenkins() - { - return (getenv("WORKSPACE") != ""); - } - //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl index 121be863..561e76d3 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgAddOnResultErr.ctl @@ -96,6 +96,8 @@ class QgAddOnResultErr return map; } + + //-------------------------------------------------------------------------------- //@private members //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl deleted file mode 100644 index b0726bb9..00000000 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgApp.ctl +++ /dev/null @@ -1,406 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "CtrlPv2Admin" - -//--------------------------------------------------------------------------------------------------------------------------------------- -class QgApp -{ - //------------------------------------------------------------------------------------------------------------------------------------- - public QgApp(string id = "") - { - _isValid = FALSE; - - if (id == "") - { - /// @todo I think we can remove this class, because always ends here. - DebugFTN("QgApp", "!!! Parameter #1 (id) is missing"); - return; - } - - _id = id; - string optsPath = _getPath() + "opts.json"; - DebugFTN("QgApp", __FUNCTION__, optsPath); - - if (!isfile(optsPath)) - { - DebugFTN("QgApp", "!!! options file does not exists:", optsPath); - return; - } - - string json; - fileToString(optsPath, json); - _options = jsonDecode(json); - - string resDir = _getResultsDir(); - - if (isdir(resDir)) - mkdir(resDir); - - _isValid = TRUE; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public static QgApp getAppFromProjName(const string projName = PROJ) - { - // parse WinCCOA_FinalyApi_22 to app id - dyn_string items = strsplit(projName, "_"); - - if (dynlen(items) < 3) - { - QgApp app = QgApp(); - return app; - } - - QgApp app = QgApp(items[3]); - return app; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - /** - Function creates new not runnable project. - - @return error code. Succes == 0 - */ - public int makeProj() - { - const string appName = getExtendedTechnicalName(); - // const string appName = getAppName(); - string sourcePath = _getPath() + "appData/" + appName; - const string projName = _getProjName(); - const string destPath = _getProjPath(); - - int rc; - dyn_string names, versions, paths; - - if (!isdir(sourcePath)) - { - DebugFTN("QgApp", __FUNCTION__, "source dir does not exist", sourcePath, _id); - return -2; - } - - paGetProjs(names, versions, paths); - - if (dynContains(names, projName) > 0) //Project is registered - paDelProj(projName, TRUE); - else if (isdir(destPath)) - rmdir(destPath, TRUE); - - dyn_string langs; - - if (dynlen(langs) <= 0) - { - for (int i = 0 ; i < getNoOfLangs(); i++) - langs[i + 1] = getLocale(i); - } - - // proj without DB - DebugFTN("QgApp", __FUNCTION__, "crete new project", _getProjName(), dirName(_getProjPath()), langs); - rc = paCreateProj(_getProjName(), dirName(_getProjPath()), - langs, - 1, "System1", // system num / name - 2, // without DB - "" // no ascii list - ); - - if (rc) - { - DebugFTN("QgApp", "!!! could not create new project", rc); - return -3; - } - - // set proj NOT runnable - paSetProjRunnable(projName, FALSE); - - sourcePath = sourcePath + "/"; - // copy content to the project - const string destPath = _getProjPath(); - const dyn_string simpleDirs = makeDynString(SCRIPTS_REL_PATH, PANELS_REL_PATH, MSG_REL_PATH, - COLORDB_REL_PATH, DATA_REL_PATH, DPLIST_REL_PATH, - HELP_REL_PATH, PICTURES_REL_PATH, SOURCE_REL_PATH, - BIN_REL_PATH, IMAGES_REL_PATH, CONFIG_REL_PATH); - - for (int i = 1; i <= dynlen(simpleDirs); i++) - { - string sourceDir = makeNativePath(sourcePath + simpleDirs[i]); - string destDir = makeNativePath(destPath + simpleDirs[i]); - - if ((CONFIG_REL_PATH != simpleDirs[i]) && isdir(destDir)) - { - // clean up WinCC OA dir, that we have only correct dirs / files form version (addOn) - rmdir(destDir, TRUE); - } - else if ((CONFIG_REL_PATH == simpleDirs[i])) - { - DebugFTN("QgApp", sourceDir, isfile(sourceDir + "config"), sourceDir + "config"); - - // remove config file, otherwise you destrou the add on project - //! @todo 06.05.2018: must not be possible - if (isfile(sourceDir + "config")) - remove(sourceDir + "config"); - } - else if ((BIN_REL_PATH == simpleDirs[i]) && !isdir(sourceDir)) - { - // use bin_ - if (isdir(sourceDir + "_" + VERSION)) - sourceDir = sourceDir + "_" + VERSION; - - const int minMinorVersion = 15; - - // copy all bin directories, really hack. - /// @todo remove this code, when multipe pipeline ( per oa version ) are running - /// @warning this works only for WinCC OA major version == 3 - for (int j = 0; j <= 100; j++) - { - int version = minMinorVersion + j; - string sDir = sourceDir + "_3." + version; - string dDir = destDir + "_3." + version; - - if (!isdir(sDir)) - continue; - - if (!copyAllFilesRecursive(sDir, dDir)) - { - DebugFTN("QgApp", "!!! could not copy dir", sDir, dDir); - return -4; - } - } - } - - DebugFTN("QgApp", "try copy", isdir(sourceDir), sourceDir); - - if (!isdir(sourceDir)) - continue; // nothing to do - - DebugFTN("QgApp", "to", destDir); - - if (!copyAllFilesRecursive(sourceDir, destDir)) - { - DebugFTN("QgApp", "!!! could not copy dir", sourceDir, destDir); - return -4; - } - } - - // create AddonInformation.json file - rc = _makeAddOnInfoFile(); - - if (rc) - { - DebugFTN("QgApp", "!!! could not create AddonInformation.json file", rc); - return -5; - } - - // add this project as subProject, so be sure we have intgrated all scripts libs ... - rc = paSetSubProjs(_getProjName(), makeDynString(PROJ)); - - if (rc) - { - DebugFTN("QgApp", "!!! could not set sub projects", rc, _getProjName(), makeDynString(PROJ)); - return -6; - } - - return 0; - } - - public string getExtendedTechnicalName() - { - return getenv("EXTENDED_TECHNICAL_NAME"); - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public string getAppName() - { - if (!mappingHasKey(_options, "data") || - !mappingHasKey(_options["data"], "filename")) - { - return ""; - } - - string filename = _options["data"]["filename"]; - filename = delExt(filename); - - return filename; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public string getVersionProperty(const string &property) - { - if (mappingHasKey(_options, "data") && mappingHasKey(_options["data"], property)) - { - return _options["data"][property]; - } - - return ""; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - public bool isValid() - { - return _isValid; - } - - int _makeAddOnInfoFile() - { - // see also https://www.dropbox.com/s/xkc6pasizej2ui2/Auto%20Generierung%20AddonInformation.docx?dl=0 - - const string destPath = _getProjPath(); - const string addOnInfoPath = destPath + DATA_REL_PATH + "AddonInformation.json"; - - - if (!isdir(destPath + DATA_REL_PATH)) - mkdir(destPath + DATA_REL_PATH); // make dir for AddonInformation.json file - - if (isfile(addOnInfoPath)) - moveFile(addOnInfoPath, addOnInfoPath + ".copy"); // make copy of original file (+lShopp) - - if (!mappingHasKey(_options, "data") || !mappingHasKey(_options["data"], "product_id")) - { - DebugFTN("QgApp", __FUNCTION__, "missing product_id", _options); - return -1; - } - - const string productId = _options["data"]["product_id"]; - - string serverUrl = getenv("SERVER_HOST_NAME"); - string token = getenv("WinCCOA_TOKEN"); - - if (serverUrl == "") - serverUrl = "WinCCOA.com"; - - string url = "https://" + token + - serverUrl + - "/rest/products?expand=contractor&filter=%5B%7B++%22property%22%3A+%22id%22%2C++%22value%22%3A+" + - productId + - "%2C++%22operator%22%3A+%22%3D%22%7D%5D"; - mapping result; - int rc = netGet(url, result); - - if (rc || result["httpStatusCode"] != 200) - { - DebugFTN("QgApp", __FUNCTION__, "could not get data from store", url); - DebugFN("QgApp", __FUNCTION__, rc, result); - return -2; - } - - string json; - - if (mappingHasKey(result, "content")) - { - json = result["content"]; - } - - mapping addOnInfo; - mapping data = jsonDecode(json); - - try - { - addOnInfo["addon_extended_technical_name"] = (string)getenv("EXTENDED_TECHNICAL_NAME"); - - addOnInfo["addon_name"] = (string)data["data"][1]["name"]; - addOnInfo["addon_description"] = (string)data["data"][1]["description"]; - addOnInfo["addon_item_number"] = (string)data["data"][1]["item_number"]; - addOnInfo["addon_provider_name"] = (string)data["data"][1]["contractor"]["name"]; - - addOnInfo["version_name"] = (string)_options["data"]["name"]; - addOnInfo["version_internal_id"] = (string)_options["data"]["internal_number"]; - addOnInfo["version_description"] = (string)_options["data"]["description"]; - - } - catch - { - DebugFTN("QgApp", getLastException()); - DebugFTN("QgApp", __FUNCTION__, "mising key ???", "check this url", url, data, _options); - return -3; - } - - - file f = fopen(addOnInfoPath, "wb+"); - fputs(jsonEncode(addOnInfo, FALSE), f); - fclose(f); - - if (!isfile(addOnInfoPath)) - DebugFTN("QgApp", __FUNCTION__, "Check te file", addOnInfoPath); - - return 0; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - string _getResultsDir() - { - return makeNativePath(_getPath() + "_results/"); - } - - public string getSourcePath() - { - return _getPath(); - } - //------------------------------------------------------------------------------------------------------------------------------------- - string _getPath() - { - string dir = getenv("WORKSPACE"); - - if ((dir != "") && isdir(dir)) - return makeNativePath(dir + "/"); - - if (_id == "") - return ""; - - if (_WIN32) - { - string tmpDir = dirName(tmpnam()); - return makeNativePath(tmpDir + "WinCCOA/apps/" + _id + "/"); - } - else if (_UNIX) - return makeNativePath("/tmp/WinCCOA/apps/" + _id + "/"); - else - return ""; - } - - public string getProjName() - { - return _getProjName(); - } - //------------------------------------------------------------------------------------------------------------------------------------- - string _getProjName() - { - return "WinCCOA_FinalyApi_" + _id; - } - - //------------------------------------------------------------------------------------------------------------------------------------- - string _getProjPath(const string relPath = "") - { - return makeNativePath(_getPath() + _getProjName() + "/" + relPath); - } - - //------------------------------------------------------------------------------------------------------------------------------------- - // members - string _id; - bool _isValid; - - /* - { - "id":22, - "product_id":6, - "name":"2", - "filename":"Shift_Calender.zip", - "created_at":"2017-08-29 09:08:48", - "created_by":5, - "updated_by":4, - "updated_at":"2017-12-09 08:12:09", - "is_feature":0, - "is_bugfix":1, - "release_date":"1970-01-01", - "description":"Update for new version​ 3.16!", - "internal_number":2, - "internal_filename":"22", - "active":null - } - */ - mapping _options; -}; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl index f346821e..7aa93d64 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBase.ctl @@ -10,7 +10,7 @@ //-------------------------------------------------------------------------------- // used libraries (#uses) #uses "classes/ErrorHdl/OaLogger" -#uses "classes/QualityGates/AddOn/FileSys/QgAddOnTmpSourceDir" +#uses "classes/QualityGates/QgBaseError" #uses "classes/QualityGates/QgResultPublisher" #uses "classes/oaTest/OaTest" #uses "classes/QualityGates/Qg" @@ -23,7 +23,6 @@ QgMsgCat myQgMsgCat = QgMsgCat(); OaTest myTest = OaTest(); - //-------------------------------------------------------------------------------- /** Error codes used in QgBase.cat */ @@ -166,7 +165,6 @@ class QgBase //-------------------------------------------------------------------------------- //@protected members //-------------------------------------------------------------------------------- - protected QgAddOnTmpSourceDir _sourceDir = QgAddOnTmpSourceDir(); protected QgResultPublisher _publisher = QgResultPublisher(); protected shared_ptr _result; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl new file mode 100644 index 00000000..39c71553 --- /dev/null +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgBaseError.ctl @@ -0,0 +1,17 @@ +//-------------------------------------------------------------------------------- +/** Error codes used in QgBase.cat +*/ +enum QgBaseError +{ + Exception = 1, + /// Assertion return error: $1 + AssertionError = 10, + /// Assertion works: $1 + AssertionOK, + AssertionErrorAccepted, + NotImplemented = 20, + Start, + Calculate, + Validate, + Done +}; \ No newline at end of file diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl index 74595541..2f9c007d 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgOverloadedFilesCheck/QgOverloadedFilesCheck.ctl @@ -143,18 +143,20 @@ class QgOverloadedFilesCheck if (isAllowed(relPath)) { - assertion.setAssertionText("assert.isOverloadedAllowed", makeMapping("file.name", relPath)); - assertion.setReasonText("reason.isOverloadedAllowed", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); + const mapping dollars = makeMapping("file.name", relPath, + "file.isOverloadedFrom", overloadedFrom); + assertion.setAssertionText("assert.isOverloadedAllowed", dollars); + assertion.setReasonText("reason.isOverloadedAllowed", dollars); 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 } else { - assertion.setAssertionText("assert.isOverloaded", makeMapping("file.name", relPath)); - assertion.setReasonText("reason.isOverloaded", makeMapping("file.name", relPath, - "file.isOverloadedFrom", overloadedFrom)); + const mapping dollars = makeMapping("file.name", relPath, + "file.isOverloadedFrom", overloadedFrom); + assertion.setAssertionText("assert.isOverloaded", dollars); + assertion.setReasonText("reason.isOverloaded", dollars); assertion.assertFalse(overloadedFrom != "", settings.getScorePoints()); // negative logic, for better look in store } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl index 357f015d..a757db73 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgResultPublisher.ctl @@ -8,6 +8,7 @@ // #uses "classes/QualityGates/Qg" +#uses "classes/QualityGates/QgTest" #uses "classes/QualityGates/AddOn/FileSys/QgAddOnResultsDir" #uses "classes/QualityGates/QgVersionResult" @@ -36,25 +37,6 @@ class QgResultPublisher { } - //------------------------------------------------------------------------------ - public static string stateToString(const QgResultState &state) - { - switch (state) - { - case QgResultState::success: - return "success"; - - case QgResultState::warning: - return "warning"; - - case QgResultState::error: - return "error"; - } - - DebugFTN("QgBase", __FUNCTION__, "internall error, this state does not exists", state); - return ""; - } - //------------------------------------------------------------------------------ public int publish() { @@ -65,9 +47,6 @@ class QgResultPublisher if (!resDir.exists()) resDir.create(); - if (_publishState(resDir)) - return sendNotification(-1); - if (_publishSummary(resDir)) return sendNotification(-2); @@ -90,36 +69,10 @@ class QgResultPublisher return errCode; } - //------------------------------------------------------------------------------ - protected int _publishState(const QgAddOnResultsDir &resDir) - { - string resPath; - - if (Qg::isRunningOnJenkins()) - resPath = resDir.getDirPath() + "_state"; - else - resPath = resDir.getDirPath() + "State"; - - file f = fopen(resPath, "wb+"); - - if (ferror(f)) - return -1; - - fputs(stateToString(state), f); - fclose(f); - return 0; - } - //------------------------------------------------------------------------------ protected int _publishSummary(const QgAddOnResultsDir &resDir) { - string resPath; - - if (Qg::isRunningOnJenkins()) - resPath = resDir.getDirPath() + "_data"; - else - resPath = resDir.getDirPath() + "sum.json"; - + const string resPath = resDir.getDirPath() + "sum.json"; file f = fopen(resPath, "wb+"); if (ferror(f)) @@ -133,10 +86,10 @@ class QgResultPublisher //------------------------------------------------------------------------------ protected int _publishFull(const QgAddOnResultsDir &resDir) { - if (Qg::isRunningOnJenkins() || true) - return _publishFullOnJenkins(resDir); - else + if (!QgTest::isStartedByTestFramework()) return _publishFullLocale(resDir); + + return 0; } //-------------------------------------------------------------------------------- @@ -172,77 +125,4 @@ class QgResultPublisher fclose(f); return 0; } - - //------------------------------------------------------------------------------ - private int _publishFullOnJenkins(const QgAddOnResultsDir &resDir) - { - string path = resDir.getDirPath() + "QgTestVersion/"; - - mkdir(path); - - int testId = Qg::idToNum(); - - if (testId <= 0) - { - DebugFTN("QgBase", __FUNCTION__, "could not calculate test id", Qg::getId(), Qg::getAllIds()); - return -1; - } - - file f = fopen(path + "_Id", "wb+"); - - if (ferror(f)) - { - DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "_Id"); - return -2; - } - - fputs((string)testId, f); - fclose(f); - - DebugFN("QgBase", __FUNCTION__, path); - f = fopen(path + "_Results", "wb+"); - - if (ferror(f)) - { - DebugFTN("QgBase", __FUNCTION__, "could not create file", path + "_Results"); - return -3; - } - - mapping map; - - switch (qgVersionResultType) - { - case QgVersionResultType::TableView: - { - map["fields"] = fields; - map["root"] = makeMapping(); - map["root"]["children"] = makeDynMapping(); - map["root"]["children"][1] = result.scoreToMap(); - map["root"]["children"][2] = result.toMap(); -// result.clear(); - break; - } - - case QgVersionResultType::SimpleTreeView: - case QgVersionResultType::TreeView: - { - map["score"] = result.scoreToMap(); - map["details"] = result.toMap(); -// result.clear(); - break; - } - } - -// [result.text] = result.toMap(); - DebugFTN("QgBase", __FUNCTION__, "write QgVersionResultJsonFormat to json file"); - fputs(jsonEncode(map, jsonFormat == QgVersionResultJsonFormat::Compact), f); - fclose(f); - - DebugFTN("QgBase", __FUNCTION__, "write " + path + "_Score file"); - f = fopen(path + "_Score", "wb+"); - fputs((string)result.score, f); - fclose(f); - return 0; - } - }; diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl index 4f2d66a4..1e02733d 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/FunctionData.ctl @@ -133,9 +133,10 @@ class FunctionData shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_FunctionData"); - assertion.setAssertionText("assert.function.CCN"); - assertion.setReasonText("reason.function.CCN", makeMapping("function.name", getName(), - "function.CCN", getCCN())); + const mapping dollars = makeMapping("function.name", getName(), + "function.CCN", getCCN()); + assertion.setAssertionText("assert.function.CCN", dollars); + assertion.setReasonText("reason.function.CCN", dollars); assertion.assertLessEqual(getCCN(), settings.getHighLimit(DEFAULT_CNN_HIGH), settings.getScorePoints()); @@ -154,9 +155,10 @@ class FunctionData shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_FunctionData"); - assertion.setAssertionText("assert.function.NLOC"); - assertion.setReasonText("reason.function.NLOC", makeMapping("function.name", getName(), - "function.NLOC", getNLOC())); + const mapping dollars = makeMapping("function.name", getName(), + "function.NLOC", getNLOC()); + assertion.setAssertionText("assert.function.NLOC", dollars); + assertion.setReasonText("reason.function.NLOC", dollars); assertion.assertBetween(getNLOC(), settings.getLowLimit(DEFAULT_NLOC_LOW), @@ -176,9 +178,10 @@ class FunctionData shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_FunctionData"); - assertion.setAssertionText("assert.function.paramCount"); - assertion.setReasonText("reason.function.paramCount", makeMapping("function.name", getName(), - "function.paramCount", getNLOC())); + const mapping dollars = makeMapping("function.name", getName(), + "function.paramCount", getNLOC()); + assertion.setAssertionText("assert.function.paramCount", dollars); + assertion.setReasonText("reason.function.paramCount", dollars); assertion.assertLessEqual(getParamCount(), settings.getHighLimit(10), settings.getScorePoints()); @@ -196,9 +199,10 @@ class FunctionData shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_FunctionData"); - assertion.setAssertionText("assert.function.countOfLines"); - assertion.setReasonText("reason.function.countOfLines", makeMapping("function.name", getName(), - "function.countOfLines", getLinesCount())); + const mapping dollars = makeMapping("function.name", getName(), + "function.countOfLines", getLinesCount()); + assertion.setAssertionText("assert.function.countOfLines", dollars); + assertion.setReasonText("reason.function.countOfLines", dollars); assertion.info(getLinesCount(), settings.getScorePoints()); result.addChild(assertion); } 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 5f219e79..fba5828d 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptData.ctl @@ -361,8 +361,9 @@ class ScriptData // ognore all not calculated files (crypted, empty files ...) shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.isCalculated"); - assertion.setReasonText("reason.script.isCalculated", makeMapping("script.name", getName())); + const mapping dollars = makeMapping("script.name", getName()); + assertion.setAssertionText("assert.script.isCalculated", dollars); + assertion.setReasonText("reason.script.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { @@ -396,9 +397,10 @@ class ScriptData // check count of functions. shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.countOfFunctions"); - assertion.setReasonText("reason.script.countOfFunctions", makeMapping("script.name", getName(), - "countOfFunctions", getCountOfFunctions())); + const mapping dollars = makeMapping("script.name", getName(), + "countOfFunctions", getCountOfFunctions()); + assertion.setAssertionText("assert.script.countOfFunctions", dollars); + assertion.setReasonText("reason.script.countOfFunctions", dollars); assertion.assertBetween(getCountOfFunctions(), getMinCountOfFunctions(), getMaxCountOfFunctions(), settings.getScorePoints()); result.addChild(assertion); } @@ -419,9 +421,10 @@ class ScriptData { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.avgCCN"); - assertion.setReasonText("reason.script.avgCCN", makeMapping("script.name", getName(), - "avgCCN", getAvgCCN())); + const mapping dollars = makeMapping("script.name", getName(), + "avgCCN", getAvgCCN()); + assertion.setAssertionText("assert.script.avgCCN", dollars); + assertion.setReasonText("reason.script.avgCCN", dollars); assertion.assertLessEqual(getAvgCCN(), getMaxAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -441,9 +444,10 @@ class ScriptData { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.NLOC"); - assertion.setReasonText("reason.script.NLOC", makeMapping("script.name", getName(), - "NLOC", getNLOC())); + const mapping dollars = makeMapping("script.name", getName(), + "NLOC", getNLOC()); + assertion.setAssertionText("assert.script.NLOC", dollars); + assertion.setReasonText("reason.script.NLOC", dollars); assertion.assertBetween(getNLOC(), getMinNLOC(), getMaxNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -464,9 +468,10 @@ class ScriptData { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptData"); - assertion.setAssertionText("assert.script.avgNLOC"); - assertion.setReasonText("reason.script.avgNLOC", makeMapping("script.name", getName(), - "avgNLOC", getAvgNLOC())); + const mapping dollars = makeMapping("script.name", getName(), + "avgNLOC", getAvgNLOC()); + assertion.setAssertionText("assert.script.avgNLOC", dollars); + assertion.setReasonText("reason.script.avgNLOC", dollars); assertion.info(getAvgNLOC(), settings.getScorePoints()); // does not check it, only information character // assertion.assertLessEqual(getAvgNLOC(), getMaxAvgCCN()); result.addChild(assertion); 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 c53e466c..4cd350a3 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/CtrlCode/ScriptFile.ctl @@ -103,8 +103,9 @@ class ScriptFile : QgFile // ignore all example files, the example are terrible scripts shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.isExampleFile"); - assertion.setReasonText("reason.file.isExampleFile", makeMapping("file.name", getName())); + const mapping dollars = makeMapping("file.name", getName()); + assertion.setAssertionText("assert.file.isExampleFile", dollars); + assertion.setReasonText("reason.file.isExampleFile", dollars); assertion.allowNextErr(TRUE); if (!assertion.assertFalse(this.isExample(), settings.getScorePoints())) @@ -125,9 +126,10 @@ class ScriptFile : QgFile // check for valid extensions shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.extension"); - assertion.setReasonText("reason.file.extension", makeMapping("file.name", getName(), - "file.extension", _extension)); + const mapping dollars = makeMapping("file.name", getName(), + "file.extension", _extension); + assertion.setAssertionText("assert.file.extension", dollars); + assertion.setReasonText("reason.file.extension", dollars); if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { @@ -148,8 +150,9 @@ class ScriptFile : QgFile // ognore all not calculated files (crypted, empty files ...) shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_ScriptFile"); - assertion.setAssertionText("assert.file.isCalculated"); - assertion.setReasonText("reason.file.isCalculated", makeMapping("file.name", getName())); + const mapping dollars = makeMapping("file.name", getName()); + assertion.setAssertionText("assert.file.isCalculated", dollars); + assertion.setReasonText("reason.file.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { 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 241448ee..b312792e 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/Panels/PanelCheck.ctl @@ -269,8 +269,9 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isExampleFile"); - assertion.setReasonText("reason.panel.isExampleFile", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("panel.name", getName()); + assertion.setAssertionText("assert.panel.isExampleFile", dollars); + assertion.setReasonText("reason.panel.isExampleFile", dollars); assertion.allowNextErr(TRUE); if (!assertion.assertFalse(isExample(), settings.getScorePoints())) @@ -294,8 +295,9 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isBackUp"); - assertion.setReasonText("reason.panel.isBackUp", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("panel.name", getName()); + assertion.setAssertionText("assert.panel.isBackUp", dollars); + assertion.setReasonText("reason.panel.isBackUp", dollars); if (!assertion.assertFalse(isBackUp(), settings.getScorePoints())) { @@ -318,9 +320,10 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.extension"); - assertion.setReasonText("reason.panel.extension", makeMapping("panel.name", getName(), - "panel.extension", _extension)); + const mapping dollars = makeMapping("panel.name", getName(), + "panel.extension", _extension); + assertion.setAssertionText("assert.panel.extension", dollars); + assertion.setReasonText("reason.panel.extension", dollars); if (!assertion.assertDynContains(settings.getReferenceValues(), strtolower(_extension), settings.getScorePoints())) { @@ -343,8 +346,9 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isCrypted"); - assertion.setReasonText("reason.panel.isCrypted", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("panel.name", getName()); + assertion.setAssertionText("assert.panel.isCrypted", dollars); + assertion.setReasonText("reason.panel.isCrypted", dollars); if (!assertion.assertFalse(_pnl.isCrypted(), settings.getScorePoints())) { @@ -367,8 +371,9 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.isCalculated"); - assertion.setReasonText("reason.panel.isCalculated", makeMapping("panel.name", getName())); + const mapping dollars = makeMapping("panel.name", getName()); + assertion.setAssertionText("assert.panel.isCalculated", dollars); + assertion.setReasonText("reason.panel.isCalculated", dollars); if (!assertion.assertTrue(isCalculated(), settings.getScorePoints())) { @@ -389,9 +394,10 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.countOfProperties"); - assertion.setReasonText("reason.panel.countOfProperties", makeMapping("panel.name", getName(), - "panel.countOfProperties", _pnl.getCountOfProperties())); + const mapping dollars = makeMapping("panel.name", getName(), + "panel.countOfProperties", _pnl.getCountOfProperties()); + assertion.setAssertionText("assert.panel.countOfProperties", dollars); + assertion.setReasonText("reason.panel.countOfProperties", dollars); assertion.info(_pnl.getCountOfProperties(), settings.getScorePoints()); result.addChild(assertion); } @@ -406,9 +412,10 @@ class PanelCheck : QgFile { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); - assertion.setAssertionText("assert.panel.countOfEvents"); - assertion.setReasonText("reason.panel.countOfEvents", makeMapping("panel.name", getName(), - "panel.countOfEvents", _pnl.getCountOfEvents())); + const mapping dollars = makeMapping("panel.name", getName(), + "panel.countOfEvents", _pnl.getCountOfEvents()); + assertion.setAssertionText("assert.panel.countOfEvents", dollars); + assertion.setReasonText("reason.panel.countOfEvents", dollars); assertion.assertLessEqual(_pnl.getCountOfEvents(), settings.getHighLimit(DEFAULT_EVENTCOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } @@ -423,9 +430,10 @@ class PanelCheck : QgFile shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_Panels"); // countOfShapes - assertion.setAssertionText("assert.panel.countOfShapes"); - assertion.setReasonText("reason.panel.countOfShapes", makeMapping("panel.name", getName(), - "panel.countOfShapes", _pnl.getCountOfShapes())); + const mapping dollars = makeMapping("panel.name", getName(), + "panel.countOfShapes", _pnl.getCountOfShapes()); + assertion.setAssertionText("assert.panel.countOfShapes", dollars); + assertion.setReasonText("reason.panel.countOfShapes", dollars); assertion.assertLessEqual(_pnl.getCountOfShapes(), settings.getHighLimit(DEFAULT_SHAPECOUNT_HIGH), settings.getScorePoints()); result.addChild(assertion); } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl index dc143e19..78862ed0 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticCodeDir.ctl @@ -164,9 +164,10 @@ class StaticCodeDir : StaticDir assertion.setMsgCatName("QgStaticCheck_StaticCodeDir"); // NLOC in dir - assertion.setAssertionText("assert.dir.NLOC"); - assertion.setReasonText("reason.dir.NLOC", makeMapping("dir.name", getName(), - "dir.NLOC", getNLOC())); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.NLOC", getNLOC()); + assertion.setAssertionText("assert.dir.NLOC", dollars); + assertion.setReasonText("reason.dir.NLOC", dollars); assertion.info(getNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -183,9 +184,10 @@ class StaticCodeDir : StaticDir 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())); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.avgNLOC", getAvgNLOC()); + assertion.setAssertionText("assert.dir.avgNLOC", dollars); + assertion.setReasonText("reason.dir.avgNLOC", dollars); assertion.info(getAvgNLOC(), settings.getScorePoints()); result.addChild(assertion); } @@ -200,9 +202,10 @@ class StaticCodeDir : StaticDir 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())); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.CCN", getCCN()); + assertion.setAssertionText("assert.dir.CCN", dollars); + assertion.setReasonText("reason.dir.CCN", dollars); assertion.info(getCCN(), settings.getScorePoints()); result.addChild(assertion); } @@ -218,9 +221,10 @@ class StaticCodeDir : StaticDir 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())); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.CCN", getAvgCCN()); + assertion.setAssertionText("assert.dir.avgCCN", dollars); + assertion.setReasonText("reason.dir.avgCCN", dollars); assertion.info(getAvgCCN(), settings.getScorePoints()); result.addChild(assertion); } diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl index f1756044..f4d4116a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgStaticCheck/StaticDir.ctl @@ -20,10 +20,12 @@ class StaticDir : QgDir dynClear(_files); dynClear(_childs); - if (!dirPath.endsWith("/") && !dirPath.endsWith("\\")) - dirPath += makeNativePath("/"); // ensure trailing path delimiter + dirPath = makeUnixPath(dirPath); - QgDir::setDirPath(dirPath); + if (!dirPath.isEmpty() && !dirPath.endsWith("/")) + dirPath += "/"; // ensure trailing path delimiter + + QgDir::setDirPath(makeNativePath(dirPath)); } //------------------------------------------------------------------------------ @@ -47,10 +49,11 @@ class StaticDir : QgDir dynClear(_files); dynClear(_childs); + _allFilesCount = 0; if (!exists()) { - logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist", getDirPath()); + logger.warning(0, Qg::getId(), __FUNCTION__, "Directory does not exist: " + getDirPath()); return -1; } @@ -113,8 +116,9 @@ class StaticDir : QgDir { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.hasFilesRecursive"); - assertion.setReasonText("reason.dir.hasFilesRecursive", makeMapping("dir.name", getName())); + const mapping dollars = makeMapping("dir.name", getName()); + assertion.setAssertionText("assert.dir.hasFilesRecursive", dollars); + assertion.setReasonText("reason.dir.hasFilesRecursive", dollars); if (!assertion.assertGreatherEqual(getCountOfFilesRecursive(), settings.getLowLimit(DEFAULT_FILESREC_LOW), @@ -135,8 +139,9 @@ class StaticDir : QgDir { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.isEmpty"); - assertion.setReasonText("reason.dir.isEmpty", makeMapping("dir.name", getName())); + const mapping dollars = makeMapping("dir.name", getName()); + assertion.setAssertionText("assert.dir.isEmpty", dollars); + assertion.setReasonText("reason.dir.isEmpty", dollars); if (!assertion.assertFalse(isEmpty, settings.getScorePoints())) { @@ -155,9 +160,10 @@ class StaticDir : QgDir { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.subDirCount"); - assertion.setReasonText("reason.dir.subDirCount", makeMapping("dir.name", getName(), - "dir.subDirCount", subDirCount)); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.subDirCount", subDirCount); + assertion.setAssertionText("assert.dir.subDirCount", dollars); + assertion.setReasonText("reason.dir.subDirCount", dollars); assertion.assertLessEqual(subDirCount, settings.getHighLimit(DEFAULT_SUBDIRCOUNT_HIGH), settings.getScorePoints()); @@ -173,9 +179,10 @@ class StaticDir : QgDir { shared_ptr assertion = new QgVersionResult(); assertion.setMsgCatName("QgStaticCheck_StaticDir"); - assertion.setAssertionText("assert.dir.filesCount"); - assertion.setReasonText("reason.dir.filesCount", makeMapping("dir.name", getName(), - "dir.filesCount", filesCount)); + const mapping dollars = makeMapping("dir.name", getName(), + "dir.filesCount", filesCount); + assertion.setAssertionText("assert.dir.filesCount", dollars); + assertion.setReasonText("reason.dir.filesCount", dollars); assertion.assertLessEqual(filesCount, settings.getHighLimit(DEFAULT_FILESCOUNT_HIGH), settings.getScorePoints()); @@ -267,7 +274,6 @@ class StaticDir : QgDir } //------------------------------------------------------------------------------ -// public QgVersionResult result = QgVersionResult(); //!< Quality gate result public shared_ptr result; //-------------------------------------------------------------------------------- diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl index 7ab0de2a..31553e5f 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgTest.ctl @@ -29,6 +29,19 @@ class QgTest : OaTest //@public members //-------------------------------------------------------------------------------- + //------------------------------------------------------------------------------ + /** Function check if the quality gate has been started by WinCC TestFramework + @return true when started by WinCC TestFramework, false otherwise. + */ + public static bool isStartedByTestFramework() + { + // this file is generated by WinCC OA Testframework, before test manager has + // been started. Therefore we "know" it is started by the testframework. + // see also OaTestBase::isStartedByTF() + // yes it will be better to use origin function, but it is private ;-( + return isfile(PROJ_PATH + "fullResult.json"); + } + //------------------------------------------------------------------------------ /** @brief Function calculates QG score. @details Calculates the QG-score depended of test-results. Calculate how many @@ -59,6 +72,7 @@ class QgTest : OaTest return perc; } + //------------------------------------------------------------------------------ public void addScoreDetail(const mapping &info) { try diff --git a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl index ccb4c987..0615b750 100644 --- a/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/classes/QualityGates/QgVersionResult.ctl @@ -10,13 +10,13 @@ #uses "csv" #uses "classes/QualityGates/QgMsgCat" #uses "classes/QualityGates/Qg" +#uses "classes/QualityGates/QgBaseError" +#uses "classes/QualityGates/QgTest" #uses "classes/Variables/Float" enum QgVersionResultType { - TableView, - TreeView, - SimpleTreeView + TableView }; enum QgVersionResultJsonFormat @@ -54,7 +54,6 @@ struct QgVersionResult string assertKey; mapping assertDollars; - string reason; string reasonKey; mapping reasonDollars; string location; @@ -145,16 +144,6 @@ struct QgVersionResult map["text"] = "Score"; break; } - - case QgVersionResultType::SimpleTreeView: - case QgVersionResultType::TreeView: - { - map[KEY_SCORE_TOTAL_POINTS] = totalPoints; - map[KEY_SCORE_ERROR_POINTS] = errorPoints; - map[KEY_SCORE_PERCENT] = f.round(2); - break; - } - } return map; @@ -208,7 +197,7 @@ struct QgVersionResult } //------------------------------------------------------------------------------ - anytype toMap(const bool clearObjectOnReturn = TRUE) + mapping toMap() { mapping map; string goodRange; @@ -262,88 +251,13 @@ struct QgVersionResult if (hasError) { - if (reason != "") - map["reason"] = reason; - else if (reasonKey != "") - map["reason"] = msgCat.getText(reasonKey, reasonDollars); - } - - break; - } - - case QgVersionResultType::TreeView: - { - if (goodRange != "") - map["goodRange"] = goodRange; - - if (value != "") - map["value"] = value; - - if (errorPoints > 0) - { - map["totalPoints"] = totalPoints; - map["errorPoints"] = errorPoints; - } - else if (totalPoints > 0) - map["totalPoints"] = totalPoints; - - if (hasError && reason != "") - map["reason"] = reason; - - - if (dynlen(children)) - { - for (int i = 1; i <= dynlen(children); i++) - { - map[children[i].text] = children[i].toMap(); - } + map["reason"] = msgCat.getText(reasonKey, reasonDollars); } break; } - - case QgVersionResultType::SimpleTreeView: - { - dyn_string ret; - - if (goodRange != "") - dynAppend(ret, "goodRange: " + goodRange); - - if (value != "") - dynAppend(ret, "value: " + value); - - if (errorPoints > 0) - { - dynAppend(ret, "errorPoints: " + errorPoints); - } - - if (hasError && reason != "") - dynAppend(ret, "reason: " + reason); - - - if (dynlen(children)) - { - for (int i = 1; i <= dynlen(children); i++) - { - map[children[i].text] = children[i].toMap(); - } - - if (clearObjectOnReturn) - clear(); - - return map; - } - - if (clearObjectOnReturn) - clear(); - - return strjoin(ret, ", "); - } } - if (clearObjectOnReturn) - clear(); - return map; } @@ -490,17 +404,16 @@ struct QgVersionResult //------------------------------------------------------------------------------ void clear() { - lowerBound = ""; - upperBound = ""; - value = ""; - referenceValue = ""; - text = ""; - reason = ""; - hasError = FALSE; - dynClear(children); - _operand = "-"; - totalPoints = 0; - errorPoints = 0; + this.lowerBound = ""; + this.upperBound = ""; + this.value = ""; + this.referenceValue = ""; + this.text = ""; + this.hasError = FALSE; + dynClear(this.children); + this._operand = "-"; + this.totalPoints = 0; + this.errorPoints = 0; } //------------------------------------------------------------------------------ @@ -539,26 +452,40 @@ struct QgVersionResult if (hasError && !_allowNextErr) { errorPoints += points; - lastErr = reason; - - const int prio = mappingHasKey(userData, "KnownBug") ? PRIO_INFO : PRIO_WARNING; - throwError(makeError("QgBase", prio, ERR_CONTROL, 10, msgCat.getText(reasonKey, reasonDollars))); + // only for testing + lastErr = this.assertKey; if (_enableOaTestOutput()) oaUnitFail(assertKey, userData); + else + { + const int prio = mappingHasKey(userData, "KnownBug") ? PRIO_INFO : PRIO_WARNING; + OaLogger logger = OaLogger("QgBase"); + + if (mappingHasKey(userData, "KnownBug")) + logger.info(QgBaseError::AssertionErrorAccepted, msgCat.getText(reasonKey, reasonDollars), userData["Note"]); + else + logger.warning(QgBaseError::AssertionError, msgCat.getText(reasonKey, reasonDollars), userData["Note"]); + } } else { if (_enableOaTestOutput()) + { oaUnitPass(assertKey, userData); + } else - throwError(makeError("QgBase", PRIO_INFO, ERR_CONTROL, 11, msgCat.getText(assertKey, assertDollars))); + { + OaLogger logger = OaLogger("QgBase"); + logger.info(QgBaseError::AssertionOK, assertKey, userData); + } } _allowNextErr = FALSE; } //------------------------------------------------------------------------------ + /// @todo replace this code by OaTest-knownBug-handler protected getKnownBugId(mapping &userData) { if (dynlen(knownBugs) <= 0) @@ -596,13 +523,12 @@ struct QgVersionResult //------------------------------------------------------------------------------ /** @brief enabled or disabled oaUnitResults - @todo mPunk 30.10.2018: make it configureable, otherwise does not work in jenkins - @return TRUE hen are oaUnit results enabled + @return TRUE when are oaUnit results enabled */ + public static bool enableOaTestCheck = true; protected static bool _enableOaTestOutput() { - return true; - return Qg::isRunningOnJenkins(); + return QgTest::isStartedByTestFramework() && enableOaTestCheck; } //------------------------------------------------------------------------------ diff --git a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl index c13bf113..39a2818a 100644 --- a/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/gedi/qualityCheck_ext.ctl @@ -154,12 +154,6 @@ void tool_QualityGates_QgOverloadedFilesCheck() _startCtrlMan("QualityGates/StaticTests/QgOverloadedFilesCheck"); } -void tool_QualityGates_UnitTests() -{ - tool_QualityGates_showBusy("UnitTests"); - _startCtrlMan("QualityGates/QgTestRunner"); -} - void tool_QualityGates_OpenResult() { ModuleOnWithPanel("QgResult-1", -1, -1, 400, 400, 1, 1, "Scale", "vision/QualityChecks/QG_Main.pnl", "QG Result Overview", makeDynString("")); diff --git a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl index ce7c1255..8483e83e 100644 --- a/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl +++ b/WinCCOA_QualityChecks/scripts/libs/scriptEditor/ctrlPPCheck_ext.ctl @@ -127,7 +127,7 @@ void ctrlPPCheck() res["countOfParams.avg"] = script.getAvgParamCount(); - map["script"] = res;//script.result.toMap(); + map["script"] = res; } diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/rule/ctrl.xml b/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/rule/ctrl.xml deleted file mode 100644 index 2038c80f..00000000 --- a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/rule/ctrl.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - substr \( \w , \w , 1 \) - - TokenSubStrAt0Test - error - substr(s, pos, 1) is a slow way to say s[pos] - - - - - [a-b][a - - badPattern - error - substr(s, pos, 1) is a slow way to say s[pos] - - - - - - - emptyPattern - error - substr(s, pos, 1) is a slow way to say s[pos] - - - - - [a-b][a - - - error - substr(s, pos, 1) is a slow way to say s[pos] - - - - - [a-b][a - - emptySeverity - - substr(s, pos, 1) is a slow way to say s[pos] - - - - - diff --git a/WinCCOA_QualityChecks_tests/scripts/QgCtrlppcheckTests.ctl b/WinCCOA_QualityChecks_tests/scripts/QgCtrlppcheckTests.ctl deleted file mode 100644 index 5d33cc39..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/QgCtrlppcheckTests.ctl +++ /dev/null @@ -1,169 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -//-------------------------------------------------------------------------------- -// used libraries (#uses) -#uses "classes/QualityGates/Tools/CppCheck/CppCheckError" -#uses "fileSys" -#uses "CtrlOaUnit" -#uses "classes/QualityGates/Tools/CppCheck/CppCheck" -#uses "classes/QualityGates/Qg" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- - -class TstCppCheck : CppCheck -{ - public checkFile(const string &testFile) - { - string s; - fileToString(testFile, s); - s = substr(s, 0, strpos(s, "\n")); // get fist lines - const string key = "// start options: "; - int idx = strpos(s, key); - if ( idx >= 0 ) - s = " " + substr(s, idx + strlen(key)); - else - s = ""; - - DebugN(__FUNCTION__, testFile, s); - start(testFile + s); - stdErrToErrList(); - } - - public compare(const string &refFile) - { - const string tcId = "Ctrlppcheck." + baseName(refFile); - string str; - fileToString(refFile, str); - TstCppCheck reference; - - if ( str == "" ) - { - oaUnitAbort(tcId, "reference file is empty"); - return; - } - reference.strToErrList(str); - -// if ( dynlen(errList) != dynlen(reference.errList) ) -// { -// oaUnitFail(tcId, "Count of error does not match with reference file:\n" + refFile); -// return; -// } - - dyn_string simpleErrStrings; - for(int i = 1; i <= dynlen(reference.errList); i++) - { - reference.errList[i].path = ""; - } - for(int i = 1; i <= dynlen(errList); i++) - { - errList[i].path = ""; - dynAppend(simpleErrStrings, errList[i].toStdErrString()); - } - - - for(int i = 1; i <= dynlen(reference.errList); i++) - { - CppCheckError expErr = reference.errList[i]; - string expErrorStr = expErr.toStdErrString(); - mapping map = makeMapping("ErrMsg", "Ctrlppcheck can not found this error:" + - "\n File:\n" + refFile + - "\n ExpectedValue:\n" + expErrorStr); - if ( expErr.knownBug != "" ) - map["KnownBug"] = expErr.knownBug; - // DebugN(__FUNCTION__, map, expErr); - oaUnitAssertGreater(tcId, dynContains(simpleErrStrings, expErrorStr), 0, map); - } - - - } -}; - -class TstCtrlppcheck : StTest -{ - public dyn_string _getAllTcIds() - { - // list with our testcases - return makeDynString("Ctrlppcheck"); - } - - public int _startTest() - { - const string tcId = _getTcId(); - - switch( tcId ) - { - case "Ctrlppcheck": - { - string path = getPath(SCRIPTS_REL_PATH, "tests/ctrlPpCheck/testscripts"); - dyn_string files = getFileNamesRecursive(path); - - for(int i = 1; i <= dynlen(files); i++) - { - string testFile = makeUnixPath(files[i]); - TstCppCheck check; - check.settings.enableXmlFormat(TRUE); - - check.settings.enableLibCheck = FALSE; - check.settings.enableHeadersCheck = TRUE; - check.settings.includeSubProjects = TRUE; - check.settings.inconclusive = FALSE; - check.settings.verbose = FALSE; - check.settings.inlineSuppressions = FALSE; - - // load configs - check.settings.addLibraryFile(getPath(DATA_REL_PATH, "ctrlPpCheck/cfg/ctrl.xml")); // general - check.settings.addLibraryFile(getPath(DATA_REL_PATH, "ctrlPpCheck/cfg/ctrl_" + VERSION + ".xml")); // version specific - check.settings.addLibraryFile(getPath(DATA_REL_PATH, "ctrlPpCheck/cfg/__proj__.xml")); // proj specific - - // load rules - check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/ctrl.xml")); // general - check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/ctrl_" + VERSION + ".xml")); // version specific - check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/__proj__.xml")); // proj specific - - check.settings.addEnabled("all"); - check.settings.enableXmlFormat(TRUE); - - check.checkFile(testFile); - - string refFile = testFile; - strreplace(refFile, SCRIPTS_REL_PATH + "tests/", DATA_REL_PATH); - strreplace(refFile, ".ctl", ".xml"); - - check.compare(refFile); - - // make a copy for futher analysis - string resDir = PROJ_PATH + LOG_REL_PATH + "ctrlPpCheck/testscripts/"; - if ( !isdir(resDir) ) - mkdir(resDir); - - moveFile(PROJ_PATH + LOG_REL_PATH + "cppcheck-result.xml", resDir + baseName(refFile)); - - } - return 0; - } - } - - return -1; - } -}; - -//-------------------------------------------------------------------------------- -main() -{ - TstCtrlppcheck test = TstCtrlppcheck(); - - test.startAll(); - - exit(0); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/QgTestRunner.ctl b/WinCCOA_QualityChecks_tests/scripts/QgTestRunner.ctl deleted file mode 100644 index a4a2d4d7..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/QgTestRunner.ctl +++ /dev/null @@ -1,391 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "classes/Math/Math" -#uses "CtrlXml" -#uses "classes/FileSys/Dir" -#uses "classes/QualityGates/QgTest" -#uses "classes/QualityGates/AddOn/Output/QgAddOnResult" -#uses "classes/QualityGates/QgApp" - - - -class QgTestSummary -{ - public int fromQuickResult() - { - string json; - - fileToString(PROJ_PATH + "quickResult.json", json); - mapping map = jsonDecode(json); - - if( mappinglen(map) == 0 ) - return -1; - - if( mappingHasKey(map, "Aborted") ) - _aborted = map[ "Aborted" ]; - if( mappingHasKey(map, "Failed") ) - _failed = map[ "Failed" ]; - if( mappingHasKey(map, "Passed") ) - _passed = map[ "Passed" ]; - if( mappingHasKey(map, "KnownBugs") ) - _knownBugs = map[ "KnownBugs" ]; - - return 0; - } - - public mapping toMap() - { - return makeMapping("Aborted", _aborted, - "Failed", _failed, - "Passed", _passed, - "KnownBugs", _knownBugs); - } - - public int getAll() - { - return _aborted + _failed + _passed + _knownBugs; - } - - public int getAborted() - { - return _aborted; - } - - public int getFailed() - { - return _failed; - } - - public int getPassed() - { - return _passed; - } - - public int getKnownBugs() - { - return _knownBugs; - } - - public QgTestSummary opPlus(const QgTestSummary &summary) - { - _aborted += summary.getAborted(); - _failed += summary.getFailed(); - _passed += summary.getPassed(); - _knownBugs += summary.getKnownBugs(); - - return this; - } - - int _aborted, _failed, _passed, _knownBugs; - - public int exitCode; -}; - -class QgLibTest -{ - public QgLibTest(const string path = "") - { - _path = path; - } - - public int test() - { - string path = makeUnixPath(_path); - string relPath = substr(path, strlen(_baseDir) ); - - strreplace(relPath, ".ctc", ".ctl"); // encrypted lib has decrypted test - - string testPath = getPath(SCRIPTS_REL_PATH, "tests/libs/" + relPath); - - if( testPath == "" ) - { - DebugTN(__FUNCTION__, "For this test script does not exist unit-test", relPath); - return 1; - } - - string cmd; - if( _WIN32 ) - { - cmd = getPath(BIN_REL_PATH, getComponentName(CTRL_COMPONENT) + ".exe"); - } - else if( _UNIX ) - { - cmd = getPath(BIN_REL_PATH, getComponentName(CTRL_COMPONENT) ); - } - else - { - DebugTN(__FUNCTION__, "this platform is not implemented"); - return -1; - } - - if( cmd == "" ) - { - DebugTN(__FUNCTION__, "missing ctrl manager"); - return -2; - } - - Dir ctrlCovDir = Dir(dirName(getCtrlCovReportPath() ) ); - if( !ctrlCovDir.exists() ) - ctrlCovDir.mk(); - - cmd += " " + makeUnixPath("tests/libs/" + relPath) + " -proj " + PROJ + " -n -log +stderr -dumpCoverageOnExit -coveragereportfile " + getCtrlCovReportPath(FALSE); - - fclose(fopen(PROJ_PATH + "quickResult.json", "wb+") ); - string stdOut, stdErr; - _sum.exitCode = system(cmd, stdOut, stdErr); - if( _sum.exitCode ) - { - DebugTN(__FUNCTION__, "command exited with rc = " + _sum.exitCode, cmd, stdOut, stdErr); - return -3; - } - - _sum.fromQuickResult(); - - remove(PROJ_PATH + "quickResult.json"); - return 0; - } - - public QgTestSummary getSum() - { - return _sum; - } - - public string getName() - { - return baseName(_path); - } - - public mapping toMap() - { - mapping map; - map = _sum.toMap(); - return map; - } - - string getCtrlCovReportPath(const bool fullPath = TRUE) - { - string relPath = substr(_path, strlen(_baseDir) ) + ".xml"; - - if( !fullPath ) - return relPath; - - return makeNativePath(PROJ_PATH + LOG_REL_PATH + relPath); - } - - - string _path; - QgTestSummary _sum; - - string _baseDir = PROJ_PATH + LIBS_REL_PATH; -}; - -class QqTestDir -{ - public QqTestDir(const string path = "") - { - _path = path; - } - - public int test() - { - _path = makeUnixPath(_path); - if( _path == "" || !isdir(_path) ) - { - DebugTN(__FUNCTION__, "Directory is does not exist", _path); - return 0; - } - - dyn_string libs = getFileNames(_path, "*"); - - for( int i = 1; i <= dynlen(libs); i++ ) - { - QgLibTest lib = QgLibTest(_path + libs[i]); - int rc = lib.test(); - if ( rc == 0 ) - DebugN(__FUNCTION__, "Summary", lib.toMap(), _path + libs[i]); - - QgTestSummary sum = lib.getSum(); - - if ( sum.exitCode ) - { - countOfCrashes++; - } - if ( sum.getAll() <= 0 ) - { - countOfNotTestedObjects++; - } - else - { - _sum.opPlus(lib.getSum() ); - dynAppend(_libs, lib); - } - } - - dyn_string dirs = getFileNames(_path, "*", FILTER_DIRS); - - for( int i = 1; i <= dynlen(dirs); i++ ) - { - if( dirs[ i ] == "" || dirs[ i ] == "." || dirs[ i ] == ".." ) - continue; - - QqTestDir dir = QqTestDir(_path + dirs[ i ] + "/"); - dir.test(); - _sum.opPlus(dir.getSum()); - countOfNotTestedObjects += dir.countOfNotTestedObjects; - countOfCrashes += dir.countOfCrashes; - dynAppend(_childs, dir); - } - - return 0; - } - - public mapping toMap() - { - mapping map; - - if( dynlen(_childs) > 0 ) - { - map[ "@dirs" ] = makeMapping(); - - for( int i = 1; i <= dynlen(_childs); i++ ) - map[ "@dirs" ][ _childs[ i ].getName() ] = _childs[ i ].toMap(); - } - - if( dynlen(_libs) > 0 ) - { - map[ "@files" ] = makeMapping(); - - for( int i = 1; i <= dynlen(_libs); i++ ) - map[ "@files" ][ _libs[ i ].getName() ] = _libs[ i ].toMap(); - } - - return map; - } - - public string getName() - { - return baseName(_path); - } - - public QgTestSummary getSum() - { - return _sum; - } - - public int countOfNotTestedObjects; - public int countOfCrashes; - - QgTestSummary _sum = QgTestSummary(); - dyn_anytype _libs; - dyn_anytype _childs; - - string _path; -}; - -class QgTestRunner : QgTest -{ - public dyn_string _tcIds = makeDynString("UnitTests"); - - QqTestDir _libDir = QqTestDir(PROJ_PATH + LIBS_REL_PATH); - public int _startSingle() - { - switch( _testCaseId ) - { - case "UnitTests": - { - return _libDir.test(); - } - } - return -1; - } - - - public int setUp() - { - if( QgTest::setUp() ) - return -1; - - _data["qgTestVersionResults"] = makeMapping(); - return 0; - } - - public float getAllCount() - { - QgTestSummary sum = _libDir.getSum(); - return (float)sum.getAll(); - } - - public float getErrorCount() - { - QgTestSummary sum = _libDir.getSum(); - - return (float)sum.getFailed() + (float)sum.getAborted() + _libDir.countOfNotTestedObjects + _libDir.countOfCrashes; - } - - - public int tearDown() - { - _data["qgTestVersionResults"] = _libDir.toMap(); - - QgTestSummary sum = _libDir.getSum(); - _data["qgSummary"] = sum.toMap(); - - _data["score"] = calculateScore(); - return QgTest::tearDown(); - } - - public float calculateScore() - { - float perc = QgTest::calculateScore(); - QgTestSummary sum = _libDir.getSum(); - - mapping map = _data["qgTestVersionResults"]["Score"]; - - if ( _libDir.countOfCrashes > 0 ) - map[QgAddOnResult::KEY_SCORE_REASON] = myQgMsgCat.getText("reasonCrashFound", makeMapping("count", _libDir.countOfCrashes)); - else if ( _libDir.countOfNotTestedObjects ) - map[QgAddOnResult::KEY_SCORE_REASON] = myQgMsgCat.getText("reasonNotTestedObject", makeMapping("count", _libDir.countOfNotTestedObjects)); - else - return perc; - - addScoreDetail(map); - return perc; - } - - string _baseDir = PROJ_PATH + LIBS_REL_PATH; - - - public mapping _data = makeMapping(); -}; - - -class QgAddOnResultUnitTestRunner: -QgAddOnResult -{ - public int calculate() - { - setState(QgAddOnResultState::success); - return 0; - } -}; - -main() -{ - Qg::setId("UnitTests"); - QgAddOnResultUnitTestRunner result = QgAddOnResultUnitTestRunner(); - - QgTestRunner test = QgTestRunner(); - if( test.start() ) - result.setErr(test.getErrPrio(), test.getErrCode(), test.getErrNote() ); - else - result.setData(test._data); - - exit(result.publish() ); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/Testcpp.ctl b/WinCCOA_QualityChecks_tests/scripts/Testcpp.ctl deleted file mode 100644 index 8ebb125c..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/Testcpp.ctl +++ /dev/null @@ -1,69 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -void main() -{ - int i = 1; - int ifoo3; - string f; // variable f never used - string dp; - string sfoo2; - - for (i ; i 0) ) - { - errout.rc = "35889"; - errout.err = "WinCC OA syntax error at pos: " + errPos; - return; - } - // Clear the error buffer.. - errout.err = ""; - errout.rc = 0; - - string testScript = PROJ_PATH + SCRIPTS_REL_PATH + "test.ctl"; - file f = fopen(testScript, "wb+"); - fputs(code, f); - fflush(f); - fclose(f); - - CppCheck checker; - checker.settings = settings; - checker.checkFiles(makeDynString(testScript)); - - errout.rc = checker.rc; - errout.err = checker.stdErr; - - - remove(testScript); - } - -// protected ASSERT_THROW(int val, int expVal) -// { -// string tcData = "\n" + "Script:\n" + script; -// oaUnitAssertEqual(testCaseId, val, expVal, tcData); -// } - - /// @todo No idea why it is used in test. Just print the values here and make the implementation later - protected TODO_ASSERT_EQUALS(const string &s1, const string &s2, const string &error) - { - DebugN(__FUNCTION__, s1, s2, error); - } - - protected ASSERT_EQUALS(string expVal, string val) - { - string totalPath = makeNativePath(PROJ_PATH + SCRIPTS_REL_PATH + "test.ctl"); - string relativePath = SCRIPTS_REL_PATH + "test.ctl"; - strreplace(expVal, "test.cpp", makeNativePath("scripts/test.ctl")); - - strreplace(expVal, "\r", ""); - strreplace(val, "\r", ""); - - strreplace(val, "(error) There is no rule to execute. Tokenlist: raw\n", ""); - strreplace(val, "(error) There is no rule to execute. Tokenlist: normal\n", ""); - strreplace(val, "(error) There is no rule to execute. Tokenlist: simple\n", ""); - - strreplace(relativePath, "\\", "/"); - strreplace(val, totalPath, relativePath); - - - - string tcData = "\n" + "Script:\n" + script + - "\n" + "ExpMessage:\n" + expVal + - "\n" + "ErrMessage:\n" + val; - if ( assertMatch && (expVal != "" ) && (strpos(val, expVal) >= 0) ) - oaUnitPass(testCaseId, dbgPass ? tcData : ""); - else if ( val == expVal ) - oaUnitPass(testCaseId, dbgPass ? tcData : ""); - else - { - oaUnitFail(testCaseId, tcData); - } - } - - protected TEST_CASE(const function_ptr func) - { - try - { - testCaseId = (string)func; - oaUnitInfo(testCaseId, "Start test case"); - callFunction(func); - } - catch - { - throwError(getLastException()); - } - } - - protected string testCaseId; -// protected string testCaseIdPrefix; -}; diff --git a/WinCCOA_QualityChecks_tests/scripts/removeTestProj.ctl b/WinCCOA_QualityChecks_tests/scripts/removeTestProj.ctl deleted file mode 100644 index 6a65bc95..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/removeTestProj.ctl +++ /dev/null @@ -1,25 +0,0 @@ -// -// CtrlppCheck -// a static code analysis tool for WinCC OA's Ctrl language -// -// Copyright 2022 SIEMENS AG -// -// SPDX-License-Identifier: GPL-3.0-only -// - -#uses "CtrlPv2Admin" - -main(string proj) -{ - dyn_string ds, dsVer, dsPath; - paGetProjs(ds, dsVer, dsPath); - for(int i = 1; i <= dynlen(dsPath); i++) - { - string projName = baseName(dsPath[i]); - - if ( projName == proj ) - paDelProj(dsPath[i], FALSE); // deregister given project - if ( !isdir(dsPath[i]) ) - paDelProj(dsPath[i], FALSE); // deregister not exisitng projects - } -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/cppCheckTestFile.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/cppCheckTestFile.ctl deleted file mode 100644 index 81f70b97..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/cppCheckTestFile.ctl +++ /dev/null @@ -1,62 +0,0 @@ -// http://cppcheck.sourceforge.net/manual.html#idm739 -void main() -{ - int ii; - int i = 1; - string str; - for (i ; i. - */ - -struct TestSomething : public TestFixture -{ - public TestSomething() - { - } - - public void run() { - // define settings - settings.addEnabled("portability"); - - // define test cases - TEST_CASE(novardecl); - // some other test cases ... - } - - /** @test comment the test case here like: portybility test for function params - */ - - void functionpar() { - check("int foo(int *p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("[test.ctl:3]: (portability) Assigning a pointer to an integer is not portable.", errout.str()); - - check("int foo(int p[])\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("[test.ctl:3]: (portability) Assigning a pointer to an integer is not portable.", errout.str()); - // ... some more assertions - } - -}; - -void main() -{ - TestSomething test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/test64bit.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/test64bit.ctl deleted file mode 100644 index 1ae9d0d1..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/test64bit.ctl +++ /dev/null @@ -1,367 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2019 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// #include "check64bit.h" -// #include "settings.h" -// #include "testsuite.h" -// #include "tokenize.h" - - -struct Test64BitPortability : public TestFixture { - public Test64BitPortability() - { -// testCaseIdPrefix = "Test64BitPortability"; - } - -// CppCheckSettings settings; - - public void run() /*OVERRIDE*/ { - settings.addEnabled("portability"); - - TEST_CASE(novardecl); - TEST_CASE(functionpar); - TEST_CASE(functionparWinCCOA); - - TEST_CASE(structmember); - TEST_CASE(structmemberWinCC_OA); - - TEST_CASE(ptrcompare); - TEST_CASE(ptrcompareWinCC_OA); - - TEST_CASE(ptrarithmetic); - TEST_CASE(ptrarithmeticWinCC_OA); - - TEST_CASE(returnIssues); - TEST_CASE(returnIssuesWinCC_OA); - } - - void novardecl() { - // if the variable declarations can't be seen then skip the warning - check("void foo()\n" - "{\n" - " a = p;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: a\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: p\n", errout.str()); - } - - void functionpar() { - check("int foo(int *p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); - - check("int foo(int p[])\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); - - check("int foo(int p[])\n" - "{\n" - " int *a = p;\n" - " return a;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); - - check("void foo(int x)\n" - "{\n" - " int *p = x;\n" - " *p = 0;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 38", errout.str()); - - check("int f(const char *p) {\n" // #4659 - " return 6 + p[2] * 256;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 17", errout.str()); - - check("int foo(int *p) {\n" // #6096 - " bool a = p;\n" - " return a;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); - } - - void functionparWinCCOA() { - //int, const int, address to int, const address to int - check("int foo(int p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - check("int foo(const int p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - check("int foo(const int &p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - check("int foo(int &p)\n" - "{\n" - " int a = p;\n" - " return a + 4;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // char to int - check("int f(const char p) {\n" - " return 6 + p[2] * 256;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // int to bool - check("int foo(int p) {\n" - " bool a = p;\n" - " return a;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void structmember() { - check("struct Foo { int *p; };\n" - "void f(struct Foo *foo) {\n" - " int i = foo->p;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 17", errout.str()); - } - - void structmemberWinCC_OA() { - check("struct Foo { int p; };\n" - "void f(Foo foo) {\n" - " int i = foo.p;\n" - "}"); - } - - void ptrcompare() { - // Ticket #2892 - check("void foo(int *p) {\n" - " int a = (p != NULL);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void ptrcompareWinCC_OA() { - check("void foo(int p) {\n" - " int a = (p != nullptr);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void ptrarithmetic() { - // #3073 - check("void foo(int *p) {\n" - " int x = 10;\n" - " int *a = p + x;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void foo(int *p) {\n" - " int x = 10;\n" - " int *a = x + p;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void foo(int *p) {\n" - " int x = 10;\n" - " int *a = x * x;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning an integer to a pointer is not portable.\n", errout.str()); - - check("void foo(int *start, int *end) {\n" - " int len;\n" - " int len = end + 10 - start;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - /// @todo ptr aritmetic for WinCC OA - void ptrarithmeticWinCC_OA() { - } - - void returnIssues() { - check("void* foo(int i) {\n" - " return i;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 4", errout.str()); -// ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an integer in a function with pointer return type is not portable.\n", errout.str()); - - check("void* foo(int* i) {\n" - " return i;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 4", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void* foo() {\n" - " return 0;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 4", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int foo(int i) {\n" - " return i;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("struct Foo {};\n" - "\n" - "int* dostuff(Foo foo) {\n" - " return foo;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 19", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int foo(char* c) {\n" - " return c;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str()); - - check("int foo(char* c) {\n" - " return 1+c;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[test.cpp:2]: (portability) Returning an address value in a function with integer return type is not portable.\n", errout.str()); - - check("std::string foo(char* c) {\n" - " return c;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 3", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int foo(char *a, char *b) {\n" // #4486 - " return a + 1 - b;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 13", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("struct s {\n" // 4642 - " int i;\n" - "};\n" - "int func(struct s *p) {\n" - " return 1 + p->i;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 33", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("static void __iomem *f(unsigned int port_no) {\n" - " void __iomem *mmio = hpriv->mmio;\n" - " return mmio + (port_no * 0x80);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - // #7247: don't check return statements in nested functions.. - check("int foo() {\n" - " struct {\n" - " const char * name() { return \"abc\"; }\n" - " } table;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 47", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - // #7451: Lambdas - check("const int* test(std::vector outputs, const std::string& text) {\n" - " auto it = std::find_if(outputs.begin(), outputs.end(), \n" - " [&](int ele) { return \"test\" == text; });\n" - " return nullptr;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 9", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - - void returnIssuesWinCC_OA() { - check("int foo() {\n" - " return 0;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("int foo(int i) {\n" - " return i;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("struct Foo {};\n" - "\n" - "int dostuff(Foo foo) {\n" - " return foo;\n" - "}"); - ASSERT_EQUALS("", errout.str()); // this is something very bad ??? - - check("int foo(char c) {\n" - " return c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - check("int foo(char &c) {\n" - " return c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("int foo(char c) {\n" - " return 1+c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - check("int foo(char &c) {\n" - " return 1+c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("string foo(char c) {\n" - " return c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("int foo(char a, char b) {\n" // #4486 - " return a + 1 - b;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("struct s {\n" // 4642 - " int i;\n" - "};\n" - "int func(s &p) {\n" - " return 1 + p.i;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } -}; - -// REGISTER_TEST(Test64BitPortability) -void main() -{ - Test64BitPortability test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testassert.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testassert.ctl deleted file mode 100644 index 9def9940..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testassert.ctl +++ /dev/null @@ -1,206 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2019 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -// #include "checkassert.h" -// #include "settings.h" -// #include "testsuite.h" -// #include "tokenize.h" - - -struct TestAssert : public TestFixture -{ - -// Settings settings; - - - - void run() - { - settings.addEnabled("warning"); - settings.inconclusive = false; - - TEST_CASE(assignmentInAssert); - TEST_CASE(functionCallInAssert); - TEST_CASE(memberFunctionCallInAssert); - TEST_CASE(safeFunctionCallInAssert); - } - - - void safeFunctionCallInAssert() - { - check( - "int a;\n" - "bool b = false;\n" - "int foo() {\n" - " if (b) { a = 1+2; }\n" - " return a;\n" - "}\n" - "void main(){ assert(foo() == 3); }\n" - ); - ASSERT_EQUALS("", errout.str()); - - check( - "int foo(int a) {\n" - " int b=a+1;\n" - " return b;\n" - "}\n" - "void main(){ assert(foo(1) == 2); }\n" - ); - ASSERT_EQUALS("", errout.str()); - } - - void functionCallInAssert() - { - /* knownBug TFS(#158013) - check( - "int a;\n" - "int foo() {\n" - " a = 1+2;\n" - " return a;\n" - "}\n" - "void main(){assert(foo() == 3);}\n" - ); - ASSERT_EQUALS("[test.cpp:6]: (warning) Assert statement calls a function which may have desired side effects: 'foo'.\n", errout.str()); - */ - // Ticket #4937 "false positive: Assert calls a function which may have desired side effects" - check("struct Square {\n" - " static void dummy(){1+1;}\n" - "};\n" - "\n" - "struct SquarePack {\n" - " static bool isRank1Or8( Square sq ) {\n" - " sq &= 0x38;\n" - " return sq == 0 || sq == 0x38;\n" - " }\n" - "};\n" - "void foo() {\n" - " Square push2;\n" - " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("struct Square {\n" - " static void dummy(){1+1;}\n" - "};\n" - "\n" - "struct SquarePack {\n" - " static bool isRank1Or8( Square &sq ) {\n" - " sq &= 0x38;\n" - " return sq == 0 || sq == 0x38;\n" - " }\n" - "};\n" - "void foo() {\n" - " Square push2;\n" - " assert( !SquarePack::isRank1Or8(push2) );\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:8]: (warning) Assert statement calls a function which may have desired side effects: 'isRank1Or8'.\n", errout.str()); - */ - } - - void memberFunctionCallInAssert() - { - /* knownBug TFS(#158013) - check("struct SquarePack {\n" - " void Foo(){}\n" - "};\n" - "void foo(SquarePack s) {\n" - " assert( s.Foo() );\n" - "}"); - ASSERT_EQUALS("[test.cpp:5]: (warning) Assert statement calls a function which may have desired side effects: 'Foo'.\n", errout.str()); - */ - - check("struct SquarePack {\n" - " static void Foo(){}\n" - "};\n" - "void foo(SquarePack& s) {\n" - " assert( s.Foo() );\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("struct SquarePack {\n" - "};\n" - "void foo(SquarePack& s) {\n" - " assert( s.Foo() );\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void assignmentInAssert() - { - /* knownBug TFS(#158013) - check("void f() {\n" - " int a; a = 1;\n" - " assert(a = 2);\n" - "}\n" - ); - ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); - */ - check("void f(int a) {\n" - " assert(a == 2);\n" - "}\n" - ); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("void f(int a, int b) {\n" - " assert((a == 2) && (b = 1));\n" - "}\n" - ); - ASSERT_EQUALS("[test.cpp:2]: (warning) Assert statement modifies 'b'.\n", errout.str()); - */ - /* knownBug TFS(#158013) - check("void f() {\n" - " int a; a = 0;\n" - " assert(a += 2);\n" - "}\n" - ); - ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); - */ - /* knownBug TFS(#158013) - check("void f() {\n" - " int a; a = 0;\n" - " assert(a *= 2);\n" - "}\n" - ); - ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); - */ - /* knownBug TFS(#158013) - check("void f() {\n" - " int a; a = 0;\n" - " assert(a -= 2);\n" - "}\n" - ); - ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); - */ - /* knownBug TFS(#158013) - check("void f() {\n" - " int a = 0;\n" - " assert(a--);\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Assert statement modifies 'a'.\n", errout.str()); - */ - } -}; - -// REGISTER_TEST(TestAssert) -void main() -{ - TestAssert test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testautovariables.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testautovariables.ctl deleted file mode 100644 index ad2e8276..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testautovariables.ctl +++ /dev/null @@ -1,438 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2019 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// #include "checkautovariables.h" -// #include "settings.h" -// #include "testsuite.h" -// #include "tokenize.h" - - -struct TestAutoVariables : TestFixture -{ - - void check(const string &code, bool inconclusive = false) - { - settings.inconclusive = inconclusive; - TestFixture::check(code); - } -// void check(const char code[], bool inconclusive = false, bool runSimpleChecks = true, const char* filename = "test.cpp") { - // Clear the error buffer.. -// errout.str(""); -// -// settings.inconclusive = inconclusive; -// - // Tokenize.. -// Tokenizer tokenizer(&settings, this); -// std::istringstream istr(code); -// tokenizer.tokenize(istr, filename); -// -// CheckAutoVariables checkAutoVariables(&tokenizer, &settings, this); -// checkAutoVariables.returnReference(); -// checkAutoVariables.assignFunctionArg(); -// checkAutoVariables.checkVarLifetime(); -// -// if (runSimpleChecks) { -// tokenizer.simplifyTokenList2(); -// - // Check auto variables -// checkAutoVariables.autoVariables(); -// } -// } - - void run() - { - settings.addEnabled("warning"); - settings.addEnabled("style"); - -// LOAD_LIB_2(settings.library, "std.cfg"); - - TEST_CASE(testautovar10); // ticket #2930 - void f(char *p) { p = '\0'; } - TEST_CASE(testautovar13); // ticket #5537 - crash - TEST_CASE(testautovar15); // ticket #6538 - - TEST_CASE(returnLocalVariable2); - - // return reference.. - TEST_CASE(returnReferenceLiteral); - TEST_CASE(returnReferenceCalculation); - - // global namespace - TEST_CASE(testglobalnamespace); - - TEST_CASE(testconstructor); // ticket #5478 - crash - - TEST_CASE(variableIsUsedInScope); // ticket #5599 crash in variableIsUsedInScope() - } - - - - void testautovar1() - { - check("void func1(int **res)\n" - "{\n" - " int num = 2;\n" - " *res = #\n" - "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - - check("void func1(int **res)\n" - "{\n" - " int num = 2;\n" - " res = #\n" - "}"); - ASSERT_EQUALS("[test.cpp:4]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n" + - "[test.cpp:4]: (style) Variable 'res' is assigned a value that is never used.\n", - errout.str()); - - check("void func1(int **res)\n" - "{\n" - " int num = 2;\n" - " foo.res = #\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void testautovar2() - { - check("class Fred {\n" - " void func1(int **res);\n" - "}\n" - "void Fred::func1(int **res)\n" - "{\n" - " int num = 2;\n" - " *res = #\n" - "}"); - ASSERT_EQUALS("[test.cpp:7]: (error) Address of local auto-variable assigned to a function parameter.\n" + - "[test.cpp:2]: (style) Unused private function: 'Fred::func1'\n", - errout.str()); - - check("class Fred {\n" - " void func1(int **res);\n" - "}\n" - "void Fred::func1(int **res)\n" - "{\n" - " int num = 2;\n" - " res = #\n" - "}"); - ASSERT_EQUALS("[test.cpp:7]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n" + - "[test.cpp:7]: (style) Variable 'res' is assigned a value that is never used.\n" + - "[test.cpp:2]: (style) Unused private function: 'Fred::func1'\n", - errout.str()); - - check("class Fred {\n" - " void func1(int **res);\n" - "}\n" - "void Fred::func1(int **res)\n" - "{\n" - " int num = 2;\n" - " foo.res = #\n" - "}"); - ASSERT_EQUALS("[test.cpp:2]: (style) Unused private function: 'Fred::func1'\n", errout.str()); - } - - void testautovar3() // ticket #2925 - { - check("void foo(int **p)\n" - "{\n" - " int x[100];\n" - " *p = x;\n" - "}"); - ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - } - - void testautovar4() // ticket #2928 - { - check("void foo(int **p)\n" - "{\n" - " static int x[100];\n" - " *p = x;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void testautovar5() // ticket #2926 - { - check("void foo(struct AB *ab)\n" - "{\n" - " char a;\n" - " ab->a = &a;\n" - "}", false); - ASSERT_EQUALS("", errout.str()); - - check("void foo(struct AB *ab)\n" - "{\n" - " char a;\n" - " ab->a = &a;\n" - "}", true); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - } - - void testautovar6() // ticket #2931 - { - check("void foo(struct X *x)\n" - "{\n" - " char a[10];\n" - " x->str = a;\n" - "}", false); - ASSERT_EQUALS("", errout.str()); - - check("void foo(struct X *x)\n" - "{\n" - " char a[10];\n" - " x->str = a;\n" - "}", true); - ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - } - - void testautovar7() // ticket #3066 - { - check("struct txt_scrollpane_s * TXT_NewScrollPane(struct txt_widget_s * target)\n" - "{\n" - " struct txt_scrollpane_s * scrollpane;\n" - " target->parent = &scrollpane->widget;\n" - " return scrollpane;\n" - "}", false); - ASSERT_EQUALS("", errout.str()); - } - - void testautovar8() - { - check("void foo(int*& p) {\n" - " int i = 0;\n" - " p = &i;\n" - "}", false); - ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - - check("void foo(std::string& s) {\n" - " s = foo;\n" - "}", false); - ASSERT_EQUALS("", errout.str()); - } - - void testautovar9() - { - check("struct FN {int i;};\n" - "struct FP {FN* f};\n" - "void foo(int*& p, FN* p_fp) {\n" - " FN fn;\n" - " FP fp;\n" - " p = &fn.i;\n" - " p = &p_fp->i;\n" - " p = &fp.f->i;\n" - "}", false); - ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); - } - - void testautovar10() // #2930 - assignment of function parameter - { - check("void foo(int b) {\n" - " b = foo(b);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Assignment of function parameter 'b' has no effect outside the function.\n" - "[scripts/test.ctl:2]: (warning) Variable is assigned a value that is never used: 'b'\n", - errout.str()); - - check("void foo(int b) {\n" - " b += 1;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Assignment of function parameter 'b' has no effect outside the function.\n" - "[scripts/test.ctl:2]: (warning) Variable is assigned a value that is never used: 'b'\n", - errout.str()); - - check("void foo(string s) {\n" - " string b = \"\";\n" - " s = foo(b);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Assignment of function parameter 's' has no effect outside the function.\n" - "[scripts/test.ctl:3]: (warning) Variable is assigned a value that is never used: 's'\n", - errout.str()); - - check("void foo(shared_ptr p) {\n" // don't warn for self assignment, there is another warning for this - " p = p;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Redundant assignment of 'p' to itself.\n" - "[scripts/test.ctl:2]: (warning) Variable is assigned a value that is never used: 'p'\n", - errout.str()); - - check("void foo(shared_ptr p, shared_ptr buf) {\n" - " if (!p) p = buf;\n" - " p = 0;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Assignment of function parameter 'p' has no effect outside the function.\n" - "[scripts/test.ctl:2] -> [scripts/test.ctl:3]: (style) Variable is reassigned a value before the old one has been used: 'p'\n" - "[scripts/test.ctl:3]: (warning) Variable is assigned a value that is never used: 'p'\n", - errout.str()); - - check("void foo(shared_ptr p, shared_ptr buf) {\n" - " if (!p) p = buf;\n" - " do_something(p);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(shared_ptr p, shared_ptr buf) {\n" - " while (!p) p = buf;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - /* knownBug TFS(#158013) - check("class Foo {};\n" - "void foo(shared_ptr p) {\n" - " p = 0;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Variable 'p' is assigned a value that is never used.\n", errout.str()); - */ - - check("class Foo {};\n" - "void foo(Foo p) {\n" - " p = 0;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Assignment of function parameter 'p' has no effect outside the function.\n" - "[scripts/test.ctl:3]: (warning) Variable is assigned a value that is never used: 'p'\n", - errout.str()); - - check("class Foo {};\n" - "void foo(Foo &p) {\n" - " p = 0;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(int& p) {\n" - " p = 0;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("double foo(double d) {\n" // #5005 - " int i = d;\n" - " d = i;\n" - " return d;" - "}", false, false); - ASSERT_EQUALS("", errout.str()); - } - - void testautovar13() // Ticket #5537 - { - check("class FileManager {\n" - " FileManager() : UniqueRealDirs(*new UniqueDirContainer())\n" - " {}\n" - " ~FileManager() {\n" - " delete &UniqueRealDirs;\n" - " }\n" - "};\n"); - //Missing ASSERT_EQUALS? - } - void testautovar15() // Ticket #6538 - { - check("const dyn_float darkOutline = makeDynFloat(0.05f, 0.05f, 0.05f, 0.95f);\n" - "const float darkLuminosity = 0.05 +\n" - " 0.0722f * pow(darkOutline[2], 2.2);\n" - "\n" - "const dyn_float ChooseOutlineColor(const dyn_float& textColor, float something) {\n" - " const float lumdiff = something;\n" - " if (lumdiff > 5.0f)\n" - " return darkOutline;\n" - " return 0;\n" - "}\n", - false, false); - ASSERT_EQUALS("[scripts/test.ctl:1]: (style) The name darkOutline does not match the following rule(s): const\n" - "[scripts/test.ctl:2]: (style) The name darkLuminosity does not match the following rule(s): const\n" - "[scripts/test.ctl:6]: (style) The name lumdiff does not match the following rule(s): const\n", - errout.str()); - } - - void returnLocalVariable2() - { - check("string foo()\n" - "{\n" - " dyn_char str = makeDynChar();\n" - " return str;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - check("class Fred\n" - "{\n" - " public string foo()\n" - " {\n" - " dyn_char str = makeDynChar();\n" - " return str;\n" - " }\n" - "};\n"); - ASSERT_EQUALS("", errout.str()); - } - - void returnReferenceLiteral() - { - check("const string a() {\n" - " return \"foo\";\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } - - void returnReferenceCalculation() - { - check("const string a(const string& str) {\n" - " return \"foo\" + str;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void testglobalnamespace() - { - check("class SharedPtrHolder\n" - "{\n" - " shared_ptr pNum;\n" - " public void SetNum(const shared_ptr apNum)\n" - " {\n" - " pNum = apNum;\n" - " }\n" - "};\n"); - - ASSERT_EQUALS("[scripts/test.ctl:1]: (style) The class 'SharedPtrHolder' does not have a constructor although it has private member variables.\n", errout.str()); - } - - void testconstructor() // Ticket #5478 - crash while checking a constructor - { - check("class const_tree_iterator {\n" - " const_tree_iterator(bool (*_incream)(node_type*&)) {}\n" - " const_tree_iterator& parent() {\n" - " return const_tree_iterator(foo);\n" - " }\n" - "};"); - } - //Missing ASSERT_EQUALS? - void variableIsUsedInScope() - { - check("void removed_cb (GList *uids) {\n" - " for (; uids; uids = uids->next) {\n" - " }\n" - "}\n" - "void opened_cb () {\n" - " g_signal_connect (G_CALLBACK (removed_cb));\n" - "}"); - //Missing ASSERT_EQUALS? - } -}; - -// REGISTER_TEST(TestAutoVariables) -void main() -{ - TestAutoVariables test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testbool.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testbool.ctl deleted file mode 100644 index 15703b12..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testbool.ctl +++ /dev/null @@ -1,1397 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2019 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -// #include "checkbool.h" -// #include "settings.h" -// #include "testsuite.h" -// #include "tokenize.h" -// - -struct TestBool : public TestFixture { -// public -// TestBool() : TestFixture("TestBool") { -// } - public TestBool(){} - -// private -// Settings settings; - - void run() { - settings.addEnabled("style"); - settings.addEnabled("warning"); - settings.inconclusive = true; - assertMatch = TRUE; - - TEST_CASE(bitwiseOnBoolean); // if (bool & bool) - TEST_CASE(incrementBoolean); - TEST_CASE(assignBoolToPointer); - TEST_CASE(assignBoolToFloat); - - TEST_CASE(comparisonOfBoolExpressionWithInt1); - TEST_CASE(comparisonOfBoolExpressionWithInt2); - TEST_CASE(comparisonOfBoolExpressionWithInt3); - TEST_CASE(comparisonOfBoolExpressionWithInt4); - - TEST_CASE(comparisonOfBoolWithInt1); - TEST_CASE(comparisonOfBoolWithInt2); - TEST_CASE(comparisonOfBoolWithInt3); - TEST_CASE(comparisonOfBoolWithInt4); - TEST_CASE(comparisonOfBoolWithInt5); - TEST_CASE(comparisonOfBoolWithInt6); // #4224 - integer is casted to bool - TEST_CASE(comparisonOfBoolWithInt7); // #4846 - (!x == true) - - TEST_CASE(checkComparisonOfFuncReturningBool1); - TEST_CASE(checkComparisonOfFuncReturningBool2); - TEST_CASE(checkComparisonOfFuncReturningBool3); - TEST_CASE(checkComparisonOfFuncReturningBool4); - TEST_CASE(checkComparisonOfFuncReturningBool5); - TEST_CASE(checkComparisonOfFuncReturningBool6); - TEST_CASE(checkComparisonOfBoolWithBool); - - // Converting pointer addition result to bool - TEST_CASE(pointerArithBool1); - - TEST_CASE(returnNonBool); - TEST_CASE(returnNonBoolWinCC_OA); - - TEST_CASE(winCC_OA_const); - - - - } - -// void check(const char code[], bool experimental = false, const char filename[] = "scripts/test.ctl") { - // Clear the error buffer.. -// errout.str(""); -// -// settings.experimental = experimental; -// - // Tokenize.. -// Tokenizer tokenizer(&settings, this); -// std::istringstream istr(code); -// tokenizer.tokenize(istr, filename); -// - // Check... -// CheckBool checkBool(&tokenizer, &settings, this); -// checkBool.runChecks(&tokenizer, &settings, this); -// tokenizer.simplifyTokenList2(); -// checkBool.runSimplifiedChecks(&tokenizer, &settings, this); -// } - -/// @test make sence only for cpp code, not WinnCC OA relevant - void assignBoolToPointer() { - check("void foo(bool *p) {\n" - " p = false;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 14", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Boolean value assigned to pointer.\n", errout.str()); - - check("void foo(bool *p) {\n" - " p = (x[rSize];\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 33", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - // ticket #6588 (c mode) - check("struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\n" - "void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\n" - " const int *qmat = n < 4;\n" /* KO */ - " const int *rmat = n < 4 ? " /* OK */ - " ctx->q_intra_matrix :" - " ctx->q_chroma_intra_matrix;\n" - "}", /*experimental=*/false, "test.c"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 28", errout.str()); -// ASSERT_EQUALS("[test.c:3]: (error) Boolean value assigned to pointer.\n", errout.str()); - - // ticket #6588 (c++ mode) - check("struct MpegEncContext { int *q_intra_matrix, *q_chroma_intra_matrix; };\n" - "void dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int n, int qscale) {\n" - " const int *qmat = n < 4;\n" /* KO */ - " const int *rmat = n < 4 ? " /* OK */ - " ctx->q_intra_matrix :" - " ctx->q_chroma_intra_matrix;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 28", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:3]: (error) Boolean value assigned to pointer.\n", errout.str()); - - // ticket #6665 - check("void pivot_big(char *first, int compare(const void *, const void *)) {\n" - " char *a = first, *b = first + 1, *c = first + 2;\n" - " char* m1 = compare(a, b) < 0\n" - " ? (compare(b, c) < 0 ? b : (compare(a, c) < 0 ? c : a))\n" - " : (compare(a, c) < 0 ? a : (compare(b, c) < 0 ? c : b));\n" - "}", /*experimental=*/false, "test.c"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - // #7381 - check("void foo(bool *p, bool b) {\n" - " p = b;\n" - " p = &b;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 14", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Boolean value assigned to pointer.\n", errout.str()); - } - - void assignBoolToFloat() { - check("void foo1() {\n" - " double d = false;\n" - "}"); - //ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Boolean value assigned to floating point variable.\n", errout.str()); no such error in code - // Shouldn't an error of an unused variable be thrown? (Like in the ASSERT_EQUALS below) - ASSERT_EQUALS("", errout.str()); - - check("void foo2() {\n" - " float d = true;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Variable is assigned a value that is never used: 'd'\n", errout.str()); - - check("void foo3() {\n" - " double d = (2>1);\n" - "}"); - ASSERT_EQUALS("", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Boolean value assigned to floating point variable.\n", errout.str()); - - // stability - don't crash: - check("void foo4() {\n" - " unknown = false;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Undefined variable: unknown\n", errout.str()); - - check("struct S {\n" - " float p;\n" - "};\n" - "void f() {\n" - " S s = {0};\n" - " s.p = true;\n" - "}\n"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 48", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:6]: (style) Boolean value assigned to floating point variable.\n", errout.str()); - check("struct S {\n" - " float p;\n" - "};\n" - "void f() {\n" - " S s;\n" - " s.p = true;\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:6]: (warning) Variable is assigned a value that is never used: 's.p'\n", errout.str()); - } - - void comparisonOfBoolExpressionWithInt1() { - check("void f(int x) {\n" - " if ((x && 0x0f)==6)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((x && 0x0f)==0)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: a\n", errout.str()); - - check("void f(int x) {\n" - " if ((x || 0x0f)==6)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((x || 0x0f)==0)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: a\n", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void f(int x) {\n" - " if ((x & 0x0f)==6)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: a\n", errout.str()); - - check("void f(int x) {\n" - " if ((x | 0x0f)==6)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Expression '(X | 0xf) == 0x6' is always false.", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - - check("void f(int x) {\n" - " if ((5 && x)==3)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((5 && x)==3 || (8 && x)==9)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((5 && x)!=3)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - - check("void f(int x) {\n" - " if ((5 && x) > 3)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((5 && x) > 0)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(int x) {\n" - " if ((5 && x) < 0)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if ((5 && x) < 1)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(int x) {\n" - " if ((5 && x) > 1)\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - - check("void f(int x) {\n" - " if (0 < (5 && x))\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(int x) {\n" - " if (0 > (5 && x))\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if (1 > (5 && x))\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(int x) {\n" - " if (1 < (5 && x))\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(bool x ) {\n" - " if ( x > false )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( false < x )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( x < false )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( false > x )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( x >= false )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( false >= x )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( x <= false )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("void f(bool x ) {\n" - " if ( false <= x )\n" - " a++;\n" - "}\n" - ); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("typedef int (*func)(bool invert);\n" - "void x(int, func f);\n" - "void foo(int error) {\n" - " if (error == ABC) { }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 0", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int f() { return !a+b, <= or >=) operator.\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: a\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: b\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: c\n", - errout.str()); - } - - void comparisonOfBoolExpressionWithInt2() { - check("void f(int x) {\n" - " if (!x == 10) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if (!x != 10) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if (x != 10) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(int x) {\n" - " if (10 == !x) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x) {\n" - " if (10 != !x) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(int x, int y) {\n" - " if (y != !x) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(int x, bool y) {\n" - " if (y != !x) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(int x) {\n" - " if (10 != x) {\n" - " printf(\"x not equal to 10\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("bool f(int x, int y) {\n" - " return (!y == !x);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("int f(int a) {\n" - " return (x()+1 == !a);\n" - "}"); - TODO_ASSERT_EQUALS("error", "", errout.str()); - - check("void f() { if (!!a + !!b + !!c >1){} }"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n" - "[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'if'\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: a\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: b\n" - "[scripts/test.ctl:1]: (warning) Undefined variable: c\n", - errout.str()); - - check("void f(int a, int b, int c) { if (a != !b || c) {} }"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - - check("void f(int a, int b, int c) { if (1 < !!a + !!b + !!c) {} }"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n" - "[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("void f(int a, int b, int c) { if (1 < !(a+b)) {} }"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n",errout.str()); - } - - void comparisonOfBoolExpressionWithInt3() { - check("int f(int x) {\n" - " return t<0>() && x;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 31", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void comparisonOfBoolExpressionWithInt4() { - // #5016 - check("void f() {\n" - " for(int i = 4; i > -1 < 5 ; --i) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("bool f(int a, int b, int c) {\n" - " return (a > b) < c;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); - - check("bool f(int a, int b, int c) {\n" - " return x(a > b) < c;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - - check("bool f(int a, int b, int c) {\n" - " return a > b == c;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // templates - check("struct Tokenizer { TokenList list; };\n" - "void Tokenizer::f() {\n" - " std::list locationList;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 29", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - // #5063 - or - check("void f() {\n" - " return a > b or c < d;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 26", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int f() {\n" - " return (a < b) != 0U;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Undefined variable: a\n" - "[scripts/test.ctl:2]: (warning) Undefined variable: b\n", - errout.str()); - - check("int f() {\n" - " return (a < b) != 0x0;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Undefined variable: a\n" - "[scripts/test.ctl:2]: (warning) Undefined variable: b\n", - errout.str()); - - check("int f() {\n" - " return (a < b) != 42U;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - } - - void checkComparisonOfFuncReturningBool1() { - check("void f(){\n" - " int temp = 4;\n" - " if(compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n" - "bool compare2(int temp){\n" - " if(temp==4){\n" - " return false;\n" - " }\n" - " else\n" - " return true;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - } - - void checkComparisonOfFuncReturningBool2() { - check("void f(){\n" - " int temp = 4;\n" - " bool a = true;\n" - " if(compare(temp) > a){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - } - - void checkComparisonOfFuncReturningBool3() { - check("void f(){\n" - " int temp = 4;\n" - " if(compare(temp) > temp){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Comparison of a boolean expression with an integer.\n" - "[scripts/test.ctl:3]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n",+ - errout.str()); - } - - void checkComparisonOfFuncReturningBool4() { - check("void f(){\n" - " int temp = 4;\n" - " bool b = compare2(6);\n" - " if(compare1(temp)> b){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n" - "bool compare2(int temp){\n" - " if(temp == 5){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - } - - void checkComparisonOfFuncReturningBool5() { - check("void f(){\n" - " int temp = 4;\n" - " if(compare1(temp) > !compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n" - "bool compare2(int temp){\n" - " if(temp==4){\n" - " return false;\n" - " }\n" - " else\n" - " return true;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - } - - void checkComparisonOfFuncReturningBool6() { - check("int compare1(int temp);\n" - "namespace Foo {\n" - " bool compare1(int temp);\n" - "}\n" - "void f(){\n" - " int temp = 4;\n" - " if(compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 22", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("namespace Foo {\n" - " bool compare1(int temp);\n" - "}\n" - "int compare1(int temp);\n" - "void f(){\n" - " int temp = 4;\n" - " if(compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 0", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int compare1(int temp);\n" - "namespace Foo {\n" - " bool compare1(int temp);\n" - " void f(){\n" - " int temp = 4;\n" - " if(compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 22", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:6]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - - check("int compare1(int temp);\n" - "namespace Foo {\n" - " bool compare1(int temp);\n" - " void f(){\n" - " int temp = 4;\n" - " if(::compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 22", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool compare1(int temp);\n" - "void f(){\n" - " int temp = 4;\n" - " if(foo.compare1(temp) > compare2(temp)){\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 23", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void checkComparisonOfBoolWithBool() { - - // @test settings.experimental works for cppCheck intern only. It has no start option for this settings. - // Ignore that for WinCC OA tests - /* - const string code = "void f(){\n" - " int temp = 4;\n" - " bool b = compare2(6);\n" - " bool a = compare1(4);\n" - " if(b > a){\n" - " printf(\"foo\");\n" - " }\n" - "}\n" - "bool compare1(int temp){\n" - " if(temp==4){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n" - "bool compare2(int temp){\n" - " if(temp == 5){\n" - " return true;\n" - " }\n" - " else\n" - " return false;\n" - "}\n"; - check(code, true); - ASSERT_EQUALS("[scripts/test.ctl:5]: (style) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); - check(code, false); - ASSERT_EQUALS("", errout.str());*/ - } - - void bitwiseOnBoolean() { // 3062 - check("void f(bool a, bool b) {\n" - " if(a & !b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" - "[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("void f(bool a, bool b) {\n" - " if(a | !b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '||'?\n" - "[scripts/test.ctl:2]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" - "[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("bool a, b;\n" - "void f() {\n" - " if(a & b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'b' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:3]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("bool a, b;\n" - "void f() {\n" - " if(a & !b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:3]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" - "[scripts/test.ctl:3]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("bool a, b;\n" - "void f() {\n" - " if(a | b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '||'?\n" - "[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'b' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:3]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("bool a, b;\n" - "void f() {\n" - " if(a | !b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '||'?\n" - "[scripts/test.ctl:3]: (style) Boolean result is used in bitwise operation. Clarify expression with parentheses.\n" - "[scripts/test.ctl:3]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("void f(bool a, int b) {\n" - " if(a & b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Boolean variable/expression 'a' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("void f(int a, bool b) {\n" - " if(a & b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Boolean variable/expression 'b' is used in bitwise operation. Did you mean '&&'?\n" - "[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", - errout.str()); - - check("void f(int a, int b) {\n" - " if(a & b) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - - check("void f(bool b) {\n" - " foo(bar, &b);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 30", errout.str()); - - check("void f(bool &b) {\n" - " foo(bar, b);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Undefined variable: bar\n", errout.str()); - } - - void incrementBoolean() { - check("bool bValue = true;\n" - "void f() { bValue++; }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Incrementing/Decrementing a variable/expression 'bValue' of type 'bool' with operator++ is not allowed. You should assign it the value 'true' or 'false' instead.\n", errout.str()); - - check("void f(bool test){\n" - " test++;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Incrementing/Decrementing a variable/expression 'test' of type 'bool' with operator++ is not allowed. You should assign it the value 'true' or 'false' instead.\n" - "[scripts/test.ctl:2]: (warning) Assignment of function parameter 'test' has no effect outside the function.\n", - errout.str()); - - check("void f(int test){\n" - " test++;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Assignment of function parameter 'test' has no effect outside the function.\n", errout.str()); - } - - void comparisonOfBoolWithInt1() { - check("void f(bool x) {\n" - " if (x < 10) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(bool x) {\n" - " if (10 >= x) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(bool x) {\n" - " if (x != 0) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(bool x) {\n" // #3356 - " if (x == 1) {\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - - check("void f(bool x) {\n" - " if (x != 10) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(bool x) {\n" - " if (x == 10) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - - check("void f(bool x) {\n" - " if (x == 0) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("DensePropertyMap visited;"); // #4075 - ASSERT_EQUALS("WinCC OA syntax error at pos: 16", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void comparisonOfBoolWithInt2() { - check("void f(bool x, int y) {\n" - " if (x == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); - - check("void f(int x, bool y) {\n" - " if (x == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); - - check("void f(bool x, bool y) {\n" - " if (x == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(bool x, fooClass y) {\n" - " if (x == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 15", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("class fooClass{};\n" - "void f(bool x, fooClass y) {\n" - " if (x == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'class'\n", errout.str()); // this shall not work !? - } - - void comparisonOfBoolWithInt3() { - check("void f(int y) {\n" - " if (y > false) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer.\n" - "[scripts/test.ctl:2]: (warning) Comparison of a variable having boolean value using relational (<, >, <= or >=) operator.\n", - errout.str()); - - check("void f(int y) {\n" - " if (true == y) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer.\n", errout.str()); - - check("void f(bool y) {\n" - " if (y == true) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f(bool y) {\n" - " if (false < 5) {\n" - " printf(\"foo\");\n" - " }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n", errout.str()); - } - - void comparisonOfBoolWithInt4() { - check("void f(int x) {\n" - " if (!x == 1) { }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - } - - void comparisonOfBoolWithInt5() { - check("void SetVisible(int index, bool visible) {\n" - " bool (SciTEBase::*ischarforsel)(char ch);\n" - " if (visible != GetVisible(index)) { }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 64", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool - check("void SetVisible(bool b, int i) {\n" - " if (b == (bool)i) { }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - } - - void comparisonOfBoolWithInt7() { // #4846 - (!x==true) - check("void f(int x) {\n" - " if (!x == true) { }\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) The scope is empty: 'if'\n", errout.str()); - } - - // @test WinCC OA does not support pointers - void pointerArithBool1() { // #5126 - check("void f(char *p) {\n" - " if (p+1){}\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - - check("void f(char *p) {\n" - " do {} while (p+1);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - - check("void f(char *p) {\n" - " while (p-1) {}\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - - check("void f(char *p) {\n" - " for (int i = 0; p+1; i++) {}\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - - check("void f(char *p) {\n" - " if (p && p+1){}\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - - check("void f(char *p) {\n" - " if (p+2 || p) {}\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (error) Converting pointer arithmetic result to bool. The bool is always true unless there is undefined behaviour.\n", errout.str()); - } - - // @test this syntax is not supported by WinCC OA - void returnNonBool() { - check("bool f(void) {\n" - " return 0;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - " return 1;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - " return 2;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " return -1;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " return 1 + 1;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:2]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " int x = 0;\n" - " return x;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - " int x = 10;\n" - " return x;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " return 2 < 1;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - " int ret = 0;\n" - " if (a)\n" - " ret = 1;\n" - " return ret;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - " int ret = 0;\n" - " if (a)\n" - " ret = 3;\n" - " return ret;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:5]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " if (a)\n" - " return 3;\n" - " return 4;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:3]: (style) Non-boolean value returned from function returning bool\n" -// "[scripts/test.ctl:4]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - " return;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - "auto x = [](void) { return -1; };\n" - "return false;\n" - "}\n"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - "auto x = [](void) { return -1; };\n" - "return 2;\n" - "}\n"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - - check("bool f(void) {\n" - "auto x = [](void) -> int { return -1; };\n" - "return false;\n" - "}\n"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("bool f(void) {\n" - "auto x = [](void) -> int { return -1; };\n" - "return 2;\n" - "}\n"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 11", errout.str()); -// ASSERT_EQUALS("[scripts/test.ctl:3]: (style) Non-boolean value returned from function returning bool\n", errout.str()); - } - - - void returnNonBoolWinCC_OA() { - check("bool f() {\n" - " return 0;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", errout.str()); - - check("bool f() {\n" - " return 1;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.", errout.str()); - - check("bool f() {\n" - " return 2;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:2]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", - errout.str()); - - check("bool f() {\n" - " return -1;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:2]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", - errout.str()); - - check("bool f() {\n" - " return 1 + 1;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:2]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", - errout.str()); - - check("bool f() {\n" - " int x = 0;\n" - " return x;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", errout.str()); - - check("bool f() {\n" - " int x = 10;\n" - " return x;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:3]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n", errout.str()); - - check("bool f() {\n" - " return 2 < 1;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("bool f() {\n" - " int ret = 0;\n" - " if (a)\n" - " ret = 1;\n" - " return ret;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:5]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("bool f() {\n" - " int ret = 0;\n" - " if (a)\n" - " ret = 3;\n" - " return ret;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:5]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:5]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - - check("bool f() {\n" - " if (a)\n" - " return 3;\n" - " return 4;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:4]: (warning) Non-boolean value returned from function returning bool\n" - "[scripts/test.ctl:3]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n" - "[scripts/test.ctl:4]: (warning, inconclusive) Return value 'int' does not match with declaration 'bool'.\n" - "[scripts/test.ctl:2]: (warning) Undefined variable: a\n", - errout.str()); - - check("bool f() {\n" - " return;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 21", errout.str()); // this looks like a bug. Because it shall return some value, but in the line 2 is return only. - } - - void winCC_OA_const() - { - check("bool f() {\n" - "return false;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - check("bool f() {\n" - "return FALSE;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - check("bool f() {\n" - "return true;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - check("bool f() {\n" - "return TRUE;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - check("bool f() {\n" - "return TRUE == true;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - check("bool f() {\n" - "return TRUE == false;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - check("bool f() {\n" - "return TRUE != false;\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } -}; - -// REGISTER_TEST(TestBool) - -void main() -{ - TestBool test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testfunctions.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testfunctions.ctl deleted file mode 100644 index 72ada048..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testfunctions.ctl +++ /dev/null @@ -1,726 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2019 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -// #include - -// #include "checkfunctions.h" -// #include "library.h" -// #include "settings.h" -// #include "standards.h" -// #include "testsuite.h" -// #include "tokenize.h" - - -struct TestFunctions : public TestFixture -{ -// public: -// TestFunctions() : TestFixture("TestFunctions") { -// } - -// private: -// Settings settings; - - void run() - { - settings.addEnabled("style"); - settings.addEnabled("warning"); - settings.addEnabled("portability"); -// settings.standards.posix = true; -// settings.standards.c = Standards::C11; -// settings.standards.cpp = Standards::CPP11; -// settings.addLibraryFile("std.cfg"); -// LOAD_LIB_2(settings.library, "std.cfg"); -// settings.addLibraryFile("posix.cfg"); -// LOAD_LIB_2(settings.library, "posix.cfg"); - - // Prohibited functions - TEST_CASE(prohibitedFunctions_posix); - TEST_CASE(prohibitedFunctions_posix_WinCC_OA); - - TEST_CASE(prohibitedFunctions_index); - TEST_CASE(prohibitedFunctions_qt_index); // FP when using the Qt function 'index'? - TEST_CASE(prohibitedFunctions_rindex); - TEST_CASE(prohibitedFunctions_var); // no false positives for variables - TEST_CASE(prohibitedFunctions_gets); // dangerous function - TEST_CASE(prohibitedFunctions_alloca); - TEST_CASE(prohibitedFunctions_declaredFunction); // declared function ticket #3121 - TEST_CASE(prohibitedFunctions_std_gets); // test std::gets - - TEST_CASE(prohibitedFunctions_multiple); // multiple use of obsolete functions - - TEST_CASE(prohibitedFunctions_c_declaration); // c declared function - TEST_CASE(prohibitedFunctions_functionWithBody); // function with body - TEST_CASE(prohibitedFunctions_crypt); // Non-reentrant function - TEST_CASE(prohibitedFunctions_crypt_WinCC_OA); // Non-reentrant function - - TEST_CASE(prohibitedFunctions_namespaceHandling); -/// @todo clearify followin functions - // Invalid function usage - TEST_CASE(invalidFunctionUsageStrings); - - // Math function usage - TEST_CASE(mathfunctionCall_fmod); - TEST_CASE(mathfunctionCall_sqrt); - TEST_CASE(mathfunctionCall_log); - TEST_CASE(mathfunctionCall_acos); - TEST_CASE(mathfunctionCall_asin); - TEST_CASE(mathfunctionCall_pow); - TEST_CASE(mathfunctionCall_atan2); - } - -// void check(const char code[], const char filename[]="test.cpp", const Settings* settings_=nullptr) { - // Clear the error buffer.. -// errout.str(""); -// -// if (!settings_) -// settings_ = &settings; -// - // Tokenize.. -// Tokenizer tokenizer(settings_, this); -// std::istringstream istr(code); -// tokenizer.tokenize(istr, filename); -// -// CheckFunctions checkFunctions(&tokenizer, settings_, this); -// checkFunctions.runChecks(&tokenizer, settings_, this); -// - // Simplify... -// tokenizer.simplifyTokenList2(); -// - // Check... -// checkFunctions.runSimplifiedChecks(&tokenizer, settings_, this); -// } - - void prohibitedFunctions_posix() - { - check("void f()\n" - "{\n" - " bsd_signal(SIGABRT, SIG_IGN);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: SIGABRT\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: SIG_IGN\n", - errout.str()); - - check("int f()\n" - "{\n" - " int bsd_signal(0);\n" - " return bsd_signal;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 28", errout.str()); - - check("void f()\n" - "{\n" - " struct hostent *hp;\n" - " if(!hp = gethostbyname(\"127.0.0.1\")) {\n" - " exit(1);\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 15", errout.str()); -// ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'gethostbyname' called. It is recommended to use 'getaddrinfo' instead.\n", errout.str()); - - check("void f()\n" - "{\n" - " long addr;\n" - " addr = inet_addr(\"127.0.0.1\");\n" - " if(!hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET)) {\n" - " exit(1);\n" - " }\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 116", errout.str()); -// ASSERT_EQUALS("[test.cpp:5]: (style) Obsolescent function 'gethostbyaddr' called. It is recommended to use 'getnameinfo' instead.\n", errout.str()); - - check("void f()\n" - "{\n" - " usleep( 1000 );\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void prohibitedFunctions_posix_WinCC_OA() - { - - const string oaRule = getPath(DATA_REL_PATH, "ctrlPpCheck/cfg/ctrl.xml"); - settings.addRuleFile(oaRule); - - /* knownBug TFS(#158013) (probably an issue because the file aboth does not exist) - check("int main(int p)\n" - "{\n" - " bool b = isMotif();\n" - " DebugN(b);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (style) Obsolescent function 'isMotif' called. It is recommended to use '' instead.\n", errout.str()); - */ - - check("int f()\n" - "{\n" - " bool isMotif = false;\n" - " return isMotif;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void f()\n" - "{\n" - " if( \"\" == gethostbyname(\"127.0.0.1\")) {\n" - " exit(1);\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - //settings.unloadLibrary(oaLib); - - check("void f()\n" - "{\n" - " if( \"\" == getHostByName(\"127.0.0.1\")) {\n" - " exit(1);\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - //settings.unloadLibrary(oaLib); - } - - void prohibitedFunctions_index() - { - check("namespace n1 {\n" - " int index(){};\n" - "}\n" - "int main()\n" - "{\n" - " n1::index();\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 0", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("std::size_t f()\n" - "{\n" - " std::size_t index(0);\n" - " index++;\n" - " return index;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 3", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("int f()\n" - "{\n" - " return this->index();\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 25", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void f()\n" - "{\n" - " int index( 0 );\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 24", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("const char f()\n" - "{\n" - " const char var[6] = \"index\";\n" - " const char i = index(var, 0);\n" - " return i;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 35", errout.str()); -// ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", -// errout.str()); - } - - void prohibitedFunctions_qt_index() - { - check("void TDataModel::forceRowRefresh(int row) {\n" - " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 15", errout.str()); -// ASSERT_EQUALS("[test.cpp:2]: (style) Obsolescent function 'index' called. It is recommended to use 'strchr' instead.\n", errout.str()); - } - - void prohibitedFunctions_rindex() - { - check("void f()\n" - "{\n" - " int rindex( 0 );\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 25", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void f()\n" - "{\n" - " const char var[7] = \"rindex\";\n" - " print(rindex(var, 0));\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 29", errout.str()); -// ASSERT_EQUALS("[test.cpp:4]: (style) Obsolescent function 'rindex' called. It is recommended to use 'strrchr' instead.\n", errout.str()); - } - - - void prohibitedFunctions_var() - { - check("class Fred {\n" - "public:\n" - " Fred() : index(0) { }\n" - " int index;\n" - "};"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 19", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void prohibitedFunctions_gets() - { - check("void f()\n" - "{\n" - " char *x = gets(a);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str()); - - check("void f()\n" - "{\n" - " foo(x, gets(a));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Undefined variable: x\n" - "[scripts/test.ctl:3]: (warning) Undefined variable: a\n", - errout.str()); - } - - void prohibitedFunctions_alloca() - { - check("void f()\n" - "{\n" - " char *x = alloca(10);\n" - "}", "test.cpp"); // #4382 - there are no VLAs in C++ - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'alloca' called.\n", errout.str()); - - check("void f()\n" - "{\n" - " char *x = alloca(10);\n" - "}", "test.c"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("[test.c:3]: (warning) Obsolete function 'alloca' called. In C99 and later it is recommended to use a variable length array instead.\n", errout.str()); - -// settings.standards.c = Standards::C89; -// settings.standards.cpp = Standards::CPP03; - check("void f()\n" - "{\n" - " char *x = alloca(10);\n" - "}", "test.cpp"); // #4382 - there are no VLAs in C++ - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void f()\n" - "{\n" - " char *x = alloca(10);\n" - "}", "test.c"); // #7558 - no alternative to alloca in C89 - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("void f()\n" - "{\n" - " char *x = alloca(10);\n" - "}", "test.c"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 20", errout.str()); -// ASSERT_EQUALS("", errout.str()); -// settings.standards.c = Standards::C11; -// settings.standards.cpp = Standards::CPP11; - } - - // ticket #3121 - void prohibitedFunctions_declaredFunction() - { - check("int ftime ( int a )\n" - "{\n" - " return a;\n" - "}\n" - "int main ()\n" - "{\n" - " int b ; b = ftime ( 1 ) ;\n" - " return 0 ;\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:7]: (warning) Variable is assigned a value that is never used: 'b'\n", errout.str()); - } - - // test std::gets - void prohibitedFunctions_std_gets() - { - check("void f(char * str)\n" - "{\n" - " char *x = std::gets(str);\n" - " char *y = gets(str);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n" -// "[test.cpp:4]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str()); - } - - // multiple use - void prohibitedFunctions_multiple() - { - check("void f(char * str)\n" - "{\n" - " char *x = std::gets(str);\n" - " usleep( 1000 );\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n" -// "[test.cpp:4]: (style) Obsolescent function 'usleep' called. It is recommended to use 'nanosleep' or 'setitimer' instead.\n", errout.str()); - } - - void prohibitedFunctions_c_declaration() - { - check("char * gets ( char * c ) ;\n" - "int main ()\n" - "{\n" - " char s [ 10 ] ;\n" - " gets ( s ) ;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 5", errout.str()); -// ASSERT_EQUALS("[test.cpp:5]: (warning) Obsolete function 'gets' called. It is recommended to use 'fgets' or 'gets_s' instead.\n", errout.str()); - - check("int getcontext(ucontext_t *ucp);\n" - "int f (ucontext_t *ucp)\n" - "{\n" - " getcontext ( ucp ) ;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 15", errout.str()); -// ASSERT_EQUALS("[test.cpp:4]: (portability) Obsolescent function 'getcontext' called. Applications are recommended to be rewritten to use POSIX threads.\n", errout.str()); - } - - void prohibitedFunctions_functionWithBody() - { - check("char * gets ( char * c ) { return c; }\n" - "int main ()\n" - "{\n" - " char s [ 10 ] ;\n" - " gets ( s ) ;\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 5", errout.str()); -// ASSERT_EQUALS("", errout.str()); - } - - void prohibitedFunctions_crypt() - { - check("void f(char *pwd)\n" - "{\n" - " char *cpwd;" - " crypt(pwd, cpwd);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 12", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function crypt() is not used.\n" -// "[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str()); - - check("void f()\n" - "{\n" - " char *pwd = getpass(\"Password:\");" - " char *cpwd;" - " crypt(pwd, cpwd);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 57", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function crypt() is not used.\n" -// "[test.cpp:3]: (portability) Non reentrant function 'crypt' called. For threadsafe applications it is recommended to use the reentrant replacement function 'crypt_r'.\n", errout.str()); - - check("int f()\n" - "{\n" - " int crypt = 0;" - " return crypt;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - // @todo crypt is laos wincc oa function and this can not match - void prohibitedFunctions_crypt_WinCC_OA() - { - check("void f(char pwd)\n" - "{\n" - " char cpwd = crypt(pwd);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Variable is assigned a value that is never used: 'cpwd'\n", errout.str()); - } - - void prohibitedFunctions_namespaceHandling() - { - check("int f()\n" - "{\n" - " time_t t = 0;" - " std::localtime(&t);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 36", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); - - // Pass return value - check("int f()\n" - "{\n" - " time_t t = 0;" - " struct tm *foo = localtime(&t);\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 46", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (portability) Non reentrant function 'localtime' called. For threadsafe applications it is recommended to use the reentrant replacement function 'localtime_r'.\n", errout.str()); - - // Access via global namespace - check("int f()\n" - "{\n" - " ::getpwent();\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 14", errout.str()); -// ASSERT_EQUALS("[test.cpp:3]: (warning) Return value of function getpwent() is not used.\n" -// "[test.cpp:3]: (portability) Non reentrant function 'getpwent' called. For threadsafe applications it is recommended to use the reentrant replacement function 'getpwent_r'.\n", errout.str()); - - // Be quiet on function definitions - check("int getpwent()\n" - "{\n" - " return 123;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // Be quiet on other namespaces - check("int f()\n" - "{\n" - " foobar::getpwent();\n" - "}"); - ASSERT_EQUALS("WinCC OA syntax error at pos: 22", errout.str()); -// ASSERT_EQUALS("", errout.str()); - - check("struct foobar{static void getpwent(){}};\n" - "int f()\n" - "{\n" - " foobar::getpwent();\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'getpwent'\n", errout.str()); - - // Be quiet on class member functions - check("struct Foobar{static void getpwent(){}};\n" - "Foobar foobar;\n" - "int f()\n" - "{\n" - " foobar.getpwent();\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:1]: (warning, inconclusive) The scope is empty: 'getpwent'\n", errout.str()); - } - - void mathfunctionCall_sqrt() - { - // sqrt - check("void foo()\n" - "{\n" - " DebugN(sqrt(-1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (error) Invalid sqrt() argument nr 1. The value is -1 but the valid values are '0.0:'.\n", errout.str()); - - // implementation-defined behaviour for "finite values of x<0" only: - check("void foo()\n" - "{\n" - " DebugN(sqrt(-0.));\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(sqrt(1));\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void mathfunctionCall_log() - { - // log,log10 - check("void foo()\n" - "{\n" - " DebugN(log(-2));\n" - " DebugN(log10(-2));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing value -2 to log() leads to implementation-defined result.\n" - "[scripts/test.ctl:4]: (warning) Passing value -2 to log10() leads to implementation-defined result.\n", - errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(log(-1));\n" - " DebugN(log10(-1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing value -1 to log() leads to implementation-defined result.\n" - "[scripts/test.ctl:4]: (warning) Passing value -1 to log10() leads to implementation-defined result.\n", - errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(log(-1.0));\n" - " DebugN(log10(-1.0));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing value -1.0 to log() leads to implementation-defined result.\n" - "[scripts/test.ctl:4]: (warning) Passing value -1.0 to log10() leads to implementation-defined result.\n", - errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(log(-0.1));\n" - " DebugN(log10(-0.1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing value -0.1 to log() leads to implementation-defined result.\n" - "[scripts/test.ctl:4]: (warning) Passing value -0.1 to log10() leads to implementation-defined result.\n", - errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(log(0));\n" - " DebugN(log10(0.0));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing value 0 to log() leads to implementation-defined result.\n" - "[scripts/test.ctl:4]: (warning) Passing value 0.0 to log10() leads to implementation-defined result.\n", - errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(log(1E-3));\n" - " DebugN(log10(1E-3));\n" - " DebugN(log(1.0E-3));\n" - " DebugN(log10(1.0E-3));\n" - " DebugN(log(1.0E+3));\n" - " DebugN(log10(1.0E+3));\n" - " DebugN(log(2.0));\n" - " DebugN(log10(2.0));\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void mathfunctionCall_acos() - { - // acos - check("float foo()\n" - "{\n" - " return acos(-1) \n" - " + acos(0.1) \n" - " + acos(0.0001) \n" - " + acos(0.01) \n" - " + acos(1.0E-1) \n" - " + acos(-1.0E-1) \n" - " + acos(+1.0E-1) \n" - " + acos(0.1E-1) \n" - " + acos(+0.1E-1) \n" - " + acos(-0.1E-1); \n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(acos(1.1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (error) Invalid acos() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(acos(-1.1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.cptl:3]: (error) Invalid acos() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n", errout.str()); - } - - void mathfunctionCall_asin() - { - // asin - check("float foo()\n" - "{\n" - " return asin(1) \n" - " + asin(-1) \n" - " + asin(0.1) \n" - " + asin(0.0001) \n" - " + asin(0.01) \n" - " + asin(1.0E-1) \n" - " + asin(-1.0E-1) \n" - " + asin(+1.0E-1) \n" - " + asin(0.1E-1) \n" - " + asin(+0.1E-1) \n" - " + asin(-0.1E-1); \n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(asin(1.1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.cptl:3]: (error) Invalid asin() argument nr 1. The value is 1.1 but the valid values are '-1.0:1.0'.\n", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(asin(-1.1));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (error) Invalid asin() argument nr 1. The value is -1.1 but the valid values are '-1.0:1.0'.\n", errout.str()); - } - - void mathfunctionCall_pow() - { - // pow - check("void foo()\n" - "{\n" - " DebugN(pow(0,-10));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing values 0 and -10 to pow() leads to implementation-defined result.\n", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(pow(0,10));\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void mathfunctionCall_atan2() - { - // atan2 - check("float foo()\n" - "{\n" - " DebugN(atan2(1,1)) ;\n" - " DebugN(atan2(-1,-1)) ;\n" - " DebugN(atan2(0.1,1)) ;\n" - " DebugN(atan2(0.0001,100)) ;\n" - " DebugN(atan2(0.0,1e-1)) ;\n" - " DebugN(atan2(1.0E-1,-3)) ;\n" - " DebugN(atan2(-1.0E-1,+2)) ;\n" - " DebugN(atan2(+1.0E-1,0)) ;\n" - " DebugN(atan2(0.1E-1,3)) ;\n" - " DebugN(atan2(+0.1E-1,1)) ;\n" - " DebugN(atan2(-0.1E-1,8)) ;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(atan2(0,0));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing values 0 and 0 to atan2() leads to implementation-defined result.\n", errout.str()); - } - - void mathfunctionCall_fmod() - { - // fmod - check("void foo()\n" - "{\n" - " DebugN(fmod(1.0,0));\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) Passing values 1.0 and 0 to fmod() leads to implementation-defined result.\n", errout.str()); - - check("void foo()\n" - "{\n" - " DebugN(fmod(1.0,1));\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } -}; - -// REGISTER_TEST(TestFunctions) - -void main() -{ - TestFunctions test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testio.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testio.ctl deleted file mode 100644 index 2a089670..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/unitTests/testio.ctl +++ /dev/null @@ -1,943 +0,0 @@ -#uses "classes/QualityGates/Tools/CppCheck/TestFixture" - -// #include "checkio.h" -// #include "platform.h" -// #include "settings.h" -// #include "testsuite.h" -// #include "tokenize.h" - - -struct TestIO : TestFixture -{ - - void run() - { - settings.inconclusive = false; - settings.addEnabled("portability"); - - TEST_CASE(wrongMode_simple); - TEST_CASE(wrongMode_complex); - TEST_CASE(useClosedFile); - TEST_CASE(fileIOwithoutPositioning); - TEST_CASE(seekOnAppendedFile); - TEST_CASE(fflushOnInputStream); - - TEST_CASE(testScanf1); // Scanf without field limiters - - TEST_CASE(testScanfArgument); - TEST_CASE(testPrintfArgument); - TEST_CASE(testPosixPrintfScanfParameterPosition); // #4900 - - //TEST_CASE(testMicrosoftPrintfArgument); // ticket #4902 - //TEST_CASE(testMicrosoftScanfArgument); - - TEST_CASE(testTernary); // ticket #6182 - TEST_CASE(testUnsignedConst); // ticket #6132 - - TEST_CASE(testAstType); // #7014 - - TEST_CASE(testPrintfTypeAlias1); - } - - void wrongMode_simple() - { - // Read mode - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"r\");\n" - " fread(f, data);\n" - " rewind(f);\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:7]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); - - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"r+\");\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - - // Write mode - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"w\");\n" - " fwrite(f, data);\n" - " rewind(f);\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:7]: (error) Read operation on a file that was opened only for writing.\n", errout.str()); - - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"w+\");\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file& f) {\n" - " blob data = 0;\n" - " f = tmpfile();\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // Append mode - /* knownBug TFS(#158013) (The first part of the expMessage COULD be wrong) - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"a\");\n" - " fwrite(f, data);\n" - " rewind(f);\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:6]: (warning) Repositioning operation performed on a file opened in append mode has no effect.\n" - "[scripts/test.ctl:7]: (error) Read operation on a file that was opened only for writing.\n", errout.str()); - */ - - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"a+\");\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // Variable declared locally - check("void foo() {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " file f = fopen(name, \"r\");\n" - " fwrite(f, data);\n" - " fclose(f);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); - - // Call unknown function - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"a\");\n" - " fwrite(f, data);\n" - " bar(f);\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // Crash tests - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, mode);\n" // No assertion failure (#3830) - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (warning) Undefined variable: mode\n", errout.str()); - - check("void fopen(string const &filepath, string const &mode);"); // #3832 - } - - void wrongMode_complex() - { - check("void foo(file f, bool a) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " if(a) f = fopen(name, \"w\");\n" - " else f = fopen(name, \"r\");\n" - " if(a) fwrite(f, data);\n" - " else fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(bool a) {\n" - " file f;\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " if(a) f = fopen(name, \"w\");\n" - " else f = fopen(name, \"r\");\n" - " if(a) fwrite(f, data);\n" - " else fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(bool a) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " file f = fopen(name, \"w\");\n" - " if(a) fwrite(f, data);\n" - " else fread(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:6]: (error) Read operation on a file that was opened only for writing.\n", errout.str()); - } - - void useClosedFile() - { - check("void foo(file& f) {\n" - " blob data = 0;\n" - " fclose(f);\n" - " fwrite(f, data);\n" - " rewind(f);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (error) Used file that is not opened.\n" - "[scripts/test.ctl:5]: (error) Used file that is not opened.\n", - errout.str()); - - check("void foo(file& f) {\n" - " blob data = 0;\n" - " if(!ferror(f)) {\n" - " fclose(f);\n" - " return;" - " }\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file& f) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " fclose(f);\n" - " f = fopen(name, \"r\");\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file& f, file& g) {\n" - " string name = \"dummy\";\n" - " blob data = 0;\n" - " f = fopen(name, \"r\");\n" - " f = g;\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo() {\n" - " file f;\n" - " blob data = 0;\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (information, inconclusive) Uninitialized variable: f\n" - "[scripts/test.ctl:4]: (error) Used file that is not opened.\n", - errout.str()); - - check("void foo() {\n" // #3965 - " dyn_anytype fs = makeDynAnytype();\n" - " string name = \"dummy\";\n" - " string mode = \"\";\n" - " dynAppend(fs, fopen(name, mode));\n" - " fclose(fs[1]);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // #4368: multiple functions - check("file fp = nullptr;\n" - "\n" - "void close()\n" - "{\n" - " fclose(fp);\n" - "}\n" - "\n" - "void dump()\n" - "{\n" - " if (fp == nullptr) return;\n" - " fprintf(fp, \"Here's the output.\\n\");\n" - "}\n" - "\n" - "int main()\n" - "{\n" - " fp = fopen(\"test.txt\", \"w\");\n" - " dump();\n" - " close();\n" - " return 0;\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("file fp = nullptr;\n" - "\n" - "void close()\n" - "{\n" - " fclose(fp);\n" - "}\n" - "\n" - "void dump()\n" - "{\n" - " fclose(fp);\n" - " fprintf(fp, \"Here's the output.\\n\");\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:11]: (error) Used file that is not opened.\n", errout.str()); - - // #4466 - check("void chdcd_parse_nero(file infile, int mode) {\n" - " switch (mode) {\n" - " case 0x0300:\n" - " fclose(infile);\n" - " return;\n" - " case 0x0500:\n" - " fclose(infile);\n" - " return;\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) //Should behave like above (but doesn't) - check("void chdcd_parse_nero(file infile, int mode) {\n" - " switch (mode) {\n" - " case 0x0300:\n" - " fclose(infile);\n" - " exit(0);\n" - " case 0x0500:\n" - " fclose(infile);\n" - " return;\n" - " }\n" - "}"); - ASSERT_EQUALS("", errout.str()); - */ - - // #4649 - check("struct files{file f1; file f2;};\n" - "void foo(string name, string mode) {\n" - " files a;\n" - " a.f1 = fopen(name,mode);\n" - " a.f2 = fopen(name,mode);\n" - " fclose(a.f1);\n" - " fclose(a.f2);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - // #1473 - check("void foo() {\n" - " file a = fopen(\"aa\", \"r\");\n" - " while (fclose(a)) {}\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (error) Used file that is not opened.\n", errout.str()); - - // #6823 - check("void foo() {\n" - " dyn_anytype fs = makeDynAnytype();\n" - " dynAppend(fs, fopen(\"1\", \"w\"));\n" - " dynAppend(fs, fopen(\"2\", \"w\"));\n" - " fclose(fs[1]);\n" - " fclose(fs[2]);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void fileIOwithoutPositioning() - { - check("void foo(file f) {\n" - " blob data = 0;\n" - " fwrite(f, data);\n" - " fread(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (error) Read and write operations without a call to a positioning function (fseek or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); - - check("void foo(file f) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (error) Read and write operations without a call to a positioning function (fseek or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); - - check("void foo(file f, bool read) {\n" - " blob data = 0;\n" - " if(read)\n" - " fread(f, data);\n" - " else\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file f) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " fflush(f);\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file f) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " rewind(f);\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("void foo(file f, int pos) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " fseek(f, pos, SEEK_SET);\n" //SEEK_SET should be known. is also referenced in the fseek documentation - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo(file f) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " fseek(f, 0, SEEK_SET);\n" //SEEK_SET should be known. is also referenced in the fseek documentation - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - */ - - check("void foo(file f) {\n" - " blob data = 0;\n" - " fread(f, data);\n" - " long pos = ftell(f);\n" - " fwrite(f, data);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:5]: (error) Read and write operations without a call to a positioning function (fseek or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); - - // #6452 - member functions - /* knownBug TFS(#158013) SEEK_CUR should be known (see documentation of fseek) - check("class FileStream\n" - "{\n" - " void insert(const blob &writeData, int readCount) {\n" - " blob data = 0;\n" - " int charactersRead = fread(f, data, readCount);\n" - " fseek(f, 0, SEEK_CUR);\n" - " fwrite(f, writeData);\n" - " }\n" - " file f;\n" - "};"); - ASSERT_EQUALS("", errout.str()); - */ - - check("class FileStream {\n" - " void insert(const blob &writeData, int readCount){\n" - " blob data = 0;\n" - " int charactersRead = fread(f, data, readCount);\n" - " unknown(0);\n" - " fwrite(f, writeData);\n" - " }\n" - " file f;\n" - "};\n"); - ASSERT_EQUALS("", errout.str()); - - check("class FileStream {\n" - " void insert(const blob &writeData, int readCount){\n" - " blob data = 0;\n" - " int bytesRead = fread(f, data, readCount); \n" - " known(0);\n" - " fwrite(f, writeData);\n" - " }\n" - " file f;\n" - "};\n" - "void known(int i){}"); - ASSERT_EQUALS("[scripts/test.ctl:6]: (error) Read and write operations without a call to a positioning function (fseek or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); - - check("class FileStream {\n" - " void insert(int readCount){\n" - " blob data = 0;\n" - " int bytesRead = fread(f, X.data(), readCount);\n" - " known(0);\n" - " fwrite(f, X.data());\n" - " }\n" - " file f;\n" - "};\n" - "void known(int i){}"); - ASSERT_EQUALS("[scripts/test.ctl:6]: (error) Read and write operations without a call to a positioning function (fseek or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); - } - - void seekOnAppendedFile() - { - /* knownBug TFS(#158013) - check("void foo() {\n" - " file f = fopen(\"\", \"a+\");\n" - " fseek(f, 0, SEEK_SET);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo() {\n" - " file f = fopen(\"\", \"w\");\n" - " fseek(f, 0, SEEK_SET);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo() {\n" - " file f = fopen(\"\", \"a\");\n" - " fseek(f, 0, SEEK_SET);\n" - "}"); - ASSERT_EQUALS("[test.cpp:3]: (warning) Repositioning operation performed on a file opened in append mode has no effect.\n", errout.str()); - */ - - check("void foo() {\n" - " file f = fopen(\"\", \"a\");\n" - " fflush(f);\n" - "}"); - ASSERT_EQUALS("", errout.str()); // #5578 - /* knownBug TFS(#158013) - check("void foo() {\n" - " file f = fopen(\"\", \"a\");\n" - " fclose(f);\n" - " f = fopen(\"\", \"r\");\n" - " fseek(f, 0, SEEK_SET);\n" - "}"); - ASSERT_EQUALS("", errout.str()); // #6566 - */ - } - - void fflushOnInputStream() - { - check("void foo(file& f, string path) {\n" - " f = fopen(path, \"r\");\n" - " fflush(f);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems.\n", errout.str()); - - check("void foo(file& f, string path) {\n" - " f = fopen(path, \"w\");\n" - " fflush(f);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - - check("void foo(file& f) {\n" - " fflush(f);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void testScanf1() - { - check("void foo(string foo, string bar) {\n" - " int a;\n" - " file f = fopen(\"test\", \"r\");\n" - " a = fscanf(f, \"aa %s\", bar);\n" - " sscanf(foo, \"%[^~]\", bar);\n" - " fclose(f);\n" - "}"); - ASSERT_EQUALS("", errout.str()); - } - - void testScanfArgument() - { - check("void foo(file &f, string foo, string &ref, string ip_port, int &a, int &port) {\n" - " sscanf(foo, \"%1d\", a);\n" - " fscanf(f, \"%7ms\", ref);\n" // #3461 - " sscanf(ip_port, \"%*[^:]:%4d\", port);\n" // #3468 - "}"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("void foo(file &f, int foo, string bar) {\n" - " fscanf(f, \"%1d\", foo, bar);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) fscanf format string requires 1 parameter but 2 are given.\n", errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo(string foo, int bar) {\n" - " sscanf(foo, \"%1d%1d\", bar);\n" - "}"); - ASSERT_EQUALS("[test.cpp:2]: (error) sscanf format string requires 2 parameters but only 1 is given.\n", errout.str()); - */ - } - - void testPrintfArgument() - { - /* knownBug TFS(#158013) - check("void foo(file f, string str1, string str2) {\n" - " fprintf(f,\"%u%s\");\n" - " sprintf(str1, \"%-*.*s\", 32, str2);\n" // #3364 - "}"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (error) fprintf format string requires 2 parameters but only 0 are given.\n" - "[scripts/test.ctl:3]: (error) sprintf format string requires 3 parameters but only 2 are given.\n", - errout.str()); - */ - - check("void foo(file f, int indent, string str1) {\n" - " fprintf(f,\"%PRId64\", 123);\n" - " fprintf(f, \"error: %m\");\n" // #3339 - " fprintf(f, \"%*cText.\", indent, ' ');\n" // #3313 - " sprintf(str1, \"%*\", 32);\n" // #3364 - "}"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("struct Bar\n" - "{\n" - " int i;\n" - "};\n" - "struct Baz\n" - "{\n" - " int i;\n" - "};\n" - "class Foo\n" - "{\n" - " double d;\n" - " vector bar;\n" - " Baz baz;\n" - "};\n" - "dyn_int a;\n" - "vector f;\n" - "void foo(string str1, const Foo foo)\n" - "{\n" - " sprintf(str1, \"%d %f %f %d %f %f\",\n" - " foo.d, foo.bar[0].i, a[0],\n" - " f[0].d, f[0].baz.i, f[0].bar[0].i);\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:19]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'double'.\n" - "[scripts/test.ctl:19]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:19]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\n" - "[scripts/test.ctl:19]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'double'.\n" - "[scripts/test.ctl:19]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'int'.\n" - "[scripts/test.ctl:19]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("short f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed short'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed short'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("int f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%d %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("uint f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%u %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("long f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%ld %u %lu %I64u %I64d %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 4) requires 'unsigned __int64' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 5) requires '__int64' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'signed long'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("ulong f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%lu %d %ld %I64d %I64u %f %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 4) requires '__int64' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 5) requires 'unsigned __int64' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 6) requires 'double' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 7) requires 'long double' but the argument type is 'unsigned long'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 8) requires an address but the argument type is 'unsigned long'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("float f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'float'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'float'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("double f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%f %d %ld %u %lu %I64d %I64u %Lf %p\", f(), f(), f(), f(), f(), f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %u in format string (no. 4) requires 'unsigned int' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 5) requires 'unsigned long' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %I64d in format string (no. 6) requires '__int64' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 7) requires 'unsigned __int64' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 8) requires 'long double' but the argument type is 'double'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 9) requires an address but the argument type is 'double'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("int f() { return 0; }\n" - "void foo(string str1) { sprintf(str1, \"%I64d %I64u %I64x %d\", f(), f(), f(), f()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %I64d in format string (no. 1) requires '__int64' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %I64u in format string (no. 2) requires 'unsigned __int64' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %I64x in format string (no. 3) requires 'unsigned __int64' but the argument type is 'signed int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("struct Fred { int i; };\n" - "Fred f;\n" - "void foo(string str1) { sprintf(str1, \"%d %u %lu %f %Lf %p\", f.i, f.i, f.i, f.i, f.i, f.i); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("struct Fred { uint u; };\n" - "Fred f;\n" - "void foo(string str1) { sprintf(str1, \"%u %d %ld %f %Lf %p\", f.u, f.u, f.u, f.u, f.u, f.u); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("struct Fred { uint ui() { return 0; } };\n" - "Fred f;\n" - "void foo(string str1) { sprintf(str1, \"%u %d %ld %f %Lf %p\", f.ui(), f.ui(), f.ui(), f.ui(), f.ui(), f.ui()); }"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'unsigned int'.\n" - "[scripts/test.ctl:2]: (warning) %p in format string (no. 6) requires an address but the argument type is 'unsigned int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("struct Fred { int i; };\n" - "Fred bar() { return Fred(); }\n" - "void foo(string str1) { sprintf(str1, \"%d %u %lu %f %Lf %p\", bar().i, bar().i, bar().i, bar().i, bar().i, bar().i); }"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:3]: (warning) %lu in format string (no. 3) requires 'unsigned long' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:3]: (warning) %Lf in format string (no. 5) requires 'long double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:3]: (warning) %p in format string (no. 6) requires an address but the argument type is 'signed int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("struct Base { int length() { } };\n" - "struct Derived : Base { };\n" - "void foo(Derived d, string str1)\n" - "{\n" - " sprintf(str1, \"%f\", d.length());\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:5]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("vector v;\n" - "void foo(string str1) {\n" - " sprintf(str1, \"%d %u %f\", v[0], v[0], v[0]);\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'signed int'.\n", - errout.str()); - */ - - // #4999 (crash) - check("int bar(int a){ return a; }\n" - "void foo(string str1) {\n" - " sprintf(str1, \"%d\", bar(0));\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("void foo(string str1, int i) {\n" - " dyn_long l = makeDynLong();\n" - " sprintf(str1, \"%d %x %u %f\", l[i], l[i], l[i], l[i]);\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:3]: (warning) %x in format string (no. 2) requires 'unsigned int' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'signed long'.\n" - "[scripts/test.ctl:3]: (warning) %f in format string (no. 4) requires 'double' but the argument type is 'signed long'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("void f(string str1)\n" // #5104 - "{\n" - " vector v1 = makeDynInt(1, 0);\n" - " sprintf(str1, \"%d\", v1[0]);\n" - " vector v2 = makeDynInt(1, 0);\n" - " sprintf(str1, \"%d\", v2[0]);\n" - " vector v3 = makeDynUInt(1, 0);\n" - " sprintf(str1, \"%u\", v3[0]);\n" - " vector v4 = makeDynUInt(1, 0);\n" - " sprintf(str1, \"%x\", v4[0]);\n" - " vector v5 = makeDynDouble(1, 0);\n" - " sprintf(str1, \"%f\", v5[0]);\n" - " vector v6 = makeDynBool(1, 0);\n" - " sprintf(str1, \"%u\", v6[0]);\n" - " vector v7 = makeDynString(1, 0);\n" - " sprintf(str1, \"%s\", v7[0]);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - */ - /* knownBug TFS(#158013) - check("vector v;\n" // #5151 - "void foo(string str1) {\n" - " sprintf(str1, \"%c %u %f\", v.at(32), v.at(32), v.at(32));\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char'.\n" - "[scripts/test.ctl:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'char'.\n", - errout.str()); - */ - - // #5486 - check("void foo(string str1)\n" - "{\n" - " int test = 0;\n" - " sprintf(str1, \"%zd\", test);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - // #6009 - /* knownBug TFS(#158013) - check("string StringByReturnValue(){}\n" - "int IntByReturnValue(){}\n" - "void MyFunction(string str1)\n" - "{\n" - " sprintf(str1, \"%s - %s\", StringByReturnValue(), IntByReturnValue());\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:4]: (warning) %s in format string (no. 1) requires 'char *' but the argument type is 'std::string'.\n" - "[scripts/test.ctl:4]: (warning) %s in format string (no. 2) requires 'char *' but the argument type is 'signed int'.\n", - errout.str()); - */ - - // Ticket #7445 - check("struct S { uint x; };\n" - "S s = new S(0);\n" - "void foo(string str1)\n" - "{\n" - " sprintf(str1, \"%d\", s.x);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - - // Ticket #7601 - /* knownBug TFS(#158013) - check("void foo(string str1, char c, short s, int i, uint ui, long l, ulong ul)\n" - "{\n" - " sprintf(str1, \"%hhd %hhd %hhd %hhd %hhd %hhd\", c, s, i, ui, l, ul);\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:2]: (warning) %hhd in format string (no. 2) requires 'char' but the argument type is 'short'.\n" - "[test.cpp:2]: (warning) %hhd in format string (no. 3) requires 'char' but the argument type is 'int'.\n" - "[test.cpp:2]: (warning) %hhd in format string (no. 4) requires 'char' but the argument type is 'uint'.\n" - "[test.cpp:2]: (warning) %hhd in format string (no. 5) requires 'char' but the argument type is 'long'.\n" - "[test.cpp:2]: (warning) %hhd in format string (no. 6) requires 'char' but the argument type is 'ulong'.\n", - errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo(string str1, char c, short s, int i, uint ui, long l, ulong ul)\n" - "{\n" - " sprintf(str1, \"%hd %hd %hd %hd %hd %hd\", c, s, i, ui, l, ul);\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:2]: (warning) %hd in format string (no. 1) requires 'short' but the argument type is 'char'.\n" - "[scripts/test.ctl:2]: (warning) %hd in format string (no. 3) requires 'short' but the argument type is 'int'.\n" - "[scripts/test.ctl:2]: (warning) %hd in format string (no. 4) requires 'short' but the argument type is 'uint'.\n" - "[scripts/test.ctl:2]: (warning) %hd in format string (no. 5) requires 'short' but the argument type is 'long'.\n" - "[scripts/test.ctl:2]: (warning) %hd in format string (no. 6) requires 'short' but the argument type is 'ulong'.\n", - errout.str()); - */ - - // #7837 - Use ValueType for function call - check("struct S\n" - "{\n" - " double f;\n" - "};\n" - "void foo(string str1, S x)\n" - "{\n" - " sprintf(str1, \"%f\", x.f(4.0));\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } - - void testPosixPrintfScanfParameterPosition() // #4900 - No support for parameters in format strings - { - /* knownBug TFS(#158013) //inconclusive should be set to false, but an inconclusive message is still returned - check("void foo(string str1)\n" - "{\n" - " int bar;\n" - " sprintf(str1, \"%1$d\", 1);\n" - " sprintf(str1, \"%1$d, %d, %1$d\", 1, 2);\n" - " sscanf(str1, \"%1$d\", bar);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - */ - /* knownBug TFS(#158013) - check("void foo(string str1) {\n" - " int bar;\n" - " sprintf(str1, \"%1$d\");\n" - " sprintf(str1, \"%1$d, %d, %4$d\", 1, 2, 3);\n" - " sscanf(str1, \"%2$d\", bar);\n" - " sprintf(str1, \"%0$f\", 0.0);\n" - "}"); - ASSERT_EQUALS("[scripts/test.ctl:3]: (error) sprintf format string requires 1 parameter but only 0 are given.\n" - "[scripts/test.ctl:4]: (warning) sprintf: referencing parameter 4 while 3 arguments given\n" - "[scripts/test.ctl:5]: (warning) sscanf: referencing parameter 2 while 1 arguments given\n" - "[scripts/test.ctl:6]: (warning) sprintf: parameter positions start at 1, not 0\n", - errout.str()); - */ - } - - void testTernary() // ticket #6182 - { - check("void test(string str1, const string &val) {\n" - " sprintf(str1, \"%s\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } - - void testUnsignedConst() // ticket #6321 - { - check("void test(string str1) {\n" - " const unsigned x = 5;\n" - " sprintf(str1, \"%u\", x);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } - - void testAstType() // ticket #7014 - { - check("void test() {\n" - " printf(\"%c\", \"hello\"[0]);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - } - - void testPrintfTypeAlias1() - { - check("using INT = int;\n" - "INT i;\n" - "const INT pci;\n" - "void foo(string str1) {\n" - " sprintf(str1, \"%d %p\", i, pci);\n" - "}\n"); - ASSERT_EQUALS("", errout.str()); - /* knownBug TFS(#158013) - check("using INT = int;\n" - "INT i;\n" - "const INT pci;\n" - "void foo(string str1) {\n" - " sprintf(str1, \"%f %f\", i, pci);\n" - "}\n"); - ASSERT_EQUALS("[scripts/test.ctl:8]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n" - "[scripts/test.ctl:8]: (warning) %f in format string (no. 2) requires 'double' but the argument type is 'const signed int'.\n", - errout.str()); - */ - } -}; - -void main() -{ - TestIO test; - test.run(); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/Qg.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/Qg.ctl deleted file mode 100644 index e7d549c7..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/Qg.ctl +++ /dev/null @@ -1,72 +0,0 @@ -/*! - * @brief Tests for class: Qg - * - * @author lschopp - */ - -//-------------------------------------------------------------------------------- -// used libraries (#uses) -#uses "classes/QualityGates/Qg" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -class TstQg : StTest -{ - public dyn_string _getAllTcIds() - { - // list with our testcases - return makeDynString("Qg::get/setId()", "Qg::getAllIds()", "Qg::idToNum()"); - } - - public int _startTest() - { - const string tcId = _getTcId(); - - switch( tcId ) - { - case "Qg::get/setId()": - { - oaUnitAssertEqual(tcId, Qg::getId(), ""); - Qg::setId("some one ID"); - oaUnitAssertEqual(tcId, Qg::getId(), "some one ID"); - return 0; - } - case "Qg::getAllIds()": - { - oaUnitAssertEqual(tcId, Qg::getAllIds(), makeDynString("QgStaticCheck_Pictures", "QgStaticCheck_Scripts", "QgStaticCheck_Panels", - "QgSyntaxCheck", - "QgStaticCheck_OverloadedFiles", "Documentation", - "UnitTests", "CtrlCoverage", "QgCtrlppCheck", - "QgStaticCheck_Libs")); - return 0; - } - case "Qg::idToNum()": - { - Qg::setId("some one ID"); - oaUnitAssertEqual(tcId, Qg::idToNum(), 0); - - Qg::setId(Qg::getAllIds()[1]); - oaUnitAssertEqual(tcId, Qg::idToNum(), 1); - - Qg::setId(Qg::getAllIds()[dynlen(Qg::getAllIds())]); - oaUnitAssertEqual(tcId, Qg::idToNum(), dynlen(Qg::getAllIds())); - return 0; - } - } - - return -1; - } -}; - -//-------------------------------------------------------------------------------- -main() -{ - TstQg test = TstQg(); - - test.startAll(); - - exit(0); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/WinCCOA/FileSys/Dir.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/WinCCOA/FileSys/Dir.ctl deleted file mode 100644 index 376ffad0..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/WinCCOA/FileSys/Dir.ctl +++ /dev/null @@ -1,91 +0,0 @@ -/*! - * @brief Tests for class: Dir - * - * - * @author lschopp - */ - -//-------------------------------------------------------------------------------- -// used libraries (#uses) -#uses "classes/FileSys/Dir" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -class TstDir : StTest -{ - public dyn_string _getAllTcIds() - { - // list with our testcases - return makeDynString("Dir"); - } - - public int _startTest() - { - const string tcId = _getTcId(); - - switch( tcId ) - { - case "Dir": - { - Dir dir = Dir(); - Dir dir2 = Dir("non existing/ path"); - - oaUnitAssertEqual(tcId, dir.getDirPath(), ""); - oaUnitAssertEqual(tcId, dir2.getDirPath(), makeNativePath("non existing/ path")); - - oaUnitAssertFalse(tcId, dir.exists()); - oaUnitAssertFalse(tcId, dir2.exists()); - - dir.setDirPath(PROJ_PATH); - oaUnitAssertEqual(tcId, dir.getDirPath(), makeNativePath(PROJ_PATH)); - oaUnitAssertTrue(tcId, dir.exists()); - - dir.setDirPath(PROJ_PATH + createUuid()); - oaUnitAssertFalse(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.mk(), 0); - oaUnitAssertTrue(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.mk(), 0); - oaUnitAssertTrue(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.rm(), 0); - oaUnitAssertFalse(tcId, dir.exists()); - - string dirPath = dir.getDirPath(); - dir.setDirPath(dirPath + "/a/b/123/c"); - oaUnitAssertFalse(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.mk(), 0); - oaUnitAssertTrue(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.rm(), 0); - oaUnitAssertFalse(tcId, dir.exists()); - - - dir.setDirPath(dirPath); - oaUnitAssertTrue(tcId, dir.exists()); - oaUnitAssertEqual(tcId, dir.rm(), 0); - oaUnitAssertFalse(tcId, dir.exists()); - - oaUnitAssertEqual(tcId, dir.rm(), -1); - oaUnitAssertEqual(tcId, dir2.rm(), -1); - - dir.setDirPath(""); - oaUnitAssertEqual(tcId, dir.rm(), -1); - - return 0; - } - } - - return -1; - } -}; - -//-------------------------------------------------------------------------------- -main() -{ - TstDir test = TstDir(); - - test.startAll(); - - exit(0); -} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/fileSys.ctl b/WinCCOA_QualityChecks_tests/scripts/tests/libs/fileSys.ctl deleted file mode 100644 index e7708cc1..00000000 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/fileSys.ctl +++ /dev/null @@ -1,53 +0,0 @@ -/*! - * @brief Tests for lib: fileSys - * - * @author lschopp - */ - -//-------------------------------------------------------------------------------- -// used libraries (#uses) -#uses "fileSys" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ - -//-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -class TstFileSys : StTest -{ - public dyn_string _getAllTcIds() - { - // list with our testcases - return makeDynString("fileSys getFileNamesRecursive"); - } - - public int _startTest() - { - const string tcId = _getTcId(); - - switch( tcId ) - { - case "fileSys getFileNamesRecursive": - { - oaUnitAssertEqual(tcId, getFileNamesRecursive(""), makeDynString()); - oaUnitAssertEqual(tcId, getFileNamesRecursive("non existin path"), makeDynString()); - oaUnitAssertEqual(tcId, dynlen(getFileNamesRecursive(PROJ_PATH, "panel*")), 0); - oaUnitAssertEqual(tcId, dynlen(getFileNamesRecursive(PROJ_PATH, "*.ctl", FILTER_DIRS)), 0); - oaUnitAssertGreater(tcId, dynlen(getFileNamesRecursive(PROJ_PATH, "*.ctl")), 0); - return 0; - } - } - - return -1; - } -}; - -//-------------------------------------------------------------------------------- -main() -{ - TstFileSys test = TstFileSys(); - - test.start(); - - exit(0); -} diff --git a/WinCC_OA_Test/Projects/Global/readme.md b/WinCC_OA_Test/Projects/Global/readme.md new file mode 100644 index 00000000..7952db43 --- /dev/null +++ b/WinCC_OA_Test/Projects/Global/readme.md @@ -0,0 +1,3 @@ +# Global projects + +this project will be load in all test projects diff --git a/WinCC_OA_Test/Projects/TfCustomizedQG/config/config.level b/WinCC_OA_Test/Projects/TfCustomizedQG/config/config.level new file mode 100644 index 00000000..b4bab29b --- /dev/null +++ b/WinCC_OA_Test/Projects/TfCustomizedQG/config/config.level @@ -0,0 +1,3 @@ +[ctrl] +LoadCtrlLibs = "classes/testFramework/HookTfTestRunner.ctl" +LoadCtrlLibs = "classes/testFramework/testProject/HookTfTestProject.ctl" \ No newline at end of file diff --git a/WinCC_OA_Test/Projects/TfCustomizedQG/config/progs b/WinCC_OA_Test/Projects/TfCustomizedQG/config/progs new file mode 100644 index 00000000..78a8aa60 --- /dev/null +++ b/WinCC_OA_Test/Projects/TfCustomizedQG/config/progs @@ -0,0 +1,18 @@ +version 1 + +auth "" "" +#Manager | Start | SecKill | Restart# | ResetMin | Options +WCCILpmon | manual | 30 | 3 | 1 | +WCCOActrl | manual | 30 | 2 | 2 |testRunner.ctl Regressions-tests -n +WCCOActrl | manual | 30 | 2 | 2 |oaTestParsers/jsonToQc.ctl -n +WCCOActrl | manual | 30 | 2 | 2 |oaTestParsers/jsonToJUnit.ctl -n +WCCOActrl | manual | 30 | 2 | 2 |astyle.ctl -n +WCCOAui | manual | 30 | 2 | 2 |-n -m gedi +WCCOAui | always | 30 | 2 | 2 |-p vision/tf/main.pnl -n +WCCOActrl | manual | 30 | 2 | 2 |getBestMatch.ctl -n Subprojects/TestFramework/ UiFiles/scripts/libs/classes/userManagement +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgScriptsCheck.ctl scripts C:/ws/WinCCOA/develop_3.x/UiFiles/scripts -n +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgScriptsCheck.ctl libs C:/ws/WinCCOA/develop_3.x/UiFiles/scripts/libs -n +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgOverloadedFilesCheck.ctl -n +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgPanelsCheck.ctl C:/ws/WinCCOA/develop_3.x/UiFiles/panels -n +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgPicturesCheck.ctl C:/ws/WinCCOA/develop_3.x/UiFiles/pictures -n +WCCOActrl | manual | 30 | 2 | 2 |QualityGates/StaticTests/QgCtrlppCheck.ctl C:/ws/WinCCOA/develop_3.x/UiFiles/scripts -n diff --git a/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/HookTfTestRunner.ctl b/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/HookTfTestRunner.ctl new file mode 100644 index 00000000..0d29d601 --- /dev/null +++ b/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/HookTfTestRunner.ctl @@ -0,0 +1,110 @@ +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/testFramework/TfTestRunner" + +//-------------------------------------------------------------------------------- +// declare variables and constants + + +//-------------------------------------------------------------------------------- +/** + * @brief This class is hook for TfTestRunner + */ +class HookTfTestRunner : TfTestRunner +{ +//-------------------------------------------------------------------------------- +//@public members +//-------------------------------------------------------------------------------- + + //------------------------------------------------------------------------------ + /** + * @brief Function setups the test environment. + * @details Customized version of TfTestRunner::setupEnvironment() + * We need to register all installed no deploy packages here and set the helper result path + * @return Error code. Returns 0 when successful. Otherwise -1. + */ + public int setupEnvironment() + { + if (TfTestRunner::setupEnvironment()) + return -1; + + string currentTestSuite = getenv("CURRENT_TEST_SUITE"); + + if (currentTestSuite == "") + currentTestSuite = "__TF__"; + + string resDir = TfFileSys::getTestInstallPath(TfFileSysPath::ResultsPartly) + makeNativePath("/" + currentTestSuite + "/" + PROJ + "/"); + + if (!isdir(resDir)) + mkdir(resDir); + + // if (TstNoPosix::isStaredByJenkins()) + if (currentTestSuite != "__TF__") + { + oaUnitSetup(resDir + "result.json", makeMapping("Format", (int)OaTestResultFileFormat::JsonFull)); + TfErrHdl::outputFormat = OaTestResultFileFormat::JsonFull; + } + + if (gualityGates.isRegistered()) + { + DebugTN(__FUNCTION__, "Is registered at the moment", gualityGates); + return 0; + } + + gualityGates.setInstallDir(dirName(TfFileSys::getTestInstallPath())); + gualityGates.setRunnable(false); + gualityGates.registerProj(); + return 0; + } + + //------------------------------------------------------------------------------ + public void onExit(const anytype &exitCode) + { + gualityGates.unregisterProj(); + oaUnitAssertEqual("WinCC_OA_Test_Validation", (int)exitCode, 0, "verify exit code"); + oaUnitTearDown(); + TfTestRunner::onExit(exitCode); + } + +//-------------------------------------------------------------------------------- +//@protected members +//-------------------------------------------------------------------------------- + public static int registerNoDeployPacket(const string &packetName, const string installDir = WINCCOA_PATH) + { + ProjEnvProject packet = ProjEnvProject(packetName); + packet.setInstallDir(installDir); + packet.setVersion(VERSION); + packet.setRunnable(FALSE); + packet.setName("noDeploy " + packetName); + + // check if a project directory exist. + if (!packet.exists()) + { + DebugTN(__FUNCTION__, getenv("NODE_NAME"), "packet does not exist", packet); + return -1; + } + + // re-register project + if (packet.isRegistered()) + { + DebugFTN(__FUNCTION__, __FUNCTION__, "packet is registered", packetName); + return 0; + } + + if (packet.registerProj()) + { + DebugTN(__FUNCTION__, getenv("NODE_NAME"), "can NOT register packet", packet); + return -2; + } + + DebugFTN(__FUNCTION__, __FUNCTION__, "packet registered", packetName); + + return 0; + } + +//-------------------------------------------------------------------------------- +//@private members +//-------------------------------------------------------------------------------- + //------------------------------------------------------------------------------ + ProjEnvProject gualityGates = ProjEnvProject("WinCCOA_QualityChecks"); +}; diff --git a/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/testProject/HookTfTestProject.ctl b/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/testProject/HookTfTestProject.ctl new file mode 100644 index 00000000..f31e331e --- /dev/null +++ b/WinCC_OA_Test/Projects/TfCustomizedQG/scripts/libs/classes/testFramework/testProject/HookTfTestProject.ctl @@ -0,0 +1,22 @@ +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/testFramework/testProject/TfTestProject" + +//-------------------------------------------------------------------------------- +/*! + * Hook class of TfTestProject: + Changes here overrides TfTestProject workflow + */ +class HookTfTestProject : TfTestProject +{ +//-------------------------------------------------------------------------------- +//@protected members +//-------------------------------------------------------------------------------- + + protected dyn_string _getDefaultSubProjects() + { + dyn_string list = TfTestProject::_getDefaultSubProjects(); + dynAppend(list, "WinCCOA_QualityChecks"); + return list; + } +}; diff --git a/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/FileSys/QgDir.ctl b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/FileSys/QgDir.ctl new file mode 100644 index 00000000..d2f127af --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/FileSys/QgDir.ctl @@ -0,0 +1,82 @@ +/*! + * @brief Tests for class: QgDir + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/FileSys/QgDir" /*!< tested object */ +#uses "classes/oaTest/OaTest" + +//-------------------------------------------------------------------------------- +class TstDir : OaTest +{ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("QgDir"); + } + + protected int startTestCase(const string tcId) + { + switch( tcId ) + { + case "QgDir": + { + QgDir dir = QgDir(); + QgDir dir2 = QgDir("non existing/ path"); + + assertEqual(dir.getDirPath(), ""); + assertEqual(dir2.getDirPath(), makeNativePath("non existing/ path")); + + assertFalse(dir.exists()); + assertFalse(dir2.exists()); + + dir.setDirPath(PROJ_PATH); + assertEqual(dir.getDirPath(), makeNativePath(PROJ_PATH)); + assertTrue(dir.exists()); + + dir.setDirPath(PROJ_PATH + createUuid()); + assertFalse(dir.exists()); + assertEqual(dir.mk(), 0); + assertTrue(dir.exists()); + assertEqual(dir.mk(), 0); + assertTrue(dir.exists()); + assertEqual(dir.rm(), 0); + assertFalse(dir.exists()); + + string dirPath = dir.getDirPath(); + dir.setDirPath(dirPath + "/a/b/123/c"); + assertFalse(dir.exists()); + assertEqual(dir.mk(), 0); + assertTrue(dir.exists()); + assertEqual(dir.rm(), 0); + assertFalse(dir.exists()); + + + dir.setDirPath(dirPath); + assertTrue(dir.exists()); + assertEqual(dir.rm(), 0); + assertFalse(dir.exists()); + + assertEqual(dir.rm(), -1); + assertEqual(dir2.rm(), -1); + + dir.setDirPath(""); + assertEqual(dir.rm(), -1); + + return 0; + } + } + + return -1; + } +}; + +//-------------------------------------------------------------------------------- +main() +{ + TstDir test; + test.startAll(); +} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Math/Math.ctl b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Math/Math.ctl similarity index 58% rename from WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Math/Math.ctl rename to WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Math/Math.ctl index 1f1a25a5..6d06695f 100644 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Math/Math.ctl +++ b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Math/Math.ctl @@ -7,34 +7,32 @@ //-------------------------------------------------------------------------------- // used libraries (#uses) #uses "classes/Math/Math" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ +#uses "classes/oaTest/OaTest" //-------------------------------------------------------------------------------- // declare variables and constans //-------------------------------------------------------------------------------- -class TstMath : StTest +class TstMath : OaTest { - public dyn_string _getAllTcIds() + public dyn_string getAllTestCaseIds() { // list with our testcases return makeDynString("Math::getPercent()"); } - public int _startTest() + protected int startTestCase(const string tcId) { - const string tcId = _getTcId(); - switch( tcId ) { case "Math::getPercent()": { - oaUnitAssertEqual(tcId, Math::getPercent(100, 0), 0.0); - oaUnitAssertEqual(tcId, Math::getPercent(100, 5), 5.0); - oaUnitAssertEqual(tcId, Math::getPercent(500, 5), 1.0); - oaUnitAssertEqual(tcId, Math::getPercent(100, 100), 100.0); - oaUnitAssertEqual(tcId, Math::getPercent(0, 100), 0.0); - oaUnitAssertEqual(tcId, Math::getPercent(-100, 1), -1.0); + assertEqual(Math::getPercent(100, 0), 0.0); + assertEqual(Math::getPercent(100, 5), 5.0); + assertEqual(Math::getPercent(500, 5), 1.0); + assertEqual(Math::getPercent(100, 100), 100.0); + assertEqual(Math::getPercent(0, 100), 0.0); + assertEqual(Math::getPercent(-100, 1), -1.0); return 0; } } diff --git a/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/QualityGates/Qg.ctl b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/QualityGates/Qg.ctl new file mode 100644 index 00000000..d0155ac1 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/QualityGates/Qg.ctl @@ -0,0 +1,49 @@ +/*! + * @brief Tests for class: Qg + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/Qg" /*!< tested object */ +#uses "classes/oaTest/OaTest" + +//-------------------------------------------------------------------------------- +// declare variables and constans + +//-------------------------------------------------------------------------------- +class TstQg : OaTest +{ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("Qg::get/setId()"); + } + + protected int startTestCase(const string tcId) + { + switch( tcId ) + { + case "Qg::get/setId()": + { + assertEqual(Qg::getId(), ""); + Qg::setId("some one ID"); + assertEqual(Qg::getId(), "some one ID"); + return 0; + } + } + + return -1; + } +}; + +//-------------------------------------------------------------------------------- +main() +{ + TstQg test = TstQg(); + + test.startAll(); + + exit(0); +} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Variables/Float.ctl b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Variables/Float.ctl similarity index 57% rename from WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Variables/Float.ctl rename to WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Variables/Float.ctl index 7d733de8..e2624db6 100644 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/Variables/Float.ctl +++ b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/classes/Variables/Float.ctl @@ -7,25 +7,23 @@ //-------------------------------------------------------------------------------- // used libraries (#uses) #uses "classes/Variables/Float" /*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ +#uses "classes/oaTest/OaTest" //-------------------------------------------------------------------------------- // declare variables and constans //-------------------------------------------------------------------------------- -class TstFloat : StTest +class TstFloat : OaTest { - public dyn_string _getAllTcIds() + public dyn_string getAllTestCaseIds() { // list with our testcases return makeDynString("Float"); } - public int _startTest() + protected int startTestCase(const string tcId) { - const string tcId = _getTcId(); - switch( tcId ) { case "Float": @@ -35,26 +33,26 @@ class TstFloat : StTest f2 = 33; Float f = Float(f1 / f2); - oaUnitAssertEqual(tcId, (string)f.round(), "3.03"); - oaUnitAssertEqual(tcId, (string)f.round(4), "3.0303"); - oaUnitAssertEqual(tcId, (string)f.round(0), "3"); + assertEqual((string)f.round(), "3.03"); + assertEqual((string)f.round(4), "3.0303"); + assertEqual((string)f.round(0), "3"); f.set(f2 / f1); - oaUnitAssertEqual(tcId, (string)f.round(), "0.33"); + assertEqual((string)f.round(), "0.33"); f.set(0); - oaUnitAssertEqual(tcId, (string)f.round(), "0"); + assertEqual((string)f.round(), "0"); f.set(1.4356); - oaUnitAssertEqual(tcId, (string)f.round(), "1.44"); - oaUnitAssertEqual(tcId, f.get(), 1.4356); + assertEqual((string)f.round(), "1.44"); + assertEqual(f.get(), 1.4356); f.set(1.4323); - oaUnitAssertEqual(tcId, (string)f.round(), "1.43"); - oaUnitAssertEqual(tcId, f.get(), 1.4323); + assertEqual((string)f.round(), "1.43"); + assertEqual(f.get(), 1.4323); f.set(1.4323); - oaUnitAssertEqual(tcId, (string)f.round(-1), "1"); + assertEqual((string)f.round(-1), "1"); return 0; } diff --git a/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/fileSys.ctl b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/fileSys.ctl new file mode 100644 index 00000000..3e0d6649 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_Common/sub_unit/scripts/tests/libs/fileSys.ctl @@ -0,0 +1,46 @@ +/*! + * @brief Tests for lib: fileSys + * + * @author lschopp + */ + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "fileSys" /*!< tested object */ +#uses "classes/oaTest/OaTest" + +//-------------------------------------------------------------------------------- +class TstFileSys : OaTest +{ + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("fileSys getFileNamesRecursive"); + } + + protected int startTestCase(const string tcId) + { + switch( tcId ) + { + case "fileSys getFileNamesRecursive": + { + fclose(fopen(PROJ_PATH + LIBS_REL_PATH + "dummy.ctl", "w")); + assertEqual(getFileNamesRecursive(""), makeDynString()); + assertEqual(getFileNamesRecursive("non existin path"), makeDynString()); + assertEqual(dynlen(getFileNamesRecursive(PROJ_PATH + PANELS_REL_PATH, "panel*")), 0); + assertEqual(dynlen(getFileNamesRecursive(PROJ_PATH + LIBS_REL_PATH, "*.ctl", FILTER_DIRS)), 0); + assertEqual(getFileNamesRecursive(PROJ_PATH + LIBS_REL_PATH, "*.ctl"), makeDynString(makeNativePath(PROJ_PATH + LIBS_REL_PATH + "dummy.ctl"))); + return 0; + } + } + + return -1; + } +}; + +//-------------------------------------------------------------------------------- +main() +{ + TstFileSys test; + test.startAll(); +} diff --git a/WinCC_OA_Test/TestSuites/suite_Common/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_Common/testProj.unit.config new file mode 100644 index 00000000..b11b2594 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_Common/testProj.unit.config @@ -0,0 +1,17 @@ +{ + "FILE_VERSION":"1.0", + "ID":"Common_Unit", + "NAME":"Unit tests for common ctrl code", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"tests/libs/fileSys.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/FileSys/QgDir.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/Variables/Float.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/Qg.ctl -n" }, + { "MANAGER_OPTIONS":"tests/libs/classes/Math/Math.ctl -n" } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_Common/testSuite.config b/WinCC_OA_Test/TestSuites/suite_Common/testSuite.config new file mode 100644 index 00000000..b41abebe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_Common/testSuite.config @@ -0,0 +1,7 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for general ctrl code", + "TEST_PROJECTS": [ + "unit" + ] +} \ No newline at end of file diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/ToyotaITC/01.w_Defects/bit_shift.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/ToyotaITC/01.w_Defects/bit_shift.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/ToyotaITC/01.w_Defects/bit_shift.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/ToyotaITC/01.w_Defects/bit_shift.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/arraysize.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/arraysize.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/arraysize.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/arraysize.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/autovar.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/autovar.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/autovar.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/autovar.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/badPerformanceInLoops.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/badPerformanceInLoops.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/badPerformanceInLoops.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/badPerformanceInLoops.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/badPerformanceInLoops_inconclusive.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/badPerformanceInLoops_inconclusive.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/badPerformanceInLoops_inconclusive.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/badPerformanceInLoops_inconclusive.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkBitwiseOnBoolean.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkBitwiseOnBoolean.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkBitwiseOnBoolean.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkBitwiseOnBoolean.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkDivideBoolean.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkDivideBoolean.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkDivideBoolean.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkDivideBoolean.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkIncrementBoolean.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkIncrementBoolean.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkIncrementBoolean.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkIncrementBoolean.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkReturnValueOfFunction.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkReturnValueOfFunction.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkReturnValueOfFunction.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkReturnValueOfFunction.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkUninitVar.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkUninitVar.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkUninitVar.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkUninitVar.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkVaarg.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkVaarg.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkVaarg.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkVaarg.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkio.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkio.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/checkio.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/checkio.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/demo.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/demo.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/demo.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/demo.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/emptyScope.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/emptyScope.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/emptyScope.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/emptyScope.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/ruletest.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/ruletest.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/ruletest.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/ruletest.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/shadowVar.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/shadowVar.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/shadowVar.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/shadowVar.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/suspiciousSemicolon.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/suspiciousSemicolon.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/suspiciousSemicolon.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/suspiciousSemicolon.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_01.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_01.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_01.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_01.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_02.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_02.xml similarity index 99% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_02.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_02.xml index 588c0e5c..68b21b31 100644 --- a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_02.xml +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_02.xml @@ -1,4 +1,3 @@ - diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_03.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_03.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_03.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_03.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_04.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_04.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_04.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_04.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_05.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_05.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_05.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_05.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_06.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_06.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_06.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_06.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_07.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_07.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_07.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_07.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_08.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_08.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/syntaxErrors/missingBracket_08.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/syntaxErrors/missingBracket_08.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/testUndeclaredVariable.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/testUndeclaredVariable.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/testUndeclaredVariable.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/testUndeclaredVariable.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/testlibraryFucntionArgCount.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/testlibraryFucntionArgCount.xml similarity index 83% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/testlibraryFucntionArgCount.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/testlibraryFucntionArgCount.xml index 59c32140..747f6d08 100644 --- a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/testlibraryFucntionArgCount.xml +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/testlibraryFucntionArgCount.xml @@ -8,10 +8,10 @@ - + - + diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/unkownEvaluationOrder.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/unkownEvaluationOrder.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/unkownEvaluationOrder.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/unkownEvaluationOrder.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/unreadVariable.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/unreadVariable.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/unreadVariable.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/unreadVariable.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/variableNaming.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/variableNaming.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/variableNaming.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/variableNaming.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/vector.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/vector.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/vector.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/vector.xml diff --git a/WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/y2038.xml b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/y2038.xml similarity index 100% rename from WinCCOA_QualityChecks_tests/data/ctrlPpCheck/testscripts/y2038.xml rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/data/references/y2038.xml diff --git a/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/QgCtrlppcheckTests.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/QgCtrlppcheckTests.ctl new file mode 100644 index 00000000..afe2d99d --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/QgCtrlppcheckTests.ctl @@ -0,0 +1,171 @@ +// +// CtrlppCheck +// a static code analysis tool for WinCC OA's Ctrl language +// +// Copyright 2022 SIEMENS AG +// +// SPDX-License-Identifier: GPL-3.0-only +// + +//-------------------------------------------------------------------------------- +// used libraries (#uses) +#uses "classes/QualityGates/Tools/CppCheck/CppCheckError" +#uses "fileSys" +#uses "classes/QualityGates/Tools/CppCheck/CppCheck" +#uses "classes/QualityGates/Qg" /*!< tested object */ +#uses "classes/oaTest/OaTest" + +//-------------------------------------------------------------------------------- + +class MockCppCheck : CppCheck +{ + public void checkFile(const string &testFile) + { + string s; + fileToString(testFile, s); + s = substr(s, 0, strpos(s, "\n")); // get fist lines + const string key = "// start options: "; + int idx = strpos(s, key); + if ( idx >= 0 ) + s = " " + substr(s, idx + strlen(key)); + else + s = ""; + + DebugN(__FUNCTION__, testFile, s); + start(testFile + s); + stdErrToErrList(); + } + + public void compare(const string &refFile) + { + DebugTN(__FUNCTION__, refFile); + const string tcId = "Ctrlppcheck." + baseName(refFile); + string str; + bool hasFailedRead = fileToString(refFile, str, "UTF8"); + str = str.trim(); + oaUnitAssertTrue(tcId, hasFailedRead, "Read reference file: " + refFile); + MockCppCheck reference; + + if (str.isEmpty()) + { + oaUnitAbort(tcId, "Reference file " + refFile + " is empty"); + return; + } + reference.strToErrList(str); + +// if ( dynlen(errList) != dynlen(reference.errList) ) +// { +// oaUnitFail(tcId, "Count of error does not match with reference file:\n" + refFile); +// return; +// } + + dyn_string simpleErrStrings; + for(int i = 1; i <= dynlen(reference.errList); i++) + { + reference.errList[i].path = ""; + } + for(int i = 1; i <= dynlen(errList); i++) + { + errList[i].path = ""; + dynAppend(simpleErrStrings, errList[i].toStdErrString()); + } + + + for(int i = 1; i <= dynlen(reference.errList); i++) + { + CppCheckError expErr = reference.errList[i]; + string expErrorStr = expErr.toStdErrString(); + mapping map = makeMapping("ErrMsg", "Ctrlppcheck can not found this error:" + + "\n File:\n" + refFile + + "\n ExpectedValue:\n" + expErrorStr); + if ( expErr.knownBug != "" ) + map["KnownBug"] = expErr.knownBug; + // DebugN(__FUNCTION__, map, expErr); + oaUnitAssertGreater(tcId, dynContains(simpleErrStrings, expErrorStr), 0, map); + } + + + } +}; + +class TstCtrlppcheck : OaTest +{ + public string testScriptPath; + + public dyn_string getAllTestCaseIds() + { + // list with our testcases + return makeDynString("Ctrlppcheck"); + } + + protected int startTestCase(const string tcId) + { + switch( tcId ) + { + case "Ctrlppcheck": + { + const string path = getPath(SCRIPTS_REL_PATH, "testScripts/" + testScriptPath); + if (path.isEmpty()) + { + return abort("Test script does not exists: " + SCRIPTS_REL_PATH + "testScripts/" + testScriptPath); + } + this.info("check file: " + path); + + string refFile = testScriptPath; + strreplace(refFile, ".ctl", ".xml"); + refFile = getPath(DATA_REL_PATH, "references/" + refFile); + + if (refFile.isEmpty() || !isfile(refFile)) + { + return abort("Reference file does not exists."); + } + + const string testFile = makeUnixPath(path); + MockCppCheck check; + check.settings.enableXmlFormat(TRUE); + + check.settings.enableLibCheck = FALSE; + // check.settings.enableHeadersCheck = TRUE; + check.settings.includeSubProjects = TRUE; + check.settings.inconclusive = FALSE; + check.settings.verbose = FALSE; + check.settings.inlineSuppressions = FALSE; + + // load configs + check.settings.addLibraryFile(getPath(DATA_REL_PATH, "DevTools/Base/ctrl.xml")); // general + check.settings.addLibraryFile(getPath(DATA_REL_PATH, "DevTools/Base/ctrl_" + VERSION + ".xml")); // version specific + check.settings.addLibraryFile(getPath(DATA_REL_PATH, "ctrlPpCheck/cfg/__proj__.xml")); // proj specific + + // load rules + check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/ctrl.xml")); // general + check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/ctrl_" + VERSION + ".xml")); // version specific + check.settings.addRuleFile(getPath(DATA_REL_PATH, "ctrlPpCheck/rule/__proj__.xml")); // proj specific + + check.settings.addEnabled("all"); + check.settings.enableXmlFormat(TRUE); + + check.checkFile(testFile); + + check.compare(refFile); + + // make a copy for futher analysis + string resDir = PROJ_PATH + LOG_REL_PATH + "ctrlPpCheck/"; + if ( !isdir(resDir) ) + mkdir(resDir); + + moveFile(PROJ_PATH + LOG_REL_PATH + "cppcheck-result.xml", resDir + baseName(refFile)); + return 0; + } + } + + return -1; + } +}; + +//-------------------------------------------------------------------------------- +main(const string testScriptPath) +{ + TstCtrlppcheck test; + test.testScriptPath = testScriptPath; + test.startAll(); +} diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/ToyotaITC/01.w_Defects/bit_shift.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/ToyotaITC/01.w_Defects/bit_shift.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/ToyotaITC/01.w_Defects/bit_shift.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/ToyotaITC/01.w_Defects/bit_shift.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/arraysize.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/arraysize.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/arraysize.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/arraysize.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/autovar.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/autovar.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/autovar.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/autovar.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/badPerformanceInLoops.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/badPerformanceInLoops.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/badPerformanceInLoops.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/badPerformanceInLoops.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/badPerformanceInLoops_inconclusive.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/badPerformanceInLoops_inconclusive.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/badPerformanceInLoops_inconclusive.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/badPerformanceInLoops_inconclusive.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkBitwiseOnBoolean.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkBitwiseOnBoolean.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkBitwiseOnBoolean.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkBitwiseOnBoolean.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkDivideBoolean.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkDivideBoolean.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkDivideBoolean.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkDivideBoolean.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkIncrementBoolean.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkIncrementBoolean.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkIncrementBoolean.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkIncrementBoolean.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkReturnValueOfFunction.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkReturnValueOfFunction.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkReturnValueOfFunction.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkReturnValueOfFunction.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkUninitVar.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkUninitVar.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkUninitVar.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkUninitVar.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkVaarg.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkVaarg.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkVaarg.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkVaarg.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkio.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkio.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/checkio.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/checkio.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/demo.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/demo.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/demo.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/demo.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/emptyScope.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/emptyScope.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/emptyScope.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/emptyScope.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/ruletest.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/ruletest.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/ruletest.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/ruletest.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/shadowVar.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/shadowVar.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/shadowVar.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/shadowVar.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/suspiciousSemicolon.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/suspiciousSemicolon.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/suspiciousSemicolon.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/suspiciousSemicolon.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_01.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_01.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_01.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_01.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_02.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_02.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_02.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_02.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_03.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_03.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_03.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_03.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_04.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_04.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_04.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_04.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_05.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_05.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_05.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_05.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_06.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_06.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_06.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_06.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_07.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_07.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_07.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_07.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_08.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_08.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/syntaxErrors/missingBracket_08.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/syntaxErrors/missingBracket_08.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/testUndeclaredVariable.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/testUndeclaredVariable.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/testUndeclaredVariable.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/testUndeclaredVariable.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/testlibraryFucntionArgCount.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/testlibraryFucntionArgCount.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/testlibraryFucntionArgCount.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/testlibraryFucntionArgCount.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/unkownEvaluationOrder.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/unkownEvaluationOrder.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/unkownEvaluationOrder.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/unkownEvaluationOrder.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/unreadVariable.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/unreadVariable.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/unreadVariable.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/unreadVariable.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/variableNaming.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/variableNaming.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/variableNaming.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/variableNaming.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/vector.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/vector.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/vector.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/vector.ctl diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/y2038.ctl b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/y2038.ctl similarity index 100% rename from WinCCOA_QualityChecks_tests/scripts/tests/ctrlppCheck/testscripts/y2038.ctl rename to WinCC_OA_Test/TestSuites/suite_CtrlppCheck/sub_app/scripts/testscripts/y2038.ctl diff --git a/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.app.config b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.app.config new file mode 100644 index 00000000..ab02ae8b --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.app.config @@ -0,0 +1,46 @@ +{ + "FILE_VERSION":"1.0", + "ID":"CtrlppCheck_App", + "NAME":"Application tests for CtrlppCheck", + "SUB_PROJS": [ + "sub_app" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl arraysize.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl autovar.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl badPerformanceInLoops.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl badPerformanceInLoops_inconclusive.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkBitwiseOnBoolean.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkDivideBoolean.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkIncrementBoolean.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkio.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkReturnValueOfFunction.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkUninitVar.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl checkVaarg.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl demo.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl emptyScope.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl ruletest.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl shadowVar.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl suspiciousSemicolon.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl testlibraryFucntionArgCount.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl testUndeclaredVariable.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl unkownEvaluationOrder.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl unreadVariable.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl variableNaming.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl vector.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl y2038.ctl -n" }, + # ToyotaITC + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl ToyotaITC/01.w_Defects/bit_shift.ctl -n" }, + # syntax check + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_01.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_02.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_03.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_04.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_05.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_06.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_07.ctl -n" }, + { "MANAGER_OPTIONS":"QgCtrlppcheckTests.ctl syntaxErrors/missingBracket_08.ctl -n" } + ] +} diff --git a/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.unit.config new file mode 100644 index 00000000..5d2839ef --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testProj.unit.config @@ -0,0 +1,15 @@ +{ + "FILE_VERSION":"1.0", + "ID":"CtrlppCheck_Unit", + "NAME":"Unit tests for CtrlppCheck", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { + "MANAGER_OPTIONS":"someTestScript.ctl" + } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testSuite.config b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testSuite.config new file mode 100644 index 00000000..85ee8083 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_CtrlppCheck/testSuite.config @@ -0,0 +1,8 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for CtrlppCheck", + "TEST_PROJECTS": [ + # "unit", + "app" + ] +} \ No newline at end of file diff --git a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl similarity index 52% rename from WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl rename to WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl index 5a8ef866..a646dd77 100644 --- a/WinCCOA_QualityChecks_tests/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/sub_unit/scripts/tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl @@ -7,58 +7,62 @@ //-------------------------------------------------------------------------------- // used libraries (#uses) #uses "classes/QualityGates/QgStaticCheck/Pictures/PicturesDir"/*!< tested object */ -#uses "classes/StTest" /*!< oaTest basic class */ +#uses "classes/oaTest/OaTest" +#uses "classes/QualityGates/QgVersionResult" //-------------------------------------------------------------------------------- -// declare variables and constans - -//-------------------------------------------------------------------------------- -class TstQg : StTest +class TstQg : OaTest { - public dyn_string _getAllTcIds() + + //------------------------------------------------------------------------------ + public dyn_string getAllTestCaseIds() { // list with our testcases - return makeDynString("PicturesDir::ctor", "PicturesDir-checkLimits", - "PicturesDir::exists", "PicturesDir::calculate", + return makeDynString("PicturesDir::ctor", + "PicturesDir::exists", + "PicturesDir::calculate", "PicturesDir::validate"); } - public int _startTest() + //------------------------------------------------------------------------------ + public int setUp() { - const string tcId = _getTcId(); + if ( OaTest::setUp() ) + return -1; + // eliminate fail positives + QgVersionResult::enableOaTestCheck = false; + return 0; + } + + //------------------------------------------------------------------------------ + protected int startTestCase(const string tcId) + { switch( tcId ) { case "PicturesDir::ctor": { PicturesDir dir = PicturesDir(); - oaUnitAssertEqual(tcId, dir.getName(), ""); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 0); + assertEqual(dir.getName(), ""); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); dir.setDir(PROJ_PATH); - oaUnitAssertEqual(tcId, dir.getName(), PROJ); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 0); + assertEqual(dir.getName(), PROJ); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); return 0; } - case "PicturesDir-checkLimits": - { - oaUnitAssertEqual(tcId, PicturesDir::getMaxCountOfSubDirs(), 5); - oaUnitAssertEqual(tcId, PicturesDir::getMaxCountOfFiles(), 10); - return 0; - } - case "PicturesDir::exists": { PicturesDir dir = PicturesDir(); - oaUnitAssertFalse(tcId, dir.exists()); + assertFalse(dir.exists()); dir.setDir(PROJ_PATH); - oaUnitAssertTrue(tcId, dir.exists()); + assertTrue(dir.exists()); dir.setDir(PROJ_PATH + "abc"); - oaUnitAssertFalse(tcId, dir.exists()); + assertFalse(dir.exists()); return 0; } @@ -68,48 +72,48 @@ class TstQg : StTest string tmpDir = _makeTmpDir(); // not existing - oaUnitAssertEqual(tcId, dir.calculate(), -1); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfFilesRecursive(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 0); + assertEqual(dir.calculate(), -1); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); // existing, but empty dir.setDir(tmpDir); - oaUnitAssertEqual(tcId, dir.calculate(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfFilesRecursive(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 0); + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 0); + assertEqual(dir.getCountOfFilesRecursive(), 0); + assertEqual(dir.getCountOfSubDirs(), 0); // existing with 2 sub dirs and 1 file mkdir(tmpDir + "subDir1"); mkdir(tmpDir + "subDir2"); fclose(fopen(tmpDir + "file.png", "wb+")); - oaUnitAssertEqual(tcId, dir.calculate(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 1); - oaUnitAssertEqual(tcId, dir.getCountOfFilesRecursive(), 1); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 2); + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 1); + assertEqual(dir.getCountOfSubDirs(), 2); // existing witth 3 files in defirent sub dirs fclose(fopen(tmpDir + "subDir1/file.PNG", "wb+")); fclose(fopen(tmpDir + "subDir1/file.txt", "wb+")); - oaUnitAssertEqual(tcId, dir.calculate(), 0); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 1); - oaUnitAssertEqual(tcId, dir.getCountOfFilesRecursive(), 3); - oaUnitAssertEqual(tcId, dir.getCountOfSubDirs(), 2); + assertEqual(dir.calculate(), 0); + assertEqual(dir.getCountOfFiles(), 1); + assertEqual(dir.getCountOfFilesRecursive(), 3); + assertEqual(dir.getCountOfSubDirs(), 2); - dyn_anytype childs = dir.getChilds(); - oaUnitAssertEqual(tcId, dynlen(childs), 2); - oaUnitAssertEqual(tcId, childs[1].getName(), "subDir1"); + dyn_anytype childs = dir.getSubDirs(); + assertEqual(dynlen(childs), 2); + assertEqual(childs[1].getName(), "subDir1"); dir.setDir(PROJ_PATH); - oaUnitAssertTrue(tcId, dir.exists()); + assertTrue(dir.exists()); dir.setDir(PROJ_PATH + "abc"); - oaUnitAssertFalse(tcId, dir.exists()); + assertFalse(dir.exists()); rmdir(tmpDir, TRUE); return 0; @@ -124,10 +128,10 @@ class TstQg : StTest // check empty dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 1); - oaUnitAssertEqual(tcId, dir.result.totalPoints, 1); - oaUnitAssertEqual(tcId, QgVersionResult::lastErr, "reason.dir.isEmpty"); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(dir.result.totalPoints, 1); + assertEqual(QgVersionResult::lastErr, "reason.dir.isEmpty"); // return ; // check with 10 files, try it with different extentions @@ -143,20 +147,20 @@ class TstQg : StTest fclose(fopen(tmpDir + "file10.png", "wb+")); dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 0); - oaUnitAssertEqual(tcId, dir.result.totalPoints, 23); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 10); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 23); + assertEqual(dir.getCountOfFiles(), 10); // to mutch files fclose(fopen(tmpDir + "file11.png", "wb+")); dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 1); - oaUnitAssertEqual(tcId, dir.result.totalPoints, 25); - oaUnitAssertEqual(tcId, QgVersionResult::lastErr, "reason.dir.filesCount"); - oaUnitAssertEqual(tcId, dir.getCountOfFiles(), 11); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(dir.result.totalPoints, 25); + assertEqual(QgVersionResult::lastErr, "reason.dir.filesCount"); + assertEqual(dir.getCountOfFiles(), 11); // DebugN(dir.result.children); remove(tmpDir + "file11.png"); @@ -173,18 +177,18 @@ class TstQg : StTest fclose(fopen(tmpDir + "subDir5/file1.png", "wb+")); dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 0); - oaUnitAssertEqual(tcId, dir.result.totalPoints, 48); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 0); + assertEqual(dir.result.totalPoints, 48); // to mutch sub dirs mkdir(tmpDir + "subDir6"); fclose(fopen(tmpDir + "subDir6/file1.png", "wb+")); dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 1); - oaUnitAssertEqual(tcId, QgVersionResult::lastErr, "reason.dir.subDirCount"); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(QgVersionResult::lastErr, "reason.dir.subDirCount"); // DebugN(dir); rmdir(tmpDir + "subDir6", TRUE); @@ -192,9 +196,9 @@ class TstQg : StTest fclose(fopen(tmpDir + "subDir5/file1.txt", "wb+")); dir.calculate(); - oaUnitAssertEqual(tcId, dir.validate(), 0); - oaUnitAssertEqual(tcId, dir.result.errorPoints, 1); - oaUnitAssertEqual(tcId, QgVersionResult::lastErr, "reason.file.extention"); + assertEqual(dir.validate(), 0); + assertEqual(dir.result.errorPoints, 1); + assertEqual(QgVersionResult::lastErr, "reason.file.extention"); // DebugN(dir); // claen up after test @@ -206,6 +210,7 @@ class TstQg : StTest return -1; } + //------------------------------------------------------------------------------ string _makeTmpDir() { string tmpDir = dirName(tmpnam()) + "QgPictureDir/"; @@ -221,11 +226,8 @@ class TstQg : StTest }; //-------------------------------------------------------------------------------- -main() +void main() { - TstQg test = TstQg(); - + TstQg test; test.startAll(); - - exit(0); } diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config new file mode 100644 index 00000000..8346f4e3 --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testProj.unit.config @@ -0,0 +1,13 @@ +{ + "FILE_VERSION":"1.0", + "ID":"QgPicturesCheck", + "NAME":"Unit tests for QgPicturesCheck", + "SUB_PROJS": [ + "sub_unit" + ], + # no database needed + "PACK_SEL" : 2, + "TEST_MANAGERS":[ + { "MANAGER_OPTIONS":"tests/libs/classes/QualityGates/QgStaticCheck/Pictures/PicturesDir.ctl -n" } + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testSuite.config b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testSuite.config new file mode 100644 index 00000000..b41abebe --- /dev/null +++ b/WinCC_OA_Test/TestSuites/suite_QgPicturesCheck/testSuite.config @@ -0,0 +1,7 @@ +{ + "FILE_VERSION": "1.0", + "NAME": "Tests for general ctrl code", + "TEST_PROJECTS": [ + "unit" + ] +} \ No newline at end of file diff --git a/WinCC_OA_Test/executeTests.cmd b/WinCC_OA_Test/executeTests.cmd new file mode 100644 index 00000000..1f1f7a8e --- /dev/null +++ b/WinCC_OA_Test/executeTests.cmd @@ -0,0 +1,95 @@ +echo off +REM Execute all relevant tests + +REM --------------------------------------------------------------------------- +cls + +REM --------------------------------------------------------------------------- +REM default values +SET WINCC_OA_INSTALL_PATH=C:\Siemens\Automation\WinCC_OA\ +SET WINCC_OA_VERSION=3.20 +set WINCC_OA_TEST_PATH=%cd%\ +set WINCC_OA_TEST_RUN_ID=Regressions-tests + +REM get input params +:loopStdIn +IF NOT "%1"=="" ( + + REM print help + IF "%1"=="-OaVersion" ( + SET WINCC_OA_VERSION=%2 + SHIFT + ) + IF "%1"=="-OaInstallPath" ( + SET WINCC_OA_INSTALL_PATH=%2 + SHIFT + ) + IF "%1"=="-OaTestPath" ( + SET WINCC_OA_TEST_PATH=%2 + SHIFT + ) + IF "%1"=="-OaTestRunId" ( + SET WINCC_OA_TEST_RUN_ID=%2 + SHIFT + ) + + SHIFT + GOTO :loopStdIn +) + +set WINCC_OA_INSTALL_PATH=%WINCC_OA_INSTALL_PATH%%WINCC_OA_VERSION% + +REM --------------------------------------------------------------------------- +REM register CtrlTestFramework + +set oaBinPath=%WINCC_OA_INSTALL_PATH%\bin\ + +echo Register TestFramework-customized project +set _cfgPath=%WINCC_OA_TEST_PATH%\Projects\TfCustomizedQG\config\config + +echo [general] > %_cfgPath% +echo #WinCC OA path >> %_cfgPath% +echo pvss_path = "%WINCC_OA_INSTALL_PATH%" >> %_cfgPath% + +echo #TestFramework self >> %_cfgPath% +REM echo proj_path = "%WINCC_OA_INSTALL_PATH%\TestFramework_%WINCC_OA_VERSION%" >> %_cfgPath% +echo proj_path = "C:\ws\WinCCOA\develop_3.x\Subprojects\TestFramework" >> %_cfgPath% + +echo #global test project >> %_cfgPath% +echo proj_path = "%WINCC_OA_TEST_PATH%Projects\Global" >> %_cfgPath% +echo #customized testFramework project >> %_cfgPath% +echo proj_path = "%WINCC_OA_TEST_PATH%Projects\TfCustomizedQG" >> %_cfgPath% + +echo proj_version = "%WINCC_OA_VERSION%" >> %_cfgPath% +echo #default languages >> %_cfgPath% +echo langs = "de_AT.utf8" >> %_cfgPath% +echo langs = "en_US.utf8" >> %_cfgPath% +echo langs = "ru_RU.utf8" >> %_cfgPath% + +echo pmonPort = 5999 >> %_cfgPath% + +echo [testFramework] >> %_cfgPath% +echo #path with tests >> %_cfgPath% +echo installPath = "%WINCC_OA_TEST_PATH%" >> %_cfgPath% + +REM re-register project +call %oaBinPath%WCCILpmon.exe -config %WINCC_OA_TEST_PATH%Projects\TfCustomizedQG\config\config -n -autofreg -status -log +stderr +IF %ERRORLEVEL% NEQ 0 IF %ERRORLEVEL% NEQ 3 ( + REM ERRORLEVEL == 0 - fisrt registration + REM ERRORLEVEL == 3 - re-registration + echo ERRORLEVEL: %ERRORLEVEL% + exit 0 +) + +REM --------------------------------------------------------------------------- +REM execute tests +echo ****** Execute WinCC OA Tests : %WINCC_OA_TEST_RUN_ID% +call %oaBinPath%WCCOActrl.exe -config %WINCC_OA_TEST_PATH%Projects\TfCustomizedQG\config\config -n testRunner.ctl {'registerGlobalProject':true,'registerAllTools':true,'registerAllTemplates':true,'cleanOldResults':true,'cleanStoredProjects':true,'showLogViewer':true,'TfTestManager.checkForPossibleFreezeTests':true,'testRunId':'%WINCC_OA_TEST_RUN_ID%'} -log +stderr -lang en_US.utf8 + + +REM --------------------------------------------------------------------------- +REM convert to jUnit +echo ****** Convert results into jUnit format +call %oaBinPath%WCCOActrl.exe -config %WINCC_OA_TEST_PATH%Projects\TfCustomizedQG\config\config -n oaTestParsers/jsonToJUnit.ctl -log +stderr -lang en_US.utf8 + + diff --git a/WinCC_OA_Test/general.config b/WinCC_OA_Test/general.config new file mode 100644 index 00000000..57e7abff --- /dev/null +++ b/WinCC_OA_Test/general.config @@ -0,0 +1,4 @@ +# **************** general configuration ****************** +{ + "fileVersion": "1.1" +} diff --git a/WinCC_OA_Test/readme.md b/WinCC_OA_Test/readme.md new file mode 100644 index 00000000..1e3ff7d4 --- /dev/null +++ b/WinCC_OA_Test/readme.md @@ -0,0 +1,25 @@ +# WinCC OA tests for QualityChecks + +Here are located all WinCC OA tests based on WinCC CtrlTestFramework to validate QualityChecks. + +Execute the test run "Regressions-tests" to validate all regressions before you commit some changes. + +## Execute tests + +To execute WinCC OA tests starts the script *executeTests.cmd* form command line. +This script will prepare everything necessary to execute the test, executes the tests and convert the result to jUnit (might be used in CI/CD pipelines to show results) + +``` bat +cd WinCC_OA_Test +executeTests.cmd +``` + +Following options are possible: +-OaVersion ,defines the WinCC OA Version (default 3.20) +-OaInstallPath ,define the installation path of WinCC OA (default C:\Siemens\Automation\WinCC_OA\) +-OaTestPath ,define the test path (default *thisWorkspace*\WinCC_OA_Test\) +-OaTestRunId , defines test-run ID to be executed (default Regressions-tests ) + +``` bat +executeTests.cmd -OaVersion 3.19 -OaInstallPath C:\Siemens\Automation\WinCC_OA\ -OaTestPath C:\ws\Siemens\CtrlppCheck\WinCC_OA_Test\ -OaTestRunId Regressions-tests +``` diff --git a/WinCC_OA_Test/testRuns.config b/WinCC_OA_Test/testRuns.config new file mode 100644 index 00000000..44d5164b --- /dev/null +++ b/WinCC_OA_Test/testRuns.config @@ -0,0 +1,39 @@ +{ + "TEST_RUNS":{ + "Regressions-tests":{ + "DESCRIPTION":"All regression tests", + "NAME":"Regression tests", + "TEST_RUNS":[ + "Common", + "CtrlppCheck" +# There are still too many failuers +# Need to be analyzed and fixed. You are welcome to do that ;-) +# "QgPicturesCheck" + ] + }, + "Common":{ + "DESCRIPTION":"Common tests", + "NAME":"Common tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_Common" + } + }, + "CtrlppCheck":{ + "DESCRIPTION":"Ctrlppcheck tests", + "NAME":"Ctrlppcheck tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_CtrlppCheck" + } + }, + "QgPicturesCheck":{ + "DESCRIPTION":"QgPicturesCheck tests", + "NAME":"QgPicturesCheck tests", + "TEST_SUITE":{ + "CONFIG":"testSuite.config", + "ID":"suite_QgPicturesCheck" + } + } + } +} \ No newline at end of file