aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/unittests
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2021-11-10 00:54:35 -0500
commit58fb7a0cee13d84170aac52f3f89d91888e1afe3 (patch)
tree1d6312ba15f9ece5a8031e5280dfb8b38be8dfa3 /src/test/unittests
parent28db84b46139c9bb2bbcac8c6cc56e71d1e35629 (diff)
parentbeb08eb751fa8e1f72042f263316ab5e5ddb596d (diff)
Update upstream source from tag 'upstream/2.4.0+dfsg'
Update to upstream version '2.4.0+dfsg' with Debian dir 4b6668cc08c7b0e56b1e1f7b4e89ecdb316182a0
Diffstat (limited to 'src/test/unittests')
-rw-r--r--src/test/unittests/CMakeLists.txt8
-rw-r--r--src/test/unittests/Main.cpp8
-rw-r--r--src/test/unittests/barrier/ArgParserTests.cpp4
-rw-r--r--src/test/unittests/barrier/ClientArgsParsingTests.cpp4
-rw-r--r--src/test/unittests/barrier/ClipboardChunkTests.cpp4
-rw-r--r--src/test/unittests/barrier/ClipboardTests.cpp16
-rw-r--r--src/test/unittests/barrier/GenericArgsParsingTests.cpp36
-rw-r--r--src/test/unittests/barrier/KeyMapTests.cpp42
-rw-r--r--src/test/unittests/barrier/KeyStateTests.cpp12
-rw-r--r--src/test/unittests/base/StringTests.cpp36
-rw-r--r--src/test/unittests/ipc/IpcLogOutputterTests.cpp20
-rw-r--r--src/test/unittests/net/FingerprintDatabaseTests.cpp95
-rw-r--r--src/test/unittests/net/SecureUtilsTests.cpp73
-rw-r--r--src/test/unittests/platform/OSXKeyStateTests.cpp12
14 files changed, 282 insertions, 88 deletions
diff --git a/src/test/unittests/CMakeLists.txt b/src/test/unittests/CMakeLists.txt
index c46375c..8cf5e9a 100644
--- a/src/test/unittests/CMakeLists.txt
+++ b/src/test/unittests/CMakeLists.txt
@@ -1,11 +1,11 @@
# barrier -- mouse and keyboard sharing utility
# Copyright (C) 2012-2016 Symless Ltd.
# Copyright (C) 2009 Nick Bolton
-#
+#
# 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
@@ -50,8 +50,6 @@ list(APPEND headers ${platform_sources})
include_directories(
../../
- ../../../ext/gtest/include
- ../../../ext/gmock/include
../../../ext
)
@@ -67,4 +65,4 @@ endif()
add_executable(unittests ${sources})
target_link_libraries(unittests
- arch base client server common io net platform server synlib mt ipc gtest gmock ${libs} ${OPENSSL_LIBS})
+ arch base client server common io net platform server synlib mt ipc ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${libs} ${OPENSSL_LIBS})
diff --git a/src/test/unittests/Main.cpp b/src/test/unittests/Main.cpp
index 7f0d0fe..52ad252 100644
--- a/src/test/unittests/Main.cpp
+++ b/src/test/unittests/Main.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Nick Bolton
- *
+ *
* 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
@@ -35,12 +35,12 @@ main(int argc, char **argv)
Arch arch;
arch.init();
-
+
Log log;
log.setFilter(kDEBUG4);
testing::InitGoogleTest(&argc, argv);
-
+
// gtest seems to randomly finish with error codes (e.g. -1, -1073741819)
// even when no tests have failed. not sure what causes this, but it
// happens on all platforms and keeps leading to false positives.
diff --git a/src/test/unittests/barrier/ArgParserTests.cpp b/src/test/unittests/barrier/ArgParserTests.cpp
index e14877e..311162f 100644
--- a/src/test/unittests/barrier/ArgParserTests.cpp
+++ b/src/test/unittests/barrier/ArgParserTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- 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
diff --git a/src/test/unittests/barrier/ClientArgsParsingTests.cpp b/src/test/unittests/barrier/ClientArgsParsingTests.cpp
index 5a1e7d0..7aaa5db 100644
--- a/src/test/unittests/barrier/ClientArgsParsingTests.cpp
+++ b/src/test/unittests/barrier/ClientArgsParsingTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- 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
diff --git a/src/test/unittests/barrier/ClipboardChunkTests.cpp b/src/test/unittests/barrier/ClipboardChunkTests.cpp
index e0e37be..784dee8 100644
--- a/src/test/unittests/barrier/ClipboardChunkTests.cpp
+++ b/src/test/unittests/barrier/ClipboardChunkTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2015-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
diff --git a/src/test/unittests/barrier/ClipboardTests.cpp b/src/test/unittests/barrier/ClipboardTests.cpp
index f710751..c1afdfb 100644
--- a/src/test/unittests/barrier/ClipboardTests.cpp
+++ b/src/test/unittests/barrier/ClipboardTests.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Nick Bolton
- *
+ *
* 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
@@ -192,7 +192,7 @@ TEST(ClipboardTests, marshall_withTextAdded_lastSizeCharIs14)
EXPECT_EQ(14, (int)actual[11]);
}
-// TODO: there's some integer -> char encoding going on here. i find it
+// TODO: there's some integer -> char encoding going on here. i find it
// hard to believe that the clipboard is the only thing doing this. maybe
// we should refactor this stuff out of the clipboard.
TEST(ClipboardTests, marshall_withTextSize285_sizeCharsValid)
@@ -212,12 +212,12 @@ TEST(ClipboardTests, marshall_withTextSize285_sizeCharsValid)
String actual = clipboard.marshall();
- // 4 asserts here, but that's ok because we're really just asserting 1
+ // 4 asserts here, but that's ok because we're really just asserting 1
// thing. the 32-bit size value is split into 4 chars. if the size is 285
- // (29 more than the 8-bit max size), the last char "rolls over" to 29
- // (this is caused by a bit-wise & on 0xff and 8-bit truncation). each
- // char before the last stores a bit-shifted version of the number, each
- // 1 more power than the last, which is done by bit-shifting [0] by 24,
+ // (29 more than the 8-bit max size), the last char "rolls over" to 29
+ // (this is caused by a bit-wise & on 0xff and 8-bit truncation). each
+ // char before the last stores a bit-shifted version of the number, each
+ // 1 more power than the last, which is done by bit-shifting [0] by 24,
// [1] by 16, [2] by 8 ([3] is not bit-shifted).
EXPECT_EQ(0, actual[8]); // 285 >> 24 = 285 / (256^3) = 0
EXPECT_EQ(0, actual[9]); // 285 >> 16 = 285 / (256^2) = 0
diff --git a/src/test/unittests/barrier/GenericArgsParsingTests.cpp b/src/test/unittests/barrier/GenericArgsParsingTests.cpp
index f43070b..7f19918 100644
--- a/src/test/unittests/barrier/GenericArgsParsingTests.cpp
+++ b/src/test/unittests/barrier/GenericArgsParsingTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- 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
@@ -50,7 +50,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_logLevelCmd_setLogLevel)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kLogLevelCmd, i);
String logFilter(argsBase.m_logFilter);
@@ -68,7 +68,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_logFileCmd_saveLogFilename)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kLogFileCmd, i);
String logFile(argsBase.m_logFile);
@@ -86,7 +86,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_logFileCmdWithSpace_saveLogFilena
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kLogFileCmdWithSpace, i);
String logFile(argsBase.m_logFile);
@@ -104,7 +104,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_noDeamonCmd_daemonFalse)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kNoDeamonCmd, i);
EXPECT_FALSE(argsBase.m_daemon);
@@ -120,7 +120,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_deamonCmd_daemonTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kDeamonCmd, i);
EXPECT_EQ(true, argsBase.m_daemon);
@@ -136,7 +136,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_nameCmd_saveName)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kNameCmd, i);
EXPECT_EQ("mock", argsBase.m_name);
@@ -152,7 +152,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_noRestartCmd_restartFalse)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kNoRestartCmd, i);
EXPECT_FALSE(argsBase.m_restartable);
@@ -168,7 +168,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_restartCmd_restartTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kRestartCmd, i);
EXPECT_EQ(true, argsBase.m_restartable);
@@ -184,7 +184,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_backendCmd_backendTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kBackendCmd, i);
EXPECT_EQ(true, argsBase.m_backend);
@@ -200,7 +200,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_noHookCmd_noHookTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kNoHookCmd, i);
EXPECT_EQ(true, argsBase.m_noHooks);
@@ -219,7 +219,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_helpCmd_showHelp)
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
ON_CALL(app, help()).WillByDefault(Invoke(showMockHelp));
-
+
argParser.parseGenericArgs(argc, kHelpCmd, i);
EXPECT_EQ(true, g_helpShowed);
@@ -239,7 +239,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_versionCmd_showVersion)
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
ON_CALL(app, version()).WillByDefault(Invoke(showMockVersion));
-
+
argParser.parseGenericArgs(argc, kVersionCmd, i);
EXPECT_EQ(true, g_versionShowed);
@@ -255,7 +255,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_noTrayCmd_disableTrayTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kNoTrayCmd, i);
EXPECT_EQ(true, argsBase.m_disableTray);
@@ -271,7 +271,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_ipcCmd_enableIpcTrue)
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kIpcCmd, i);
EXPECT_EQ(true, argsBase.m_enableIpc);
@@ -288,7 +288,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_dragDropCmdOnNonLinux_enableDragD
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kDragDropCmd, i);
EXPECT_EQ(true, argsBase.m_enableDragDrop);
@@ -306,7 +306,7 @@ TEST(GenericArgsParsingTests, parseGenericArgs_dragDropCmdOnLinux_enableDragDrop
ArgParser argParser(NULL);
ArgsBase argsBase;
argParser.setArgsBase(argsBase);
-
+
argParser.parseGenericArgs(argc, kDragDropCmd, i);
EXPECT_FALSE(argsBase.m_enableDragDrop);
diff --git a/src/test/unittests/barrier/KeyMapTests.cpp b/src/test/unittests/barrier/KeyMapTests.cpp
index 5980633..20c1c55 100644
--- a/src/test/unittests/barrier/KeyMapTests.cpp
+++ b/src/test/unittests/barrier/KeyMapTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2016 Symless
- *
+ *
* 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
@@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define BARRIER_TEST_ENV
+
#include "barrier/KeyMap.h"
#include "test/global/gtest.h"
@@ -28,7 +30,7 @@ using ::testing::ReturnRef;
using ::testing::SaveArg;
namespace barrier {
-
+
TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem)
{
KeyMap keyMap;
@@ -44,7 +46,7 @@ TEST(KeyMapTests, findBestKey_requiredDown_matchExactFirstItem)
EXPECT_EQ(0, keyMap.findBestKey(entryList, currentState, desiredState));
}
-
+
TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactFirstItem)
{
KeyMap keyMap;
@@ -82,7 +84,7 @@ TEST(KeyMapTests, findBestKey_requiredAndExtraSensitiveDown_matchExactSecondItem
EXPECT_EQ(1, keyMap.findBestKey(entryList, currentState, desiredState));
}
-
+
TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
{
KeyMap keyMap;
@@ -101,7 +103,7 @@ TEST(KeyMapTests, findBestKey_extraSensitiveDown_matchExactSecondItem)
itemList2.push_back(item2);
entryList.push_back(itemList1);
entryList.push_back(itemList2);
-
+
EXPECT_EQ(1, keyMap.findBestKey(entryList, currentState, desiredState));
}
@@ -123,7 +125,7 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_matchOneRequiredChangeItem)
itemList2.push_back(item2);
entryList.push_back(itemList1);
entryList.push_back(itemList2);
-
+
EXPECT_EQ(1, keyMap.findBestKey(entryList, currentState, desiredState));
}
@@ -148,7 +150,7 @@ TEST(KeyMapTests, findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem)
EXPECT_EQ(1, keyMap.findBestKey(entryList, currentState, desiredState));
}
-
+
TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch)
{
KeyMap keyMap;
@@ -161,31 +163,31 @@ TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch)
KeyModifierMask desiredState = 0;
itemList.push_back(item);
entryList.push_back(itemList);
-
+
EXPECT_EQ(-1, keyMap.findBestKey(entryList, currentState, desiredState));
}
-
+
TEST(KeyMapTests, isCommand_shiftMask_returnFalse)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierShift;
-
+
EXPECT_FALSE(keyMap.isCommand(mask));
}
-
+
TEST(KeyMapTests, isCommand_controlMask_returnTrue)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierControl;
-
+
EXPECT_EQ(true, keyMap.isCommand(mask));
}
-
+
TEST(KeyMapTests, isCommand_alternateMask_returnTrue)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierAlt;
-
+
EXPECT_EQ(true, keyMap.isCommand(mask));
}
@@ -193,15 +195,15 @@ TEST(KeyMapTests, isCommand_alternateGraphicMask_returnTrue)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierAltGr;
-
+
EXPECT_EQ(true, keyMap.isCommand(mask));
}
-
+
TEST(KeyMapTests, isCommand_metaMask_returnTrue)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierMeta;
-
+
EXPECT_EQ(true, keyMap.isCommand(mask));
}
@@ -209,8 +211,8 @@ TEST(KeyMapTests, isCommand_superMask_returnTrue)
{
KeyMap keyMap;
KeyModifierMask mask= KeyModifierSuper;
-
+
EXPECT_EQ(true, keyMap.isCommand(mask));
}
-
+
}
diff --git a/src/test/unittests/barrier/KeyStateTests.cpp b/src/test/unittests/barrier/KeyStateTests.cpp
index d4154d8..bc41933 100644
--- a/src/test/unittests/barrier/KeyStateTests.cpp
+++ b/src/test/unittests/barrier/KeyStateTests.cpp
@@ -2,11 +2,11 @@
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2012-2016 Symless Ltd.
* Copyright (C) 2011 Nick Bolton
- *
+ *
* 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
@@ -100,7 +100,7 @@ TEST(KeyStateTests, sendKeyEvent_halfDuplex_addEventCalledTwice)
KeyStateImpl keyState(eventQueue, keyMap);
IKeyStateEvents keyStateEvents;
keyStateEvents.setEvents(&eventQueue);
-
+
ON_CALL(keyMap, isHalfDuplex(_, _)).WillByDefault(Return(true));
ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents));
@@ -116,7 +116,7 @@ TEST(KeyStateTests, sendKeyEvent_keyRepeat_addEventCalledOnce)
KeyStateImpl keyState(eventQueue, keyMap);
IKeyStateEvents keyStateEvents;
keyStateEvents.setEvents(&eventQueue);
-
+
ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents));
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
@@ -131,7 +131,7 @@ TEST(KeyStateTests, sendKeyEvent_keyDown_addEventCalledOnce)
KeyStateImpl keyState(eventQueue, keyMap);
IKeyStateEvents keyStateEvents;
keyStateEvents.setEvents(&eventQueue);
-
+
ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents));
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
@@ -146,7 +146,7 @@ TEST(KeyStateTests, sendKeyEvent_keyUp_addEventCalledOnce)
KeyStateImpl keyState(eventQueue, keyMap);
IKeyStateEvents keyStateEvents;
keyStateEvents.setEvents(&eventQueue);
-
+
ON_CALL(eventQueue, forIKeyState()).WillByDefault(ReturnRef(keyStateEvents));
EXPECT_CALL(eventQueue, addEvent(_)).Times(1);
diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp
index 39ad6e8..cc8e4fc 100644
--- a/src/test/unittests/base/StringTests.cpp
+++ b/src/test/unittests/base/StringTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- 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
@@ -56,12 +56,38 @@ TEST(StringTests, sprintf_formatWithArgument_formatedString)
TEST(StringTests, toHex_plaintext_hexString)
{
- String subject = "foobar";
+ std::vector<std::uint8_t> subject{'f', 'o', 'o', 'b', 'a', 'r'};
int width = 2;
- string::toHex(subject, width);
+ EXPECT_EQ("666f6f626172", string::to_hex(subject, width));
+}
+
+TEST(StringTests, fromhex_plaintext_string)
+{
+ auto result = string::from_hex("666f6f626172");
+ std::string expected = "foobar";
+ EXPECT_EQ(result, std::vector<std::uint8_t>(expected.begin(), expected.end()));
+}
+
+TEST(StringTests, fromhex_plaintext_string_colons)
+{
+ auto result = string::from_hex("66:6f:6f:62:61:72");
+ std::string expected = "foobar";
+ EXPECT_EQ(result, std::vector<std::uint8_t>(expected.begin(), expected.end()));
+}
- EXPECT_EQ("666f6f626172", subject);
+TEST(StringTests, fromhex_binary_string)
+{
+ auto result = string::from_hex("01020304050600fff9");
+ auto expected = std::vector<std::uint8_t>{1, 2, 3, 4, 5, 6, 0, 0xff, 0xf9};
+ EXPECT_EQ(result, expected);
+}
+
+TEST(StringTests, fromhex_invalid_string)
+{
+ EXPECT_TRUE(string::from_hex("66:6").empty());
+ EXPECT_TRUE(string::from_hex("66:612").empty());
+ EXPECT_TRUE(string::from_hex("66:WW").empty());
}
TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)
diff --git a/src/test/unittests/ipc/IpcLogOutputterTests.cpp b/src/test/unittests/ipc/IpcLogOutputterTests.cpp
index bbfed9c..6db9ac9 100644
--- a/src/test/unittests/ipc/IpcLogOutputterTests.cpp
+++ b/src/test/unittests/ipc/IpcLogOutputterTests.cpp
@@ -1,11 +1,11 @@
/*
* barrier -- mouse and keyboard sharing utility
* Copyright (C) 2015-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
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define TEST_ENV
+#define BARRIER_TEST_ENV
#include "test/mock/ipc/MockIpcServer.h"
@@ -50,7 +50,7 @@ TEST(IpcLogOutputterTests, write_threadingEnabled_bufferIsSent)
{
MockIpcServer mockServer;
mockServer.delegateToFake();
-
+
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(AtLeast(3));
@@ -67,7 +67,7 @@ TEST(IpcLogOutputterTests, write_threadingEnabled_bufferIsSent)
TEST(IpcLogOutputterTests, write_overBufferMaxSize_firstLineTruncated)
{
MockIpcServer mockServer;
-
+
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(1);
EXPECT_CALL(mockServer, send(IpcLogLineMessageEq("mock 2\nmock 3\n"), _)).Times(1);
@@ -85,7 +85,7 @@ TEST(IpcLogOutputterTests, write_overBufferMaxSize_firstLineTruncated)
TEST(IpcLogOutputterTests, write_underBufferMaxSize_allLinesAreSent)
{
MockIpcServer mockServer;
-
+
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(1);
@@ -107,7 +107,7 @@ TEST(IpcLogOutputterTests, write_underBufferMaxSize_allLinesAreSent)
TEST(IpcLogOutputterTests, write_overBufferRateLimit_lastLineTruncated)
{
MockIpcServer mockServer;
-
+
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(2);
@@ -123,7 +123,7 @@ TEST(IpcLogOutputterTests, write_overBufferRateLimit_lastLineTruncated)
outputter.write(kNOTE, "mock 3");
outputter.sendBuffer();
-
+
// after waiting the time limit send another to make sure
// we can log after the time limit passes.
// HACK: sleep causes the unit test to fail intermittently,
@@ -140,7 +140,7 @@ TEST(IpcLogOutputterTests, write_overBufferRateLimit_lastLineTruncated)
TEST(IpcLogOutputterTests, write_underBufferRateLimit_allLinesAreSent)
{
MockIpcServer mockServer;
-
+
ON_CALL(mockServer, hasClients(_)).WillByDefault(Return(true));
EXPECT_CALL(mockServer, hasClients(_)).Times(2);
@@ -154,7 +154,7 @@ TEST(IpcLogOutputterTests, write_underBufferRateLimit_allLinesAreSent)
outputter.write(kNOTE, "mock 1");
outputter.write(kNOTE, "mock 2");
outputter.sendBuffer();
-
+
// after waiting the time limit send another to make sure
// we can log after the time limit passes.
outputter.write(kNOTE, "mock 3");
diff --git a/src/test/unittests/net/FingerprintDatabaseTests.cpp b/src/test/unittests/net/FingerprintDatabaseTests.cpp
new file mode 100644
index 0000000..61bed0e
--- /dev/null
+++ b/src/test/unittests/net/FingerprintDatabaseTests.cpp
@@ -0,0 +1,95 @@
+/*
+ barrier -- mouse and keyboard sharing utility
+ Copyright (C) Barrier contributors
+
+ 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 "net/FingerprintDatabase.h"
+#include "test/global/gtest.h"
+
+namespace barrier {
+
+TEST(FingerprintDatabase, parse_db_line)
+{
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("").valid());
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("abcd").valid());
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("v1:algo:something").valid());
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("v2:algo:something").valid());
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("v2:algo:01020304abc").valid());
+ ASSERT_FALSE(FingerprintDatabase::parse_db_line("v2:algo:01020304ZZ").valid());
+ ASSERT_EQ(FingerprintDatabase::parse_db_line("v2:algo:01020304ab"),
+ (FingerprintData{"algo", {1, 2, 3, 4, 0xab}}));
+}
+
+TEST(FingerprintDatabase, read)
+{
+ std::istringstream stream;
+ stream.str(R"(
+v2:algo1:01020304ab
+v2:algo2:03040506ab
+AB:CD:EF:00:01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16
+)");
+ FingerprintDatabase db;
+ db.read_stream(stream);
+
+ std::vector<FingerprintData> expected = {
+ { "algo1", { 1, 2, 3, 4, 0xab } },
+ { "algo2", { 3, 4, 5, 6, 0xab } },
+ { "sha1", { 0xab, 0xcd, 0xef, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 } },
+ };
+ ASSERT_EQ(db.fingerprints(), expected);
+}
+
+TEST(FingerprintDatabase, write)
+{
+ std::ostringstream stream;
+
+ FingerprintDatabase db;
+ db.add_trusted({ "algo1", { 1, 2, 3, 4, 0xab } });
+ db.add_trusted({ "algo2", { 3, 4, 5, 6, 0xab } });
+ db.write_stream(stream);
+
+ ASSERT_EQ(stream.str(), R"(v2:algo1:01020304ab
+v2:algo2:03040506ab
+)");
+}
+
+TEST(FingerprintDatabase, clear)
+{
+ FingerprintDatabase db;
+ db.add_trusted({ "algo1", { 1, 2, 3, 4, 0xab } });
+ db.clear();
+ ASSERT_TRUE(db.fingerprints().empty());
+}
+
+TEST(FingerprintDatabase, add_trusted_no_duplicates)
+{
+ FingerprintDatabase db;
+ db.add_trusted({ "algo1", { 1, 2, 3, 4, 0xab } });
+ db.add_trusted({ "algo2", { 3, 4, 5, 6, 0xab } });
+ db.add_trusted({ "algo1", { 1, 2, 3, 4, 0xab } });
+ ASSERT_EQ(db.fingerprints().size(), 2);
+}
+
+TEST(FingerprintDatabase, is_trusted)
+{
+ FingerprintDatabase db;
+ db.add_trusted({ "algo1", { 1, 2, 3, 4, 0xab } });
+ ASSERT_TRUE(db.is_trusted({ "algo1", { 1, 2, 3, 4, 0xab } }));
+ ASSERT_FALSE(db.is_trusted({ "algo2", { 1, 2, 3, 4, 0xab } }));
+ ASSERT_FALSE(db.is_trusted({ "algo1", { 1, 2, 3, 4, 0xac } }));
+}
+
+} // namespace barrier
diff --git a/src/test/unittests/net/SecureUtilsTests.cpp b/src/test/unittests/net/SecureUtilsTests.cpp
new file mode 100644
index 0000000..0cce693
--- /dev/null
+++ b/src/test/unittests/net/SecureUtilsTests.cpp
@@ -0,0 +1,73 @@
+/*
+ barrier -- mouse and keyboard sharing utility
+ Copyright (C) 2021 Barrier contributors
+
+ 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 "net/SecureUtils.h"
+
+#include "test/global/gtest.h"
+#include "test/global/TestUtils.h"
+
+namespace barrier {
+
+TEST(SecureUtilsTest, FormatSslFingerprintHexWithSeparators)
+{
+ auto fingerprint = generate_pseudo_random_bytes(0, 32);
+ ASSERT_EQ(format_ssl_fingerprint(fingerprint, true),
+ "28:FD:0A:98:8A:0E:A1:6C:D7:E8:6C:A7:EE:58:41:71:"
+ "CA:B2:8E:49:25:94:90:25:26:05:8D:AF:63:ED:2E:30");
+}
+
+TEST(SecureUtilsTest, CreateFingerprintRandomArt)
+{
+ ASSERT_EQ(create_fingerprint_randomart(generate_pseudo_random_bytes(0, 32)),
+ "+-----------------+\n"
+ "|*X+. . |\n"
+ "|*oo + |\n"
+ "| + = |\n"
+ "| B . . |\n"
+ "|.+... o S |\n"
+ "|E+ ++. . |\n"
+ "|B*++.. . |\n"
+ "|+o*o o . |\n"
+ "|+o*Bo . |\n"
+ "+-----------------+");
+ ASSERT_EQ(create_fingerprint_randomart(generate_pseudo_random_bytes(1, 32)),
+ "+-----------------+\n"
+ "| .oo+ . .B=. |\n"
+ "| .o.+ . o o.= |\n"
+ "|o..+.. o . E * |\n"
+ "|oo..+ . * * |\n"
+ "|B o.....S. o . |\n"
+ "|+=o..... |\n"
+ "| + + . |\n"
+ "|o. .. |\n"
+ "|..o.. |\n"
+ "+-----------------+");
+ ASSERT_EQ(create_fingerprint_randomart(generate_pseudo_random_bytes(2, 32)),
+ "+-----------------+\n"
+ "| ... .o.o.|\n"
+ "| o .=.E|\n"
+ "| . + o ...+.|\n"
+ "| * o = o ... |\n"
+ "| * + S & . |\n"
+ "| = + % @ |\n"
+ "| . . = X o |\n"
+ "| . . O . |\n"
+ "| . + |\n"
+ "+-----------------+");
+}
+
+} // namespace barrier
diff --git a/src/test/unittests/platform/OSXKeyStateTests.cpp b/src/test/unittests/platform/OSXKeyStateTests.cpp
index dd9e80f..0e4ec83 100644
--- a/src/test/unittests/platform/OSXKeyStateTests.cpp
+++ b/src/test/unittests/platform/OSXKeyStateTests.cpp
@@ -30,27 +30,27 @@ TEST(OSXKeyStateTests, mapModifiersFromOSX_OSXMask_returnBarrierMask)
OSXKeyState keyState(&eventQueue, keyMap);
KeyModifierMask outMask = 0;
-
+
UInt32 shiftMask = 0 | kCGEventFlagMaskShift;
outMask = keyState.mapModifiersFromOSX(shiftMask);
EXPECT_EQ(KeyModifierShift, outMask);
-
+
UInt32 ctrlMask = 0 | kCGEventFlagMaskControl;
outMask = keyState.mapModifiersFromOSX(ctrlMask);
EXPECT_EQ(KeyModifierControl, outMask);
-
+
UInt32 altMask = 0 | kCGEventFlagMaskAlternate;
outMask = keyState.mapModifiersFromOSX(altMask);
EXPECT_EQ(KeyModifierAlt, outMask);
-
+
UInt32 cmdMask = 0 | kCGEventFlagMaskCommand;
outMask = keyState.mapModifiersFromOSX(cmdMask);
EXPECT_EQ(KeyModifierSuper, outMask);
-
+
UInt32 capsMask = 0 | kCGEventFlagMaskAlphaShift;
outMask = keyState.mapModifiersFromOSX(capsMask);
EXPECT_EQ(KeyModifierCapsLock, outMask);
-
+
UInt32 numMask = 0 | kCGEventFlagMaskNumericPad;
outMask = keyState.mapModifiersFromOSX(numMask);
EXPECT_EQ(KeyModifierNumLock, outMask);