diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c2370a57 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +/build/ +/cmake-build-debug/ +/server/ +/test/cmake-build-debug/ +/include/osmformat.pb.o +/include/osmformat.pb.h +/include/vector_tile.pb.h diff --git a/.gitignore b/.gitignore index 2ba65273..8ca2341a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ tilemaker # protocol buffers generated headers include/osmformat.pb.h include/vector_tile.pb.h + +# cmake directories +cmake-build-debug/ +test/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 86caf964..4481ce35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,13 +105,49 @@ file(GLOB tilemaker_src_files src/shp_mem_tiles.cpp src/tilemaker.cpp src/write_geometry.cpp - ) +) add_executable(tilemaker vector_tile.pb.cc osmformat.pb.cc ${tilemaker_src_files}) -target_link_libraries(tilemaker ${PROTOBUF_LIBRARY} ${LIBSHP_LIBRARIES} ${SQLITE3_LIBRARIES} ${LUAJIT_LIBRARY} ${LUA_LIBRARIES} ${ZLIB_LIBRARY} ${THREAD_LIB} ${CMAKE_DL_LIBS} - Boost::system Boost::filesystem Boost::program_options Boost::iostreams) +target_link_libraries(tilemaker + ${PROTOBUF_LIBRARY} + ${LIBSHP_LIBRARIES} + ${SQLITE3_LIBRARIES} + ${LUAJIT_LIBRARY} + ${LUA_LIBRARIES} + ${ZLIB_LIBRARY} + ${THREAD_LIB} + ${CMAKE_DL_LIBS} + Boost::system + Boost::filesystem + Boost::program_options + Boost::iostreams +) if(MSVC) target_link_libraries(tilemaker unofficial::sqlite3::sqlite3) endif() install(TARGETS tilemaker RUNTIME DESTINATION bin) + +# Unit tests +add_library(libtilemaker SHARED STATIC + src/helpers.cpp + include/helpers.h + vector_tile.pb.cc + osmformat.pb.cc +) +target_link_libraries(libtilemaker + ${PROTOBUF_LIBRARY} + ${LIBSHP_LIBRARIES} + ${SQLITE3_LIBRARIES} + ${LUAJIT_LIBRARY} + ${LUA_LIBRARIES} + ${ZLIB_LIBRARY} + ${THREAD_LIB} + ${CMAKE_DL_LIBS} + Boost::system + Boost::filesystem + Boost::program_options + Boost::iostreams +) + +add_subdirectory(test) diff --git a/Dockerfile b/Dockerfile index 10efe2a2..f854e7c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,22 +19,30 @@ RUN apt-get update && \ libboost-system-dev \ libboost-iostreams-dev \ rapidjson-dev \ - cmake + cmake \ + libboost-test-dev COPY CMakeLists.txt / COPY cmake /cmake COPY src /src COPY include /include +COPY test /test WORKDIR /build -RUN cmake -DTILEMAKER_BUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ .. -RUN cmake --build . +FROM src as test +RUN cmake .. +RUN cmake --build . --target tilemaker_test +RUN cd test && ctest + +FROM src as static +RUN cmake -DTILEMAKER_BUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release .. +RUN cmake --build . --target tilemaker RUN strip tilemaker FROM debian:bullseye-slim WORKDIR / -COPY --from=src /build/tilemaker . +COPY --from=static /build/tilemaker . COPY resources /resources COPY process.lua . COPY config.json . diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000..b938c3c7 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.0) + +project(tilemaker_test) + +set(CMAKE_CXX_STANDARD 14) + +# Project settings +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".") + +# Dependencies +find_package(Boost COMPONENTS filesystem system unit_test_framework REQUIRED) + +# Assign the include directories +include_directories(${Boost_INCLUDE_DIRS}) +include_directories(${UNIT_TESTS_INCLUDES}) + +# Build unit tests +add_executable(tilemaker_test test_helpers.cpp) +target_link_libraries(tilemaker_test ${Boost_LIBRARIES} libtilemaker) + +enable_testing() +add_test(tilemaker_test tilemaker_test) diff --git a/test/test_helpers.cpp b/test/test_helpers.cpp new file mode 100644 index 00000000..556ba91b --- /dev/null +++ b/test/test_helpers.cpp @@ -0,0 +1,15 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include + +#include "../include/helpers.h" + +BOOST_AUTO_TEST_SUITE(HelpersSuite) + +BOOST_AUTO_TEST_CASE(CompressDecompress) { + std::string original = "hello world"; + std::string compressed = compress_string(original, 9); + BOOST_REQUIRE_EQUAL(decompress_string(compressed, false), original); +} + +BOOST_AUTO_TEST_SUITE_END()