deskflow/src/test/unittests/server/ConfigTests.cpp

199 lines
6.6 KiB
C++
Raw Normal View History

/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "lib/server/Config.h"
#include "test/global/gtest.h"
class OnlySystemFilter: public InputFilter::Condition {
public:
Condition* clone() const override {
return new OnlySystemFilter();
}
String format() const override {
return "";
}
InputFilter::EFilterStatus match(const Event& ev) override {
return ev.getType() == Event::kSystem ? InputFilter::kActivate : InputFilter::kNoMatch;
}
};
TEST(ServerConfigTests, serverconfig_will_deem_inequal_configs_with_different_map_size)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_inequal_configs_with_different_cell_names)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenB");
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_equal_configs_with_same_cell_names)
{
Config a(nullptr);
Config b(nullptr);
EXPECT_TRUE(a.addScreen("screenA"));
EXPECT_TRUE(a.addScreen("screenB"));
EXPECT_TRUE(a.addScreen("screenC"));
EXPECT_TRUE(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(a.connect("screenB", EDirection::kLeft, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(b.addScreen("screenA"));
EXPECT_TRUE(b.addScreen("screenB"));
EXPECT_TRUE(b.addScreen("screenC"));
EXPECT_TRUE(b.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(b.connect("screenB", EDirection::kLeft, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
a.addOption("screenA", kOptionClipboardSharing, 1);
b.addOption("screenA", kOptionClipboardSharing, 1);
a.addOption(std::string(), kOptionClipboardSharing, 1);
b.addOption(std::string(), kOptionClipboardSharing, 1);
a.getInputFilter()->addFilterRule(InputFilter::Rule{new OnlySystemFilter()});
b.getInputFilter()->addFilterRule(InputFilter::Rule{new OnlySystemFilter()});
a.addAlias("screenA", "aliasA");
b.addAlias("screenA", "aliasA");
Synergy 591 remaining sonarcloud bugs in synergy core (#6915) * (WIP)-all issues corrected, tests started * first test passing alternative solution for SonarCloud check fixed for to while translation added changelog item adding tests and fixes more tests; avoid compiling BSD Tests on Windows attempting a BSD compile patch more tests borrowing symbol detection from another test more ambitious testing changed the order of assertions for better info more tests fixed clear errors before executing expanding transformation to use string comparison including terminator on translation count a different flag for testing MS Windows differente Windows flag more tests fixing platform encoding match Windows compiler difference on #ifdef Google Test macro usage fix test added added keymap test test and initialisation fixed ms cl issue with named init test for keymap exercising keystate more configuration exercises one more test for config added Unicode test an IPv6 test more portable networking code using our own platform switching code avoiding strcpy * Fixed typo in Changelog. * +appropriate memory handling * one more test for coverage * a tad more coverage * expanded test on Config * forcing addresses be resolved before use on test * log modified * re-obtaining equivalency at continue * test added * additional test, and initialisation for Windows * added test sections for coverage * fixed count Co-authored-by: Max <maxmommersteeg@hotmail.com> Co-authored-by: SerhiiGadzhilov <71632867+SerhiiGadzhilov@users.noreply.github.com>
2021-01-19 12:52:37 +00:00
NetworkAddress addr1("localhost", 8080);
addr1.resolve();
NetworkAddress addr2("localhost", 8080);
addr2.resolve();
a.setSynergyAddress(addr1);
b.setSynergyAddress(addr2);
EXPECT_TRUE(a == b);
EXPECT_TRUE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_same_cell_names_different_options)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
a.addOption("screenA", kOptionClipboardSharing, 0);
b.addOption("screenA", kOptionClipboardSharing, 1);
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_same_cell_names_different_aliases1)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
b.addAlias("screenA", "aliasA");
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_same_cell_names_different_aliases2)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
a.addAlias("screenA", "aliasA");
b.addAlias("screenA", "aliasB");
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_different_global_options)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
a.addOption(std::string(), kOptionClipboardSharing, 0);
b.addOption(std::string(), kOptionClipboardSharing, 1);
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_different_filters)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
a.getInputFilter()->addFilterRule(InputFilter::Rule{new OnlySystemFilter()});
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_configs_with_different_address)
{
Config a(nullptr);
Config b(nullptr);
a.addScreen("screenA");
b.addScreen("screenA");
a.setSynergyAddress(NetworkAddress(8080));
b.setSynergyAddress(NetworkAddress(1010));
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_cell_neighbours1)
{
Config a(nullptr);
Config b(nullptr);
EXPECT_TRUE(a.addScreen("screenA"));
EXPECT_TRUE(a.addScreen("screenB"));
EXPECT_TRUE(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(b.addScreen("screenA"));
EXPECT_TRUE(b.addScreen("screenB"));
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_cell_neighbours2)
{
Config a(nullptr);
Config b(nullptr);
EXPECT_TRUE(a.addScreen("screenA"));
EXPECT_TRUE(a.addScreen("screenB"));
EXPECT_TRUE(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(b.addScreen("screenA"));
EXPECT_TRUE(b.addScreen("screenB"));
EXPECT_TRUE(b.connect("screenA", EDirection::kBottom, 0.0f, 0.25f, "screenB", 0.25f, 1.0f));
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}
TEST(ServerConfigTests, serverconfig_will_deem_different_cell_neighbours3)
{
Config a(nullptr);
Config b(nullptr);
EXPECT_TRUE(a.addScreen("screenA"));
EXPECT_TRUE(a.addScreen("screenB"));
EXPECT_TRUE(a.addScreen("screenC"));
EXPECT_TRUE(a.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenB", 0.5f, 1.0f));
EXPECT_TRUE(b.addScreen("screenA"));
EXPECT_TRUE(b.addScreen("screenB"));
EXPECT_TRUE(b.addScreen("screenC"));
EXPECT_TRUE(b.connect("screenA", EDirection::kBottom, 0.0f, 0.5f, "screenC", 0.5f, 1.0f));
EXPECT_FALSE(a == b);
EXPECT_FALSE(b == a);
}