Tests: Add FindBZip2 unit tests

This commit is contained in:
Roger Leigh 2016-09-08 21:28:17 +01:00 committed by Brad King
parent e9ce050342
commit 069cac584f
4 changed files with 53 additions and 0 deletions

View File

@ -1356,6 +1356,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindBoost) add_subdirectory(FindBoost)
endif() endif()
if(CMake_TEST_FindBZip2)
add_subdirectory(FindBZip2)
endif()
if(CMake_TEST_FindGSL) if(CMake_TEST_FindGSL)
add_subdirectory(FindGSL) add_subdirectory(FindGSL)
endif() endif()

View File

@ -0,0 +1,10 @@
add_test(NAME FindBZip2.Test COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/FindBZip2/Test"
"${CMake_BINARY_DIR}/Tests/FindBZip2/Test"
${build_generator_args}
--build-project TestFindBZip2
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)

View File

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.4)
project(TestFindBZip2 C)
include(CTest)
find_package(BZip2 REQUIRED)
add_definitions(-DCMAKE_EXPECTED_BZip2_VERSION="${BZip2_VERSION_STRING}")
add_executable(test_tgt main.c)
target_link_libraries(test_tgt BZip2::BZip2)
add_test(NAME test_tgt COMMAND test_tgt)
add_executable(test_var main.c)
target_include_directories(test_var PRIVATE ${BZIP2_INCLUDE_DIRS})
target_link_libraries(test_var PRIVATE ${BZIP2_LIBRARIES})
add_test(NAME test_var COMMAND test_var)

View File

@ -0,0 +1,23 @@
#include <bzlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int chunksize = 1024;
FILE* file = fopen("test.bzip2", "wb");
char* buf = malloc(sizeof(char) * chunksize);
int error, rsize;
unsigned int in, out;
BZFILE* bzfile = BZ2_bzWriteOpen(&error, file, 64, 1, 10);
/* Don't actually write anything for the purposes of the test */
BZ2_bzWriteClose(&error, bzfile, 1, &in, &out);
free(buf);
fclose(file);
remove("test.bzip2");
return 0;
}