Merge pull request #719 from p12tic/tests

Fix building of tests
This commit is contained in:
Dom Rodriguez 2020-05-30 21:14:08 +01:00 committed by GitHub
commit 5d0f6e6f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 101 deletions

View File

@ -19,6 +19,7 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/lib)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(cmd) add_subdirectory(cmd)
add_subdirectory(test)
if (BARRIER_BUILD_GUI) if (BARRIER_BUILD_GUI)
add_subdirectory(gui) add_subdirectory(gui)

View File

@ -173,6 +173,6 @@ private:
public: public:
SInt32 group() const { return m_group; } SInt32 group() const { return m_group; }
void group(const SInt32& group) { m_group = group; } void group(const SInt32& group) { m_group = group; }
KeyModifierMaskList modifierFromX() const { return m_modifierFromX; } KeyModifierMaskList& modifierFromX() { return m_modifierFromX; }
#endif #endif
}; };

View File

@ -19,7 +19,7 @@
#include "base/EventQueue.h" #include "base/EventQueue.h"
class EventQueueTimer; class EventQueueTimer {};
class TestEventQueue : public EventQueue { class TestEventQueue : public EventQueue {
public: public:

View File

@ -14,24 +14,37 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
file(GLOB_RECURSE headers "*.h") set(headers
file(GLOB_RECURSE sources "*.cpp") )
set(sources
# remove platform files (specific platform added later). arch/ArchInternetTests.cpp
file(GLOB_RECURSE remove_platform "platform/*") ipc/IpcTests.cpp
list(REMOVE_ITEM headers ${remove_platform}) net/NetworkTests.cpp
list(REMOVE_ITEM sources ${remove_platform}) Main.cpp
)
# platform # platform
if (WIN32) if (WIN32)
file(GLOB platform_sources "platform/MSWindows*.cpp") set(platform_sources
file(GLOB platform_headers "platform/MSWindows*.h") platform/MSWindowsClipboardTests.cpp
platform/MSWindowsKeyStateTests.cpp
)
set(platform_headers)
elseif (APPLE) elseif (APPLE)
file(GLOB platform_sources "platform/OSX*.cpp") set(platform_sources
file(GLOB platform_headers "platform/OSX*.h") platform/OSXClipboardTests.cpp
platform/OSXKeyStateTests.cpp
platform/OSXScreenTests.cpp
)
set(platform_headers)
elseif (UNIX) elseif (UNIX)
file(GLOB platform_sources "platform/XWindows*.cpp") set(platform_sources
file(GLOB platform_headers "platform/XWindows*.h") platform/XWindowsClipboardTests.cpp
platform/XWindowsKeyStateTests.cpp
platform/XWindowsScreenSaverTests.cpp
platform/XWindowsScreenTests.cpp
)
set(platform_headers)
endif() endif()
list(APPEND sources ${platform_sources}) list(APPEND sources ${platform_sources})
@ -55,7 +68,6 @@ endif()
include_directories( include_directories(
../../ ../../
../../lib/
../../../ext/gtest/include ../../../ext/gtest/include
../../../ext/gmock/include ../../../ext/gmock/include
) )
@ -68,4 +80,4 @@ endif()
add_executable(integtests ${sources}) add_executable(integtests ${sources})
target_link_libraries(integtests target_link_libraries(integtests
arch base client common io ipc mt net platform server barrier gtest gmock ${libs} ${OPENSSL_LIBS}) arch base client common io ipc mt net platform server synlib gtest gmock ${libs} ${OPENSSL_LIBS})

View File

@ -22,16 +22,16 @@
#define TEST_URL "https://symless.com/tests/?testString" #define TEST_URL "https://symless.com/tests/?testString"
//#define TEST_URL "http://localhost/barrier/tests/?testString" //#define TEST_URL "http://localhost/barrier/tests/?testString"
TEST(ArchInternetTests, get) TEST(ArchInternetTests, DISABLED_get)
{ {
ARCH_INTERNET internet; ARCH_INTERNET internet;
String result = internet.get(TEST_URL); std::string result = internet.get(TEST_URL);
ASSERT_EQ("Hello world!", result); ASSERT_EQ("Hello world!", result);
} }
TEST(ArchInternetTests, urlEncode) TEST(ArchInternetTests, urlEncode)
{ {
ARCH_INTERNET internet; ARCH_INTERNET internet;
String result = internet.urlEncode("hello=+&world"); std::string result = internet.urlEncode("hello=+&world");
ASSERT_EQ("hello%3D%2B%26world", result); ASSERT_EQ("hello%3D%2B%26world", result);
} }

View File

@ -76,8 +76,7 @@ TEST_F(XWindowsKeyStateTests, setActiveGroup_pollAndSet_groupIsZero)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
keyState.setActiveGroup(XWindowsKeyState::kGroupPollAndSet); keyState.setActiveGroup(XWindowsKeyState::kGroupPollAndSet);
@ -88,8 +87,7 @@ TEST_F(XWindowsKeyStateTests, setActiveGroup_poll_groupIsNotSet)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
keyState.setActiveGroup(XWindowsKeyState::kGroupPoll); keyState.setActiveGroup(XWindowsKeyState::kGroupPoll);
@ -100,8 +98,7 @@ TEST_F(XWindowsKeyStateTests, setActiveGroup_customGroup_groupWasSet)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
keyState.setActiveGroup(1); keyState.setActiveGroup(1);
@ -112,8 +109,7 @@ TEST_F(XWindowsKeyStateTests, mapModifiersFromX_zeroState_zeroMask)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
int mask = keyState.mapModifiersFromX(0); int mask = keyState.mapModifiersFromX(0);
@ -124,8 +120,7 @@ TEST_F(XWindowsKeyStateTests, mapModifiersToX_zeroMask_resultIsTrue)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
unsigned int modifiers = 0; unsigned int modifiers = 0;
bool result = keyState.mapModifiersToX(0, modifiers); bool result = keyState.mapModifiersToX(0, modifiers);
@ -137,8 +132,7 @@ TEST_F(XWindowsKeyStateTests, fakeCtrlAltDel_default_returnsFalse)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
bool result = keyState.fakeCtrlAltDel(); bool result = keyState.fakeCtrlAltDel();
@ -149,21 +143,18 @@ TEST_F(XWindowsKeyStateTests, pollActiveModifiers_defaultState_returnsZero)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
KeyModifierMask actual = keyState.pollActiveModifiers(); KeyModifierMask actual = keyState.pollActiveModifiers();
ASSERT_EQ(0, actual); ASSERT_EQ(0, actual);
} }
#if 0 // TODO: fix, causes sigsegv
TEST_F(XWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect) TEST_F(XWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCorrect)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
// set mock modifier mapping // set mock modifier mapping
std::fill(keyState.modifierFromX().begin(), keyState.modifierFromX().end(), 0); std::fill(keyState.modifierFromX().begin(), keyState.modifierFromX().end(), 0);
@ -189,14 +180,12 @@ TEST_F(XWindowsKeyStateTests, pollActiveModifiers_shiftKeyDownThenUp_masksAreCor
EXPECT_TRUE((modUp & KeyModifierShift) == 0) EXPECT_TRUE((modUp & KeyModifierShift) == 0)
<< "shift key still in mask - make sure no keys are being held down"; << "shift key still in mask - make sure no keys are being held down";
} }
#endif
TEST_F(XWindowsKeyStateTests, pollActiveGroup_defaultState_returnsZero) TEST_F(XWindowsKeyStateTests, pollActiveGroup_defaultState_returnsZero)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
SInt32 actual = keyState.pollActiveGroup(); SInt32 actual = keyState.pollActiveGroup();
@ -207,8 +196,7 @@ TEST_F(XWindowsKeyStateTests, pollActiveGroup_positiveGroup_returnsGroup)
{ {
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
keyState.group(3); keyState.group(3);
@ -222,8 +210,7 @@ TEST_F(XWindowsKeyStateTests, pollActiveGroup_xkb_areEqual)
#if HAVE_XKB_EXTENSION #if HAVE_XKB_EXTENSION
MockKeyMap keyMap; MockKeyMap keyMap;
MockEventQueue eventQueue; MockEventQueue eventQueue;
XWindowsKeyState keyState( XWindowsKeyState keyState(new XWindowsImpl(), m_display, true, &eventQueue, keyMap);
m_display, true, &eventQueue, keyMap);
// reset the group // reset the group
keyState.group(-1); keyState.group(-1);

View File

@ -29,12 +29,11 @@ TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect)
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2); EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2); EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2);
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2); EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
XWindowsScreen screen( XWindowsScreen screen(new XWindowsImpl(), ":0.0", false, false, 0, &eventQueue);
":0.0", false, false, 0, &eventQueue);
screen.fakeMouseMove(10, 20); screen.fakeMouseMove(10, 20);
int x, y; SInt32 x, y;
screen.getCursorPos(x, y); screen.getCursorPos(x, y);
ASSERT_EQ(10, x); ASSERT_EQ(10, x);
ASSERT_EQ(20, y); ASSERT_EQ(20, y);

