mirror of
https://github.com/QuasarApp/CopyrightFixer.git
synced 2025-04-26 17:54:42 +00:00
Merge branch 'main' into task_29
This commit is contained in:
commit
19290a89c6
62
src/CopyrighFixer/CopyrighFixer/configparser.cpp
Normal file
62
src/CopyrighFixer/CopyrighFixer/configparser.cpp
Normal file
@ -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 <quasarapp.h>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
34
src/CopyrighFixer/CopyrighFixer/configparser.h
Normal file
34
src/CopyrighFixer/CopyrighFixer/configparser.h
Normal file
@ -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
|
20
src/CopyrighFixer/CopyrighFixer/signer.cpp
Normal file
20
src/CopyrighFixer/CopyrighFixer/signer.cpp
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
34
src/CopyrighFixer/CopyrighFixer/signer.h
Normal file
34
src/CopyrighFixer/CopyrighFixer/signer.h
Normal file
@ -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
|
@ -8,6 +8,7 @@
|
||||
#include <QtTest>
|
||||
#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:
|
||||
|
118
tests/units/configparsertest.cpp
Normal file
118
tests/units/configparsertest.cpp
Normal file
@ -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 <quasarapp.h>
|
||||
#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<int, CopyrighFixer::Owner> 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);
|
||||
|
||||
}
|
34
tests/units/configparsertest.h
Normal file
34
tests/units/configparsertest.h
Normal file
@ -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 <QTest>
|
||||
|
||||
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
|
26
tests/units/signertest.cpp
Normal file
26
tests/units/signertest.cpp
Normal file
@ -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 <QDebug>
|
||||
|
||||
SignerTest::SignerTest() {
|
||||
|
||||
}
|
||||
|
||||
SignerTest::~SignerTest() {
|
||||
|
||||
}
|
||||
|
||||
void SignerTest::test() {
|
||||
testSigner();
|
||||
}
|
||||
|
||||
void SignerTest::testSigner() {
|
||||
qWarning() << "The SignerTest class is not implemented";
|
||||
QVERIFY(true);
|
||||
}
|
25
tests/units/signertest.h
Normal file
25
tests/units/signertest.h
Normal file
@ -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 <QTest>
|
||||
|
||||
class SignerTest: public Test, protected TestUtils {
|
||||
public:
|
||||
SignerTest();
|
||||
~SignerTest();
|
||||
|
||||
void test();
|
||||
void testSigner();
|
||||
};
|
||||
|
||||
#endif // SIGNERTEST_H
|
Loading…
x
Reference in New Issue
Block a user