mirror of
https://github.com/QuasarApp/CopyrightFixer.git
synced 2025-04-26 17:54:42 +00:00
ref #46 Fixing tests: added method generateRandomSign.
This commit is contained in:
parent
b03938f7df
commit
a802b8e24a
@ -28,13 +28,12 @@ int Owner::getTimePoint() const {
|
||||
return _timePoint;
|
||||
}
|
||||
|
||||
void Owner::fromjson(const QJsonObject &objJs) {
|
||||
void Owner::fromJson(const QJsonObject &objJs) {
|
||||
_name = objJs.value("name").toString();
|
||||
|
||||
_timePoint = objJs.value("timePoint").toInt();
|
||||
}
|
||||
|
||||
void Owner::toJson(QJsonObject &objJs) const {
|
||||
const QJsonObject &Owner::toJson(QJsonObject &objJs) const {
|
||||
|
||||
objJs["name"] = _name;
|
||||
objJs["timePoint"] = _timePoint;
|
||||
@ -50,4 +49,9 @@ bool Owner::isValid() const {
|
||||
return _name.size() && _timePoint > 0 && _timePoint <= time(0);
|
||||
}
|
||||
|
||||
bool operator== (const Owner &o1, const Owner &o2) {
|
||||
return (o1._name == o2._name &&
|
||||
o1._timePoint == o2._timePoint);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
* @brief fromjson Reads data from json file.
|
||||
* @param objJs It's object json that contains information about the owner.
|
||||
*/
|
||||
void fromjson(const QJsonObject &objJs);
|
||||
void fromJson(const QJsonObject &objJs);
|
||||
|
||||
/**
|
||||
* @brief toJson This method that converts object Owner to json object.
|
||||
@ -64,6 +64,14 @@ public:
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* @brief operator == Comparison operator overloading method
|
||||
* @param o1 Left value.
|
||||
* @param o2 Right value.
|
||||
* @return Returns true if they are equal.
|
||||
*/
|
||||
friend bool operator== (const Owner &o1, const Owner &o2);
|
||||
|
||||
private:
|
||||
QString _name = "";
|
||||
int _timePoint = 1;
|
||||
|
@ -76,8 +76,8 @@ bool Signature::fromJson(const QString &pathToFile) {
|
||||
Owner ownObj;
|
||||
QJsonArray ownLst(jsObj.value("ownersList").toArray());
|
||||
for (auto itemLst = ownLst.cbegin(); itemLst != ownLst.cend(); ++itemLst) {
|
||||
ownObj.fromjson(itemLst->toObject());
|
||||
_ownersMap.insert(ownObj.value("timePoint").toInt(), ownObj);
|
||||
ownObj.fromJson(itemLst->toObject());
|
||||
_ownersMap.insert(ownObj.getTimePoint(), ownObj);
|
||||
}
|
||||
|
||||
_licenseTitle = jsObj.value("license").toString();
|
||||
@ -91,7 +91,7 @@ bool Signature::fromJson(const QString &pathToFile) {
|
||||
|
||||
}
|
||||
|
||||
bool Signature::toJson(const QString &pathToFile) const {
|
||||
bool Signature::toJson(QString &pathToFile) const {
|
||||
|
||||
QFile file(pathToFile);
|
||||
if (file.exists()) {
|
||||
@ -142,4 +142,10 @@ bool Signature::isValid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator== (const Signature &c1, const Signature &c2) {
|
||||
return (c1._customMessage == c2._customMessage &&
|
||||
c1._licenseTitle == c2._licenseTitle &&
|
||||
c1._ownersMap == c2._ownersMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,6 +76,14 @@ public:
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
* @brief operator == Comparison operator overloading method
|
||||
* @param c1 Left value.
|
||||
* @param c2 Right value.
|
||||
* @return Returns true if they are equal.
|
||||
*/
|
||||
friend bool operator== (const Signature &c1, const Signature &c2);
|
||||
|
||||
private:
|
||||
QMap<int, Owner> _ownersMap;
|
||||
QString _licenseTitle = "";
|
||||
|
@ -5,6 +5,7 @@
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include <time.h>
|
||||
#include "CopyrighFixer/sign.h"
|
||||
#include "signtest.h"
|
||||
|
||||
@ -20,19 +21,36 @@ void SignTest::test() {
|
||||
testJsonObj();
|
||||
}
|
||||
|
||||
CopyrighFixer::Signature SignTest::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 SignTest::testJsonObj() {
|
||||
QString filename = "signature.json";
|
||||
|
||||
CopyrighFixer::Sign baseSign = generateRandomSign();
|
||||
|
||||
CopyrighFixer::Signature baseSign = generateRandomSign(filename);
|
||||
QVERIFY(baseSign.toJson(filename));
|
||||
|
||||
QVERIFY(baseSign.isValid());
|
||||
|
||||
CopyrighFixer::Sign signFromFile;
|
||||
CopyrighFixer::Signature signFromFile;
|
||||
QVERIFY(signFromFile.fromJson(filename));
|
||||
|
||||
|
||||
QVERIFY(signFromFile == baseSign);
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define SIGNTEST_H
|
||||
#include "test.h"
|
||||
#include "testutils.h"
|
||||
#include "CopyrighFixer/sign.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
@ -18,6 +19,7 @@ public:
|
||||
~SignTest();
|
||||
|
||||
void test();
|
||||
CopyrighFixer::Signature generateRandomSign(QString& filename) const;
|
||||
void testJsonObj();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user