Skip to content

Commit

Permalink
Add unit test for compression
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumerose committed Jan 21, 2022
1 parent ba942f8 commit 72d6ef7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
42 changes: 39 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
16 changes: 12 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
22 changes: 22 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions test/test_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

#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()

0 comments on commit 72d6ef7

Please sign in to comment.