#5657 Added unit tests for SerialKey

This commit is contained in:
Jerry (Xinyu Hou) 2016-10-13 17:55:38 +01:00
parent 2a452307cd
commit 235f528dd9
4 changed files with 87 additions and 115 deletions

View File

@ -22,5 +22,11 @@ endif()
add_library(shared STATIC ${sources}) add_library(shared STATIC ${sources})
include_directories(
../
../../../ext
../../../ext/gtest-1.6.0/include
)
target_link_libraries(shared arch base) target_link_libraries(shared arch base)

View File

@ -68,4 +68,4 @@ endif()
add_executable(unittests ${sources}) add_executable(unittests ${sources})
target_link_libraries(unittests target_link_libraries(unittests
arch base client server common io net platform server synergy mt ipc gtest gmock ${libs} ${OPENSSL_LIBS}) arch base client server common io net platform server synergy mt ipc gtest gmock shared ${libs} ${OPENSSL_LIBS})

View File

@ -0,0 +1,80 @@
/*
* 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/SerialKey.h"
#include "test/global/gtest.h"
TEST(SerialKeyTests, decode_empty_returnEmptyString)
{
SerialKey serial("");
std::string plainText = serial.decode("");
EXPECT_EQ(0, plainText.size());
}
TEST(SerialKeyTests, decode_invalidDigit_returnEmptyString)
{
SerialKey serial("");
std::string plainText = serial.decode("MOCKZ");
EXPECT_EQ(0, plainText.size());
}
TEST(SerialKeyTests, decode_validSerial_returnPlainText)
{
SerialKey serial("");
std::string plainText = serial.decode("53796E6572677920726F636B7321");
EXPECT_EQ("Synergy rocks!", plainText);
}
TEST(SerialKeyTests, parse_noParty_invalid)
{
SerialKey serial("");
serial.parse("MOCK");
EXPECT_FALSE(serial.isValid(0));
}
TEST(SerialKeyTests, parse_invalidPartsLenghth_invalid)
{
SerialKey serial("");
serial.parse("{Synergy;Rocks}");
EXPECT_FALSE(serial.isValid(0));
}
TEST(SerialKeyTests, parse_validV1Serial_valid)
{
SerialKey serial("");
serial.parse("{v1;basic;Bob;1;email;company name;0;86400}");
EXPECT_EQ(true, serial.isValid(0));
EXPECT_EQ(kBasic, serial.edition());
EXPECT_FALSE(serial.isExpired(0));
EXPECT_EQ(true, serial.dayLeft(0));
EXPECT_EQ(true, serial.isExpiring(1));
}
TEST(SerialKeyTests, parse_validV2Serial_valid)
{
SerialKey serial("");
serial.parse("{v2;trial;pro;Bob;1;email;company name;0;86400}");
EXPECT_EQ(true, serial.isValid(0));
EXPECT_EQ(kPro, serial.edition());
EXPECT_FALSE(serial.isExpired(0));
EXPECT_EQ(true, serial.dayLeft(0));
EXPECT_EQ(true, serial.isExpiring(1));
EXPECT_EQ(true, serial.isTrial());
}

View File

@ -1,114 +0,0 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015 Synergy Seamless 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/>.
*/
//
//#include "synergy/LicenseManager.h"
//#include "synergy/XSynergy.h"
//
//#include "test/global/gtest.h"
//
//TEST(SubscriptionTests, decode_invalidLength_throwException)
//{
// LicenseManager LicenseManager;
// String serial("ABC");
//
// EXPECT_THROW(LicenseManager.decode(serial), XSubscription);
//}
//
//TEST(SubscriptionTests, decode_unrecognizedDigit_throwException)
//{
// LicenseManager LicenseManager;
// String serial("MOCK");
//
// EXPECT_THROW(LicenseManager.decode(serial), XSubscription);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_noParity_throwException)
//{
// LicenseManager LicenseManager;
// String painText("MOCK");
// SubscriptionKey key;
//
// EXPECT_THROW(LicenseManager.parsePlainSerial(painText, key), XSubscription);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException)
//{
// LicenseManager LicenseManager;
// String painText("{MOCK}");
// SubscriptionKey key;
//
// EXPECT_THROW(LicenseManager.parsePlainSerial(painText, key), XSubscription);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_validSerial_validSubscriptionKey)
//{
// // valid until 2 March 2049
// LicenseManager LicenseManager;
// String painText("{v1;trial;Bob;1;a@a.a;mock company;2147483647;2147483647}");
// SubscriptionKey key;
// LicenseManager.parsePlainSerial(painText, key);
//
// EXPECT_EQ("trial", key.m_type);
// EXPECT_EQ("Bob", key.m_name);
// EXPECT_EQ(1, key.m_userLimit);
// EXPECT_EQ("a@a.a", key.m_email);
// EXPECT_EQ("mock company", key.m_company);
// EXPECT_EQ(2147483647, key.m_warnTime);
// EXPECT_EQ(2147483647, key.m_expireTime);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_validSerialWithoutCompany_validSubscriptionKey)
//{
// // valid until 2 March 2049
// LicenseManager LicenseManager;
// String painText("{v1;trial;Bob;1;a@a.a;;2147483647;2147483647}");
// SubscriptionKey key;
// LicenseManager.parsePlainSerial(painText, key);
//
// EXPECT_EQ("trial", key.m_type);
// EXPECT_EQ("Bob", key.m_name);
// EXPECT_EQ(1, key.m_userLimit);
// EXPECT_EQ("a@a.a", key.m_email);
// EXPECT_EQ("", key.m_company);
// EXPECT_EQ(2147483647, key.m_warnTime);
// EXPECT_EQ(2147483647, key.m_expireTime);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_expiredTrialSerial_throwException)
//{
// LicenseManager LicenseManager;
// String painText("{v1;trial;Bob;1;1398297600;1398384000}");
// SubscriptionKey key;
//
// EXPECT_THROW(LicenseManager.parsePlainSerial(painText, key), XSubscription);
//}
//
//TEST(SubscriptionTests, parsePlainSerial_expiredBasicSerial_validSubscriptionKey)
//{
// LicenseManager LicenseManager;
// String painText("{v1;basic;Bob;1;a@a.a;mock company;1398297600;1398384000}");
// SubscriptionKey key;
// LicenseManager.parsePlainSerial(painText, key);
//
// EXPECT_EQ("basic", key.m_type);
// EXPECT_EQ("Bob", key.m_name);
// EXPECT_EQ(1, key.m_userLimit);
// EXPECT_EQ("a@a.a", key.m_email);
// EXPECT_EQ("mock company", key.m_company);
// EXPECT_EQ(1398297600, key.m_warnTime);
// EXPECT_EQ(1398384000, key.m_expireTime);
//}