Merge pull request #846 from chewi/tests

Add BARRIER_BUILD_TESTS and BARRIER_USE_EXTERNAL_GTEST CMake options
This commit is contained in:
Povilas Kanapickas 2020-08-22 21:21:11 +03:00 committed by GitHub
commit c3aba1b20b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 22 deletions

View File

@ -20,6 +20,8 @@ project (barrier C CXX)
option (BARRIER_BUILD_GUI "Build the GUI" ON) option (BARRIER_BUILD_GUI "Build the GUI" ON)
option (BARRIER_BUILD_INSTALLER "Build the installer" 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_EXPORT_COMPILE_COMMANDS ON)
set (CMAKE_CXX_STANDARD 14) set (CMAKE_CXX_STANDARD 14)
@ -49,7 +51,6 @@ else()
endif() endif()
set (libs) set (libs)
include_directories (BEFORE SYSTEM ./ext/gtest/include)
if (UNIX) if (UNIX)
if (NOT APPLE) if (NOT APPLE)

View File

@ -19,7 +19,10 @@ 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_TESTS)
add_subdirectory(test)
endif()
if (BARRIER_BUILD_GUI) if (BARRIER_BUILD_GUI)
add_subdirectory(gui) add_subdirectory(gui)

View File

@ -24,7 +24,9 @@
#include "common/stdset.h" #include "common/stdset.h"
#include "common/stdvector.h" #include "common/stdvector.h"
#ifdef TEST_ENV
#include <gtest/gtest_prod.h> #include <gtest/gtest_prod.h>
#endif
namespace barrier { namespace barrier {
@ -327,6 +329,7 @@ public:
//@} //@}
private: private:
#ifdef TEST_ENV
FRIEND_TEST(KeyMapTests, FRIEND_TEST(KeyMapTests,
findBestKey_requiredDown_matchExactFirstItem); findBestKey_requiredDown_matchExactFirstItem);
FRIEND_TEST(KeyMapTests, FRIEND_TEST(KeyMapTests,
@ -340,6 +343,7 @@ private:
FRIEND_TEST(KeyMapTests, FRIEND_TEST(KeyMapTests,
findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem); findBestKey_onlyOneRequiredDown_matchTwoRequiredChangesItem);
FRIEND_TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch); FRIEND_TEST(KeyMapTests, findBestKey_noRequiredDown_cannotMatch);
#endif
private: private:
//! Ways to synthesize a key //! Ways to synthesize a key

View File

@ -14,19 +14,33 @@
# 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/>.
include_directories( if (BARRIER_USE_EXTERNAL_GTEST)
../../ext/gtest include (FindPkgConfig)
../../ext/gtest/include find_package(GTest REQUIRED)
../../ext/gmock pkg_check_modules(GMOCK REQUIRED gmock)
../../ext/gmock/include) include_directories(
${GTEST_INCLUDE_DIRS}
add_library(gtest STATIC ../../ext/gtest/src/gtest-all.cc) ${GMOCK_INCLUDE_DIRS}
add_library(gmock STATIC ../../ext/gmock/src/gmock-all.cc) )
else()
include_directories(
../../ext/gtest
../../ext/gtest/include
../../ext/gmock
../../ext/gmock/include
)
if (UNIX) add_library(gtest STATIC ../../ext/gtest/src/gtest-all.cc)
# ignore warnings in gtest and gmock add_library(gmock STATIC ../../ext/gmock/src/gmock-all.cc)
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
set_target_properties(gmock PROPERTIES COMPILE_FLAGS "-w") 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() endif()
add_subdirectory(integtests) add_subdirectory(integtests)

View File

@ -68,8 +68,6 @@ endif()
include_directories( include_directories(
../../ ../../
../../../ext/gtest/include
../../../ext/gmock/include
) )
if (UNIX) if (UNIX)
@ -80,4 +78,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 synlib gtest gmock ${libs} ${OPENSSL_LIBS}) arch base client common io ipc mt net platform server synlib ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ${libs} ${OPENSSL_LIBS})

View File

@ -23,6 +23,7 @@
#include "platform/XWindowsScreenSaver.h" #include "platform/XWindowsScreenSaver.h"
#include "test/global/gtest.h" #include "test/global/gtest.h"
#include <cstdlib>
#include <X11/Xlib.h> #include <X11/Xlib.h>
using ::testing::_; using ::testing::_;
@ -30,7 +31,12 @@ using ::testing::_;
// TODO: not working on build machine for some reason // TODO: not working on build machine for some reason
TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo) 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); Window window = DefaultRootWindow(display);
MockEventQueue eventQueue; MockEventQueue eventQueue;
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1); EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1);

View File

@ -20,16 +20,22 @@
#include "platform/XWindowsScreen.h" #include "platform/XWindowsScreen.h"
#include "test/global/gtest.h" #include "test/global/gtest.h"
#include <cstdlib>
using ::testing::_; using ::testing::_;
TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect) TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect)
{ {
const char* displayName = std::getenv("DISPLAY");
if (displayName == NULL) {
displayName = ":0.0";
}
MockEventQueue eventQueue; MockEventQueue eventQueue;
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(new XWindowsImpl(), ":0.0", false, false, 0, &eventQueue); XWindowsScreen screen(new XWindowsImpl(), displayName, false, false, 0, &eventQueue);
screen.fakeMouseMove(10, 20); screen.fakeMouseMove(10, 20);

View File

@ -50,8 +50,6 @@ list(APPEND headers ${platform_sources})
include_directories( include_directories(
../../ ../../
../../../ext/gtest/include
../../../ext/gmock/include
../../../ext ../../../ext
) )
@ -67,4 +65,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 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})

View File

@ -15,6 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define TEST_ENV
#include "barrier/KeyMap.h" #include "barrier/KeyMap.h"
#include "test/global/gtest.h" #include "test/global/gtest.h"