Add unit tests for subscription manager #4715
This commit is contained in:
parent
978c97cbc0
commit
da315ec164
|
@ -36,6 +36,7 @@ endif()
|
|||
include_directories(
|
||||
../
|
||||
../../../ext
|
||||
../../../ext/gtest-1.6.0/include
|
||||
)
|
||||
|
||||
if (UNIX)
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include "SubscriptionKey.h"
|
||||
#include "common/common.h"
|
||||
|
||||
#include "gtest/gtest_prod.h"
|
||||
|
||||
class SubscriptionManager {
|
||||
public:
|
||||
SubscriptionManager();
|
||||
|
@ -32,7 +34,16 @@ public:
|
|||
|
||||
//! Use standard output to return subscription filename to gui
|
||||
void printFilename();
|
||||
|
||||
|
||||
private:
|
||||
FRIEND_TEST(SubscriptionTests, decode_invalidLength_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, decode_unrecognizedDigit_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, decode_invalidSerial_outputPlainText);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_noParity_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException);
|
||||
FRIEND_TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException);
|
||||
|
||||
private:
|
||||
String decode(const String& input);
|
||||
void parsePlainSerial(const String& plainText, SubscriptionKey& key);
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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/SubscriptionManager.h"
|
||||
#include "synergy/XSynergy.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
TEST(SubscriptionTests, decode_invalidLength_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String serial("ABC");
|
||||
|
||||
EXPECT_THROW(subscriptionManager.decode(serial), XSubscription);
|
||||
}
|
||||
|
||||
TEST(SubscriptionTests, decode_unrecognizedDigit_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String serial("MOCK");
|
||||
|
||||
EXPECT_THROW(subscriptionManager.decode(serial), XSubscription);
|
||||
}
|
||||
|
||||
TEST(SubscriptionTests, parsePlainSerial_noParity_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String painText("MOCK");
|
||||
SubscriptionKey key;
|
||||
|
||||
EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
|
||||
}
|
||||
|
||||
TEST(SubscriptionTests, parsePlainSerial_invalidSerial_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String painText("{MOCK}");
|
||||
SubscriptionKey key;
|
||||
|
||||
EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
|
||||
}
|
||||
|
||||
TEST(SubscriptionTests, parsePlainSerial_validSerial_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String painText("{v1;trial;Bob;1;1498297600;1498384000}");
|
||||
SubscriptionKey key;
|
||||
subscriptionManager.parsePlainSerial(painText, key);
|
||||
|
||||
EXPECT_EQ("trial", key.m_type);
|
||||
EXPECT_EQ("Bob", key.m_name);
|
||||
EXPECT_EQ(1, key.m_userLimit);
|
||||
EXPECT_EQ(1498297600, key.m_warnTime);
|
||||
EXPECT_EQ(1498384000, key.m_expireTime);
|
||||
}
|
||||
|
||||
TEST(SubscriptionTests, parsePlainSerial_expiredSerial_throwException)
|
||||
{
|
||||
SubscriptionManager subscriptionManager;
|
||||
String painText("{v1;trial;Bob;1;1398297600;1398384000}");
|
||||
SubscriptionKey key;
|
||||
|
||||
EXPECT_THROW(subscriptionManager.parsePlainSerial(painText, key), XSubscription);
|
||||
}
|
Loading…
Reference in New Issue