Merge pull request #6831 from symless/SYNERGY-510-sonarcloud-major-bugs-in-synegry-core

incorporating sonar's major
This commit is contained in:
Ignacio Rodríguez 2020-11-10 17:56:59 +07:00 committed by GitHub
commit aa3cb4fd33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 28 deletions

View File

@ -1,3 +1,9 @@
===========
Bug fixes:
- #6831 Incorporating Sonar's major
Enhancements:
v1.12.x-snapshot
===========
Bug fixes:

View File

@ -61,7 +61,7 @@ ArchFileUnix::getUserDirectory()
std::string dir;
#if HAVE_GETPWUID_R
struct passwd pwent;
struct passwd* pwentp;
struct passwd* pwentp {};
#if defined(_SC_GETPW_R_SIZE_MAX)
long size = sysconf(_SC_GETPW_R_SIZE_MAX);
if (size == -1) {

View File

@ -848,12 +848,7 @@ void
XWindowsScreen::fakeMouseRelativeMove(SInt32 dx, SInt32 dy) const
{
// FIXME -- ignore xinerama for now
if (false && m_xinerama && m_xtestIsXineramaUnaware) {
// XWarpPointer(m_display, None, m_root, 0, 0, 0, 0, x, y);
}
else {
XTestFakeRelativeMotionEvent(m_display, dx, dy, CurrentTime);
}
XTestFakeRelativeMotionEvent(m_display, dx, dy, CurrentTime);
XFlush(m_display);
}

View File

@ -174,28 +174,24 @@ ArgParser::parsePlatformArg(lib::synergy::ArgsBase& argsBase, const int& argc, c
bool
ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
{
for (int i = 1; i < argc; ++i) {
if (isArg(i, argc, argv, NULL, "--get-active-desktop", 0)) {
args.m_printActiveDesktopName = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-installed-dir", 0)) {
args.m_getInstalledDir = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-profile-dir", 0)) {
args.m_getProfileDir = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--get-arch", 0)) {
args.m_getArch = true;
return true;
}
else {
return false;
}
// We support exactly one argument at a fix position
static const int only_index {1};
if (isArg(only_index, argc, argv, NULL, "--get-active-desktop", 0)) {
args.m_printActiveDesktopName = true;
return true;
}
else if (isArg(only_index, argc, argv, NULL, "--get-installed-dir", 0)) {
args.m_getInstalledDir = true;
return true;
}
else if (isArg(only_index, argc, argv, NULL, "--get-profile-dir", 0)) {
args.m_getProfileDir = true;
return true;
}
else if (isArg(only_index, argc, argv, NULL, "--get-arch", 0)) {
args.m_getArch = true;
return true;
}
return false;
}

View File

@ -15,8 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <functional>
#include <array>
#include "synergy/ArgParser.h"
#include "synergy/ArgsBase.h"
#include "synergy/ToolArgs.h"
#include "test/global/gtest.h"
@ -205,3 +209,24 @@ TEST(ArgParserTests, assembleCommand_stringArrayWithSpace_returnCommand)
EXPECT_EQ("\"stub1 space\" stub2 \"stub3 space\"", command);
}
TEST(ArgParserTests, parseToolArgs_matches_correspondingly)
{
ArgParser parser(nullptr);
std::map<const char *, std::function<bool(ToolArgs const &)>> tests = {
{"--get-active-desktop", [](ToolArgs const &a){ return a.m_printActiveDesktopName; }},
{"--get-installed-dir", [](ToolArgs const &a){ return a.m_getInstalledDir; }},
{"--get-profile-dir", [](ToolArgs const &a){ return a.m_getProfileDir; }},
{"--get-arch", [](ToolArgs const &a){ return a.m_getArch; }}
};
for (auto const &test: tests) {
ToolArgs toolArgs;
EXPECT_FALSE(test.second(toolArgs));
std::array<const char *, 2> twoArgs {"syntool", test.first};
EXPECT_TRUE(parser.parseToolArgs(toolArgs, 2, twoArgs.data()));
EXPECT_TRUE(test.second(toolArgs));
}
ToolArgs toolArgs;
std::array<const char *, 2> twoArgs {"syntool", "--garbage"};
EXPECT_FALSE(parser.parseToolArgs(toolArgs, 2, twoArgs.data()));
}