Skip to content

Commit

Permalink
Merge pull request #37 from SoapGentoo/packaging-cleanups
Browse files Browse the repository at this point in the history
Packaging cleanups
  • Loading branch information
jpetso authored Mar 11, 2018
2 parents 65e512d + 0d0a73e commit 55d79de
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "test/catch"]
path = test/catch
url = https://github.com/philsquared/Catch.git
url = https://github.com/catchorg/Catch2.git
33 changes: 25 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(cppcodec)
cmake_minimum_required(VERSION 2.8.5)
project(cppcodec CXX)
set(PROJECT_VERSION 0.1)

option(build_tests "Build tests (run as 'test' target)" ON)
include(GNUInstallDirs)
include(CTest)

# These flags are for binaries built by this particular CMake project (test_cppcodec, base64enc, etc.).
# In your own project that uses cppcodec, you might want to specify a different standard or error level.
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic")

# Request C++11
if(${CMAKE_VERSION} VERSION_LESS 3.1)
# CMake versions before 3.1 do not understand CMAKE_CXX_STANDARD
# remove this block once CMake >=3.1 has fixated in the ecosystem
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
endif()

set(PUBLIC_HEADERS
Expand Down Expand Up @@ -46,12 +59,16 @@ add_library(cppcodec OBJECT ${PUBLIC_HEADERS}) # unnecessary for building, but m
set_target_properties(cppcodec PROPERTIES LINKER_LANGUAGE CXX)
add_subdirectory(tool)

if (build_tests)
enable_testing()
if (BUILD_TESTING)
add_subdirectory(test)
endif()

foreach(h ${PUBLIC_HEADERS})
get_filename_component(HEADER_INCLUDE_DIRECTORY include/${h} PATH) # use DIRECTORY instead of PATH once requiring CMake 3.0
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${h} DESTINATION ${HEADER_INCLUDE_DIRECTORY} COMPONENT "headers")
get_filename_component(FINAL_PATH ${h} PATH) # use DIRECTORY instead of PATH once requiring CMake 3.0
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${h} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${FINAL_PATH} COMPONENT "headers")
endforeach()

if (NOT WIN32)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cppcodec.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cppcodec-1.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cppcodec-1.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
endif()
7 changes: 7 additions & 0 deletions cppcodec.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: @CMAKE_PROJECT_NAME@
Description: C++ header-only library to encode/decode base64, base64url, base32, base32hex and hex
URL: https://github.com/tplgy/cppcodec
Version: @PROJECT_VERSION@
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# For cppcodec itself, don't prefer system headers over development ones.
include_directories(BEFORE ${PROJECT_SOURCE_DIR})

find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(CATCH2 catch)
endif()

if (CATCH2_FOUND)
message(STATUS "Found system Catch2, not using bundled version")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CATCH2_CFLAGS}")
else()
message(STATUS "Did NOT find system Catch2, instead using bundled version")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/catch/single_include)
endif()

add_executable(test_cppcodec test_cppcodec.cpp)
add_test(cppcodec test_cppcodec)
132 changes: 66 additions & 66 deletions test/test_cppcodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

#define CATCH_CONFIG_MAIN
#include "catch/single_include/catch.hpp"
#include <catch.hpp>

