parent
f9f2d8e8af
commit
e26ccfdce6
|
@ -67,6 +67,7 @@ CApp::CApp(IEventQueue* events, CreateTaskBarReceiverFunc createTaskBarReceiver,
|
|||
|
||||
CApp::~CApp()
|
||||
{
|
||||
s_instance = nullptr;
|
||||
delete m_args;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define TEST_ENV
|
||||
|
||||
#include "synergy/App.h"
|
||||
|
||||
#include "test/global/gmock.h"
|
||||
|
||||
class CMockApp : public CApp
|
||||
{
|
||||
public:
|
||||
CMockApp() : CApp(NULL, NULL, NULL) { }
|
||||
|
||||
MOCK_METHOD0(help, void());
|
||||
MOCK_METHOD0(loadConfig, void());
|
||||
MOCK_METHOD1(loadConfig, bool(const CString&));
|
||||
MOCK_CONST_METHOD0(daemonInfo, const char*());
|
||||
MOCK_CONST_METHOD0(daemonName, const char*());
|
||||
MOCK_METHOD2(parseArgs, void(int, const char* const*));
|
||||
MOCK_METHOD0(version, void());
|
||||
MOCK_METHOD2(standardStartup, int(int, char**));
|
||||
MOCK_METHOD4(runInner, int(int, char**, ILogOutputter*, StartupFunc));
|
||||
MOCK_METHOD0(startNode, void());
|
||||
MOCK_METHOD0(mainLoop, int());
|
||||
MOCK_METHOD2(foregroundStartup, int(int, char**));
|
||||
MOCK_METHOD0(createScreen, CScreen*());
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define TEST_ENV
|
||||
|
||||
#include "synergy/ArgParser.h"
|
||||
|
||||
#include "test/global/gmock.h"
|
||||
|
||||
class CMockArgParser : public CArgParser
|
||||
{
|
||||
public:
|
||||
CMockArgParser() : CArgParser(NULL) { }
|
||||
|
||||
MOCK_METHOD3(parseGenericArgs, bool(int, const char* const*, int&));
|
||||
MOCK_METHOD0(checkUnexpectedArgs, bool());
|
||||
};
|
|
@ -49,4 +49,4 @@ endif()
|
|||
|
||||
add_executable(unittests ${sources})
|
||||
target_link_libraries(unittests
|
||||
arch base client server common io net platform server synergy mt gtest gmock cryptopp ${libs})
|
||||
arch base client server common io net platform server synergy mt ipc gtest gmock cryptopp ${libs})
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/ArgParser.h"
|
||||
#include "synergy/ArgsBase.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
TEST(CArgParserTests, isArg_abbreviationsArg_returnTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* argv[argc] = { "stub", "-t" };
|
||||
bool result = CArgParser::isArg(i, argc, argv, "-t", NULL);
|
||||
|
||||
EXPECT_EQ(true, result);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, isArg_fullArg_returnTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* argv[argc] = { "stub", "--test" };
|
||||
bool result = CArgParser::isArg(i, argc, argv, NULL, "--test");
|
||||
|
||||
EXPECT_EQ(true, result);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, isArg_missingArgs_returnFalse)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* argv[argc] = { "stub", "-t" };
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
bool result = CArgParser::isArg(i, argc, argv, "-t", NULL, 1);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(true, argsBase.m_shouldExit);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, searchDoubleQuotes_doubleQuotedArg_returnTrue)
|
||||
{
|
||||
CString command("\"stub\"");
|
||||
size_t left = 0;
|
||||
size_t right = 0;
|
||||
|
||||
bool result = CArgParser::searchDoubleQuotes(command, left, right);
|
||||
|
||||
EXPECT_EQ(true, result);
|
||||
EXPECT_EQ(0, left);
|
||||
EXPECT_EQ(5, right);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, searchDoubleQuotes_noDoubleQuotedArg_returnfalse)
|
||||
{
|
||||
CString command("stub");
|
||||
size_t left = 0;
|
||||
size_t right = 0;
|
||||
|
||||
bool result = CArgParser::searchDoubleQuotes(command, left, right);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(0, left);
|
||||
EXPECT_EQ(0, right);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, searchDoubleQuotes_oneDoubleQuoteArg_returnfalse)
|
||||
{
|
||||
CString command("\"stub");
|
||||
size_t left = 0;
|
||||
size_t right = 0;
|
||||
|
||||
bool result = CArgParser::searchDoubleQuotes(command, left, right);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_EQ(0, left);
|
||||
EXPECT_EQ(0, right);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, splitCommandString_oneArg_returnArgv)
|
||||
{
|
||||
CString command("stub");
|
||||
std::vector<CString> argv;
|
||||
|
||||
CArgParser::splitCommandString(command, argv);
|
||||
|
||||
EXPECT_EQ(1, argv.size());
|
||||
EXPECT_EQ("stub", argv.at(0));
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, splitCommandString_twoArgs_returnArgv)
|
||||
{
|
||||
CString command("stub1 stub2");
|
||||
std::vector<CString> argv;
|
||||
|
||||
CArgParser::splitCommandString(command, argv);
|
||||
|
||||
EXPECT_EQ(2, argv.size());
|
||||
EXPECT_EQ("stub1", argv.at(0));
|
||||
EXPECT_EQ("stub2", argv.at(1));
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, splitCommandString_doubleQuotedArgs_returnArgv)
|
||||
{
|
||||
CString command("\"stub1\" stub2 \"stub3\"");
|
||||
std::vector<CString> argv;
|
||||
|
||||
CArgParser::splitCommandString(command, argv);
|
||||
|
||||
EXPECT_EQ(3, argv.size());
|
||||
EXPECT_EQ("stub1", argv.at(0));
|
||||
EXPECT_EQ("stub2", argv.at(1));
|
||||
EXPECT_EQ("stub3", argv.at(2));
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, splitCommandString_spaceDoubleQuotedArgs_returnArgv)
|
||||
{
|
||||
CString command("\"stub1\" stub2 \"stub3 space\"");
|
||||
std::vector<CString> argv;
|
||||
|
||||
CArgParser::splitCommandString(command, argv);
|
||||
|
||||
EXPECT_EQ(3, argv.size());
|
||||
EXPECT_EQ("stub1", argv.at(0));
|
||||
EXPECT_EQ("stub2", argv.at(1));
|
||||
EXPECT_EQ("stub3 space", argv.at(2));
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, getArgv_stringArray_return2DArray)
|
||||
{
|
||||
std::vector<CString> argArray;
|
||||
argArray.push_back("stub1");
|
||||
argArray.push_back("stub2");
|
||||
argArray.push_back("stub3 space");
|
||||
const char** argv = CArgParser::getArgv(argArray);
|
||||
|
||||
CString row1(argv[0]);
|
||||
CString row2(argv[1]);
|
||||
CString row3(argv[2]);
|
||||
|
||||
EXPECT_EQ("stub1", row1);
|
||||
EXPECT_EQ("stub2", row2);
|
||||
EXPECT_EQ("stub3 space", row3);
|
||||
|
||||
delete[] argv;
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, assembleCommand_stringArray_returnCommand)
|
||||
{
|
||||
std::vector<CString> argArray;
|
||||
argArray.push_back("stub1");
|
||||
argArray.push_back("stub2");
|
||||
CString command = CArgParser::assembleCommand(argArray);
|
||||
|
||||
EXPECT_EQ("stub1 stub2", command);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, assembleCommand_ignoreSecondArg_returnCommand)
|
||||
{
|
||||
std::vector<CString> argArray;
|
||||
argArray.push_back("stub1");
|
||||
argArray.push_back("stub2");
|
||||
CString command = CArgParser::assembleCommand(argArray, "stub2");
|
||||
|
||||
EXPECT_EQ("stub1", command);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, assembleCommand_ignoreSecondArgWithOneParameter_returnCommand)
|
||||
{
|
||||
std::vector<CString> argArray;
|
||||
argArray.push_back("stub1");
|
||||
argArray.push_back("stub2");
|
||||
argArray.push_back("stub3");
|
||||
argArray.push_back("stub4");
|
||||
CString command = CArgParser::assembleCommand(argArray, "stub2", 1);
|
||||
|
||||
EXPECT_EQ("stub1 stub4", command);
|
||||
}
|
||||
|
||||
TEST(CArgParserTests, assembleCommand_stringArrayWithSpace_returnCommand)
|
||||
{
|
||||
std::vector<CString> argArray;
|
||||
argArray.push_back("stub1 space");
|
||||
argArray.push_back("stub2");
|
||||
argArray.push_back("stub3 space");
|
||||
CString command = CArgParser::assembleCommand(argArray);
|
||||
|
||||
EXPECT_EQ("\"stub1 space\" stub2 \"stub3 space\"", command);
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/ArgParser.h"
|
||||
#include "synergy/ClientArgs.h"
|
||||
#include "test/mock/synergy/MockArgParser.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
bool
|
||||
client_stubParseGenericArgs(int, const char* const*, int&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
client_stubCheckUnexpectedArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(CClientArgsParsingTests, parseClientArgs_yScrollArg_setYScroll)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(client_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(client_stubCheckUnexpectedArgs));
|
||||
CClientArgs clientArgs;
|
||||
const int argc = 3;
|
||||
const char* kYScrollCmd[argc] = { "stub", "--yscroll", "1" };
|
||||
|
||||
argParser.parseClientArgs(clientArgs, argc, kYScrollCmd);
|
||||
|
||||
EXPECT_EQ(1, clientArgs.m_yscroll);
|
||||
}
|
||||
|
||||
TEST(CClientArgsParsingTests, parseClientArgs_addressArg_setSynergyAddress)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(client_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(client_stubCheckUnexpectedArgs));
|
||||
CClientArgs clientArgs;
|
||||
const int argc = 2;
|
||||
const char* kAddressCmd[argc] = { "stub", "mock_address" };
|
||||
|
||||
bool result = argParser.parseClientArgs(clientArgs, argc, kAddressCmd);
|
||||
|
||||
EXPECT_EQ("mock_address", clientArgs.m_synergyAddress);
|
||||
EXPECT_EQ(true, result);
|
||||
}
|
||||
|
||||
TEST(CClientArgsParsingTests, parseClientArgs_noAddressArg_returnFalse)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(client_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(client_stubCheckUnexpectedArgs));
|
||||
CClientArgs clientArgs;
|
||||
const int argc = 1;
|
||||
const char* kNoAddressCmd[argc] = { "stub" };
|
||||
|
||||
bool result = argParser.parseClientArgs(clientArgs, argc, kNoAddressCmd);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(CClientArgsParsingTests, parseClientArgs_unrecognizedArg_returnFalse)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(client_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(client_stubCheckUnexpectedArgs));
|
||||
CClientArgs clientArgs;
|
||||
const int argc = 3;
|
||||
const char* kUnrecognizedCmd[argc] = { "stub", "mock_arg", "mock_address"};
|
||||
|
||||
bool result = argParser.parseClientArgs(clientArgs, argc, kUnrecognizedCmd);
|
||||
|
||||
EXPECT_FALSE(result);
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/ArgParser.h"
|
||||
#include "synergy/ArgsBase.h"
|
||||
#include "test/mock/synergy/MockApp.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
using namespace synergy;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
bool g_helpShowed = false;
|
||||
bool g_versionShowed = false;
|
||||
|
||||
void
|
||||
showMockHelp()
|
||||
{
|
||||
g_helpShowed = true;
|
||||
}
|
||||
|
||||
void
|
||||
showMockVersion()
|
||||
{
|
||||
g_versionShowed = true;
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_logLevelCmd_setLogLevel)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char* kLogLevelCmd[argc] = { "stub", "--debug", "DEBUG" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kLogLevelCmd, i);
|
||||
|
||||
CString logFilter(argsBase.m_logFilter);
|
||||
|
||||
EXPECT_EQ("DEBUG", logFilter);
|
||||
EXPECT_EQ(2, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_logFileCmd_saveLogFilename)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char* kLogFileCmd[argc] = { "stub", "--log", "mock_filename" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kLogFileCmd, i);
|
||||
|
||||
CString logFile(argsBase.m_logFile);
|
||||
|
||||
EXPECT_EQ("mock_filename", logFile);
|
||||
EXPECT_EQ(2, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_logFileCmdWithSpace_saveLogFilename)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char* kLogFileCmdWithSpace[argc] = { "stub", "--log", "mo ck_filename" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kLogFileCmdWithSpace, i);
|
||||
|
||||
CString logFile(argsBase.m_logFile);
|
||||
|
||||
EXPECT_EQ("mo ck_filename", logFile);
|
||||
EXPECT_EQ(2, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_noDeamonCmd_daemonFalse)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kNoDeamonCmd[argc] = { "stub", "-f" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kNoDeamonCmd, i);
|
||||
|
||||
EXPECT_FALSE(argsBase.m_daemon);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_deamonCmd_daemonTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kDeamonCmd[argc] = { "stub", "--daemon" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kDeamonCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_daemon);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_nameCmd_saveName)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char* kNameCmd[argc] = { "stub", "--name", "mock" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kNameCmd, i);
|
||||
|
||||
EXPECT_EQ("mock", argsBase.m_name);
|
||||
EXPECT_EQ(2, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_noRestartCmd_restartFalse)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kNoRestartCmd[argc] = { "stub", "--no-restart" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kNoRestartCmd, i);
|
||||
|
||||
EXPECT_FALSE(argsBase.m_restartable);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_restartCmd_restartTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kRestartCmd[argc] = { "stub", "--restart" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kRestartCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_restartable);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_backendCmd_backendTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kBackendCmd[argc] = { "stub", "-z" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kBackendCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_backend);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_noHookCmd_noHookTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kNoHookCmd[argc] = { "stub", "--no-hooks" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kNoHookCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_noHooks);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_helpCmd_showHelp)
|
||||
{
|
||||
g_helpShowed = false;
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kHelpCmd[argc] = { "stub", "--help" };
|
||||
|
||||
NiceMock<CMockApp> app;
|
||||
CArgParser argParser(&app);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
ON_CALL(app, help()).WillByDefault(Invoke(showMockHelp));
|
||||
|
||||
argParser.parseGenericArgs(argc, kHelpCmd, i);
|
||||
|
||||
EXPECT_EQ(true, g_helpShowed);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_versionCmd_showVersion)
|
||||
{
|
||||
g_versionShowed = false;
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kVersionCmd[argc] = { "stub", "--version" };
|
||||
|
||||
NiceMock<CMockApp> app;
|
||||
CArgParser argParser(&app);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
ON_CALL(app, version()).WillByDefault(Invoke(showMockVersion));
|
||||
|
||||
argParser.parseGenericArgs(argc, kVersionCmd, i);
|
||||
|
||||
EXPECT_EQ(true, g_versionShowed);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_noTrayCmd_disableTrayTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kNoTrayCmd[argc] = { "stub", "--no-tray" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kNoTrayCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_disableTray);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_ipcCmd_enableIpcTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kIpcCmd[argc] = { "stub", "--ipc" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kIpcCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_enableIpc);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_cryptoPassCmd_savePassword)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 3;
|
||||
const char* kCryptoPassCmd[argc] = { "stub", "--crypto-pass", "mock_password" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kCryptoPassCmd, i);
|
||||
|
||||
EXPECT_EQ("mock_password", argsBase.m_crypto.m_pass);
|
||||
EXPECT_EQ(1, argsBase.m_crypto.m_mode); // 1 == kCfb
|
||||
EXPECT_EQ(2, i);
|
||||
}
|
||||
|
||||
#ifndef WINAPI_XWINDOWS
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_dragDropCmdOnNonLinux_enableDragDropTrue)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kDragDropCmd[argc] = { "stub", "--enable-drag-drop" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kDragDropCmd, i);
|
||||
|
||||
EXPECT_EQ(true, argsBase.m_enableDragDrop);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WINAPI_XWINDOWS
|
||||
TEST(CGenericArgsParsingTests, parseGenericArgs_dragDropCmdOnLinux_enableDragDropFalse)
|
||||
{
|
||||
int i = 1;
|
||||
const int argc = 2;
|
||||
const char* kDragDropCmd[argc] = { "stub", "--enable-drag-drop" };
|
||||
|
||||
CArgParser argParser(NULL);
|
||||
CArgsBase argsBase;
|
||||
argParser.setArgsBase(argsBase);
|
||||
|
||||
argParser.parseGenericArgs(argc, kDragDropCmd, i);
|
||||
|
||||
EXPECT_FALSE(argsBase.m_enableDragDrop);
|
||||
EXPECT_EQ(1, i);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* synergy -- mouse and keyboard sharing utility
|
||||
* Copyright (C) 2014 Synergy Si, 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 COPYING 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/ArgParser.h"
|
||||
#include "synergy/ServerArgs.h"
|
||||
#include "test/mock/synergy/MockArgParser.h"
|
||||
|
||||
#include "test/global/gtest.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::NiceMock;
|
||||
|
||||
bool
|
||||
server_stubParseGenericArgs(int, const char* const*, int&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
server_stubCheckUnexpectedArgs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(CServerArgsParsingTests, parseServerArgs_addressArg_setSynergyAddress)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(server_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(server_stubCheckUnexpectedArgs));
|
||||
CServerArgs serverArgs;
|
||||
const int argc = 3;
|
||||
const char* kAddressCmd[argc] = { "stub", "--address", "mock_address" };
|
||||
|
||||
argParser.parseServerArgs(serverArgs, argc, kAddressCmd);
|
||||
|
||||
EXPECT_EQ("mock_address", serverArgs.m_synergyAddress);
|
||||
}
|
||||
|
||||
TEST(CServerArgsParsingTests, parseServerArgs_configArg_setConfigFile)
|
||||
{
|
||||
NiceMock<CMockArgParser> argParser;
|
||||
ON_CALL(argParser, parseGenericArgs(_, _, _)).WillByDefault(Invoke(server_stubParseGenericArgs));
|
||||
ON_CALL(argParser, checkUnexpectedArgs()).WillByDefault(Invoke(server_stubCheckUnexpectedArgs));
|
||||
CServerArgs serverArgs;
|
||||
const int argc = 3;
|
||||
const char* kConfigCmd[argc] = { "stub", "--config", "mock_configFile" };
|
||||
|
||||
argParser.parseServerArgs(serverArgs, argc, kConfigCmd);
|
||||
|
||||
EXPECT_EQ("mock_configFile", serverArgs.m_configFile);
|
||||
}
|
Loading…
Reference in New Issue