View File

@ -50,7 +50,6 @@ list(APPEND headers ${platform_sources})
include_directories( include_directories(
../../ ../../
../../lib/
../../../ext/gtest/include ../../../ext/gtest/include
../../../ext/gmock/include ../../../ext/gmock/include
../../../ext ../../../ext
@ -68,4 +67,4 @@ endif()
add_executable(unittests ${sources}) add_executable(unittests ${sources})
target_link_libraries(unittests target_link_libraries(unittests
arch base client server common io net platform server barrier mt ipc gtest gmock ${libs} ${OPENSSL_LIBS}) arch base client server common io net platform server synlib mt ipc gtest gmock ${libs} ${OPENSSL_LIBS})

View File

@ -22,7 +22,6 @@
TEST(ClipboardChunkTests, start_formatStartChunk) TEST(ClipboardChunkTests, start_formatStartChunk)
{ {
<<<<<<< HEAD
ClipboardID id = 0; ClipboardID id = 0;
UInt32 sequence = 0; UInt32 sequence = 0;
String mockDataSize("10"); String mockDataSize("10");
@ -34,28 +33,12 @@ TEST(ClipboardChunkTests, start_formatStartChunk)
EXPECT_EQ('1', chunk->m_chunk[6]); EXPECT_EQ('1', chunk->m_chunk[6]);
EXPECT_EQ('0', chunk->m_chunk[7]); EXPECT_EQ('0', chunk->m_chunk[7]);
EXPECT_EQ('\0', chunk->m_chunk[8]); EXPECT_EQ('\0', chunk->m_chunk[8]);
=======
ClipboardID id = 0;
UInt32 sequence = 0;
String mockDataSize("10");
ClipboardChunk* chunk = ClipboardChunk::start(id, sequence, mockDataSize);
UInt32 temp_m_chunk;
memcpy(&temp_m_chunk, &(chunk->m_chunk[1]), 4);
EXPECT_EQ(id, chunk->m_chunk[0]);
EXPECT_EQ(sequence, temp_m_chunk);
EXPECT_EQ(kDataStart, chunk->m_chunk[5]);
EXPECT_EQ('1', chunk->m_chunk[6]);
EXPECT_EQ('0', chunk->m_chunk[7]);
EXPECT_EQ('\0', chunk->m_chunk[8]);
>>>>>>> master
delete chunk; delete chunk;
} }
TEST(ClipboardChunkTests, data_formatDataChunk) TEST(ClipboardChunkTests, data_formatDataChunk)
{ {
<<<<<<< HEAD
ClipboardID id = 0; ClipboardID id = 0;
UInt32 sequence = 1; UInt32 sequence = 1;
String mockData("mock data"); String mockData("mock data");
@ -74,35 +57,12 @@ TEST(ClipboardChunkTests, data_formatDataChunk)
EXPECT_EQ('t', chunk->m_chunk[13]); EXPECT_EQ('t', chunk->m_chunk[13]);
EXPECT_EQ('a', chunk->m_chunk[14]); EXPECT_EQ('a', chunk->m_chunk[14]);
EXPECT_EQ('\0', chunk->m_chunk[15]); EXPECT_EQ('\0', chunk->m_chunk[15]);
=======
ClipboardID id = 0;
UInt32 sequence = 1;
String mockData("mock data");
ClipboardChunk* chunk = ClipboardChunk::data(id, sequence, mockData);
UInt32 temp_m_chunk;
memcpy(&temp_m_chunk, &(chunk->m_chunk[1]), 4);
EXPECT_EQ(id, chunk->m_chunk[0]);
EXPECT_EQ(sequence, temp_m_chunk);
EXPECT_EQ(kDataChunk, chunk->m_chunk[5]);
EXPECT_EQ('m', chunk->m_chunk[6]);
EXPECT_EQ('o', chunk->m_chunk[7]);
EXPECT_EQ('c', chunk->m_chunk[8]);
EXPECT_EQ('k', chunk->m_chunk[9]);
EXPECT_EQ(' ', chunk->m_chunk[10]);
EXPECT_EQ('d', chunk->m_chunk[11]);
EXPECT_EQ('a', chunk->m_chunk[12]);
EXPECT_EQ('t', chunk->m_chunk[13]);
EXPECT_EQ('a', chunk->m_chunk[14]);
EXPECT_EQ('\0', chunk->m_chunk[15]);
>>>>>>> master
delete chunk; delete chunk;
} }
TEST(ClipboardChunkTests, end_formatDataChunk) TEST(ClipboardChunkTests, end_formatDataChunk)
{ {
<<<<<<< HEAD
ClipboardID id = 1; ClipboardID id = 1;
UInt32 sequence = 1; UInt32 sequence = 1;
ClipboardChunk* chunk = ClipboardChunk::end(id, sequence); ClipboardChunk* chunk = ClipboardChunk::end(id, sequence);
@ -111,18 +71,6 @@ TEST(ClipboardChunkTests, end_formatDataChunk)
EXPECT_EQ(sequence, (UInt32)chunk->m_chunk[1]); EXPECT_EQ(sequence, (UInt32)chunk->m_chunk[1]);
EXPECT_EQ(kDataEnd, chunk->m_chunk[5]); EXPECT_EQ(kDataEnd, chunk->m_chunk[5]);
EXPECT_EQ('\0', chunk->m_chunk[6]); EXPECT_EQ('\0', chunk->m_chunk[6]);
=======
ClipboardID id = 1;
UInt32 sequence = 1;
ClipboardChunk* chunk = ClipboardChunk::end(id, sequence);
UInt32 temp_m_chunk;
memcpy(&temp_m_chunk, &(chunk->m_chunk[1]), 4);
EXPECT_EQ(id, chunk->m_chunk[0]);
EXPECT_EQ(sequence, temp_m_chunk);
EXPECT_EQ(kDataEnd, chunk->m_chunk[5]);
EXPECT_EQ('\0', chunk->m_chunk[6]);
>>>>>>> master
delete chunk; delete chunk;
} }