add initial unit test

This commit is contained in:
Valient Gough 2017-08-06 09:40:44 -07:00
parent d3d329fb43
commit 36a4f9c4dd
No known key found for this signature in database
GPG Key ID: 33C65E29813C14DF
2 changed files with 32 additions and 9 deletions

View File

@ -18,6 +18,7 @@ option(IWYU "Build with IWYU analysis." OFF)
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_LIST_DIR}/cmake") "${CMAKE_CURRENT_LIST_DIR}/cmake")
option (BUILD_UNIT_TESTS "build EncFS unit tests" ON)
option (BUILD_SHARED_LIBS "build shared libraries" OFF) option (BUILD_SHARED_LIBS "build shared libraries" OFF)
option (USE_INTERNAL_TINYXML "use built-in TinyXML2" ON) option (USE_INTERNAL_TINYXML "use built-in TinyXML2" ON)
option (ENABLE_NLS "compile with Native Language Support (using gettext)" ON) option (ENABLE_NLS "compile with Native Language Support (using gettext)" ON)
@ -173,13 +174,6 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/${EASYLOGGING_DIR}/src)
link_directories(${CMAKE_BINARY_DIR}/${EASYLOGGING_DIR}) link_directories(${CMAKE_BINARY_DIR}/${EASYLOGGING_DIR})
set(EASYLOGGING_LIBRARIES easyloggingpp) set(EASYLOGGING_LIBRARIES easyloggingpp)
# TODO: add behind TEST flag.
message("-- Including vendored googletest")
set(GOOGLETEST_DIR vendor/github.com/google/googletest)
add_subdirectory(${GOOGLETEST_DIR})
link_directories(${CMAKE_BINARY_DIR}/${GOOGLETEST_DIR}/googletest)
set(GOOGLETEST_LIBRARIES gtest)
set(SOURCE_FILES set(SOURCE_FILES
encfs/autosprintf.cpp encfs/autosprintf.cpp
encfs/base64.cpp encfs/base64.cpp
@ -236,7 +230,6 @@ if (IWYU)
endif() endif()
endif() endif()
# Set RPATH to library install path. # Set RPATH to library install path.
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
@ -284,5 +277,23 @@ if (POD2MAN)
DESTINATION ${MAN_DESTINATION}) DESTINATION ${MAN_DESTINATION})
endif (POD2MAN) endif (POD2MAN)
add_custom_target(tests COMMAND ${CMAKE_CURRENT_LIST_DIR}/test.sh) if (BUILD_UNIT_TESTS)
message("-- Including vendored googletest")
set(GOOGLETEST_DIR vendor/github.com/google/googletest)
add_subdirectory(${GOOGLETEST_DIR})
link_directories(${CMAKE_BINARY_DIR}/${GOOGLETEST_DIR}/googletest)
message("-- Including vendored benchmark library")
set(GOOGLEBENCH_DIR vendor/github.com/google/benchmark)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "benchmark tests")
add_subdirectory(${GOOGLEBENCH_DIR})
link_directories(${CMAKE_BINARY_DIR}/${GOOGLEBENCH_DIR})
set(GOOGLEBENCH_LIBRARIES benchmark)
file(GLOB_RECURSE TEST_SOURCES "encfs/*_test.cpp")
add_executable (unittests ${TEST_SOURCES})
target_link_libraries(unittests gtest gtest_main encfs)
endif ()
add_custom_target(tests COMMAND ${CMAKE_CURRENT_LIST_DIR}/test.sh)

12
encfs/MemoryPool_test.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "gtest/gtest.h"
#include "MemoryPool.h"
using namespace encfs;
TEST(MemoryPool, Allocate) {
auto block = MemoryPool::allocate(1024);
ASSERT_TRUE(block.data != nullptr);
ASSERT_TRUE(block.internalData != nullptr);
MemoryPool::release(block);
}