Skip to content

Commit

Permalink
Merge pull request debauchee#846 from chewi/tests
Browse files Browse the repository at this point in the history
Add BARRIER_BUILD_TESTS and BARRIER_USE_EXTERNAL_GTEST CMake options
  • Loading branch information
p12tic authored Aug 22, 2020
2 parents 7dbfa63 + fa46480 commit c3aba1b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ project (barrier C CXX)

option (BARRIER_BUILD_GUI "Build the GUI" ON)
option (BARRIER_BUILD_INSTALLER "Build the installer" ON)
option (BARRIER_BUILD_TESTS "Build the tests" ON)
option (BARRIER_USE_EXTERNAL_GTEST "Use external installation of Google Test framework" OFF)

set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
set (CMAKE_CXX_STANDARD 14)
Expand Down Expand Up @@ -49,7 +51,6 @@ else()
endif()

set (libs)
include_directories (BEFORE SYSTEM ./ext/gtest/include)

if (UNIX)
if (NOT APPLE)
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}/lib)

add_subdirectory(lib)
add_subdirectory(cmd)
add_subdirectory(test)

if (BARRIER_BUILD_TESTS)
add_subdirectory(test)
endif()

if (BARRIER_BUILD_GUI)
add_subdirectory(gui)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/barrier/KeyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include "common/stdset.h"
#include "common/stdvector.h"

#ifdef TEST_ENV
#include <gtest/gtest_prod.h>
#endif

namespace barrier {

Expand Down Expand Up @@ -327,6 +329,7 @@ class KeyMap {
//@}

private:
#ifdef TEST_ENV
FRIEND_TEST(KeyMapTests,
findBestKey_requiredDown_matchExactFirstItem);
FRIEND_TEST(KeyMapTests,
Expand All @@ -340,6 +343,7 @@ class KeyMap {
FRIEND_TEST(KeyMapTests,
findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem);
FRIEND_TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch);
#endif

private:
//! Ways to synthesize a key
Expand Down
38 changes: 26 additions & 12 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,33 @@
# 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_directories(
../../ext/gtest
../../ext/gtest/include
../../ext/gmock
../../ext/gmock/include)

add_library(gtest STATIC ../../ext/gtest/src/gtest-all.cc)
add_library(gmock STATIC ../../ext/gmock/src/gmock-all.cc)
if (BARRIER_USE_EXTERNAL_GTEST)
include (FindPkgConfig)
find_package(GTest REQUIRED)
pkg_check_modules(GMOCK REQUIRED gmock)
include_directories(
${GTEST_INCLUDE_DIRS}
${GMOCK_INCLUDE_DIRS}
)
else()
include_directories(
../../ext/gtest
../../ext/gtest/include
../../ext/gmock
../../ext/gmock/include
)

if (UNIX)
# ignore warnings in gtest and gmock
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
set_target_properties(gmock PROPERTIES COMPILE_FLAGS "-w")
add_library(gtest STATIC ../../ext/gtest/src/gtest-all.cc)
add_library(gmock STATIC ../../ext/gmock/src/gmock-all.cc)

set(GTEST_LIBRARIES gtest)
set(GMOCK_LIBRARIES gmock)

if (UNIX)
# ignore warnings in gtest and gmock
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
set_target_properties(gmock PROPERTIES COMPILE_FLAGS "-w")
endif()
endif()

add_subdirectory(integtests)
Expand Down
4 changes: 1 addition & 3 deletions src/test/integtests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ endif()

include_directories(
../../
../../../ext/gtest/include
../../../ext/gmock/include
)

if (UNIX)
Expand All @@ -80,4 +78,4 @@ endif()

add_executable(integtests ${sources})
target_link_libraries(integtests
arch base client common io ipc mt net platform server synlib gtest gmock ${libs} ${OPENSSL_LIBS})
arch base client common io ipc mt net platform server synlib ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${libs} ${OPENSSL_LIBS})
8 changes: 7 additions & 1 deletion src/test/integtests/platform/XWindowsScreenSaverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
#include "platform/XWindowsScreenSaver.h"

#include "test/global/gtest.h"
#include <cstdlib>
#include <X11/Xlib.h>

using ::testing::_;

// TODO: not working on build machine for some reason
TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo)
{
Display* display = XOpenDisplay(":0.0");
const char* displayName = std::getenv("DISPLAY");
if (displayName == NULL) {
displayName = ":0.0";
}

Display* display = XOpenDisplay(displayName);
Window window = DefaultRootWindow(display);
MockEventQueue eventQueue;
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1);
Expand Down
8 changes: 7 additions & 1 deletion src/test/integtests/platform/XWindowsScreenTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@
#include "platform/XWindowsScreen.h"

#include "test/global/gtest.h"
#include <cstdlib>

using ::testing::_;

TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect)
{
const char* displayName = std::getenv("DISPLAY");
if (displayName == NULL) {
displayName = ":0.0";
}

MockEventQueue eventQueue;
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2);
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
XWindowsScreen screen(new XWindowsImpl(), ":0.0", false, false, 0, &eventQueue);
XWindowsScreen screen(new XWindowsImpl(), displayName, false, false, 0, &eventQueue);

screen.fakeMouseMove(10, 20);

Expand Down
4 changes: 1 addition & 3 deletions src/test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ list(APPEND headers ${platform_sources})

include_directories(
../../
../../../ext/gtest/include
../../../ext/gmock/include
../../../ext
)

Expand All @@ -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})
2 changes: 2 additions & 0 deletions src/test/unittests/barrier/KeyMapTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#define TEST_ENV

#include "barrier/KeyMap.h"

#include "test/global/gtest.h"
Expand Down

0 comments on commit c3aba1b

Please sign in to comment.