CopyrightFixer/tests/units/signtest.cpp
2021-05-12 23:13:08 +03:00

65 lines
1.7 KiB
C++

//#
//# 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 <time.h>
#include "CopyrighFixer/sign.h"
#include "signtest.h"
SignTest::SignTest() {
}
SignTest::~SignTest() {
}
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";
// Generating a randomly populated signature object.
CopyrighFixer::Signature baseSign = generateRandomSign(filename);
// The condition will return true because the signature structure
// is correct. Which is checked in the following condition.
QVERIFY(baseSign.toJson(filename));
QVERIFY(baseSign.isValid());
CopyrighFixer::Signature signFromFile;
// After initialise the Signature object should be invalid.
QVERIFY(!signFromFile.isValid());
QVERIFY(signFromFile.fromJson(filename));
QVERIFY(signFromFile == baseSign);
}