mirror of
https://github.com/QuasarApp/CopyrightFixer.git
synced 2025-04-29 03:04:43 +00:00
ref #49 Added testUnits for configParser.
This commit is contained in:
parent
2b2f1677f4
commit
50f50b8f00
@ -25,7 +25,7 @@ bool ConfigParser::parseOptions(Config &conf) const {
|
||||
} else {
|
||||
QuasarAppUtils::Params::log("The given path does not exist or is not a directory",
|
||||
QuasarAppUtils::VerboseLvl::Error);
|
||||
return false;
|
||||
conf.setSourceDir(".");
|
||||
}
|
||||
} else {
|
||||
QuasarAppUtils::Params::log("Error: Not option sourceDir.",
|
||||
@ -37,6 +37,7 @@ bool ConfigParser::parseOptions(Config &conf) const {
|
||||
if (QFileInfo::exists(QuasarAppUtils::Params::getArg("sign"))) {
|
||||
|
||||
Signature signature;
|
||||
signature.fromJson(QuasarAppUtils::Params::getArg("sign"));
|
||||
conf.setSingValue(signature);
|
||||
|
||||
} else {
|
||||
|
@ -19,11 +19,16 @@ namespace CopyrighFixer {
|
||||
class ConfigParser {
|
||||
public:
|
||||
ConfigParser();
|
||||
|
||||
/**
|
||||
* @brief parseOptions This a method that will parse all input options.
|
||||
* @return The config object.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
};
|
||||
|
@ -6,15 +6,109 @@
|
||||
//#
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
bool ConfigParserTest::initValidConf() const {
|
||||
|
||||
QString testFileSign = "testSign.json";
|
||||
generateRandomSign(testFileSign);
|
||||
|
||||
QStringList lstOpt = {"-sourceDir", ".", "-sign", "testSign.json"};
|
||||
QuasarAppUtils::Params::parseParams(lstOpt);
|
||||
|
||||
CopyrighFixer::Config testConfig;
|
||||
CopyrighFixer::ConfigParser testParserConf;
|
||||
|
||||
QList<bool> checkList = {testParserConf.parseOptions(testConfig),
|
||||
testConfig.getSignVal().isValid()};
|
||||
|
||||
return std::all_of(checkList.cbegin(), checkList.cend(), [](bool val){return val;});
|
||||
}
|
||||
|
||||
bool ConfigParserTest::initUnvalidSrcKey() const {
|
||||
QStringList lstOpt = {"-source", ".", "-sign", "testSign.json"};
|
||||
QuasarAppUtils::Params::parseParams(lstOpt);
|
||||
|
||||
CopyrighFixer::Config testConfig;
|
||||
CopyrighFixer::ConfigParser testParserConf;
|
||||
|
||||
return testParserConf.parseOptions(testConfig);
|
||||
}
|
||||
|
||||
bool ConfigParserTest::initUnvalidSrcVal() const {
|
||||
QStringList lstOpt = {"-sourceDir", "./ParserProj", "-sign", "testSign.json"};
|
||||
QuasarAppUtils::Params::parseParams(lstOpt);
|
||||
|
||||
CopyrighFixer::Config testConfig;
|
||||
CopyrighFixer::ConfigParser testParserConf;
|
||||
|
||||
return testParserConf.parseOptions(testConfig);
|
||||
}
|
||||
|
||||
bool ConfigParserTest::initUnvalidSignKey() const {
|
||||
QStringList lstOpt = {"-sourceDir", ".", "-signa", "testSign.json"};
|
||||
QuasarAppUtils::Params::parseParams(lstOpt);
|
||||
|
||||
CopyrighFixer::Config testConfig;
|
||||
CopyrighFixer::ConfigParser testParserConf;
|
||||
|
||||
return testParserConf.parseOptions(testConfig);
|
||||
}
|
||||
|
||||
bool ConfigParserTest::initUnvalidSignVal() const {
|
||||
QStringList lstOpt = {"-sourceDir", ".", "-sign", "/home/testSign.json"};
|
||||
QuasarAppUtils::Params::parseParams(lstOpt);
|
||||
|
||||
CopyrighFixer::Config testConfig;
|
||||
CopyrighFixer::ConfigParser testParserConf;
|
||||
|
||||
return testParserConf.parseOptions(testConfig);
|
||||
}
|
||||
|
||||
void ConfigParserTest::testParsOpt() {
|
||||
|
||||
QVERIFY(initValidConf());
|
||||
QuasarAppUtils::Params::clearParsedData();
|
||||
|
||||
QVERIFY(!initUnvalidSrcKey());
|
||||
QVERIFY(initUnvalidSrcVal());
|
||||
QuasarAppUtils::Params::clearParsedData();
|
||||
|
||||
QVERIFY(!initUnvalidSignKey());
|
||||
QVERIFY(!initUnvalidSignVal());
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,11 @@
|
||||
#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:
|
||||
@ -18,7 +21,12 @@ public:
|
||||
~ConfigParserTest();
|
||||
|
||||
void test();
|
||||
CopyrighFixer::Config genValidConfig(CopyrighFixer::Config &obj) const;
|
||||
bool initValidConf() const;
|
||||
CopyrighFixer::Signature generateRandomSign(QString& filename) const;
|
||||
bool initUnvalidSrcKey() const;
|
||||
bool initUnvalidSrcVal() const;
|
||||
bool initUnvalidSignKey() const;
|
||||
bool initUnvalidSignVal() const;
|
||||
void testParsOpt();
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user