Preliminary implementation of license key expiry.
This commit is contained in:
parent
786890dbd2
commit
371a45d9c8
10 changed files with 332 additions and 80 deletions
|
|
@ -46,22 +46,15 @@ LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
|
|||
(m_serialKey.toString()));
|
||||
emit serialKeyChanged(m_serialKey);
|
||||
|
||||
if (serialKey.isTrial()) {
|
||||
emit endTrial(false);
|
||||
}
|
||||
emit showLicenseNotice(getLicenseNotice());
|
||||
if (m_serialKey.isExpired(currentTime)) {
|
||||
emit LicenseExpired();
|
||||
}
|
||||
|
||||
if (m_serialKey.edition() != serialKey.edition()) {
|
||||
m_AppConfig->setEdition(m_serialKey.edition());
|
||||
emit editionChanged(m_serialKey.edition());
|
||||
}
|
||||
|
||||
if (m_serialKey.isTrial()) {
|
||||
if (m_serialKey.isExpired(currentTime)) {
|
||||
emit endTrial(true);
|
||||
} else {
|
||||
emit beginTrial(m_serialKey.isExpiring(currentTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -119,7 +112,7 @@ void LicenseManager::refresh()
|
|||
}
|
||||
}
|
||||
if (m_serialKey.isExpired(::time(0))) {
|
||||
emit endTrial(true);
|
||||
emit LicenseExpired();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -163,3 +156,85 @@ void LicenseManager::notifyActivation(QString identity)
|
|||
|
||||
QMetaObject::invokeMethod(notifier, "notify", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QString LicenseManager::getLicenseNotice() const
|
||||
{
|
||||
QString Notice;
|
||||
|
||||
if (m_serialKey.isTemporary()){
|
||||
if (m_serialKey.isTrial()){
|
||||
Notice = getTrialNotice();
|
||||
}
|
||||
else{
|
||||
Notice = getTemporaryNotice();
|
||||
}
|
||||
}
|
||||
|
||||
return Notice;
|
||||
}
|
||||
|
||||
QString LicenseManager::getTrialNotice() const
|
||||
{
|
||||
QString Notice;
|
||||
|
||||
if (m_serialKey.isExpired(::time(0))){
|
||||
Notice = "<html><head/><body><p>Your %1 trial has expired. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%2\">"
|
||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||
"Buy now!</span></a></p></body></html>";
|
||||
Notice = Notice
|
||||
.arg(LicenseManager::getEditionName(activeEdition()))
|
||||
.arg(QString::fromStdString(m_serialKey.toString()));
|
||||
}
|
||||
else{
|
||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||
Notice = "<html><head/><body><p><span style=\""
|
||||
"font-weight:600;\">%1</span> day%3 of "
|
||||
"your %2 trial remain%5. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%4\">"
|
||||
"<span style=\"text-decoration: underline;"
|
||||
" color:#0000ff;\">Buy now!</span></a>"
|
||||
"</p></body></html>";
|
||||
Notice = Notice
|
||||
.arg (daysLeft)
|
||||
.arg (LicenseManager::getEditionName(activeEdition()))
|
||||
.arg ((daysLeft == 1) ? "" : "s")
|
||||
.arg (QString::fromStdString(m_serialKey.toString()))
|
||||
.arg ((daysLeft == 1) ? "s" : "");
|
||||
}
|
||||
|
||||
return Notice;
|
||||
}
|
||||
|
||||
QString LicenseManager::getTemporaryNotice() const
|
||||
{
|
||||
QString Notice;
|
||||
|
||||
if (m_serialKey.isExpired(::time(0))){
|
||||
Notice = "<html><head/><body><p>Your %1 has expired. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%2\">"
|
||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||
"Buy now!</span></a></p></body></html>";
|
||||
Notice = Notice
|
||||
.arg(LicenseManager::getEditionName(activeEdition()))
|
||||
.arg(QString::fromStdString(m_serialKey.toString()));
|
||||
}
|
||||
else if (m_serialKey.isExpiring(::time(0))){
|
||||
time_t daysLeft = m_serialKey.daysLeft(::time(0));
|
||||
Notice = "<html><head/><body><p><span style=\""
|
||||
"font-weight:600;\">%1</span> day%3 of "
|
||||
"your %2 remain%5. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%4\">"
|
||||
"<span style=\"text-decoration: underline;"
|
||||
" color:#0000ff;\">Buy now!</span></a>"
|
||||
"</p></body></html>";
|
||||
Notice = Notice
|
||||
.arg (daysLeft)
|
||||
.arg (LicenseManager::getEditionName(activeEdition()))
|
||||
.arg ((daysLeft == 1) ? "" : "s")
|
||||
.arg (QString::fromStdString(m_serialKey.toString()))
|
||||
.arg ((daysLeft == 1) ? "s" : "");
|
||||
}
|
||||
|
||||
return Notice;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public:
|
|||
void notifyUpdate(QString fromVersion, QString toVersion);
|
||||
static QString getEditionName(Edition edition, bool trial = false);
|
||||
void notifyActivation(QString identity);
|
||||
QString getLicenseNotice() const;
|
||||
|
||||
private:
|
||||
AppConfig* m_AppConfig;
|
||||
|
|
@ -49,6 +50,10 @@ private:
|
|||
signals:
|
||||
void serialKeyChanged (SerialKey) const;
|
||||
void editionChanged (Edition) const;
|
||||
void beginTrial (bool expiring) const;
|
||||
void endTrial (bool expired) const;
|
||||
void LicenseExpired () const;
|
||||
void showLicenseNotice(const QString& notice) const;
|
||||
|
||||
protected:
|
||||
QString getTrialNotice() const;
|
||||
QString getTemporaryNotice() const;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -171,11 +171,11 @@ MainWindow::MainWindow (AppConfig& appConfig,
|
|||
connect (m_LicenseManager, SIGNAL(editionChanged(Edition)),
|
||||
this, SLOT(setEdition(Edition)), Qt::QueuedConnection);
|
||||
|
||||
connect (m_LicenseManager, SIGNAL(beginTrial(bool)),
|
||||
this, SLOT(beginTrial(bool)), Qt::QueuedConnection);
|
||||
connect (m_LicenseManager, SIGNAL(showLicenseNotice(QString)),
|
||||
this, SLOT(showLicenseNotice(QString)), Qt::QueuedConnection);
|
||||
|
||||
connect (m_LicenseManager, SIGNAL(endTrial(bool)),
|
||||
this, SLOT(endTrial(bool)), Qt::QueuedConnection);
|
||||
connect (m_LicenseManager, SIGNAL(LicenseExpired()),
|
||||
this, SLOT(LicenseExpired()), Qt::QueuedConnection);
|
||||
#endif
|
||||
|
||||
connect (m_AppConfig, SIGNAL(sslToggled(bool)),
|
||||
|
|
@ -1152,54 +1152,21 @@ void MainWindow::setEdition(Edition edition)
|
|||
}
|
||||
|
||||
#ifndef SYNERGY_ENTERPRISE
|
||||
void MainWindow::beginTrial(bool isExpiring)
|
||||
void MainWindow::LicenseExpired()
|
||||
{
|
||||
//Hack
|
||||
//if (isExpiring) {
|
||||
time_t daysLeft = m_LicenseManager->serialKey().daysLeft(::time(0));
|
||||
QString expiringNotice ("<html><head/><body><p><span style=\""
|
||||
"font-weight:600;\">%1</span> day%3 of "
|
||||
"your %2 trial remain%5. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%4\">"
|
||||
"<span style=\"text-decoration: underline;"
|
||||
" color:#0000ff;\">Buy now!</span></a>"
|
||||
"</p></body></html>");
|
||||
expiringNotice = expiringNotice
|
||||
.arg (daysLeft)
|
||||
.arg (LicenseManager::getEditionName
|
||||
(m_LicenseManager->activeEdition()))
|
||||
.arg ((daysLeft == 1) ? "" : "s")
|
||||
.arg (QString::fromStdString
|
||||
(m_LicenseManager->serialKey().toString()))
|
||||
.arg ((daysLeft == 1) ? "s" : "");
|
||||
this->m_trialLabel->setText(expiringNotice);
|
||||
this->m_trialWidget->show();
|
||||
//}
|
||||
setWindowTitle (m_LicenseManager->activeEditionName());
|
||||
stopSynergy();
|
||||
m_AppConfig->activationHasRun(false);
|
||||
}
|
||||
|
||||
void MainWindow::endTrial(bool isExpired)
|
||||
void MainWindow::showLicenseNotice(const QString& notice)
|
||||
{
|
||||
if (isExpired) {
|
||||
QString expiredNotice (
|
||||
"<html><head/><body><p>Your %1 trial has expired. <a href="
|
||||
"\"https://symless.com/synergy/trial/thanks?id=%2\">"
|
||||
"<span style=\"text-decoration: underline;color:#0000ff;\">"
|
||||
"Buy now!</span></a></p></body></html>"
|
||||
);
|
||||
expiredNotice = expiredNotice
|
||||
.arg(LicenseManager::getEditionName
|
||||
(m_LicenseManager->activeEdition()))
|
||||
.arg(QString::fromStdString
|
||||
(m_LicenseManager->serialKey().toString()));
|
||||
this->m_trialWidget->hide();
|
||||
|
||||
this->m_trialLabel->setText(expiredNotice);
|
||||
if (!notice.isEmpty()) {
|
||||
this->m_trialLabel->setText(notice);
|
||||
this->m_trialWidget->show();
|
||||
stopSynergy();
|
||||
m_AppConfig->activationHasRun(false);
|
||||
} else {
|
||||
this->m_trialWidget->hide();
|
||||
}
|
||||
|
||||
setWindowTitle (m_LicenseManager->activeEditionName());
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -132,8 +132,8 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase
|
|||
public slots:
|
||||
void setEdition(Edition edition);
|
||||
#ifndef SYNERGY_ENTERPRISE
|
||||
void beginTrial(bool isExpiring);
|
||||
void endTrial(bool isExpired);
|
||||
void LicenseExpired();
|
||||
void showLicenseNotice(const QString& message);
|
||||
#endif
|
||||
void appendLogRaw(const QString& text);
|
||||
void appendLogInfo(const QString& text);
|
||||
|
|
|
|||
|
|
@ -25,16 +25,21 @@
|
|||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
static std::string hexEncode (std::string const& str);
|
||||
|
||||
SerialKey::SerialKey(Edition edition):
|
||||
m_userLimit(1),
|
||||
m_warnTime(ULLONG_MAX),
|
||||
m_expireTime(ULLONG_MAX),
|
||||
m_edition(edition),
|
||||
m_trial(false)
|
||||
m_KeyType()
|
||||
{
|
||||
std::string MyLicense = "{v2;temp;basic;Bob;1;email;company name;1600972418;1600992418}";
|
||||
std::string Hex = hexEncode(MyLicense);
|
||||
std::cout<<"MyLicense = "<<Hex<<std::endl;
|
||||
}
|
||||
|
||||
SerialKey::SerialKey(std::string serial) :
|
||||
|
|
@ -42,7 +47,7 @@ SerialKey::SerialKey(std::string serial) :
|
|||
m_warnTime(0),
|
||||
m_expireTime(0),
|
||||
m_edition(kBasic),
|
||||
m_trial(true)
|
||||
m_KeyType()
|
||||
{
|
||||
string plainText = decode(serial);
|
||||
bool valid = false;
|
||||
|
|
@ -59,9 +64,9 @@ SerialKey::isExpiring(time_t currentTime) const
|
|||
{
|
||||
bool result = false;
|
||||
|
||||
if (m_trial) {
|
||||
if (isTemporary()) {
|
||||
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
||||
if ((m_warnTime <= currentTimeAsLL) && (currentTimeAsLL < m_expireTime)) {
|
||||
if ((m_warnTime >= currentTimeAsLL) && (currentTimeAsLL < m_expireTime)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -73,8 +78,9 @@ bool
|
|||
SerialKey::isExpired(time_t currentTime) const
|
||||
{
|
||||
bool result = false;
|
||||
std::cout<<"Current time = "<<static_cast<unsigned long long>(currentTime)<<std::endl;
|
||||
|
||||
if (m_trial) {
|
||||
if (isTemporary()) {
|
||||
unsigned long long currentTimeAsLL = static_cast<unsigned long long>(currentTime);
|
||||
if (m_expireTime <= currentTimeAsLL) {
|
||||
result = true;
|
||||
|
|
@ -87,7 +93,13 @@ SerialKey::isExpired(time_t currentTime) const
|
|||
bool
|
||||
SerialKey::isTrial() const
|
||||
{
|
||||
return m_trial;
|
||||
return m_KeyType.isTrial();
|
||||
}
|
||||
|
||||
bool
|
||||
SerialKey::isTemporary() const
|
||||
{
|
||||
return m_KeyType.isTemporary();
|
||||
}
|
||||
|
||||
Edition
|
||||
|
|
@ -130,8 +142,13 @@ SerialKey::toString() const
|
|||
{
|
||||
std::ostringstream oss;
|
||||
oss << "{";
|
||||
if (isTrial()) {
|
||||
oss << "v2;trial;";
|
||||
if (isTemporary()) {
|
||||
if (isTrial()){
|
||||
oss << "v2;" << SerialKeyType::TRIAL << ";";
|
||||
}
|
||||
else{
|
||||
oss << "v2;" << SerialKeyType::TEMPORARY << ";";
|
||||
}
|
||||
} else {
|
||||
oss << "v1;";
|
||||
}
|
||||
|
|
@ -140,8 +157,8 @@ SerialKey::toString() const
|
|||
oss << m_userLimit << ";";
|
||||
oss << m_email << ";";
|
||||
oss << m_company << ";";
|
||||
oss << (isTrial() ? m_warnTime : 0) << ";";
|
||||
oss << (isTrial() ? m_expireTime : 0);
|
||||
oss << (isTemporary() ? m_warnTime : 0) << ";";
|
||||
oss << (isTemporary() ? m_expireTime : 0);
|
||||
oss << "}";
|
||||
return hexEncode(oss.str());
|
||||
}
|
||||
|
|
@ -230,7 +247,6 @@ SerialKey::parse(std::string plainSerial)
|
|||
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||
m_edition = parseEdition(parts.at(1));
|
||||
m_name = parts.at(2);
|
||||
m_trial = false;
|
||||
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
||||
m_email = parts.at(4);
|
||||
m_company = parts.at(5);
|
||||
|
|
@ -241,7 +257,7 @@ SerialKey::parse(std::string plainSerial)
|
|||
else if ((parts.size() == 9)
|
||||
&& (parts.at(0).find("v2") != string::npos)) {
|
||||
// e.g.: {v2;trial;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||
m_trial = parts.at(1) == "trial" ? true : false;
|
||||
m_KeyType.setKeyType(parts.at(1));
|
||||
m_edition = parseEdition(parts.at(2));
|
||||
m_name = parts.at(3);
|
||||
sscanf(parts.at(4).c_str(), "%d", &m_userLimit);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include <string>
|
||||
#include <ctime>
|
||||
#include "EditionType.h"
|
||||
#include "SerialKeyType.h"
|
||||
|
||||
#ifdef TEST_ENV
|
||||
#include <gtest/gtest_prod.h>
|
||||
|
|
@ -34,6 +35,7 @@ public:
|
|||
bool isExpiring(time_t currentTime) const;
|
||||
bool isExpired(time_t currentTime) const;
|
||||
bool isTrial() const;
|
||||
bool isTemporary() const;
|
||||
time_t daysLeft(time_t currentTime) const;
|
||||
std::string email() const;
|
||||
Edition edition() const;
|
||||
|
|
@ -55,14 +57,14 @@ private:
|
|||
#endif
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_email;
|
||||
std::string m_company;
|
||||
unsigned m_userLimit;
|
||||
std::string m_name;
|
||||
std::string m_email;
|
||||
std::string m_company;
|
||||
unsigned m_userLimit;
|
||||
unsigned long long m_warnTime;
|
||||
unsigned long long m_expireTime;
|
||||
Edition m_edition;
|
||||
bool m_trial;
|
||||
Edition m_edition;
|
||||
SerialKeyType m_KeyType;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -75,7 +77,7 @@ operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
|||
(lhs.m_warnTime == rhs.m_warnTime) &&
|
||||
(lhs.m_expireTime == rhs.m_expireTime) &&
|
||||
(lhs.m_edition == rhs.m_edition) &&
|
||||
(lhs.m_trial == rhs.m_trial);
|
||||
(lhs.m_KeyType == rhs.m_KeyType);
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
|
|
|||
40
src/lib/shared/SerialKeyType.cpp
Normal file
40
src/lib/shared/SerialKeyType.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#include "SerialKeyType.h"
|
||||
|
||||
const std::string SerialKeyType::TRIAL = "trial";
|
||||
const std::string SerialKeyType::TEMPORARY = "temp";
|
||||
|
||||
SerialKeyType::SerialKeyType() :
|
||||
m_isTrial(false),
|
||||
m_isTemporary(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SerialKeyType::setKeyType(const std::string& Type)
|
||||
{
|
||||
m_isTrial = false;
|
||||
m_isTemporary = false;
|
||||
|
||||
if (Type == SerialKeyType::TRIAL){
|
||||
m_isTrial = true;
|
||||
m_isTemporary = true;
|
||||
}
|
||||
else if (Type == SerialKeyType::TEMPORARY){
|
||||
m_isTemporary = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SerialKeyType::isTrial() const
|
||||
{
|
||||
return m_isTrial;
|
||||
}
|
||||
|
||||
bool SerialKeyType::isTemporary() const
|
||||
{
|
||||
return m_isTemporary;
|
||||
}
|
||||
|
||||
bool SerialKeyType::isPermanent() const
|
||||
{
|
||||
return (!m_isTemporary);
|
||||
}
|
||||
53
src/lib/shared/SerialKeyType.h
Normal file
53
src/lib/shared/SerialKeyType.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2016 Symless Ltd.
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file LICENSE that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef SERIALKEYTYPE_H
|
||||
#define SERIALKEYTYPE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class SerialKeyType
|
||||
{
|
||||
private:
|
||||
friend bool operator== (SerialKeyType const&, SerialKeyType const&);
|
||||
public:
|
||||
static const std::string TRIAL;
|
||||
static const std::string TEMPORARY;
|
||||
|
||||
public:
|
||||
SerialKeyType();
|
||||
|
||||
void setKeyType(const std::string& Type);
|
||||
bool isTrial() const;
|
||||
bool isTemporary() const;
|
||||
bool isPermanent() const;
|
||||
|
||||
protected:
|
||||
bool m_isTrial;
|
||||
bool m_isTemporary;
|
||||
};
|
||||
|
||||
inline bool
|
||||
operator== (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
||||
return (lhs.m_isTrial == rhs.m_isTrial) && (lhs.m_isTemporary == rhs.m_isTemporary);
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!= (SerialKeyType const& lhs, SerialKeyType const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
#endif // SERIALKEYTYPE_H
|
||||
|
|
@ -74,6 +74,7 @@ TEST(SerialKeyTests, parse_validV2Serial_valid)
|
|||
EXPECT_EQ(true, serial.daysLeft(0));
|
||||
EXPECT_EQ(true, serial.isExpiring(1));
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpiring_validV2TrialBasicSerial_returnFalse)
|
||||
|
|
@ -81,6 +82,7 @@ TEST(SerialKeyTests, isExpiring_validV2TrialBasicSerial_returnFalse)
|
|||
// {v2;trial;basic;Bob;1;email;company name;1;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_FALSE(serial.isExpiring(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
}
|
||||
|
|
@ -90,6 +92,7 @@ TEST(SerialKeyTests, isExpiring_expiringV2TrialBasicSerial_returnTrue)
|
|||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_EQ(true, serial.isExpiring(1));
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +101,7 @@ TEST(SerialKeyTests, isExpiring_expiredV2TrialBasicSerial_returnFalse)
|
|||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_FALSE(serial.isExpiring(86401));
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +110,7 @@ TEST(SerialKeyTests, isExpired_validV2TrialBasicSerial_returnFalse)
|
|||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_FALSE(serial.isExpired(0));
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +119,7 @@ TEST(SerialKeyTests, isExpired_expiringV2TrialBasicSerial_returnFalse)
|
|||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_FALSE(serial.isExpired(1));
|
||||
}
|
||||
|
||||
|
|
@ -122,6 +128,7 @@ TEST(SerialKeyTests, isExpired_expiredV2TrialBasicSerial_returnTrue)
|
|||
// {v2;trial;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(true, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_EQ(true, serial.isExpired(86401));
|
||||
}
|
||||
|
||||
|
|
@ -145,3 +152,33 @@ TEST(SerialKeyTests, daysLeft_expiredV2TrialBasicSerial_returnZero)
|
|||
SerialKey serial("7B76323B747269616C3B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B303B38363430307D");
|
||||
EXPECT_EQ(0, serial.daysLeft(86401));
|
||||
}
|
||||
|
||||
//Temporary linces tests
|
||||
TEST(SerialKeyTests, isExpiring_validV2TemporaryBasicSerial_returnFalse)
|
||||
{
|
||||
// {v2;temp;basic;Bob;1;email;company name;1;86400}
|
||||
SerialKey serial("7B76323B74656D703B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
||||
EXPECT_EQ(false, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_FALSE(serial.isExpiring(0));
|
||||
EXPECT_EQ(kBasic, serial.edition());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpiring_expiringV2TemporaryBasicSerial_returnTrue)
|
||||
{
|
||||
// {v2;temp;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B74656D703B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
||||
EXPECT_EQ(false, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_EQ(true, serial.isExpiring(1));
|
||||
}
|
||||
|
||||
TEST(SerialKeyTests, isExpired_expiredV2TemporaryBasicSerial_returnTrue)
|
||||
{
|
||||
// {v2;temp;basic;Bob;1;email;company name;0;86400}
|
||||
SerialKey serial("7B76323B74656D703B62617369633B426F623B313B656D61696C3B636F6D70616E79206E616D653B313B38363430307D");
|
||||
EXPECT_EQ(false, serial.isTrial());
|
||||
EXPECT_EQ(true, serial.isTemporary());
|
||||
EXPECT_EQ(true, serial.isExpired(86401));
|
||||
}
|
||||
|
||||
|
|
|
|||
57
src/test/unittests/shared/SerialKeyTypeTests.cpp
Normal file
57
src/test/unittests/shared/SerialKeyTypeTests.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2016 Symless Inc.
|
||||
*
|
||||
* This package is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* found in the file LICENSE that should have accompanied this file.
|
||||
*
|
||||
* This package is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define TEST_ENV
|
||||
|
||||
#include "shared/SerialKeyType.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_false)
|
||||
{
|
||||
SerialKeyType KeyType;
|
||||
EXPECT_EQ(false, KeyType.isTrial());
|
||||
EXPECT_EQ(false, KeyType.isTemporary());
|
||||
EXPECT_EQ(true, KeyType.isPermanent());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTypeTests, TrialTemporaryKeyType_true)
|
||||
{
|
||||
SerialKeyType KeyType;
|
||||
KeyType.setKeyType("trial");
|
||||
EXPECT_EQ(true, KeyType.isTrial());
|
||||
EXPECT_EQ(true, KeyType.isTemporary());
|
||||
EXPECT_EQ(false, KeyType.isPermanent());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTypeTests, TemporaryKeyType_true)
|
||||
{
|
||||
SerialKeyType KeyType;
|
||||
KeyType.setKeyType("temp");
|
||||
EXPECT_EQ(false, KeyType.isTrial());
|
||||
EXPECT_EQ(true, KeyType.isTemporary());
|
||||
EXPECT_EQ(false, KeyType.isPermanent());
|
||||
}
|
||||
|
||||
TEST(SerialKeyTypeTests, PermanentKeyType_true)
|
||||
{
|
||||
SerialKeyType KeyType;
|
||||
KeyType.setKeyType("");
|
||||
EXPECT_EQ(false, KeyType.isTrial());
|
||||
EXPECT_EQ(false, KeyType.isTemporary());
|
||||
EXPECT_EQ(true, KeyType.isPermanent());
|
||||
}
|
||||
Loading…
Reference in a new issue