gen: Added new license type Commercial Site License

This commit is contained in:
Eberhard Graether
2018-04-10 15:27:11 +02:00
parent 50dc290d40
commit 2c8cc114eb
3 changed files with 27 additions and 14 deletions
+21 -11
View File
@@ -88,7 +88,11 @@ std::string License::getMessage(bool withNewlines) const
message += LicenseConstants::PRODUCT_STRING + separator;
message += LicenseConstants::LICENSED_TO_STRING + m_user + separator;
message += LicenseConstants::LICENSE_TYPE_STRING + m_type;
if (m_numberOfUsers > 1)
if (m_type == LicenseConstants::TEST_LICENSE_STRING || m_type == LicenseConstants::SITE_LICENSE_STRING)
{
message += (m_createdWithSeats ? " (unlimited seats)" : " (unlimited users)");
}
else if (m_numberOfUsers > 1)
{
message += " (" + std::to_string(m_numberOfUsers) + (m_createdWithSeats ? " Seats)" : " users)");
}
@@ -96,10 +100,7 @@ std::string License::getMessage(bool withNewlines) const
{
message += (m_createdWithSeats ? " (1 Seat)" : " (1 user)");
}
else if (m_type == LicenseConstants::TEST_LICENSE_STRING)
{
message += (m_createdWithSeats ? " (unlimited seats)" : " (unlimited users)");
}
message += separator;
message += getExpireLine() + separator;
message += LicenseConstants::SEPARATOR_STRING + separator;
@@ -192,31 +193,40 @@ std::string License::getExpireLine() const
+ m_expire;
}
std::string License::getExpireLineUI() const
{
return toLowerCase(m_type == LicenseConstants::TEST_LICENSE_STRING ?
LicenseConstants::VALID_UNTIL_STRING :
LicenseConstants::VALID_UP_TO_STRING)
+ m_expire;
}
std::string License::getLicenseInfo() const
{
std::string info = m_user + "\n";
info += m_type + "\n";
info += getExpireLine() + "\n";
// get info depending on license type
if (isNonCommercialLicenseType())
{
info += "not registered for commercial development";
info += "not registered for commercial development\n";
}
else if (m_type == LicenseConstants::TEST_LICENSE_STRING)
else if (m_type == LicenseConstants::TEST_LICENSE_STRING || m_type == LicenseConstants::SITE_LICENSE_STRING)
{
info += "unlimited users";
info += "unlimited users\n";
}
else if (m_numberOfUsers > 1)
{
info += std::to_string(m_numberOfUsers) + " users";
info += std::to_string(m_numberOfUsers) + " users\n";
}
else
{
info += "1 user";
info += "1 user\n";
}
info += getExpireLineUI();
return info;
}
+2
View File
@@ -17,6 +17,7 @@ namespace LicenseConstants {
const char BEGIN_LICENSE_STRING[] = "-----BEGIN LICENSE-----";
const char END_LICENSE_STRING[] = "-----END LICENSE-----";
const char TEST_LICENSE_STRING[] = "Test License";
const char SITE_LICENSE_STRING[] = "Commercial Site License";
const char PRODUCT_STRING[] = "Product: Sourcetrail";
const char LICENSED_TO_STRING[] = "Licensed to: ";
const char LICENSE_TYPE_STRING[] = "License type: ";
@@ -71,6 +72,7 @@ public:
size_t numberOfUsers = 0
);
std::string getExpireLine() const;
std::string getExpireLineUI() const;
/// if Test License return >=0 or -1 if expired
/// for non Test License -2
+4 -3
View File
@@ -80,15 +80,15 @@ public:
License license;
license.loadFromString(generator.encodeLicense("TestUser", "Private License", 1, "2017.4"));
std::string testInfo = "TestUser\nPrivate License\nValid up to version: 2017.4\n1 user";
std::string testInfo = "TestUser\nPrivate License\n1 user\nvalid up to version: 2017.4";
TS_ASSERT_EQUALS(license.getLicenseInfo(), testInfo);
license.loadFromString(generator.encodeLicense("TestUser", "Volume License", 20, "2017.3"));
testInfo = "TestUser\nVolume License\nValid up to version: 2017.3\n20 users";
testInfo = "TestUser\nVolume License\n20 users\nvalid up to version: 2017.3";
TS_ASSERT_EQUALS(license.getLicenseInfo(), testInfo);
license.loadFromString(generator.encodeLicense("TestUser", "Private/Academic Single User License", 0, "2018.1"));
testInfo = "TestUser\nPrivate/Academic Single User License\nValid up to version: 2018.1\nnot registered for commercial development";
testInfo = "TestUser\nPrivate/Academic Single User License\nnot registered for commercial development\nvalid up to version: 2018.1";
TS_ASSERT_EQUALS(license.getLicenseInfo(), testInfo);
}
@@ -104,6 +104,7 @@ public:
TS_ASSERT_EQUALS(license.getUser(), "TestUser");
TS_ASSERT_EQUALS(license.getType(), "Private License");
TS_ASSERT_EQUALS(license.getNumberOfUsers(), 20);
TS_ASSERT(license.isValid());
}