From 763ad31ea8bd8e0a542ee3f901c533c83fd1bb6e Mon Sep 17 00:00:00 2001 From: Matheus Gomes Date: Sun, 21 Jan 2024 00:09:34 +0000 Subject: [PATCH] Modularised the library into a module --- CMakeLists.txt | 1 + CMakePresets.json | 12 +- azure-pipelines.yml | 10 +- base64pp/CMakeLists.txt | 17 +-- base64pp/base64pp.cpp | 144 ++++++++++-------- base64pp/include/base64pp/base64pp.h | 41 ----- conan/conanfile.py | 67 -------- docker/Dockerfile | 3 + scripts/helpers/conan-install.sh | 7 +- ...n-install.ps1 => install-dependencies.ps1} | 6 +- scripts/pipeline/ubuntu_build.yml | 8 +- scripts/pipeline/windows_build.yml | 2 +- tests/base64pp_tests.cpp | 71 ++++----- 13 files changed, 157 insertions(+), 232 deletions(-) delete mode 100644 base64pp/include/base64pp/base64pp.h delete mode 100644 conan/conanfile.py rename scripts/helpers/{conan-install.ps1 => install-dependencies.ps1} (84%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d2472a..32114e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN On) + if(NOT WIN32 AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) if (NOT DEFINED CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}") diff --git a/CMakePresets.json b/CMakePresets.json index c09600e..b56b0dd 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -44,8 +44,10 @@ "generator": "Ninja", "cacheVariables": { "CMAKE_C_COMPILER": "clang-17", - "CMAKE_CXX_COMPILER": "clang++-17", - "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic" + "CMAKE_CXX_COMPILER": "clang++-17", + "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -pedantic", + "CMAKE_CXX_SCAN_FOR_MODULES": true, + "CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS": "/usr/bin/clang-scan-deps-17" } }, { @@ -60,16 +62,18 @@ { "name": "vs2022", "hidden": true, - "generator": "Visual Studio 17 2022", + "generator": "Ninja", "cacheVariables": { + "CMAKE_CXX_COMPILER": "cl.exe", "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS_INIT} $env{CMAKE_CXX_FLAGS} /W4 /WX /EHsc" } }, { "name": "vs2022-shared", "hidden": true, - "generator": "Visual Studio 17 2022", + "generator": "Ninja", "cacheVariables": { + "CMAKE_CXX_COMPILER": "cl.exe", "CMAKE_CXX_FLAGS_INIT": "$env{CMAKE_CXX_FLAGS_INIT} $env{CMAKE_CXX_FLAGS} /W4 /WX /EHsc", "BUILD_SHARED_LIBS": true } diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 11e1d37..f85c9ef 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -49,7 +49,7 @@ stages: parameters: jobName: ubuntu_build_x86_64_debug buildType: Debug - cmakePreset: unix-deb + cmakePreset: unix-deb-ninja cmakeExtraArgs: -DBUILD_DOCS="On" containerName: ubuntu18.04-gcc11-conan2-doxygen1.9.6 artifactName: UbuntuDebugBuild @@ -61,7 +61,8 @@ stages: cmakePreset: unix-deb-ninja containerName: ubuntu18.04-gcc11-conan2-doxygen1.9.6 artifactName: UbuntuClangDebugBuild - compiler: clang + cxx: clang++ + cc: clang compilerStd: 20 compilerLibCxx: libstdc++11 compilerVersion: 17 @@ -70,7 +71,7 @@ stages: parameters: jobName: ubuntu_build_x86_64_release buildType: Release - cmakePreset: unix-rel + cmakePreset: unix-rel-ninja containerName: ubuntu18.04-gcc11-conan2-doxygen1.9.6 artifactName: UbuntuReleaseBuild @@ -81,7 +82,8 @@ stages: cmakePreset: unix-rel-ninja containerName: ubuntu18.04-gcc11-conan2-doxygen1.9.6 artifactName: UbuntuClangReleaseBuild - compiler: clang + cxx: clang++ + cc: clang compilerStd: 20 compilerLibCxx: libstdc++11 compilerVersion: 17 diff --git a/base64pp/CMakeLists.txt b/base64pp/CMakeLists.txt index f5e6068..142a28c 100644 --- a/base64pp/CMakeLists.txt +++ b/base64pp/CMakeLists.txt @@ -4,21 +4,20 @@ set(BASE64PP_SOURCES set(BASE64PP_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/include) -add_library(base64pp base64pp.cpp) +add_library(base64pp) +target_sources(base64pp + PUBLIC + FILE_SET CXX_MODULES FILES + base64pp.cpp +) +# Extra modules stuff target_include_directories(base64pp PUBLIC ${BASE64PP_INCLUDE_DIR}) -include(GenerateExportHeader) -set(BASE64PP_EXPORT_FILE "${CMAKE_CURRENT_LIST_DIR}/include/base64pp") -generate_export_header(base64pp EXPORT_FILE_NAME "${BASE64PP_INCLUDE_DIR}/base64pp/base64pp_export.h") - -file(GLOB BASE64PP_PUBLIC_HEADERS ${BASE64PP_INCLUDE_DIR}/**/*.h) -set_target_properties(base64pp - PROPERTIES PUBLIC_HEADER "${BASE64PP_PUBLIC_HEADERS}") - include(GNUInstallDirs) install(TARGETS base64pp) # Generate PKG-Config configure_file("${CMAKE_CURRENT_SOURCE_DIR}/base64pp.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/base64pp.pc" @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/base64pp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + diff --git a/base64pp/base64pp.cpp b/base64pp/base64pp.cpp index 0414405..a14c0c1 100644 --- a/base64pp/base64pp.cpp +++ b/base64pp/base64pp.cpp @@ -1,6 +1,7 @@ +module; + #include #include -#include #include #include #include @@ -9,80 +10,82 @@ #include #include -namespace +export module base64pp; + +std::array constexpr encode_table{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', + '9', '+', '/'}; + +std::array constexpr decode_table{0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x3E, 0x64, 0x64, 0x64, 0x3F, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x00, 0x01, 0x02, + 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, + 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64}; + +std::array encode_tripplet(std::uint8_t a, std::uint8_t b, std::uint8_t c) { - std::array constexpr encode_table{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', - 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', '+', '/'}; - - std::array constexpr decode_table{0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x3E, 0x64, 0x64, - 0x64, 0x3F, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, - 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x1A, 0x1B, 0x1C, - 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, - 0x2F, 0x30, 0x31, 0x32, 0x33, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, - 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64}; - - std::array encode_tripplet(std::uint8_t a, std::uint8_t b, std::uint8_t c) - { - std::uint32_t const concat_bits = (a << 16) | (b << 8) | c; + std::uint32_t const concat_bits = (a << 16) | (b << 8) | c; - auto const b64_char1 = encode_table[(concat_bits >> 18) & 0b0011'1111]; - auto const b64_char2 = encode_table[(concat_bits >> 12) & 0b0011'1111]; - auto const b64_char3 = encode_table[(concat_bits >> 6) & 0b0011'1111]; - auto const b64_char4 = encode_table[concat_bits & 0b0011'1111]; - return {b64_char1, b64_char2, b64_char3, b64_char4}; - } + auto const b64_char1 = encode_table[(concat_bits >> 18) & 0b0011'1111]; + auto const b64_char2 = encode_table[(concat_bits >> 12) & 0b0011'1111]; + auto const b64_char3 = encode_table[(concat_bits >> 6) & 0b0011'1111]; + auto const b64_char4 = encode_table[concat_bits & 0b0011'1111]; + return {b64_char1, b64_char2, b64_char3, b64_char4}; +} - inline bool is_valid_base64_char(char c) +inline bool is_valid_base64_char(char c) +{ + auto const decode_byte = decode_table[c]; + return decode_byte != 0x64; +} + +inline bool is_valid_base64_str(std::string_view const encoded_str) +{ + if ((encoded_str.size() % 4) == 1) { - auto const decode_byte = decode_table[c]; - return decode_byte != 0x64; + return false; } - inline bool is_valid_base64_str(std::string_view const encoded_str) + if (!std::all_of(begin(encoded_str), end(encoded_str) - 2, [](char c) { return is_valid_base64_char(c); })) { - if ((encoded_str.size() % 4) == 1) - { - return false; - } - - if (!std::all_of(begin(encoded_str), end(encoded_str) - 2, [](char c) { return is_valid_base64_char(c); })) - { - return false; - } - - auto const last = rbegin(encoded_str); - if (!is_valid_base64_char(*next(last))) - { - return (*next(last) == '=') && (*last == '='); - } - - return is_valid_base64_char(*last) || (*last == '='); + return false; } - std::array decode_quad(char a, char b, char c, char d) + auto const last = rbegin(encoded_str); + if (!is_valid_base64_char(*next(last))) { - std::uint32_t const concat_bytes = - (decode_table[a] << 18) | (decode_table[b] << 12) | (decode_table[c] << 6) | decode_table[d]; - - std::uint8_t const byte1 = (concat_bytes >> 16) & 0b1111'1111; - std::uint8_t const byte2 = (concat_bytes >> 8) & 0b1111'1111; - std::uint8_t const byte3 = concat_bytes & 0b1111'1111; - return {byte1, byte2, byte3}; + return (*next(last) == '=') && (*last == '='); } -} // namespace -std::string base64pp::encode(std::span input) + return is_valid_base64_char(*last) || (*last == '='); +} + +std::array decode_quad(char a, char b, char c, char d) +{ + std::uint32_t const concat_bytes = + (decode_table[a] << 18) | (decode_table[b] << 12) | (decode_table[c] << 6) | decode_table[d]; + + std::uint8_t const byte1 = (concat_bytes >> 16) & 0b1111'1111; + std::uint8_t const byte2 = (concat_bytes >> 8) & 0b1111'1111; + std::uint8_t const byte3 = concat_bytes & 0b1111'1111; + return {byte1, byte2, byte3}; +} + +//! @brief This function will encode a blob of data into a base64 +//! string. +//! @param input - a span pointing to a binary blob to encode. +//! @return a base64 string containing the encoded data. +export std::string encode(std::span input) { auto const size = input.size(); auto const full_tripples = size / 3; @@ -120,12 +123,23 @@ std::string base64pp::encode(std::span input) return output; } -std::string base64pp::encode_str(std::string_view input) +//! @brief Overload of the encode function for string_view. This converts +//! the string input to a span and calls the conventional `encode`. +//! @param input - a string_view to be encoded into base64. +//! @return a base64 string containing the encoded string. +export std::string encode_str(std::string_view input) { return encode({reinterpret_cast(input.data()), input.size()}); } -std::optional> base64pp::decode(std::string_view encoded_str) +//! @brief Decodes a base64 encoded string, returning an optional +//! blob. If the decoding fails, it returns std::nullopt +//! @param encoded_str - the base64 encoded string +//! @return an optional containing a valid blob of data, if +//! decoding was successful. Otherwise, returns std::nullopt +//! @note this function accepts unpadded strings, if they are valid +//! otherwise. It rejects odd-sized unpadded strings. +export std::optional> decode(std::string_view encoded_str) { if (encoded_str.size() == 0) { diff --git a/base64pp/include/base64pp/base64pp.h b/base64pp/include/base64pp/base64pp.h deleted file mode 100644 index 5cc64bb..0000000 --- a/base64pp/include/base64pp/base64pp.h +++ /dev/null @@ -1,41 +0,0 @@ -//! @file base64pp.h -//! @brief This file defines the public functions -//! for the base64pp library -#ifndef BASE64PP_H -#define BASE64PP_H - -#include "base64pp_export.h" -#include -#include -#include -#include -#include -#include - -//! base64pp API namespace -namespace base64pp -{ - - //! @brief This function will encode a blob of data into a base64 - //! string. - //! @param input - a span pointing to a binary blob to encode. - //! @return a base64 string containing the encoded data. - std::string BASE64PP_EXPORT encode(std::span input); - - //! @brief Overload of the encode function for string_view. This converts - //! the string input to a span and calls the conventional `encode`. - //! @param input - a string_view to be encoded into base64. - //! @return a base64 string containing the encoded string. - std::string BASE64PP_EXPORT encode_str(std::string_view input); - - //! @brief Decodes a base64 encoded string, returning an optional - //! blob. If the decoding fails, it returns std::nullopt - //! @param encoded_str - the base64 encoded string - //! @return an optional containing a valid blob of data, if - //! decoding was successful. Otherwise, returns std::nullopt - //! @note this function accepts unpadded strings, if they are valid - //! otherwise. It rejects odd-sized unpadded strings. - std::optional> BASE64PP_EXPORT decode(std::string_view encoded_str); -} // namespace base64pp - -#endif // BASE64PP_H diff --git a/conan/conanfile.py b/conan/conanfile.py deleted file mode 100644 index 629bf5a..0000000 --- a/conan/conanfile.py +++ /dev/null @@ -1,67 +0,0 @@ -from conan import ConanFile -from conan.errors import ConanInvalidConfiguration -from conan.tools.build import check_min_cppstd -from conan.tools.files import get, copy -from conan.tools.cmake import cmake_layout, CMakeToolchain, CMake, CMakeDeps - -from os.path import join - - -class Base64pp(ConanFile): - - settings = ("os", "compiler", "build_type", "arch") - - def source(self): - get(self, "https://github.com/matheusgomes28/base64pp/archive/refs/tags/v0.1.0-rc0.zip", strip_root=True) - - def layout(self): - self.folders.source = "src" - self.folders.build = "build" - - self.cpp.source.includedirs = ["include"] - self.cpp.build.libdirs = ["lib"] - self.cpp.build.libs = ["base64pp"] - - cmake_layout(self, src_folder="src", build_folder="build") - - def configure(self): - print(dir(self.settings)) - self.settings.compiler.cppstd = 20 - - def validate(self): - check_min_cppstd(self, 20, False) - - compiler = self.settings.get_safe("compiler", "unknown") - compiler_version_major = self.settings.get_safe("compiler.version", "0") - required_versions = { - "gcc": 10, - "clang": 12, - "msvc": 191 - } - - if compiler not in required_versions.keys(): - raise ConanInvalidConfiguration(f"compiler not supported by Base64pp") - - if int(compiler_version_major) < required_versions[compiler]: - raise ConanInvalidConfiguration(f"you have {compiler} {compiler_version_major}, need {compiler} >= {required_versions[compiler]}") - - - def generate(self): - - tc = CMakeToolchain(self) - tc.generate() - CMakeDeps(self).generate() - - def build(self): - cmake = CMake(self) - cmake.configure() - cmake.build() - - def package(self): - cmake = CMake(self) - cmake.install() - - def package_info(self): - self.cpp_info.libs = ["base64pp"] - self.cpp_info.libdirs = ["lib"] - self.cpp_info.includedirs = ["include"] diff --git a/docker/Dockerfile b/docker/Dockerfile index ef473d3..34a5257 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -38,16 +38,19 @@ RUN apt-get update \ clang-format-17 \ clang-tidy-17 \ clang-tools-17 \ + libclang-rt-17-dev \ && mkdir "/conan" \ && pip3 install --upgrade --no-cache --ignore-installed pip \ && pip3 install --no-cache -q --ignore-installed conan==2.0.17 \ && chmod -R 777 "/conan" \ && pip3 install --no-cache -q --ignore-installed ninja==1.11.1 \ && pip3 install --no-cache --ignore-installed cmake==3.28 \ + && pip3 install --no-cache --ignore-installed ninja \ && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 10 \ && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 10 \ && update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-11 10 \ && update-alternatives --install /usr/bin/clang clang /usr/bin/clang-17 10 \ + && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-17 10 \ && update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-17 10 \ && update-alternatives --install /usr/bin/clang-scan-deps clang-scan-deps /usr/bin/clang-scan-deps-17 10 \ && update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-17 10 \ diff --git a/scripts/helpers/conan-install.sh b/scripts/helpers/conan-install.sh index c8e7003..cfcfa66 100755 --- a/scripts/helpers/conan-install.sh +++ b/scripts/helpers/conan-install.sh @@ -8,14 +8,15 @@ set -euo pipefail ' PROJECT_DIR="$(cd "$(dirname "$0")/../.." && pwd)" BUILD_TYPE=${BUILD_TYPE-Debug} -COMPILER=${COMPILER-"gcc"} +CXX=${CXX-"g++"} +CC=${CC-"gcc"} COMPILER_STD=${COMPILER_STD-"17"} COMPILER_LIBCXX=${COMPILER_LIBCXX-"libstdc++11"} COMPILER_VERSION=${COMPILER_VERSION-"11"} conan profile detect --force sed -i "s/build_type=Release/build_type=${BUILD_TYPE}/g" "$(conan profile path default)" -sed -i "s/compiler=.*/compiler=${COMPILER}/g" "$(conan profile path default)" +sed -i "s/compiler=.*/compiler=${CC}/g" "$(conan profile path default)" sed -i "s/compiler.cppstd=.*/compiler.cppstd=${COMPILER_STD}/g" "$(conan profile path default)" sed -i "s/compiler.libcxx=.*/compiler.libcxx=${COMPILER_LIBCXX}/g" "$(conan profile path default)" sed -i "s/compiler.version=.*/compiler.version=${COMPILER_VERSION}/g" "$(conan profile path default)" @@ -27,7 +28,7 @@ if [ "${BUILD_TYPE}" = "Release" ]; then fi # Install all dependencies -CXX="${COMPILER}" CC="${COMPILER}" conan install \ +CXX="${CXX}" CC="${CC}" conan install \ --output-folder="${CONAN_DIR}" \ --build=missing \ "${PROJECT_DIR}" diff --git a/scripts/helpers/conan-install.ps1 b/scripts/helpers/install-dependencies.ps1 similarity index 84% rename from scripts/helpers/conan-install.ps1 rename to scripts/helpers/install-dependencies.ps1 index b56d96b..bf59234 100644 --- a/scripts/helpers/conan-install.ps1 +++ b/scripts/helpers/install-dependencies.ps1 @@ -8,7 +8,8 @@ param ( # needs to work for the build # Install conan with chocolatey -choco install conan --version=2.0.1 --installargs '/PathType:Machine' -y --no-progress +choco install conan --version=2.0.17 --installargs '/PathType:Machine' -y --no-progress +choco install ninja --version=1.11.1 --installargs '/PathType:Machine' -y --no-progress if(!$?) { Exit $LASTEXITCODE } # Set this because refreshenv doesn't work @@ -30,6 +31,9 @@ $ConanProfile = Get-Content -Path "$(conan profile path default)" if(!$?) { Exit $LASTEXITCODE } $ConanProfile = $ConanProfile -Replace "build_type=Release", "build_type=$BuildType" $ConanProfile = $ConanProfile -Replace "compiler.runtime=dynamic", "compiler.runtime=static" +$ConanProfile += "[conf]" +$ConanProfile += "tools.cmake.cmaketoolchain:generator=Ninja" + Write-Output "---- New conan profile -----" Set-Content -Path $ConanProfileFile -Value $ConanProfile Write-Output $ConanProfile diff --git a/scripts/pipeline/ubuntu_build.yml b/scripts/pipeline/ubuntu_build.yml index bb73142..512aee1 100644 --- a/scripts/pipeline/ubuntu_build.yml +++ b/scripts/pipeline/ubuntu_build.yml @@ -16,9 +16,12 @@ parameters: type: string - name: artifactName type: string -- name: compiler +- name: cc type: string default: gcc +- name: cxx + type: string + default: g++ - name: compilerStd type: string default: 17 @@ -37,7 +40,8 @@ jobs: steps: - ${{ if eq(parameters.buildType, 'Debug') }}: - bash: | - COMPILER=${{ parameters.compiler }} \ + CC=${{ parameters.cc }} \ + CXX=${{ parameters.cxx }} \ COMPILER_STD=${{ parameters.compilerStd }} \ COMPILER_LIBCXX=${{ parameters.compilerLibCxx }} \ COMPILER_VERSION=${{ parameters.compilerVersion }} \ diff --git a/scripts/pipeline/windows_build.yml b/scripts/pipeline/windows_build.yml index 3e1607a..a711b3d 100644 --- a/scripts/pipeline/windows_build.yml +++ b/scripts/pipeline/windows_build.yml @@ -24,7 +24,7 @@ jobs: steps: - ${{ if eq(parameters.buildType, 'Debug') }}: - - pwsh: .\scripts\helpers\conan-install.ps1 -BuildType ${{ parameters.buildType }} + - pwsh: .\scripts\helpers\install-dependencies.ps1 -BuildType ${{ parameters.buildType }} displayName: Installing Conan Dependencies - pwsh: | diff --git a/tests/base64pp_tests.cpp b/tests/base64pp_tests.cpp index c64c961..e81067c 100644 --- a/tests/base64pp_tests.cpp +++ b/tests/base64pp_tests.cpp @@ -1,14 +1,15 @@ +import base64pp; + #include -#include #include #include #include + // NOLINTNEXTLINE -TEST(Base64Encode, EncodesEmpty) -{ +TEST(Base64Encode, EncodesEmpty){ std::string const expected{}; - std::string const actual{base64pp::encode({})}; + std::string const actual{encode({})}; ASSERT_EQ(expected, actual); } @@ -17,7 +18,7 @@ TEST(Base64Encode, EncodesThreeBytesZeros) { std::array const input{0x00, 0x00, 0x00}; auto const expected{"AAAA"}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(expected, actual); } @@ -26,7 +27,7 @@ TEST(Base64Encode, EncodesThreeBytesRandom) { std::array const input{0xFE, 0xE9, 0x72}; auto const expected{"/uly"}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(expected, actual); } @@ -35,7 +36,7 @@ TEST(Base64Encode, EncodesTwoBytes) { std::array const input{0x00, 0x00}; auto const expected{"AAA="}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(expected, actual); } @@ -44,7 +45,7 @@ TEST(Base64Encode, EncodesOneByte) { std::array const input{0x00}; auto const expected{"AA=="}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(expected, actual); } @@ -53,7 +54,7 @@ TEST(Base64Encode, EncodesFourBytes) { std::array const input{0x74, 0x68, 0x65, 0x20}; auto const expected{"dGhlIA=="}; - auto actual{base64pp::encode({begin(input), end(input)})}; + auto actual{encode({begin(input), end(input)})}; ASSERT_EQ(expected, actual); } @@ -62,7 +63,7 @@ TEST(Base64Encode, EncodesFiveBytes) { std::array const input{0x20, 0x62, 0x72, 0x6f, 0x77}; auto const expected{"IGJyb3c="}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(actual, expected); } @@ -71,7 +72,7 @@ TEST(Base64Encode, EncodesSixBytes) { std::array const input{0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73}; auto const expected{"IGp1bXBz"}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(actual, expected); } @@ -83,7 +84,7 @@ TEST(Base64Encode, EncodesBrownFox) 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67}; auto const expected{"dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(actual, expected); } @@ -95,7 +96,7 @@ TEST(Base64Encode, EncodesBrownFastFoxNullInMiddle) 0x72, 0x20, 0x74, 0x68, 0x65, 0x00, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67}; auto const expected{"dGhlIHF1aWNrISBicm93biBmb3gganVtcHMgb3ZlciB0aGUAIGxhenkgZG9n"}; - auto const actual{base64pp::encode({begin(input), end(input)})}; + auto const actual{encode({begin(input), end(input)})}; ASSERT_EQ(actual, expected); } @@ -103,7 +104,7 @@ TEST(Base64Encode, EncodesBrownFastFoxNullInMiddle) TEST(Base64Decode, FailDecodeOneString) { std::string const input{"1"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, std::nullopt); } @@ -112,7 +113,7 @@ TEST(Base64Decode, FailDecodeOneString) TEST(Base64Decode, FailDecodeOneStringPadded) { std::string const input{"1==="}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, std::nullopt); } @@ -121,7 +122,7 @@ TEST(Base64Decode, FailDecodeOneStringPadded) TEST(Base64Decode, FailDecodeOneCharRemaining) { std::string const input{"something"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, std::nullopt); } @@ -130,7 +131,7 @@ TEST(Base64Decode, FailDecodeOneCharRemaining) TEST(Base64Decode, FailDecodeNonSize4Bigger) { std::string const input{"SomethingEntirelyDifferent"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::vector const expected{0x4A, 0x89, 0x9E, 0xB6, 0x18, 0xA7, 0x80, 0x49, 0xED, 0x8A, 0xB7, 0xA5, 0xC8, 0x38, 0x9F, 0x7D, 0xEA, 0xDE, 0x9E}; @@ -142,7 +143,7 @@ TEST(Base64Decode, FailDecodeNonSize4Bigger) TEST(Base64Decode, FailDecodeNonBase64Short) { std::string const input{"a aa"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, std::nullopt); } @@ -151,7 +152,7 @@ TEST(Base64Decode, FailDecodeNonBase64Short) TEST(Base64Decode, FailDecodeNonBase64Longer) { std::string const input{"aaa`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, std::nullopt); } @@ -160,7 +161,7 @@ TEST(Base64Decode, FailDecodeNonBase64Longer) TEST(Base64Decode, DecodesMissingTwoPads0) { std::string const input{"12"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::vector const expected{0xD7}; ASSERT_TRUE(actual); @@ -172,7 +173,7 @@ TEST(Base64Decode, DecodesMissingTwoPads0) TEST(Base64Decode, DecodesMissingTwoPads1) { std::string const input = "AA"; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::vector const expected{0x00}; ASSERT_TRUE(actual); @@ -183,7 +184,7 @@ TEST(Base64Decode, DecodesMissingTwoPads1) TEST(Base64Decode, DecodesMissingOnePad0) { std::string const input = "AAA"; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::vector const expected{0x00, 0x00}; ASSERT_TRUE(actual); @@ -194,7 +195,7 @@ TEST(Base64Decode, DecodesMissingOnePad0) TEST(Base64Decode, DecodesMissingOnePad1) { std::string const input{"12a"}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::vector const expected{0xD7, 0x66}; ASSERT_TRUE(actual); @@ -207,7 +208,7 @@ TEST(Base64Decode, DecodesMissingOnePad1) TEST(Base64Decode, DecodesMissingIssueExample) { std::string const input = "eyJuYW1lIjoiSm9obiBEb2UifQ"; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; std::string const expected_str = R"({"name":"John Doe"})"; std::vector const expected{begin(expected_str), end(expected_str)}; @@ -221,7 +222,7 @@ TEST(Base64Decode, DecodesEmptyString) { std::string const input{}; std::vector expected{}; - auto const actual{base64pp::decode("")}; + auto const actual{decode("")}; ASSERT_EQ(expected, actual); } @@ -231,7 +232,7 @@ TEST(Base64Decode, DecodesZeroArray) { std::string const input{"AAAA"}; std::vector const expected{0x00, 0x00, 0x00}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, expected); } @@ -241,7 +242,7 @@ TEST(Base64Decode, DecodesZeroArrayTwice) { std::string const input{"AAAAAAAA"}; std::vector const expected{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, expected); } @@ -251,7 +252,7 @@ TEST(Base64Decode, DecodesZeroArrayOneByte) { std::string const input{"AA=="}; std::vector const expected{0x00}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, expected); } @@ -261,7 +262,7 @@ TEST(Base64Decode, DecodesZeroArrayTwoBytes) { std::string const input{"AAA="}; std::vector const expected{0x00, 0x00}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, expected); } @@ -273,7 +274,7 @@ TEST(Base64Decode, DecodesQuickFox) std::vector const expected{0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79, 0x20, 0x64, 0x6f, 0x67}; - auto const actual{base64pp::decode(input)}; + auto const actual{decode(input)}; ASSERT_EQ(actual, expected); } @@ -286,8 +287,8 @@ TEST(Base64RoundTripTests, AllPossibleBytes) all_possible_bytes.push_back(static_cast(i)); } - auto const encode_string = base64pp::encode({begin(all_possible_bytes), end(all_possible_bytes)}); - auto const decoded_bytes = base64pp::decode(encode_string); + auto const encode_string = encode({begin(all_possible_bytes), end(all_possible_bytes)}); + auto const decoded_bytes = decode(encode_string); ASSERT_TRUE(decoded_bytes); ASSERT_EQ(all_possible_bytes, *decoded_bytes); } @@ -310,10 +311,10 @@ TEST(Base64RoundTripTests, ExhaustiveTests) for (auto const& b64_string : base64_strings) { - auto const decoded = base64pp::decode(b64_string); + auto const decoded = decode(b64_string); ASSERT_TRUE(decoded); - auto const encoded_round_trip = base64pp::encode({begin(*decoded), end(*decoded)}); + auto const encoded_round_trip = encode({begin(*decoded), end(*decoded)}); ASSERT_EQ(encoded_round_trip, b64_string); } } @@ -332,7 +333,7 @@ TEST(Base64OverloadTests, EncodesString1) for (auto const& [input, expected] : test_cases) { - auto const actual = base64pp::encode_str(input); + auto const actual = encode_str(input); ASSERT_EQ(actual, expected); } }