#include <cppcodec/base32_crockford.hpp>
#include <cppcodec/base32_hex.hpp>
Expand Down Expand Up @@ -125,16 +125,16 @@ TEST_CASE("Douglas Crockford's base32", "[base32][crockford]") {
REQUIRE(base32::decode<std::string>("-C-SQ--PY-") == "foo");

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base32::decode("0"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("000"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("000000"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("000000000"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("0"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("000"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("000000"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("000000000"), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base32::decode("00======"), cppcodec::symbol_error&); // no padding for Crockford
REQUIRE_THROWS_AS(base32::decode("Uu"), cppcodec::symbol_error&); // only a checksum symbol here
REQUIRE_THROWS_AS(base32::decode("++"), cppcodec::symbol_error&); // make sure it's not base64
REQUIRE_THROWS_AS(base32::decode("//"), cppcodec::symbol_error&); // ...ditto
REQUIRE_THROWS_AS(base32::decode("00======"), cppcodec::symbol_error); // no padding for Crockford
REQUIRE_THROWS_AS(base32::decode("Uu"), cppcodec::symbol_error); // only a checksum symbol here
REQUIRE_THROWS_AS(base32::decode("++"), cppcodec::symbol_error); // make sure it's not base64
REQUIRE_THROWS_AS(base32::decode("//"), cppcodec::symbol_error); // ...ditto
}

// Only test overloads once (for base32_crockford, since it happens to be the first one).
Expand Down Expand Up @@ -324,20 +324,20 @@ TEST_CASE("base32hex", "[base32][hex]") {
REQUIRE(base32::decode<std::string>("cPnMuOj1") == "fooba");

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base32::decode("0"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("00"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("00==="), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("0======="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("000====="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("000000=="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("0"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("00"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("00==="), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("0======="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("000====="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("000000=="), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base32::decode("W0======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("X0======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("Y0======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("Z0======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("CPNM UOJ1"), cppcodec::symbol_error&); // no spaces
REQUIRE_THROWS_AS(base32::decode("CPNM-UOJ1"), cppcodec::symbol_error&); // no dashes
REQUIRE_THROWS_AS(base32::decode("W0======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("X0======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("Y0======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("Z0======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("CPNM UOJ1"), cppcodec::symbol_error); // no spaces
REQUIRE_THROWS_AS(base32::decode("CPNM-UOJ1"), cppcodec::symbol_error); // no dashes
}
}

Expand Down Expand Up @@ -431,20 +431,20 @@ TEST_CASE("base32 (RFC 4648)", "[base32][rfc4648]") {
REQUIRE(base32::decode<std::string>("mZxW6yTb") == "fooba");

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base32::decode("A"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("AA"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("AA==="), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base32::decode("A======="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("AAA====="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("AAAAAA=="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base32::decode("A"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("AA"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("AA==="), cppcodec::padding_error);
REQUIRE_THROWS_AS(base32::decode("A======="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("AAA====="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base32::decode("AAAAAA=="), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base32::decode("0A======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("1A======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("8A======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("9A======"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base32::decode("GEZD GNBV"), cppcodec::symbol_error&); // no spaces
REQUIRE_THROWS_AS(base32::decode("GEZD-GNBV"), cppcodec::symbol_error&); // no dashes
REQUIRE_THROWS_AS(base32::decode("0A======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("1A======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("8A======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("9A======"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base32::decode("GEZD GNBV"), cppcodec::symbol_error); // no spaces
REQUIRE_THROWS_AS(base32::decode("GEZD-GNBV"), cppcodec::symbol_error); // no dashes
}
}

Expand Down Expand Up @@ -571,17 +571,17 @@ TEST_CASE("base64 (RFC 4648)", "[base64][rfc4648]") {
REQUIRE(base64::decode("////") == std::vector<uint8_t>({255, 255, 255}));

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("AA"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("ABCDE"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("A==="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("AAAA===="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("AAAAA==="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("AA"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("ABCDE"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("A==="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base64::decode("AAAA===="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base64::decode("AAAAA==="), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base64::decode("A&B="), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base64::decode("--"), cppcodec::symbol_error&); // this is not base64url
REQUIRE_THROWS_AS(base64::decode("__"), cppcodec::symbol_error&); // ...ditto
REQUIRE_THROWS_AS(base64::decode("A&B="), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base64::decode("--"), cppcodec::symbol_error); // this is not base64url
REQUIRE_THROWS_AS(base64::decode("__"), cppcodec::symbol_error); // ...ditto
}
}

Expand Down Expand Up @@ -679,13 +679,13 @@ TEST_CASE("base64 (unpadded URL-safe)", "[base64][url_unpadded]") {
REQUIRE(base64::decode("____") == std::vector<uint8_t>({255, 255, 255}));

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("AAAAA"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base64::decode("AAAAA"), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base64::decode("A&B"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base64::decode("++"), cppcodec::symbol_error&); // this is not standard base64
REQUIRE_THROWS_AS(base64::decode("//"), cppcodec::symbol_error&); // ...ditto
REQUIRE_THROWS_AS(base64::decode("A&B"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base64::decode("++"), cppcodec::symbol_error); // this is not standard base64
REQUIRE_THROWS_AS(base64::decode("//"), cppcodec::symbol_error); // ...ditto
}
}

Expand Down Expand Up @@ -779,17 +779,17 @@ TEST_CASE("base64 (URL-safe)", "[base64][url]") {
REQUIRE(base64::decode("____") == std::vector<uint8_t>({255, 255, 255}));

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("AA"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("ABCDE"), cppcodec::padding_error&);
REQUIRE_THROWS_AS(base64::decode("A==="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("AAAA===="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("AAAAA==="), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(base64::decode("A"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("AA"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("ABCDE"), cppcodec::padding_error);
REQUIRE_THROWS_AS(base64::decode("A==="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base64::decode("AAAA===="), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(base64::decode("AAAAA==="), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(base64::decode("A&B="), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(base64::decode("++"), cppcodec::symbol_error&); // this is not standard base64
REQUIRE_THROWS_AS(base64::decode("//"), cppcodec::symbol_error&); // ...ditto
REQUIRE_THROWS_AS(base64::decode("A&B="), cppcodec::symbol_error);
REQUIRE_THROWS_AS(base64::decode("++"), cppcodec::symbol_error); // this is not standard base64
REQUIRE_THROWS_AS(base64::decode("//"), cppcodec::symbol_error); // ...ditto
}
}

Expand Down Expand Up @@ -880,13 +880,13 @@ TEST_CASE("hex (lowercase)", "[hex][lower]") {
REQUIRE(hex::decode<std::string>("666F6f6261") == "fooba");

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(hex::decode("0"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(hex::decode("000"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(hex::decode("0"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(hex::decode("000"), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(hex::decode("1g"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(hex::decode("66 6f"), cppcodec::symbol_error&); // no spaces
REQUIRE_THROWS_AS(hex::decode("66-6f"), cppcodec::symbol_error&); // no dashes
REQUIRE_THROWS_AS(hex::decode("1g"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(hex::decode("66 6f"), cppcodec::symbol_error); // no spaces
REQUIRE_THROWS_AS(hex::decode("66-6f"), cppcodec::symbol_error); // no dashes
}
}

Expand Down Expand Up @@ -977,12 +977,12 @@ TEST_CASE("hex (uppercase)", "[hex][upper]") {
REQUIRE(hex::decode<std::string>("666f6F6261") == "fooba");

// An invalid number of symbols should throw the right kind of parse_error.
REQUIRE_THROWS_AS(hex::decode("0"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(hex::decode("000"), cppcodec::invalid_input_length&);
REQUIRE_THROWS_AS(hex::decode("0"), cppcodec::invalid_input_length);
REQUIRE_THROWS_AS(hex::decode("000"), cppcodec::invalid_input_length);

// An invalid symbol should throw a symbol error.
REQUIRE_THROWS_AS(hex::decode("1G"), cppcodec::symbol_error&);
REQUIRE_THROWS_AS(hex::decode("66 6F"), cppcodec::symbol_error&); // no spaces
REQUIRE_THROWS_AS(hex::decode("66-6F"), cppcodec::symbol_error&); // no dashes
REQUIRE_THROWS_AS(hex::decode("1G"), cppcodec::symbol_error);
REQUIRE_THROWS_AS(hex::decode("66 6F"), cppcodec::symbol_error); // no spaces
REQUIRE_THROWS_AS(hex::decode("66-6F"), cppcodec::symbol_error); // no dashes
}
}

0 comments on commit 55d79de

Please sign in to comment.