diff --git a/src/CopyrighFixer/CopyrighFixer/configparser.cpp b/src/CopyrighFixer/CopyrighFixer/configparser.cpp new file mode 100644 index 0000000..76bf788 --- /dev/null +++ b/src/CopyrighFixer/CopyrighFixer/configparser.cpp @@ -0,0 +1,62 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "configparser.h" +#include +#include + + +namespace CopyrighFixer { +ConfigParser::ConfigParser() { + +} + +bool ConfigParser::parseOptions(Config &conf) const { + + QFileInfo pathDirOrFile("."); + + if (QuasarAppUtils::Params::isEndable("sourceDir")) { + pathDirOrFile.setFile(QuasarAppUtils::Params::getArg("sourceDir")); + } + + if (!pathDirOrFile.isDir()) { + QuasarAppUtils::Params::log("The given path does not exist or is not a directory", + QuasarAppUtils::VerboseLvl::Error); + return false; + } + + QuasarAppUtils::Params::log("Selected source dir :" + pathDirOrFile.absoluteFilePath(), + QuasarAppUtils::Info); + conf.setSourceDir(pathDirOrFile.absoluteFilePath()); + + + if (!QuasarAppUtils::Params::isEndable("sign")) { + QuasarAppUtils::Params::log("Not option sign.", + QuasarAppUtils::VerboseLvl::Error); + return false; + } + pathDirOrFile.setFile(QuasarAppUtils::Params::getArg("sign")); + + if (!pathDirOrFile.isFile()) { + QuasarAppUtils::Params::log("The given path does not exist or is not a file signature", + QuasarAppUtils::VerboseLvl::Error); + return false; + } + + Signature signature; + bool checkSign = signature.fromJson(pathDirOrFile.absoluteFilePath()); + if (!checkSign) { + QuasarAppUtils::Params::log("The signature was not parsed", + QuasarAppUtils::VerboseLvl::Error); + return false; + } + conf.setSingValue(signature); + + return true; +}; + +} diff --git a/src/CopyrighFixer/CopyrighFixer/configparser.h b/src/CopyrighFixer/CopyrighFixer/configparser.h new file mode 100644 index 0000000..e01e1b1 --- /dev/null +++ b/src/CopyrighFixer/CopyrighFixer/configparser.h @@ -0,0 +1,34 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef CONFIGPARSER_H +#define CONFIGPARSER_H + +#include "CopyrighFixer_global.h" +#include "config.h" + +namespace CopyrighFixer { + +/** + * @brief The ConfigParser class that parse the settings received at the input of the program. + */ +class CopyrighFixer_EXPORT ConfigParser { +public: + ConfigParser(); + /** + * @brief parseOptions This a method that will parse all input options. + * @param conf The configuration object that will change(populate) when the method is called. + * @return Return true if input params exists and valid else false. + */ + bool parseOptions(Config &conf) const; + +}; + +} + + +#endif // CONFIGPARSER_H diff --git a/src/CopyrighFixer/CopyrighFixer/signer.cpp b/src/CopyrighFixer/CopyrighFixer/signer.cpp new file mode 100644 index 0000000..1c2ba52 --- /dev/null +++ b/src/CopyrighFixer/CopyrighFixer/signer.cpp @@ -0,0 +1,20 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "signer.h" + +namespace CopyrighFixer { +Signer::Signer() { + +} + +bool Signer::checkSign(const Config &objConf) { + return true; +} + +} + diff --git a/src/CopyrighFixer/CopyrighFixer/signer.h b/src/CopyrighFixer/CopyrighFixer/signer.h new file mode 100644 index 0000000..46b6c6b --- /dev/null +++ b/src/CopyrighFixer/CopyrighFixer/signer.h @@ -0,0 +1,34 @@ +//# +//# Copyright (C) 2021-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef SIGNER_H +#define SIGNER_H + +#include "CopyrighFixer_global.h" +#include "config.h" + +namespace CopyrighFixer { + +/** + * @brief The Signer class + */ +class CopyrighFixer_EXPORT Signer { +public: + Signer(); + + /** + * @brief checkSign The method that add copyright to all sources files. + * @param objConf This is a configuration object. + */ + bool checkSign(const Config &objConf); + +}; + +} + + +#endif // SIGNER_H diff --git a/tests/tstMain.cpp b/tests/tstMain.cpp index 574632b..d8d4c07 100644 --- a/tests/tstMain.cpp +++ b/tests/tstMain.cpp @@ -8,6 +8,7 @@ #include #include "cfixertest.h" #include "signtest.h" +#include "configparsertest.h" // Use This macros for initialize your own test classes. // Check exampletests @@ -33,6 +34,7 @@ private slots: // BEGIN TESTS CASES TestCase(exampleTest, ExampleTest); TestCase(signTest, SignTest); + TestCase(configParserTest, ConfigParserTest) // END TEST CASES private: diff --git a/tests/units/configparsertest.cpp b/tests/units/configparsertest.cpp new file mode 100644 index 0000000..bbd52e6 --- /dev/null +++ b/tests/units/configparsertest.cpp @@ -0,0 +1,118 @@ +//# +//# Copyright (C) 2020-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "configparsertest.h" +#include +#include "CopyrighFixer/config.h" +#include "CopyrighFixer/configparser.h" + +ConfigParserTest::ConfigParserTest() { + +} + +ConfigParserTest::~ConfigParserTest() { + +} + +void ConfigParserTest::test() { + testParsOpt(); +} + +CopyrighFixer::Signature ConfigParserTest::generateRandomSign(QString& filename) const { + + int unixTime = time(0); + + CopyrighFixer::Owner ownerObj; + ownerObj.setName("QuasarApp"); + ownerObj.setTimePoint(unixTime); + + QMap OwnerMap; + OwnerMap.insert(ownerObj.getTimePoint(), ownerObj); + + CopyrighFixer::Signature sign_toJson; + sign_toJson.setLicenseTitle("Copyright (C) 2020-2021 QuasarApp."); + sign_toJson.setMessage("Distributed under the lgplv3 software license, see the accompany."); + sign_toJson.setMapOwners(OwnerMap); + sign_toJson.toJson(filename); + + return sign_toJson; +} + +void ConfigParserTest::testParseConf() const { + QStringList lstOpt = {"-sourceDir", ".", "-sign", "testSign.json"}; + QuasarAppUtils::Params::parseParams(lstOpt); + + CopyrighFixer::Config testConfig; + CopyrighFixer::ConfigParser testParserConf; + + QVERIFY(testParserConf.parseOptions(testConfig)); + QVERIFY(testConfig.getSignVal().isValid()); +} + +void ConfigParserTest::testSrcKey() const { + QStringList lstOpt = {"-source", ".", "-sign", "testSign.json"}; + QuasarAppUtils::Params::parseParams(lstOpt); + + CopyrighFixer::Config testConfig; + CopyrighFixer::ConfigParser testParserConf; + + QVERIFY(testParserConf.parseOptions(testConfig)); +} + +void ConfigParserTest::testSrcPath() const { + + QStringList lstOpt = {"-sourceDir", "./ParserProj", "-sign", "testSign.json"}; + QuasarAppUtils::Params::parseParams(lstOpt); + + CopyrighFixer::Config testConfig; + CopyrighFixer::ConfigParser testParserConf; + + QVERIFY(!testParserConf.parseOptions(testConfig)); + +} + +void ConfigParserTest::testSignKey() const { + QStringList lstOpt = {"-sourceDir", ".", "-signa", "testSign.json"}; + QuasarAppUtils::Params::parseParams(lstOpt); + + CopyrighFixer::Config testConfig; + CopyrighFixer::ConfigParser testParserConf; + + QVERIFY(!testParserConf.parseOptions(testConfig)); + +} + +void ConfigParserTest::testSignPath() const { + QStringList lstOpt = {"-sourceDir", ".", "-sign", "/home/testSign.json"}; + QuasarAppUtils::Params::parseParams(lstOpt); + + CopyrighFixer::Config testConfig; + CopyrighFixer::ConfigParser testParserConf; + + QVERIFY(!testParserConf.parseOptions(testConfig)); + +} + +void ConfigParserTest::testParsOpt() { + + QString testFileSign = "testSign.json"; + generateRandomSign(testFileSign); + + testParseConf(); + QuasarAppUtils::Params::clearParsedData(); + + testSrcKey(); + testSrcPath(); + QuasarAppUtils::Params::clearParsedData(); + + testSignKey(); + testSignPath(); + QuasarAppUtils::Params::clearParsedData(); + + QFile::remove(testFileSign); + +} diff --git a/tests/units/configparsertest.h b/tests/units/configparsertest.h new file mode 100644 index 0000000..b54c903 --- /dev/null +++ b/tests/units/configparsertest.h @@ -0,0 +1,34 @@ +//# +//# Copyright (C) 2020-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef CONFIGPARSERTEST_H +#define CONFIGPARSERTEST_H +#include "test.h" +#include "testutils.h" +#include "CopyrighFixer/sign.h" +#include "CopyrighFixer/config.h" +#include "CopyrighFixer/configparser.h" + +#include + +class ConfigParserTest: public Test, protected TestUtils { +public: + ConfigParserTest(); + ~ConfigParserTest(); + + void test(); + void testParseConf() const; + CopyrighFixer::Signature generateRandomSign(QString& filename) const; + void testSrcKey() const; + void testSrcPath() const; + void testSignKey() const; + void testSignPath() const; + void testParsOpt(); + +}; + +#endif // CONFIGPARSERTEST_H diff --git a/tests/units/signertest.cpp b/tests/units/signertest.cpp new file mode 100644 index 0000000..1438074 --- /dev/null +++ b/tests/units/signertest.cpp @@ -0,0 +1,26 @@ +//# +//# Copyright (C) 2020-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#include "signertest.h" +#include + +SignerTest::SignerTest() { + +} + +SignerTest::~SignerTest() { + +} + +void SignerTest::test() { + testSigner(); +} + +void SignerTest::testSigner() { + qWarning() << "The SignerTest class is not implemented"; + QVERIFY(true); +} diff --git a/tests/units/signertest.h b/tests/units/signertest.h new file mode 100644 index 0000000..ab8fbff --- /dev/null +++ b/tests/units/signertest.h @@ -0,0 +1,25 @@ +//# +//# Copyright (C) 2020-2021 QuasarApp. +//# Distributed under the lgplv3 software license, see the accompanying +//# Everyone is permitted to copy and distribute verbatim copies +//# of this license document, but changing it is not allowed. +//# + +#ifndef SIGNERTEST_H +#define SIGNERTEST_H +#include "test.h" +#include "testutils.h" +#include "CopyrighFixer/signer.h" + +#include + +class SignerTest: public Test, protected TestUtils { +public: + SignerTest(); + ~SignerTest(); + + void test(); + void testSigner(); +}; + +#endif // SIGNERTEST_H