Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for compression #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:

- name: Build dependencies
run: |
vcpkg install --triplet=x64-windows-static-md lua shapelib zlib protobuf[zlib] sqlite3 boost-program-options boost-filesystem boost-geometry boost-system boost-asio boost-interprocess boost-iostreams boost-sort rapidjson
vcpkg install --triplet=x64-windows-static-md lua shapelib zlib protobuf[zlib] sqlite3 boost-program-options boost-filesystem boost-geometry boost-system boost-asio boost-interprocess boost-iostreams boost-sort boost-test rapidjson

- name: Build tilemaker
run: |
mkdir ${{ github.workspace }}\build
cd ${{ github.workspace }}\build && cmake -DTILEMAKER_BUILD_STATIC=ON -DVCPKG_TARGET_TRIPLET="x64-windows-static-md" -DCMAKE_TOOLCHAIN_FILE="c:\vcpkg\scripts\buildsystems\vcpkg.cmake" ..
cd ${{ github.workspace }}\build && cmake --build . --config RelWithDebInfo
cd ${{ github.workspace }}\build && cmake --build . --config RelWithDebInfo --target tilemaker

- name: Build openmaptiles-compatible mbtiles files of Liechtenstein
run: |
Expand Down Expand Up @@ -78,14 +78,14 @@ jobs:

- name: Build dependencies
run: |
vcpkg install --triplet=${{ matrix.triplet }} lua shapelib zlib protobuf[zlib] sqlite3 boost-program-options boost-filesystem boost-geometry boost-system boost-asio boost-interprocess boost-iostreams boost-sort rapidjson
vcpkg install --triplet=${{ matrix.triplet }} lua shapelib zlib protobuf[zlib] sqlite3 boost-program-options boost-filesystem boost-geometry boost-system boost-asio boost-interprocess boost-iostreams boost-sort boost-test rapidjson

- name: Build tilemaker
run: |
mkdir build
cd build
cmake -DTILEMAKER_BUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} -DCMAKE_TOOLCHAIN_FILE=${{ matrix.toolchain }} -DCMAKE_CXX_COMPILER=g++ ..
cmake --build .
cmake --build . --target tilemaker
strip tilemaker

- name: Build openmaptiles-compatible mbtiles files of Liechtenstein
Expand Down
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()