From edbf4dfedaec5d6e60d8111d43e71cc332f3d58f Mon Sep 17 00:00:00 2001 From: Ignacio Rodriguez Date: Tue, 3 Nov 2020 22:31:50 +0700 Subject: [PATCH] a few tests --- .vscode/launch.json | 14 ++++++ .vscode/settings.json | 25 +++++++++- src/test/unittests/synergy/ServerAppTests.cpp | 49 +++++++++++++++++++ .../synergy/ServerArgsParsingTests.cpp | 8 +++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 src/test/unittests/synergy/ServerAppTests.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..c5bd23a16 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "unittests", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/bin/unittests" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 2a8231b56..e8c7bab47 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,28 @@ "xevent", "xscreensaver", "xscreensaver's" - ] + ], + "editor.tokenColorCustomizations": { + "textMateRules": [ + { + "scope": "googletest.failed", + "settings": { + "foreground": "#f00" + } + }, + { + "scope": "googletest.passed", + "settings": { + "foreground": "#0f0" + } + }, + { + "scope": "googletest.run", + "settings": { + "foreground": "#0f0" + } + } + ] + }, + "gtest-adapter.supportLocation": true } \ No newline at end of file diff --git a/src/test/unittests/synergy/ServerAppTests.cpp b/src/test/unittests/synergy/ServerAppTests.cpp new file mode 100644 index 000000000..2b4cb2a40 --- /dev/null +++ b/src/test/unittests/synergy/ServerAppTests.cpp @@ -0,0 +1,49 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2014-2016 Symless Ltd. + * + * 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 . + */ + +#include "synergy/ArgParser.h" +#include "synergy/ServerArgs.h" + +#define TEST_ENV + +#include "synergy/ServerApp.h" + +#include "test/global/gmock.h" + +class MockServerApp : public ServerApp +{ +public: + MockServerApp() : ServerApp(nullptr, nullptr) { } +}; + +#include "test/global/gtest.h" + +// using ::testing::_; +// using ::testing::Invoke; +using ::testing::NiceMock; + +TEST(ServerAppTests, runInner_will_handle_configuration_lifetime) +{ + NiceMock app; + + EXPECT_FALSE(app.args().m_config); + + const char *argv[] {"synergyc"}; + app.runInner(1, const_cast(argv), nullptr, [](int,char**){ return 0; }); + + EXPECT_TRUE(app.args().m_config); +} diff --git a/src/test/unittests/synergy/ServerArgsParsingTests.cpp b/src/test/unittests/synergy/ServerArgsParsingTests.cpp index cc6e9a1d2..adba4057c 100644 --- a/src/test/unittests/synergy/ServerArgsParsingTests.cpp +++ b/src/test/unittests/synergy/ServerArgsParsingTests.cpp @@ -37,6 +37,14 @@ server_stubCheckUnexpectedArgs() return false; } +TEST(ServerArgs, ServerArgs_will_construct_from_copy) +{ + lib::synergy::ServerArgs serverArgs; + serverArgs.m_display = "display0"; + auto serverArgs2 {serverArgs}; + EXPECT_EQ(serverArgs.m_display, serverArgs2.m_display); +} + TEST(ServerArgsParsingTests, parseServerArgs_addressArg_setSynergyAddress) { NiceMock argParser;