From 208d8f96429d32b5415542db0a59414988f571d8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 24 Jun 2024 17:44:53 +0100 Subject: [PATCH] Implementation of Base64 encoder and decoder --- include/etl/base64.h | 8 +- include/etl/base64_decoder.h | 26 +- include/etl/base64_encoder.h | 85 +- test/CMakeLists.txt | 20 +- test/etl_profile.h | 6 +- test/meson.build | 14 +- test/run-syntax-checks.sh | 14 +- test/run-tests.sh | 18 +- test/test_base64_RFC2152_decoder.cpp | 162 +-- test/test_base64_RFC2152_encoder.cpp | 152 +- test/test_base64_RFC3501_decoder.cpp | 160 +-- test/test_base64_RFC3501_encoder.cpp | 152 +- ...64_RFC4648_URL_decoder_with_no_padding.cpp | 152 +- ...ase64_RFC4648_URL_decoder_with_padding.cpp | 153 +- ...64_RFC4648_URL_encoder_with_no_padding.cpp | 152 +- ...ase64_RFC4648_URL_encoder_with_padding.cpp | 152 +- ...base64_RFC4648_decoder_with_no_padding.cpp | 152 +- ...st_base64_RFC4648_decoder_with_padding.cpp | 150 +- ...base64_RFC4648_encoder_with_no_padding.cpp | 152 +- ...st_base64_RFC4648_encoder_with_padding.cpp | 194 +-- test/test_crc.cpp | 1258 ----------------- 21 files changed, 381 insertions(+), 2951 deletions(-) delete mode 100644 test/test_crc.cpp diff --git a/include/etl/base64.h b/include/etl/base64.h index 484bf595..21b2641b 100644 --- a/include/etl/base64.h +++ b/include/etl/base64.h @@ -114,8 +114,8 @@ namespace etl { enum enum_type { - //RFC_1421, // Not implemented yet - //RFC_2045, // Not implemented yet + //RFC_1421, // Not implemented + //RFC_2045, // Not implemented RFC_2152, RFC_3501, RFC_4648, @@ -125,8 +125,8 @@ namespace etl }; ETL_DECLARE_ENUM_TYPE(Encoding, int) - //ETL_ENUM_TYPE(RFC_1421, "RFC_1421") // Not implemented yet - //ETL_ENUM_TYPE(RFC_2045, "RFC_2045") // Not implemented yet + //ETL_ENUM_TYPE(RFC_1421, "RFC_1421") // Not implemented + //ETL_ENUM_TYPE(RFC_2045, "RFC_2045") // Not implemented ETL_ENUM_TYPE(RFC_2152, "RFC_2152") ETL_ENUM_TYPE(RFC_3501, "RFC_3501") ETL_ENUM_TYPE(RFC_4648, "RFC_4648") diff --git a/include/etl/base64_decoder.h b/include/etl/base64_decoder.h index 0da2ed40..6ceca45c 100644 --- a/include/etl/base64_decoder.h +++ b/include/etl/base64_decoder.h @@ -63,8 +63,8 @@ namespace etl { public: - typedef etl::span span_type; - typedef etl::delegate callback_type; + typedef etl::span span_type; + typedef etl::delegate callback_type; //************************************************************************* /// Decode to Base64 @@ -85,7 +85,7 @@ namespace etl { if (output_buffer_is_full()) { - callback(span(), false); + callback(span()); reset_output_buffer(); } } @@ -144,7 +144,7 @@ namespace etl ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, TInputIterator input_end) { - return (decode(input_begin, input_end) && flush()); + return decode(input_begin, input_end) && flush(); } //************************************************************************* @@ -154,7 +154,7 @@ namespace etl ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, size_t input_length) { - return (decode(input_begin, input_length) && flush()); + return decode(input_begin, input_length) && flush(); } //************************************************************************* @@ -172,7 +172,15 @@ namespace etl { if (callback.is_valid()) { - callback(span(), true); + // Send any remaining data. + if (size() != 0) + { + callback(span()); + } + + // Indicate this was the final block. + callback(span_type()); + reset_output_buffer(); } } @@ -192,7 +200,7 @@ namespace etl reset_output_buffer(); overflow_detected = false; invalid_data_detected = false; - padding_received = false; + padding_received = false; } //************************************************************************* @@ -531,8 +539,8 @@ namespace etl { public: - static ETL_CONSTANT etl::base64::Encoding Encoding = etl::base64::Encoding::RFC_2152; - static ETL_CONSTANT size_t Buffer_Size = Buffer_Size_; + static ETL_CONSTANT etl::base64::Encoding Encoding = etl::base64::Encoding::RFC_2152; + static ETL_CONSTANT size_t Buffer_Size = Buffer_Size_; ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Decode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Decode_Buffer_Size"); diff --git a/include/etl/base64_encoder.h b/include/etl/base64_encoder.h index f6ed12da..dbee7110 100644 --- a/include/etl/base64_encoder.h +++ b/include/etl/base64_encoder.h @@ -63,15 +63,15 @@ namespace etl { public: - typedef etl::span span_type; - typedef etl::delegate callback_type; + typedef etl::span span_type; + typedef etl::delegate callback_type; //************************************************************************* /// Encode to Base64 //************************************************************************* template ETL_CONSTEXPR14 - void encode(T value) + bool encode(T value) { ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral"); @@ -86,11 +86,13 @@ namespace etl { if (output_buffer_is_full()) { - callback(span(), false); + callback(span()); reset_output_buffer(); } } } + + return !error(); } //************************************************************************* @@ -98,14 +100,19 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void encode(TInputIterator input_begin, size_t input_length) + bool encode(TInputIterator input_begin, size_t input_length) { ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); while (input_length-- != 0) { - encode(*input_begin++); + if (!encode(*input_begin++)) + { + return false; + } } + + return true; } //************************************************************************* @@ -113,14 +120,19 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void encode(TInputIterator input_begin, TInputIterator input_end) + bool encode(TInputIterator input_begin, TInputIterator input_end) { ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); while (input_begin != input_end) { - encode(*input_begin++); + if (!encode(*input_begin++)) + { + return false; + } } + + return true; } //************************************************************************* @@ -128,10 +140,9 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void encode_final(TInputIterator input_begin, size_t input_length) + bool encode_final(TInputIterator input_begin, size_t input_length) { - encode(input_begin, input_length); - flush(); + return encode(input_begin, input_length) && flush(); } //************************************************************************* @@ -139,28 +150,40 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void encode_final(TInputIterator input_begin, TInputIterator input_end) + bool encode_final(TInputIterator input_begin, TInputIterator input_end) { - encode(input_begin, input_end); - flush(); + return encode(input_begin, input_end) && flush(); } //************************************************************************* /// Flush any remaining data to the output. //************************************************************************* ETL_CONSTEXPR14 - void flush() + bool flush() { // Encode any remaining input data. - encode_block(); - - if (callback.is_valid()) - { - callback(span(), true); - reset_output_buffer(); - } + bool success = encode_block(); reset_input_buffer(); + + if (success) + { + if (callback.is_valid()) + { + // Send any remaining data. + if (size() != 0) + { + callback(span()); + } + + // Indicate this was the final block. + callback(span_type()); + + reset_output_buffer(); + } + } + + return success; } //************************************************************************* @@ -255,6 +278,16 @@ namespace etl return overflowed; } + //************************************************************************* + /// Returns true if an error was detected. + //************************************************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + bool error() const + { + return overflow(); + } + protected: //************************************************************************* @@ -281,7 +314,7 @@ namespace etl /// Encode one block of data. //************************************************************************* ETL_CONSTEXPR14 - void encode_block() + bool encode_block() { switch (input_buffer_length) { @@ -341,6 +374,8 @@ namespace etl } ETL_ASSERT(!overflowed, ETL_ERROR(etl::base64_overflow)); + + return !overflowed; } //************************************************************************* @@ -473,8 +508,8 @@ namespace etl { public: - static ETL_CONSTANT etl::base64::Encoding Encoding = etl::base64::Encoding::RFC_2152; - static ETL_CONSTANT size_t Buffer_Size = Buffer_Size_; + static ETL_CONSTANT etl::base64::Encoding Encoding = etl::base64::Encoding::RFC_2152; + static ETL_CONSTANT size_t Buffer_Size = Buffer_Size_; ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4cf8562..cad0feae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -19,12 +19,18 @@ add_executable(etl_tests test_array_view.cpp test_array_wrapper.cpp test_atomic.cpp - test_base64_RFC2152.cpp - test_base64_RFC3501.cpp - test_base64_RFC4648_with_no_padding.cpp - test_base64_RFC4648_with_padding.cpp - test_base64_RFC4648_URL_with_no_padding.cpp - test_base64_RFC4648_URL_with_padding.cpp + test_base64_RFC2152_decoder.cpp + test_base64_RFC2152_encoder.cpp + test_base64_RFC3501_decoder.cpp + test_base64_RFC3501_encoder.cpp + test_base64_RFC4648_decoder_with_no_padding.cpp + test_base64_RFC4648_decoder_with_padding.cpp + test_base64_RFC4648_encoder_with_no_padding.cpp + test_base64_RFC4648_encoder_with_padding.cpp + test_base64_RFC4648_URL_decoder_with_no_padding.cpp + test_base64_RFC4648_URL_decoder_with_padding.cpp + test_base64_RFC4648_URL_encoder_with_no_padding.cpp + test_base64_RFC4648_URL_encoder_with_padding.cpp test_binary.cpp test_bip_buffer_spsc_atomic.cpp test_bit.cpp @@ -59,7 +65,7 @@ add_executable(etl_tests test_container.cpp test_correlation.cpp test_covariance.cpp - test_crc.cpp + test_crc1.cpp test_crc16.cpp test_crc16_a.cpp test_crc16_arc.cpp diff --git a/test/etl_profile.h b/test/etl_profile.h index 0e70e78b..38ec2abe 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -95,7 +95,7 @@ SOFTWARE. #define ETL_OBSERVER_FORCE_CPP03_IMPLEMENTATION #define ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION #define ETL_FSM_FORCE_CPP03_IMPLEMENTATION - #define ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION + //#define ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION // C++03 implementation is tested at the same time as the C++11 and above. #define ETL_SINGLETON_FORCE_CPP03_IMPLEMENTATION #define ETL_BYTE_FORCE_CPP03_IMPLEMENTATION #define ETL_LIST_FORCE_CPP03_IMPLEMENTATION @@ -114,10 +114,6 @@ SOFTWARE. #include "../include/etl/profiles/determine_compiler_version.h" #include "../include/etl/profiles/determine_development_os.h" -//#if ETL_CPP17_NOT_SUPPORTED -// #error THE UNIT TESTS REQUIRE C++17 SUPPORT -//#endif - #if defined(ETL_COMPILER_GCC) #if (ETL_COMPILER_VERSION < 8) #define ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED diff --git a/test/meson.build b/test/meson.build index 67cb04b9..b84a21be 100644 --- a/test/meson.build +++ b/test/meson.build @@ -8,6 +8,18 @@ etl_test_sources = files( 'test_array_view.cpp', 'test_array_wrapper.cpp', 'test_atomic.cpp', + 'test_base64_RFC2152_decoder.cppp', + 'test_base64_RFC2152_encoder.cppp', + 'test_base64_RFC3501_decoder.cppp', + 'test_base64_RFC3501_encoder.cppp', + 'test_base64_RFC4648_decoder_with_no_padding.cppp', + 'test_base64_RFC4648_decoder_with_padding.cppp', + 'test_base64_RFC4648_encoder_with_no_padding.cppp', + 'test_base64_RFC4648_encoder_with_padding.cppp', + 'test_base64_RFC4648_URL_decoder_with_no_padding.cppp', + 'test_base64_RFC4648_URL_decoder_with_padding.cppp', + 'test_base64_RFC4648_URL_encoder_with_no_padding.cppp', + 'test_base64_RFC4648_URL_encoder_with_padding.cpp', 'test_binary.cpp', 'test_bip_buffer_spsc_atomic.cpp', 'test_bit.cpp', @@ -42,7 +54,7 @@ etl_test_sources = files( 'test_container.cpp', 'test_correlation.cpp', 'test_covariance.cpp', - 'test_crc.cpp', + 'test_crc1.cpp', 'test_crc16.cpp', 'test_crc16_a.cpp', 'test_crc16_arc.cpp', diff --git a/test/run-syntax-checks.sh b/test/run-syntax-checks.sh index 06932079..d2d06c7a 100644 --- a/test/run-syntax-checks.sh +++ b/test/run-syntax-checks.sh @@ -29,12 +29,12 @@ PrintHeader() { echo "$TitleColour" echo "============================================================================" | tee -a log.txt - echo " Configuration : $configuration_name" | tee -a log.txt - echo " Compiler : $compiler " | tee -a log.txt - echo " Language standard : C++$cxx_standard " | tee -a log.txt - echo " ETL version : $etl_version " | tee -a log.txt - echo " Git branch : $(ParseGitBranch) " | tee -a log.txt - echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt + echo " Configuration : $configuration_name" | tee -a log.txt + echo " Compiler : $compiler " | tee -a log.txt + echo " Language : C++$cxx_standard " | tee -a log.txt + echo " ETL version : $etl_version " | tee -a log.txt + echo " Git branch : $(ParseGitBranch) " | tee -a log.txt + echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt echo "============================================================================" | tee -a log.txt echo "$NoColour" } @@ -43,7 +43,7 @@ PassedCompilation() { echo "$PassColour" echo "-----------------------------------------------" | tee -a log.txt - echo " Passed Compilation - $configuration_name" | tee -a log.txt + echo " Compilation Success - $configuration_name" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt echo "$NoColour" } diff --git a/test/run-tests.sh b/test/run-tests.sh index 41fd6b29..408c7481 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -38,14 +38,14 @@ PrintHeader() { echo "$TitleColour" echo "============================================================================" | tee -a log.txt - echo " Configuration : $configuration_name" | tee -a log.txt - echo " Compiler : $compiler " | tee -a log.txt - echo " Language standard : C++$cxx_standard " | tee -a log.txt - echo " Optimisation : $opt " | tee -a log.txt - echo " Sanitizer : $sanitize " | tee -a log.txt - echo " ETL version : $etl_version " | tee -a log.txt - echo " Git branch : $(ParseGitBranch) " | tee -a log.txt - echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt + echo " Configuration : $configuration_name" | tee -a log.txt + echo " Compiler : $compiler " | tee -a log.txt + echo " Language : C++$cxx_standard " | tee -a log.txt + echo " Optimisation : $opt " | tee -a log.txt + echo " Sanitizer : $sanitize " | tee -a log.txt + echo " ETL version : $etl_version " | tee -a log.txt + echo " Git branch : $(ParseGitBranch) " | tee -a log.txt + echo " Processes : ${CMAKE_BUILD_PARALLEL_LEVEL}" | tee -a log.txt echo "============================================================================" | tee -a log.txt echo "$NoColour" } @@ -67,7 +67,7 @@ PassedCompilation() { echo "$PassColour" echo "-----------------------------------------------" | tee -a log.txt - echo " Passed Compilation - $configuration_name" | tee -a log.txt + echo " Compilation Success - $configuration_name" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt echo "$NoColour" } diff --git a/test/test_base64_RFC2152_decoder.cpp b/test/test_base64_RFC2152_decoder.cpp index 5370dbcf..f8a43451 100644 --- a/test/test_base64_RFC2152_decoder.cpp +++ b/test/test_base64_RFC2152_decoder.cpp @@ -28,6 +28,8 @@ SOFTWARE. #include "unit_test_framework.h" +#include + #include "etl/base64_decoder.h" #include "etl/string.h" @@ -52,7 +54,27 @@ namespace { using codec = etl::base64_rfc2152_decoder; using codec_larger_buffer = etl::base64_rfc2152_decoder; + +#if (ETL_USING_CPP14) using codec_full_buffer = etl::base64_rfc2152_decoder< etl::base64_rfc2152_decoder<>::safe_output_buffer_size(342)>; +#else + using codec_full_buffer = etl::base64_rfc2152_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -342,8 +364,8 @@ namespace { codec_full_buffer b64; - CHECK_EQUAL(etl::base64::Encoding::RFC_2152, codec_full_buffer::Encoding); - CHECK_EQUAL("RFC_2152", codec_full_buffer::Encoding.c_str()); + CHECK_EQUAL(etl::base64::Encoding::RFC_2152, codec_full_buffer::Encoding); + CHECK_EQUAL("RFC_2152", codec_full_buffer::Encoding.c_str()); } //************************************************************************* @@ -352,7 +374,7 @@ namespace for (size_t i = 0; i < 256; ++i) { size_t minimum_size = i; - size_t safe_size = codec::safe_output_buffer_size(encoded[i].size()); + size_t safe_size = codec::safe_output_buffer_size(encoded[i].size()); CHECK_TRUE(safe_size >= minimum_size); CHECK_TRUE((safe_size - minimum_size) <= 2U); @@ -362,19 +384,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +406,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -432,19 +428,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -452,7 +435,7 @@ namespace decoded_output.clear(); received_final_block = false; - auto start = encoded[i].data(); + auto start = encoded[i].data(); auto length = encoded[i].size(); while (length >= 5) @@ -484,19 +467,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -536,19 +506,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -571,19 +528,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -606,19 +550,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -658,19 +589,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -710,19 +628,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -755,19 +660,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -866,7 +758,6 @@ namespace TEST(test_decode_overflow) { codec b64; - std::array decoded_output{ 0 }; #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); @@ -880,7 +771,6 @@ namespace TEST(test_decode_invalid_character) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycDQ#37KA"); diff --git a/test/test_base64_RFC2152_encoder.cpp b/test/test_base64_RFC2152_encoder.cpp index 573c53e4..ecf5051c 100644 --- a/test/test_base64_RFC2152_encoder.cpp +++ b/test/test_base64_RFC2152_encoder.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc2152_encoder; using codec_larger_buffer = etl::base64_rfc2152_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc2152_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc2152_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; diff --git a/test/test_base64_RFC3501_decoder.cpp b/test/test_base64_RFC3501_decoder.cpp index 9fe3fb30..5a57b5a1 100644 --- a/test/test_base64_RFC3501_decoder.cpp +++ b/test/test_base64_RFC3501_decoder.cpp @@ -52,7 +52,26 @@ namespace { using codec = etl::base64_rfc3501_decoder; using codec_larger_buffer = etl::base64_rfc3501_decoder; +#if (ETL_USING_CPP14) using codec_full_buffer = etl::base64_rfc3501_decoder< etl::base64_rfc3501_decoder<>::safe_output_buffer_size(342)>; +#else + using codec_full_buffer = etl::base64_rfc3501_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -362,19 +381,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -382,14 +388,7 @@ namespace decoded_output.clear(); received_final_block = false; - try - { - b64.decode_final(encoded[i].data(), encoded[i].size()); - } - catch (etl::exception e) - { - auto what = e.what(); - } + b64.decode_final(encoded[i].data(), encoded[i].size()); std::vector expected(input_data.begin(), input_data.begin() + i); std::vector actual(decoded_output); @@ -404,19 +403,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -439,19 +425,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -491,19 +464,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -543,19 +503,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -578,19 +525,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -613,19 +547,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -665,19 +586,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -717,19 +625,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -762,19 +657,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -873,7 +755,6 @@ namespace TEST(test_decode_overflow) { codec b64; - std::array decoded_output{ 0 }; #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); @@ -887,7 +768,6 @@ namespace TEST(test_decode_invalid_character) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycDQ#37KA"); diff --git a/test/test_base64_RFC3501_encoder.cpp b/test/test_base64_RFC3501_encoder.cpp index a9a258b1..b975e84f 100644 --- a/test/test_base64_RFC3501_encoder.cpp +++ b/test/test_base64_RFC3501_encoder.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc3501_encoder; using codec_larger_buffer = etl::base64_rfc3501_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc3501_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc3501_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; diff --git a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp index 7c4cabd0..c3bb650d 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_no_padding.cpp @@ -52,7 +52,26 @@ namespace { using codec = etl::base64_rfc4648_url_decoder ; using codec_larger_buffer = etl::base64_rfc4648_url_decoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_url_decoder::safe_output_buffer_size(342)>; +#else + using codec_full_buffer = etl::base64_rfc4648_url_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -362,19 +381,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -432,19 +425,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -484,19 +464,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -536,19 +503,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -571,19 +525,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -606,19 +547,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -658,19 +586,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -710,19 +625,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -755,19 +657,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -866,7 +755,6 @@ namespace TEST(test_decode_overflow) { codec b64; - std::array decoded_output{ 0 }; #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); @@ -880,7 +768,6 @@ namespace TEST(test_decode_invalid_character) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycDQ#37KA"); @@ -896,7 +783,6 @@ namespace TEST(test_decode_invalid_padding) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycD=y37KA"); diff --git a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp index 1acc4db4..6dd57f44 100644 --- a/test/test_base64_RFC4648_URL_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_decoder_with_padding.cpp @@ -52,7 +52,26 @@ namespace { using codec = etl::base64_rfc4648_url_padding_decoder ; using codec_larger_buffer = etl::base64_rfc4648_url_padding_decoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_url_padding_decoder::safe_output_buffer_size(344)>; +#else + using codec_full_buffer = etl::base64_rfc4648_url_padding_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -362,19 +381,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -432,19 +425,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -484,19 +464,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -536,19 +503,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -571,19 +525,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -606,19 +547,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -658,19 +586,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -710,19 +625,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -755,19 +657,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -866,7 +755,6 @@ namespace TEST(test_decode_overflow) { codec b64; - std::array decoded_output{ 0 }; #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); @@ -880,7 +768,6 @@ namespace TEST(test_decode_invalid_character) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycDQ#37KA"); @@ -896,7 +783,6 @@ namespace TEST(test_decode_invalid_padding) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycD=y37KA=="); @@ -909,4 +795,3 @@ namespace } }; } - diff --git a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp index 847eea95..1a4b59a4 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_no_padding.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc4648_url_encoder; using codec_larger_buffer = etl::base64_rfc4648_url_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_url_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc4648_url_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; diff --git a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp index 3edd3eff..e3f8b3e2 100644 --- a/test/test_base64_RFC4648_URL_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_URL_encoder_with_padding.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc4648_url_padding_encoder; using codec_larger_buffer = etl::base64_rfc4648_url_padding_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_url_padding_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc4648_url_padding_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; diff --git a/test/test_base64_RFC4648_decoder_with_no_padding.cpp b/test/test_base64_RFC4648_decoder_with_no_padding.cpp index 58b52d4b..b8ca1eae 100644 --- a/test/test_base64_RFC4648_decoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_no_padding.cpp @@ -52,7 +52,26 @@ namespace { using codec = etl::base64_rfc4648_decoder ; using codec_larger_buffer = etl::base64_rfc4648_decoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_decoder< etl::base64_rfc4648_decoder<>::safe_output_buffer_size(342)>; +#else + using codec_full_buffer = etl::base64_rfc4648_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -362,19 +381,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -432,19 +425,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -484,19 +464,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -536,19 +503,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -571,19 +525,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -606,19 +547,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -658,19 +586,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -710,19 +625,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -755,19 +657,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -866,7 +755,6 @@ namespace TEST(test_decode_overflow) { codec b64; - std::array decoded_output{ 0 }; #if ETL_USING_EXCEPTIONS CHECK_THROW((b64.decode(encoded[10].data(), encoded[10].size())), etl::base64_overflow); @@ -880,7 +768,6 @@ namespace TEST(test_decode_invalid_character) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycDQ#37KA"); @@ -896,7 +783,6 @@ namespace TEST(test_decode_invalid_padding) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycD=y37KA"); diff --git a/test/test_base64_RFC4648_decoder_with_padding.cpp b/test/test_base64_RFC4648_decoder_with_padding.cpp index 555fcb69..43229afb 100644 --- a/test/test_base64_RFC4648_decoder_with_padding.cpp +++ b/test/test_base64_RFC4648_decoder_with_padding.cpp @@ -52,7 +52,26 @@ namespace { using codec = etl::base64_rfc4648_padding_decoder ; using codec_larger_buffer = etl::base64_rfc4648_padding_decoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_padding_decoder::safe_output_buffer_size(344)>; +#else + using codec_full_buffer = etl::base64_rfc4648_padding_decoder<256>; +#endif + + std::vector decoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); + } + }; std::array input_data = { @@ -362,19 +381,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -432,19 +425,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -484,19 +464,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_size_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -536,19 +503,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -571,19 +525,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_single_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -606,19 +547,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -658,19 +586,6 @@ namespace //************************************************************************* TEST(test_decode_pointer_pointer_multi_pass_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -710,19 +625,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback) { - std::vector decoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&decoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -755,19 +657,6 @@ namespace //************************************************************************* TEST(test_decode_multi_pass_by_char_with_callback_and_larger_buffer) { - std::vector decoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&decoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(decoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -894,7 +783,6 @@ namespace TEST(test_decode_invalid_padding) { codec_larger_buffer b64; - std::array decoded_output{ 0 }; std::string invalid_chararacter("OycD=y37KA=="); diff --git a/test/test_base64_RFC4648_encoder_with_no_padding.cpp b/test/test_base64_RFC4648_encoder_with_no_padding.cpp index 14931601..21b22579 100644 --- a/test/test_base64_RFC4648_encoder_with_no_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_no_padding.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc4648_encoder; using codec_larger_buffer = etl::base64_rfc4648_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc4648_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; diff --git a/test/test_base64_RFC4648_encoder_with_padding.cpp b/test/test_base64_RFC4648_encoder_with_padding.cpp index 2849300d..56e9f822 100644 --- a/test/test_base64_RFC4648_encoder_with_padding.cpp +++ b/test/test_base64_RFC4648_encoder_with_padding.cpp @@ -53,7 +53,26 @@ namespace { using codec = etl::base64_rfc4648_padding_encoder; using codec_larger_buffer = etl::base64_rfc4648_padding_encoder; +#if ETL_USING_CPP14 using codec_full_buffer = etl::base64_rfc4648_padding_encoder::safe_output_buffer_size(256)>; +#else + using codec_full_buffer = etl::base64_rfc4648_padding_encoder<344>; +#endif + + std::string encoded_output; + bool received_final_block = false; + + codec::callback_type callback = [](const codec::span_type& sp) + { + if (sp.empty()) + { + received_final_block = true; + } + else + { + std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); + } + }; std::array input_data = { @@ -363,19 +382,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -397,19 +403,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_single_pass_with_callback_and_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -431,19 +424,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -481,19 +461,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_size_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -531,19 +498,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -565,19 +519,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_single_pass_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -599,19 +540,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -649,19 +577,6 @@ namespace //************************************************************************* TEST(test_encode_pointer_pointer_multi_pass_blocks_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -699,19 +614,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback) { - std::string encoded_output; - bool received_final_block = false; - - codec::callback_type callback = [&encoded_output, &received_final_block](codec::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec b64(callback); for (size_t i = 0; i < 256; ++i) @@ -743,19 +645,6 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_by_char_with_callback_larger_buffer) { - std::string encoded_output; - bool received_final_block = false; - - codec_larger_buffer::callback_type callback = [&encoded_output, &received_final_block](codec_larger_buffer::span_type sp, bool final) - { - std::copy(sp.begin(), sp.end(), std::back_inserter(encoded_output)); - - if (final) - { - received_final_block = true; - } - }; - codec_larger_buffer b64(callback); for (size_t i = 0; i < 256; ++i) @@ -787,14 +676,11 @@ namespace //************************************************************************* TEST(test_encode_multi_pass_blocks_with_no_callback_and_full_size_buffer) { - std::string actual; - codec_full_buffer b64; for (size_t i = 250; i < 256; ++i) { b64.restart(); - actual.clear(); auto start = input_data.data(); auto length = i; @@ -823,32 +709,32 @@ namespace //************************************************************************* #if ETL_USING_CPP14 - //template - //constexpr auto GetConstexprBase64(const etl::array input) noexcept - //{ - // etl::array output{ 0 }; - // - // using codec = etl::base64_rfc4648_encoder; - // - // codec b64; - // b64.encode_final(input.begin(), input.end()); - // etl::copy(b64.begin(), b64.end(), output.begin()); + template + constexpr auto GetConstexprBase64(const etl::array input) noexcept + { + etl::array output{ 0 }; + + using codec = etl::base64_rfc4648_encoder; + + codec b64; + b64.encode_final(input.begin(), input.end()); + etl::copy(b64.begin(), b64.end(), output.begin()); - // return output; - //} + return output; + } - //TEST(test_encode_constexpr) - //{ - // constexpr etl::array input = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + TEST(test_encode_constexpr) + { + constexpr etl::array input = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - // constexpr auto output{ GetConstexprBase64(input) }; + constexpr auto output{ GetConstexprBase64(input) }; - // std::string expected("AAECAwQFBgcICQ"); - // std::string actual(output.data(), output.size()); + std::string expected("AAECAwQFBgcICQ"); + std::string actual(output.data(), output.size()); - // CHECK_EQUAL(expected, actual); - // CHECK_TRUE(codec::safe_output_buffer_size(10) >= output.size()); - //} + CHECK_EQUAL(expected, actual); + CHECK_TRUE(codec::safe_output_buffer_size(10) >= output.size()); + } #endif //************************************************************************* diff --git a/test/test_crc.cpp b/test/test_crc.cpp deleted file mode 100644 index f0c69cfa..00000000 --- a/test/test_crc.cpp +++ /dev/null @@ -1,1258 +0,0 @@ -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2014 jwellbelove - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files(the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions : - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ - -#include "unit_test_framework.h" - -#include -#include -#include -#include - -#include "etl/crc8_ccitt.h" -#include "etl/crc8_rohc.h" -#include "etl/crc16.h" -#include "etl/crc16_ccitt.h" -#include "etl/crc16_aug_ccitt.h" -#include "etl/crc16_kermit.h" -#include "etl/crc16_modbus.h" -#include "etl/crc16_usb.h" -#include "etl/crc16_xmodem.h" -#include "etl/crc16_genibus.h" -#include "etl/crc16_x25.h" -#include "etl/crc32.h" -#include "etl/crc32_c.h" -#include "etl/crc32_bzip2.h" -#include "etl/crc32_mpeg2.h" -#include "etl/crc32_posix.h" -#include "etl/crc64_ecma.h" - -//***************************************************************************** -// The results for these tests were created from https://crccalc.com/ -//***************************************************************************** - -namespace -{ - SUITE(test_crc) - { - //************************************************************************* - TEST(test_crc8_ccitt_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xF4, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_ccitt_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc8_rohc_constructor) - { - std::string data("123456789"); - - uint8_t crc = etl::crc8_rohc(data.begin(), data.end()); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_values) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint8_t crc = crc_calculator; - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc8_rohc crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint8_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD0, int(crc)); - } - - //************************************************************************* - TEST(test_crc8_rohc_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint8_t crc1 = etl::crc32(data1.begin(), data1.end()); - uint8_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(int(crc1), int(crc2)); - - uint8_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(int(crc1), int(crc3)); - } - - //************************************************************************* - TEST(test_crc16) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16(data.begin(), data.end()); - - CHECK_EQUAL(0xBB3DU, crc); - } - - //************************************************************************* - TEST(test_crc16_add_values) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xBB3DU, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3DU, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xBB3DU, crc); - } - - //************************************************************************* - TEST(test_crc16_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0x29B1U, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x29B1U, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1U, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x29B1U, crc); - } - - //************************************************************************* - TEST(test_crc16_ccitt_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_kermit) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_kermit(data.begin(), data.end()); - - CHECK_EQUAL(0x2189U, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_values) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x2189U, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189U, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_kermit crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x2189U, crc); - } - - //************************************************************************* - TEST(test_crc16_kermit_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_kermit(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_kermit((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_kermit(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_modbus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_modbus(data.begin(), data.end()); - - CHECK_EQUAL(0x4B37U, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_values) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x4B37U, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37U, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_modbus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x4B37U, crc); - } - - //************************************************************************* - TEST(test_crc16_modbus_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_modbus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_modbus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_modbus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_usb) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_usb(data.begin(), data.end()); - - CHECK_EQUAL(0xB4C8U, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_values) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xB4C8U, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8U, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_usb crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xB4C8U, crc); - } - - //************************************************************************* - TEST(test_crc16_usb_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_usb(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_usb((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_usb(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_xmodem) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_xmodem(data.begin(), data.end()); - - CHECK_EQUAL(0x31C3U, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_values) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x31C3U, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3U, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_xmodem crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x31C3U, crc); - } - - //************************************************************************* - TEST(test_crc16_xmodem_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_xmodem(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_xmodem((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_xmodem(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_aug_ccitt(data.begin(), data.end()); - - CHECK_EQUAL(0xE5CCU, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_values) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xE5CCU, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CCU, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_aug_ccitt crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE5CCU, crc); - } - - //************************************************************************* - TEST(test_crc16_aug_ccitt_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_aug_ccitt(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_aug_ccitt((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_aug_ccitt(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_genibus) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_genibus(data.begin(), data.end()); - - CHECK_EQUAL(0xD64EU, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_values) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0xD64EU, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64EU, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_genibus crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xD64EU, crc); - } - - //************************************************************************* - TEST(test_crc16_genibus_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_genibus(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_genibus((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_genibus(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc16_x25) - { - std::string data("123456789"); - - uint16_t crc = etl::crc16_x25(data.begin(), data.end()); - - CHECK_EQUAL(0x906EU, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_values) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint16_t crc = crc_calculator; - - CHECK_EQUAL(0x906EU, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906EU, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc16_x25 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint16_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x906EU, crc); - } - - //************************************************************************* - TEST(test_crc16_x25_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint16_t crc1 = etl::crc16_x25(data1.begin(), data1.end()); - uint16_t crc2 = etl::crc16_x25((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint16_t crc3 = etl::crc16_x25(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32(data.begin(), data.end()); - - CHECK_EQUAL(0xCBF43926UL, crc); - } - - //************************************************************************* - TEST(test_crc32_add_values) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xCBF43926UL, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926UL, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xCBF43926UL, crc); - } - - //************************************************************************* - TEST(test_crc32_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint32_t crc1 = etl::crc32(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_c) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_c(data.begin(), data.end()); - - CHECK_EQUAL(0xE3069283UL, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_values) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xE3069283UL, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283UL, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_c crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xE3069283UL, crc); - } - - //************************************************************************* - TEST(test_crc32_c_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint32_t crc1 = etl::crc32_c(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_c((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_c(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_bzip2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_bzip2(data.begin(), data.end()); - - CHECK_EQUAL(0xFC891918UL, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_values) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0xFC891918UL, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918UL, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_bzip2 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0xFC891918UL, crc); - } - - //************************************************************************* - TEST(test_crc32_bzip2_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint32_t crc1 = etl::crc32_bzip2(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_bzip2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_bzip2(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_posix) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_posix(data.begin(), data.end()); - - CHECK_EQUAL(0x765E7680UL, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_values) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x765E7680UL, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680UL, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_posix crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x765E7680UL, crc); - } - - //************************************************************************* - TEST(test_crc32_posix_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint32_t crc1 = etl::crc32_posix(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_posix((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_posix(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc32_mpeg2) - { - std::string data("123456789"); - - uint32_t crc = etl::crc32_mpeg2(data.begin(), data.end()); - - CHECK_EQUAL(0x0376E6E7UL, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_values) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint32_t crc = crc_calculator; - - - CHECK_EQUAL(0x0376E6E7UL, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7UL, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc32_mpeg2 crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint32_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x0376E6E7UL, crc); - } - - //************************************************************************* - TEST(test_crc32_mpeg2_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint32_t crc1 = etl::crc32_mpeg2(data1.begin(), data1.end()); - uint32_t crc2 = etl::crc32_mpeg2((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint32_t crc3 = etl::crc32_mpeg2(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - - //************************************************************************* - TEST(test_crc64_ecma) - { - std::string data("123456789"); - - uint64_t crc = etl::crc64_ecma(data.begin(), data.end()); - - CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_values) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - for (size_t i = 0UL; i < data.size(); ++i) - { - crc_calculator.add(data[i]); - } - - uint64_t crc = crc_calculator; - - CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - crc_calculator.add(data.begin(), data.end()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_via_iterator) - { - std::string data("123456789"); - - etl::crc64_ecma crc_calculator; - - std::copy(data.begin(), data.end(), crc_calculator.input()); - - uint64_t crc = crc_calculator.value(); - - CHECK_EQUAL(0x6C40DF5F0B497347ULL, crc); - } - - //************************************************************************* - TEST(test_crc64_ecma_add_range_endian) - { - std::vector data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; - std::vector data2 = { 0x04030201UL, 0x08070605UL }; - std::vector data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; - - uint64_t crc1 = etl::crc64_ecma(data1.begin(), data1.end()); - uint64_t crc2 = etl::crc64_ecma((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); - CHECK_EQUAL(crc1, crc2); - - uint64_t crc3 = etl::crc64_ecma(data3.rbegin(), data3.rend()); - CHECK_EQUAL(crc1, crc3); - } - }; -} -