diff --git a/.gitignore b/.gitignore index ab33079c..420a66d3 100644 --- a/.gitignore +++ b/.gitignore @@ -389,3 +389,5 @@ test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt test/reflog.txt +test/etl_error_handler/assert_function/build-make +test/syntax_check/bgcc diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 51fd1fd8..8789d656 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -49,7 +49,9 @@ SOFTWARE. #include "private/chrono/weekday_indexed.h" #include "private/chrono/weekday_last.h" #include "private/chrono/month.h" -#include "private/chrono/year.h" +#include "private/chrono/month_day.h" +#include "private/chrono/year.h" +#include "private/chrono/operators.h" #endif #undef ETL_IN_CHRONO_H diff --git a/include/etl/platform.h b/include/etl/platform.h index 361fade2..1eaa1329 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -272,8 +272,8 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has weekdays (_day) -#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY) +// Indicate if etl::literals::chrono_literals has days (_days) +#if defined(ETL_DISABLE_CHRONO_LITERALS_DAY) #define ETL_HAS_CHRONO_LITERALS_DAY 0 #else #define ETL_HAS_CHRONO_LITERALS_DAY 1 @@ -288,7 +288,7 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has month (_month) +// Indicate if etl::literals::chrono_literals has month (_months) #if defined(ETL_DISABLE_CHRONO_LITERALS_MONTH) #define ETL_HAS_CHRONO_LITERALS_MONTH 0 #else @@ -296,13 +296,21 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has year (_year) +// Indicate if etl::literals::chrono_literals has year (_years) #if defined(ETL_DISABLE_CHRONO_LITERALS_YEAR) #define ETL_HAS_CHRONO_LITERALS_YEAR 0 #else #define ETL_HAS_CHRONO_LITERALS_YEAR 1 #endif +//************************************* +// Indicate if etl::literals::chrono_literals has year (_hours, _minutes, _seconds, _milliseconds, _microseconds, _nanoseconds) +#if defined(ETL_DISABLE_CHRONO_LITERALS_DURATION) +#define ETL_HAS_CHRONO_LITERALS_DURATION 0 +#else +#define ETL_HAS_CHRONO_LITERALS_DURATION 1 +#endif + //************************************* // The macros below are dependent on the profile. // C++11 diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 91557a95..511ae0a9 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -311,7 +311,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_DAY -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -321,7 +320,7 @@ namespace etl //*********************************************************************** /// Literal for days //*********************************************************************** - constexpr etl::chrono::day operator ""_day(unsigned long long d) noexcept + inline constexpr etl::chrono::day operator ""_day(unsigned long long d) noexcept { return etl::chrono::day(static_cast(d)); } @@ -329,4 +328,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 6d4a5334..10c79460 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -258,11 +258,17 @@ namespace etl { ETL_CONSTEXPR14 size_t operator()(const etl::chrono::duration& d) const { - TRep value = d.count(); - size_t num = TPeriod::num; - size_t den = TPeriod::den; + uint8_t buffer[sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t)]; - return 0; //etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + TRep value = d.count(); + intmax_t num = TPeriod::num; + intmax_t den = TPeriod::den; + + memcpy(buffer, &value, sizeof(TRep)); + memcpy(buffer + sizeof(TRep), &num, sizeof(intmax_t)); + memcpy(buffer + sizeof(TRep) + sizeof(intmax_t), &den, sizeof(intmax_t)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t)); } }; #endif @@ -349,8 +355,7 @@ namespace etl } } -#if ETL_HAS_CHRONO_LITERALS_DAY -#if ETL_USING_CPP11 +#if ETL_HAS_CHRONO_LITERALS_DURATION namespace etl { namespace literals @@ -360,7 +365,7 @@ namespace etl //*********************************************************************** /// Literal for hours duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::hours operator ""_hours(unsigned long long h) noexcept + inline ETL_CONSTEXPR etl::chrono::hours operator ""_hours(unsigned long long h) noexcept { return etl::chrono::hours(static_cast(h)); } @@ -368,7 +373,7 @@ namespace etl //*********************************************************************** /// Literal for minutes duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::minutes operator ""_minutes(unsigned long long m) noexcept + inline ETL_CONSTEXPR etl::chrono::minutes operator ""_minutes(unsigned long long m) noexcept { return etl::chrono::minutes(static_cast(m)); } @@ -376,7 +381,7 @@ namespace etl //*********************************************************************** /// Literal for seconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::seconds operator ""_seconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::seconds operator ""_seconds(unsigned long long s) noexcept { return etl::chrono::seconds(static_cast(s)); } @@ -384,7 +389,7 @@ namespace etl //*********************************************************************** /// Literal for milliseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) noexcept { return etl::chrono::milliseconds(static_cast(s)); } @@ -392,7 +397,7 @@ namespace etl //*********************************************************************** /// Literal for microseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::microseconds operator ""_microseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::microseconds operator ""_microseconds(unsigned long long s) noexcept { return etl::chrono::microseconds(static_cast(s)); } @@ -400,7 +405,7 @@ namespace etl //*********************************************************************** /// Literal for nanoseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) noexcept { return etl::chrono::nanoseconds(static_cast(s)); } @@ -408,4 +413,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 30653a58..f9693c2c 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -362,7 +362,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_MONTH -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -372,7 +371,7 @@ namespace etl //*********************************************************************** /// Literal for months //*********************************************************************** - constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept + inline constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept { return etl::chrono::month(static_cast(m)); } @@ -380,4 +379,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h new file mode 100644 index 00000000..fbcb03bc --- /dev/null +++ b/include/etl/private/chrono/month_day.h @@ -0,0 +1,156 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + namespace private_chrono + { + static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + } + + class month_day + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + month_day() = default; + + //************************************************************************* + /// Construct from month and day. + //************************************************************************* + ETL_CONSTEXPR month_day(const etl::chrono::month& m_, const etl::chrono::day& d_) ETL_NOEXCEPT + : m(m_) + , d(d_) + { + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the day. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT + { + return d; + } + + //************************************************************************* + /// Returns true if the month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + if (!m.ok() || !d.ok()) + { + return false; + } + + unsigned max_day = 0; + + unsigned m_v = static_cast(m); + max_day = private_chrono::days_in_month[m_v]; + + return (max_day > 0) && + (static_cast(d) >= 1) && + (static_cast(d) <= max_day); + } + + //************************************************************************* + /// Returns true if the two instances are equal. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return (lhs.d == rhs.d) && (lhs.m == rhs.m); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + friend [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) noexcept + { + auto cmp = lhs.m <=> rhs.m; + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.d <=> rhs.d; + } + } +#endif + + private: + + etl::chrono::month m; + etl::chrono::day d; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::month_day + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_day& md) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int m = md.month(); + unsigned int d = md.day(); + + memcpy(buffer, &m, sizeof(m)); + memcpy(buffer + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/include/etl/private/chrono/operators.h b/include/etl/private/chrono/operators.h new file mode 100644 index 00000000..169217e7 --- /dev/null +++ b/include/etl/private/chrono/operators.h @@ -0,0 +1,189 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +#ifndef ETL_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //// year_month + //constexpr auto operator/(const etl::chrono::year& y, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::year_month; + + //constexpr auto operator/( const etl::chrono::year& y, int m ) noexcept + // -> etl::chrono::year_month; + + //// month_day + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::day& d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::month& m, int d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( int m, const etl::chrono::day& d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::day& d, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::day& d, int m ) noexcept + // -> etl::chrono::month_day; + + //// month_day_last + //constexpr auto operator/( const etl::chrono::month& m, + // etl::chrono::last_spec ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( int m, etl::chrono::last_spec ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( etl::chrono::last_spec, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( etl::chrono::last_spec, int m ) noexcept + // -> etl::chrono::month_day_last; + + //// month_weekday + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/( int m, const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/(const etl::chrono::weekday_indexed& wdi, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/( const etl::chrono::weekday_indexed& wdi, int m ) noexcept + // -> etl::chrono::month_weekday; + + //// month_weekday_last + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( int m, const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( const etl::chrono::weekday_last& wdl, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( const etl::chrono::weekday_last& wdl, int m ) noexcept + // -> etl::chrono::month_weekday_last; + + //// year_month_day + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::day& d ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::year_month& ym, int d ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_day& md ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( int y, const etl::chrono::month_day& md ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::month_day& md, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::month_day& md, int y ) noexcept + // -> etl::chrono::year_month_day; + + //// year_month_day_last + //constexpr auto operator/( const etl::chrono::year_month& ym, + // etl::chrono::last_spec ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_day_last& mdl ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( int y, const etl::chrono::month_day_last& mdl ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::month_day_last& mdl, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::month_day_last& mdl, int y ) noexcept + // -> etl::chrono::year_month_day_last; + + //// year_month_weekday + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_weekday& mwd ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( int y, const etl::chrono::month_weekday& mwd ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::month_weekday& mwd, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::month_weekday& mwd, int y ) noexcept + // -> etl::chrono::year_month_weekday; + + //// year_month_weekday_last + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_weekday_last& mwdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( int y, const etl::chrono::month_weekday_last& mwdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, int y ) noexcept + // -> etl::chrono::year_month_weekday_last; + } +} \ No newline at end of file diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index fc4df27f..d294d9c8 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -370,7 +370,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_WEEKDAY -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -380,12 +379,11 @@ namespace etl //*********************************************************************** /// Literal for weekdays //*********************************************************************** - constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept + inline constexpr etl::chrono::weekday operator ""_weekday(unsigned long long wd) noexcept { - return etl::chrono::weekday(static_cast(m)); + return etl::chrono::weekday(static_cast(wd)); } } } } #endif -#endif diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index ff873e37..695d369f 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -311,7 +311,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_YEAR -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -321,7 +320,7 @@ namespace etl //*********************************************************************** /// Literal for years //*********************************************************************** - constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept + inline constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept { return etl::chrono::year(static_cast(y)); } @@ -329,4 +328,3 @@ namespace etl } } #endif -#endif diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 00000000..5a97bcac --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1 @@ +*.tar filter=lfs diff=lfs merge=lfs -text diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 648d4c4f..87fe5d39 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,307 +12,308 @@ project(etl_unit_tests LANGUAGES CXX) add_executable(etl_tests main.cpp - murmurhash3.cpp - test_algorithm.cpp - test_alignment.cpp - test_array.cpp - test_array_view.cpp - test_array_wrapper.cpp - test_atomic.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 - test_bitset_legacy.cpp - test_bitset_new_comparisons.cpp - test_bitset_new_default_element_type.cpp - test_bitset_new_explicit_single_element_type.cpp - test_bitset_new_ext_default_element_type.cpp - test_bitset_new_ext_explicit_single_element_type.cpp - test_bit_stream.cpp - test_bit_stream_reader_big_endian.cpp - test_bit_stream_reader_little_endian.cpp - test_bit_stream_writer_big_endian.cpp - test_bit_stream_writer_little_endian.cpp - test_bloom_filter.cpp - test_bresenham_line.cpp - test_bsd_checksum.cpp - test_buffer_descriptors.cpp - test_byte.cpp - test_byte_stream.cpp - test_callback_service.cpp - test_callback_timer.cpp - test_callback_timer_atomic.cpp - test_callback_timer_interrupt.cpp - test_callback_timer_locked.cpp - test_char_traits.cpp - test_checksum.cpp - +# murmurhash3.cpp +# test_algorithm.cpp +# test_alignment.cpp +# test_array.cpp +# test_array_view.cpp +# test_array_wrapper.cpp +# test_atomic.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 +# test_bitset_legacy.cpp +# test_bitset_new_comparisons.cpp +# test_bitset_new_default_element_type.cpp +# test_bitset_new_explicit_single_element_type.cpp +# test_bitset_new_ext_default_element_type.cpp +# test_bitset_new_ext_explicit_single_element_type.cpp +# test_bit_stream.cpp +# test_bit_stream_reader_big_endian.cpp +# test_bit_stream_reader_little_endian.cpp +# test_bit_stream_writer_big_endian.cpp +# test_bit_stream_writer_little_endian.cpp +# test_bloom_filter.cpp +# test_bresenham_line.cpp +# test_bsd_checksum.cpp +# test_buffer_descriptors.cpp +# test_byte.cpp +# test_byte_stream.cpp +# test_callback_service.cpp +# test_callback_timer.cpp +# test_callback_timer_atomic.cpp +# test_callback_timer_interrupt.cpp +# test_callback_timer_locked.cpp +# test_char_traits.cpp +# test_checksum.cpp test_chrono_day.cpp - test_chrono_weekday.cpp + test_chrono_duration.cpp test_chrono_month.cpp + test_chrono_weekday.cpp + test_chrono_weekday_indexed.cpp + test_chrono_weekday_last.cpp test_chrono_year.cpp - - test_circular_buffer.cpp - test_circular_buffer_external_buffer.cpp - test_circular_iterator.cpp - test_compare.cpp - test_constant.cpp - test_container.cpp - test_correlation.cpp - test_covariance.cpp - test_crc1.cpp - test_crc16.cpp - test_crc16_a.cpp - test_crc16_arc.cpp - test_crc16_aug_ccitt.cpp - test_crc16_buypass.cpp - test_crc16_ccitt.cpp - test_crc16_cdma2000.cpp - test_crc16_dds110.cpp - test_crc16_dectr.cpp - test_crc16_dectx.cpp - test_crc16_dnp.cpp - test_crc16_en13757.cpp - test_crc16_genibus.cpp - test_crc16_kermit.cpp - test_crc16_m17.cpp - test_crc16_maxim.cpp - test_crc16_mcrf4xx.cpp - test_crc16_modbus.cpp - test_crc16_profibus.cpp - test_crc16_riello.cpp - test_crc16_t10dif.cpp - test_crc16_teledisk.cpp - test_crc16_tms37157.cpp - test_crc16_usb.cpp - test_crc16_x25.cpp - test_crc16_xmodem.cpp - test_crc32.cpp - test_crc32_bzip2.cpp - test_crc32_c.cpp - test_crc32_d.cpp - test_crc32_jamcrc.cpp - test_crc32_mpeg2.cpp - test_crc32_posix.cpp - test_crc32_q.cpp - test_crc32_xfer.cpp - test_crc64_ecma.cpp - test_crc8_ccitt.cpp - test_crc8_cdma2000.cpp - test_crc8_darc.cpp - test_crc8_dvbs2.cpp - test_crc8_ebu.cpp - test_crc8_icode.cpp - test_crc8_itu.cpp - test_crc8_j1850.cpp - test_crc8_j1850_zero.cpp - test_crc8_maxim.cpp - test_crc8_rohc.cpp - test_crc8_wcdma.cpp - test_cyclic_value.cpp - test_debounce.cpp - test_delegate.cpp - test_delegate_cpp03.cpp - test_delegate_service.cpp - test_delegate_service_compile_time.cpp - test_delegate_service_cpp03.cpp - test_deque.cpp - test_endian.cpp - test_enum_type.cpp - test_error_handler.cpp - test_etl_traits.cpp - test_exception.cpp - test_expected.cpp - test_fixed_iterator.cpp - test_fixed_sized_memory_block_allocator.cpp - test_flags.cpp - test_flat_map.cpp - test_flat_multimap.cpp - test_flat_multiset.cpp - test_flat_set.cpp - test_fnv_1.cpp - test_format_spec.cpp - test_forward_list.cpp - test_forward_list_shared_pool.cpp - test_fsm.cpp - test_function.cpp - test_functional.cpp - test_gamma.cpp - test_hash.cpp - test_hfsm.cpp - test_hfsm_recurse_to_inner_state_on_start.cpp - test_histogram.cpp - test_indirect_vector.cpp - test_indirect_vector_external_buffer.cpp - test_instance_count.cpp - test_integral_limits.cpp - test_intrusive_forward_list.cpp - test_intrusive_links.cpp - test_intrusive_list.cpp - test_intrusive_queue.cpp - test_intrusive_stack.cpp - test_invert.cpp - test_io_port.cpp - test_iterator.cpp - test_jenkins.cpp - test_largest.cpp - test_limiter.cpp - test_limits.cpp - test_list.cpp - test_list_shared_pool.cpp - test_macros.cpp - test_make_string.cpp - test_map.cpp - test_math.cpp - test_math_functions.cpp - test_mean.cpp - test_memory.cpp - test_mem_cast.cpp - test_mem_cast_ptr.cpp - test_message.cpp - test_message_broker.cpp - test_message_bus.cpp - test_message_packet.cpp - test_message_router.cpp - test_message_router_registry.cpp - test_message_timer.cpp - test_message_timer_atomic.cpp - test_message_timer_interrupt.cpp - test_message_timer_locked.cpp - test_multimap.cpp - test_multiset.cpp - test_multi_array.cpp - test_multi_range.cpp - test_multi_span.cpp - test_multi_vector.cpp - test_murmur3.cpp - test_nth_type.cpp - test_numeric.cpp - test_observer.cpp - test_optional.cpp - test_overload.cpp - test_packet.cpp - test_parameter_pack.cpp - test_parameter_type.cpp - test_parity_checksum.cpp - test_pearson.cpp - test_poly_span_dynamic_extent.cpp - test_poly_span_fixed_extent.cpp - test_pool.cpp - test_pool_external_buffer.cpp - test_priority_queue.cpp - test_pseudo_moving_average.cpp - test_quantize.cpp - test_queue.cpp - test_queue_lockable.cpp - test_queue_lockable_small.cpp - test_queue_memory_model_small.cpp - test_queue_mpmc_mutex.cpp - test_queue_mpmc_mutex_small.cpp - test_queue_spsc_atomic.cpp - test_queue_spsc_atomic_small.cpp - test_queue_spsc_isr.cpp - test_queue_spsc_isr_small.cpp - test_queue_spsc_locked.cpp - test_queue_spsc_locked_small.cpp - test_random.cpp - test_reference_flat_map.cpp - test_reference_flat_multimap.cpp - test_reference_flat_multiset.cpp - test_reference_flat_set.cpp - test_rescale.cpp - test_result.cpp - test_rms.cpp - test_scaled_rounding.cpp - test_set.cpp - test_shared_message.cpp - test_singleton.cpp - test_smallest.cpp - test_span_dynamic_extent.cpp - test_span_fixed_extent.cpp - test_stack.cpp - test_standard_deviation.cpp - test_state_chart.cpp - test_state_chart_compile_time.cpp - test_state_chart_compile_time_with_data_parameter.cpp - test_state_chart_with_data_parameter.cpp - test_state_chart_with_rvalue_data_parameter.cpp - test_string_char.cpp - test_string_char_external_buffer.cpp - test_string_stream.cpp - test_string_stream_u16.cpp - test_string_stream_u32.cpp - test_string_stream_u8.cpp - test_string_stream_wchar_t.cpp - test_string_u16.cpp - test_string_u16_external_buffer.cpp - test_string_u32.cpp - test_string_u32_external_buffer.cpp - test_string_u8.cpp - test_string_u8_external_buffer.cpp - test_string_utilities.cpp - test_string_utilities_std.cpp - test_string_utilities_std_u16.cpp - test_string_utilities_std_u32.cpp - test_string_utilities_std_u8.cpp - test_string_utilities_std_wchar_t.cpp - test_string_utilities_u16.cpp - test_string_utilities_u32.cpp - test_string_utilities_u8.cpp - test_string_utilities_wchar_t.cpp - test_string_view.cpp - test_string_wchar_t.cpp - test_string_wchar_t_external_buffer.cpp - test_successor.cpp - test_task_scheduler.cpp - test_threshold.cpp - test_to_arithmetic.cpp - test_to_arithmetic_u16.cpp - test_to_arithmetic_u32.cpp - test_to_arithmetic_u8.cpp - test_to_arithmetic_wchar_t.cpp - test_to_string.cpp - test_to_u16string.cpp - test_to_u32string.cpp - test_to_u8string.cpp - test_to_wstring.cpp - test_type_def.cpp - test_type_lookup.cpp - test_type_select.cpp - test_type_traits.cpp - test_unaligned_type.cpp - test_unaligned_type_constexpr.cpp - test_unordered_map.cpp - test_unordered_multimap.cpp - test_unordered_multiset.cpp - test_unordered_set.cpp - test_user_type.cpp - test_utility.cpp - test_variance.cpp - test_variant_legacy.cpp - test_variant_pool.cpp - test_variant_pool_external_buffer.cpp - test_variant_variadic.cpp - test_vector.cpp - test_vector_external_buffer.cpp - test_vector_non_trivial.cpp - test_vector_pointer.cpp - test_vector_pointer_external_buffer.cpp - test_visitor.cpp - test_xor_checksum.cpp - test_xor_rotate_checksum.cpp +# test_circular_buffer.cpp +# test_circular_buffer_external_buffer.cpp +# test_circular_iterator.cpp +# test_compare.cpp +# test_constant.cpp +# test_container.cpp +# test_correlation.cpp +# test_covariance.cpp +# test_crc1.cpp +# test_crc16.cpp +# test_crc16_a.cpp +# test_crc16_arc.cpp +# test_crc16_aug_ccitt.cpp +# test_crc16_buypass.cpp +# test_crc16_ccitt.cpp +# test_crc16_cdma2000.cpp +# test_crc16_dds110.cpp +# test_crc16_dectr.cpp +# test_crc16_dectx.cpp +# test_crc16_dnp.cpp +# test_crc16_en13757.cpp +# test_crc16_genibus.cpp +# test_crc16_kermit.cpp +# test_crc16_m17.cpp +# test_crc16_maxim.cpp +# test_crc16_mcrf4xx.cpp +# test_crc16_modbus.cpp +# test_crc16_profibus.cpp +# test_crc16_riello.cpp +# test_crc16_t10dif.cpp +# test_crc16_teledisk.cpp +# test_crc16_tms37157.cpp +# test_crc16_usb.cpp +# test_crc16_x25.cpp +# test_crc16_xmodem.cpp +# test_crc32.cpp +# test_crc32_bzip2.cpp +# test_crc32_c.cpp +# test_crc32_d.cpp +# test_crc32_jamcrc.cpp +# test_crc32_mpeg2.cpp +# test_crc32_posix.cpp +# test_crc32_q.cpp +# test_crc32_xfer.cpp +# test_crc64_ecma.cpp +# test_crc8_ccitt.cpp +# test_crc8_cdma2000.cpp +# test_crc8_darc.cpp +# test_crc8_dvbs2.cpp +# test_crc8_ebu.cpp +# test_crc8_icode.cpp +# test_crc8_itu.cpp +# test_crc8_j1850.cpp +# test_crc8_j1850_zero.cpp +# test_crc8_maxim.cpp +# test_crc8_rohc.cpp +# test_crc8_wcdma.cpp +# test_cyclic_value.cpp +# test_debounce.cpp +# test_delegate.cpp +# test_delegate_cpp03.cpp +# test_delegate_service.cpp +# test_delegate_service_compile_time.cpp +# test_delegate_service_cpp03.cpp +# test_deque.cpp +# test_endian.cpp +# test_enum_type.cpp +# test_error_handler.cpp +# test_etl_traits.cpp +# test_exception.cpp +# test_expected.cpp +# test_fixed_iterator.cpp +# test_fixed_sized_memory_block_allocator.cpp +# test_flags.cpp +# test_flat_map.cpp +# test_flat_multimap.cpp +# test_flat_multiset.cpp +# test_flat_set.cpp +# test_fnv_1.cpp +# test_format_spec.cpp +# test_forward_list.cpp +# test_forward_list_shared_pool.cpp +# test_fsm.cpp +# test_function.cpp +# test_functional.cpp +# test_gamma.cpp +# test_hash.cpp +# test_hfsm.cpp +# test_hfsm_recurse_to_inner_state_on_start.cpp +# test_histogram.cpp +# test_indirect_vector.cpp +# test_indirect_vector_external_buffer.cpp +# test_instance_count.cpp +# test_integral_limits.cpp +# test_intrusive_forward_list.cpp +# test_intrusive_links.cpp +# test_intrusive_list.cpp +# test_intrusive_queue.cpp +# test_intrusive_stack.cpp +# test_invert.cpp +# test_io_port.cpp +# test_iterator.cpp +# test_jenkins.cpp +# test_largest.cpp +# test_limiter.cpp +# test_limits.cpp +# test_list.cpp +# test_list_shared_pool.cpp +# test_macros.cpp +# test_make_string.cpp +# test_map.cpp +# test_math.cpp +# test_math_functions.cpp +# test_mean.cpp +# test_memory.cpp +# test_mem_cast.cpp +# test_mem_cast_ptr.cpp +# test_message.cpp +# test_message_broker.cpp +# test_message_bus.cpp +# test_message_packet.cpp +# test_message_router.cpp +# test_message_router_registry.cpp +# test_message_timer.cpp +# test_message_timer_atomic.cpp +# test_message_timer_interrupt.cpp +# test_message_timer_locked.cpp +# test_multimap.cpp +# test_multiset.cpp +# test_multi_array.cpp +# test_multi_range.cpp +# test_multi_span.cpp +# test_multi_vector.cpp +# test_murmur3.cpp +# test_nth_type.cpp +# test_numeric.cpp +# test_observer.cpp +# test_optional.cpp +# test_overload.cpp +# test_packet.cpp +# test_parameter_pack.cpp +# test_parameter_type.cpp +# test_parity_checksum.cpp +# test_pearson.cpp +# test_poly_span_dynamic_extent.cpp +# test_poly_span_fixed_extent.cpp +# test_pool.cpp +# test_pool_external_buffer.cpp +# test_priority_queue.cpp +# test_pseudo_moving_average.cpp +# test_quantize.cpp +# test_queue.cpp +# test_queue_lockable.cpp +# test_queue_lockable_small.cpp +# test_queue_memory_model_small.cpp +# test_queue_mpmc_mutex.cpp +# test_queue_mpmc_mutex_small.cpp +# test_queue_spsc_atomic.cpp +# test_queue_spsc_atomic_small.cpp +# test_queue_spsc_isr.cpp +# test_queue_spsc_isr_small.cpp +# test_queue_spsc_locked.cpp +# test_queue_spsc_locked_small.cpp +# test_random.cpp +# test_reference_flat_map.cpp +# test_reference_flat_multimap.cpp +# test_reference_flat_multiset.cpp +# test_reference_flat_set.cpp +# test_rescale.cpp +# test_result.cpp +# test_rms.cpp +# test_scaled_rounding.cpp +# test_set.cpp +# test_shared_message.cpp +# test_singleton.cpp +# test_smallest.cpp +# test_span_dynamic_extent.cpp +# test_span_fixed_extent.cpp +# test_stack.cpp +# test_standard_deviation.cpp +# test_state_chart.cpp +# test_state_chart_compile_time.cpp +# test_state_chart_compile_time_with_data_parameter.cpp +# test_state_chart_with_data_parameter.cpp +# test_state_chart_with_rvalue_data_parameter.cpp +# test_string_char.cpp +# test_string_char_external_buffer.cpp +# test_string_stream.cpp +# test_string_stream_u16.cpp +# test_string_stream_u32.cpp +# test_string_stream_u8.cpp +# test_string_stream_wchar_t.cpp +# test_string_u16.cpp +# test_string_u16_external_buffer.cpp +# test_string_u32.cpp +# test_string_u32_external_buffer.cpp +# test_string_u8.cpp +# test_string_u8_external_buffer.cpp +# test_string_utilities.cpp +# test_string_utilities_std.cpp +# test_string_utilities_std_u16.cpp +# test_string_utilities_std_u32.cpp +# test_string_utilities_std_u8.cpp +# test_string_utilities_std_wchar_t.cpp +# test_string_utilities_u16.cpp +# test_string_utilities_u32.cpp +# test_string_utilities_u8.cpp +# test_string_utilities_wchar_t.cpp +# test_string_view.cpp +# test_string_wchar_t.cpp +# test_string_wchar_t_external_buffer.cpp +# test_successor.cpp +# test_task_scheduler.cpp +# test_threshold.cpp +# test_to_arithmetic.cpp +# test_to_arithmetic_u16.cpp +# test_to_arithmetic_u32.cpp +# test_to_arithmetic_u8.cpp +# test_to_arithmetic_wchar_t.cpp +# test_to_string.cpp +# test_to_u16string.cpp +# test_to_u32string.cpp +# test_to_u8string.cpp +# test_to_wstring.cpp +# test_type_def.cpp +# test_type_lookup.cpp +# test_type_select.cpp +# test_type_traits.cpp +# test_unaligned_type.cpp +# test_unaligned_type_constexpr.cpp +# test_unordered_map.cpp +# test_unordered_multimap.cpp +# test_unordered_multiset.cpp +# test_unordered_set.cpp +# test_user_type.cpp +# test_utility.cpp +# test_variance.cpp +# test_variant_legacy.cpp +# test_variant_pool.cpp +# test_variant_pool_external_buffer.cpp +# test_variant_variadic.cpp +# test_vector.cpp +# test_vector_external_buffer.cpp +# test_vector_non_trivial.cpp +# test_vector_pointer.cpp +# test_vector_pointer_external_buffer.cpp +# test_visitor.cpp +# test_xor_checksum.cpp +# test_xor_rotate_checksum.cpp ) target_compile_definitions(etl_tests PRIVATE -DETL_DEBUG) diff --git a/test/cppcheck_macro_definitions.txt b/test/cppcheck_macro_definitions.txt new file mode 100644 index 00000000..3f2fb051 --- /dev/null +++ b/test/cppcheck_macro_definitions.txt @@ -0,0 +1,5 @@ +ETL_CONSTEXPR constexpr +ETL_CONSTEXPR14 +ETL_CONSTEXPR17 +ETL_CONSTEXPR20 +ETL_IF_CONSTEXPR20 \ No newline at end of file diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp index 815cb4f4..7a9432a8 100644 --- a/test/test_chrono_day.cpp +++ b/test/test_chrono_day.cpp @@ -30,128 +30,112 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" -#include -#include +#include #include namespace { + //************************************************************************* + bool is_day_ok(etl::chrono::day day) + { + unsigned d = unsigned(day); + + if ((d < 1) || (d > 31)) + { + return (day.ok() == false); + } + else + { + return (day.ok() == true); + } + } + SUITE(test_chrono_day) { //************************************************************************* TEST(test_default_constructor) { - std::chrono::day std_day; etl::chrono::day day; - CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_FALSE(day.ok()); } //************************************************************************* TEST(test_constructor_in_range) { - for (unsigned i = 0U; i < 256; ++i) + for (unsigned expected = 1U; expected < 31; ++expected) { - std::chrono::day std_day(i); - etl::chrono::day day(i); + etl::chrono::day day(expected); - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::day std_day(0); etl::chrono::day day(0); - for (int i = 0; i < 255; ++i) + for (int expected = 0; expected < 256; ++expected, ++day) { - ++std_day; - ++day; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_post_increment) { - std::chrono::day std_day(0); etl::chrono::day day(0); - for (int i = 0; i < 255; ++i) + for (int expected = 0; expected < 256; expected++, day++) { - std::chrono::day std_last_day = std_day++; - etl::chrono::day last_day = day++; - - CHECK_EQUAL(std_last_day.ok(), last_day.ok()); - CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::day std_day(256); - etl::chrono::day day(256); + etl::chrono::day day(255); - for (int i = 0; i < 255; ++i) + for (int expected = 255; expected > 0; --expected, --day) { - --std_day; - --day; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::day std_day(256); - etl::chrono::day day(256); + etl::chrono::day day(255); - for (int i = 0; i < 255; ++i) + for (int expected = 255; expected > 0; expected--, day--) { - std::chrono::day std_last_day = std_day--; - etl::chrono::day last_day = day--; - - CHECK_EQUAL(std_last_day.ok(), last_day.ok()); - CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_plus_equal_days) { - std::chrono::day std_day(0); etl::chrono::day day(0); - - std::chrono::days std_days(2); etl::chrono::days days(2); - for (int i = 0; i < 128; ++i) + for (int expected = 2; expected < 256; expected += 2) { - std_day += std_days; - day += days; + day += days; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } @@ -162,17 +146,15 @@ namespace { for (int ds = 0; ds < 256; ++ds) { - std::chrono::day std_day(d); etl::chrono::day day(d); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); - std_day = std_day + std_days; - day = day + days; + day = day + days; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + unsigned expected = (d + ds) % 256; + + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } } @@ -182,19 +164,17 @@ namespace { for (int d = 0; d < 256; ++d) { - for (int ds = 0; ds < 256; ++ds) + for (int ds = 0; ds < d; ++ds) { - std::chrono::day std_day(d); etl::chrono::day day(d); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); - std_day = std_days + std_day; - day = days + day; + day = days + day; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + unsigned expected = (d + ds) % 256; + + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } } @@ -202,66 +182,47 @@ namespace //************************************************************************* TEST(test_minus_equal_days) { - for (int d = 0; d <= 256; ++d) + etl::chrono::day day(255); + etl::chrono::days days(2); + + for (int expected = 253; expected > 0; expected -= 2) { - for (int ds = 0; ds <= 256; ++ds) - { - std::chrono::day std_day(d); - etl::chrono::day day(d); + day -= days; - std::chrono::days std_days(ds); - etl::chrono::days days(ds); - - std_day -= std_days; - day -= days; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_day_minus_days) { - for (int d = 0; d <= 256; ++d) + etl::chrono::day day(255); + etl::chrono::days days(2); + + for (int expected = 253; expected > 0; expected -= 2) { - for (int ds = 0; ds <= 256; ++ds) - { - std::chrono::day std_day(d); - etl::chrono::day day(d); + day = day - days; - std::chrono::days std_days(ds); - etl::chrono::days days(ds); - - std_day = std_day - std_days; - day = day - days; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_day_minus_day) { - for (int d = 0; d < 256; ++d) + for (int d1 = 0; d1 < 256; ++d1) { - std::chrono::day std_day1(d); - std::chrono::day std_day2(255 - d); + for (int d2 = 0; d2 < 256; ++d2) + { + etl::chrono::day day1(d1); + etl::chrono::day day2(d2); - std::chrono::day day1(d); - std::chrono::day day2(255 - d); - - auto std_days12 = std_day1 - std_day2; - auto std_days21 = std_day2 - std_day1; - - auto days12 = day1 - day2; - auto days21 = day2 - day1; - - CHECK_EQUAL(std_days12.count(), days12.count()); - CHECK_EQUAL(std_days21.count(), days21.count()); + etl::chrono::days result_days = day1 - day2; + int expected_days = d1 - d2; + CHECK_EQUAL(expected_days, result_days.count()); + } } } @@ -275,14 +236,12 @@ namespace //************************************************************************* TEST(test_literal_day) { - using namespace std::literals::chrono_literals; using namespace etl::literals::chrono_literals; - std::chrono::day std_day = 25d; - etl::chrono::day day = 25_day; + etl::chrono::day day = 25_day; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(day.ok()); + CHECK_EQUAL(25, unsigned(day)); } //************************************************************************* @@ -329,5 +288,3 @@ namespace } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp new file mode 100644 index 00000000..e1e0a5d8 --- /dev/null +++ b/test/test_chrono_month_day.cpp @@ -0,0 +1,384 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include + +#if ETL_USING_CPP20 + +namespace +{ + SUITE(test_chrono_month_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + etl::chrono::month_day md; + + CHECK_FALSE(md.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::month std_month(i); + etl::chrono::month month(i); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 255; ++i) + { + ++std_month; + ++month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month++; + etl::chrono::month last_month = month++; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + --std_month; + --month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month--; + etl::chrono::month last_month = month--; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_plus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month += std_months; + month += months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_plus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month + std_months; + month = month + months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_months_plus_month) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_months + std_month; + month = months + month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_minus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month -= std_months; + month -= months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month - std_months; + month = month - months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_month) + { + for (int m = 0; m < 256; ++m) + { + std::chrono::month std_month1(m); + std::chrono::month std_month2(255 - m); + + std::chrono::month month1(m); + std::chrono::month month2(255 - m); + + auto std_months12 = std_month1 - std_month2; + auto std_months21 = std_month2 - std_month1; + + auto months12 = month1 - month2; + auto months21 = month2 - month1; + + CHECK_EQUAL(std_months12.count(), months12.count()); + CHECK_EQUAL(std_months21.count(), months21.count()); + } + } + + //************************************************************************* + TEST(test_min_max_month) + { + CHECK_EQUAL(1U, etl::chrono::month::min()); + CHECK_EQUAL(12U, etl::chrono::month::max()); + } + + //************************************************************************* + TEST(test_literal_month) + { + using namespace etl::literals::chrono_literals; + + etl::chrono::month month1 = 1_month; + etl::chrono::month month2 = 2_month; + etl::chrono::month month3 = 3_month; + etl::chrono::month month4 = 4_month; + etl::chrono::month month5 = 5_month; + etl::chrono::month month6 = 6_month; + etl::chrono::month month7 = 7_month; + etl::chrono::month month8 = 8_month; + etl::chrono::month month9 = 9_month; + etl::chrono::month month10 = 10_month; + etl::chrono::month month11 = 11_month; + etl::chrono::month month12 = 12_month; + + CHECK_TRUE(month1.ok()); + CHECK_TRUE(month2.ok()); + CHECK_TRUE(month3.ok()); + CHECK_TRUE(month4.ok()); + CHECK_TRUE(month5.ok()); + CHECK_TRUE(month6.ok()); + CHECK_TRUE(month7.ok()); + CHECK_TRUE(month8.ok()); + CHECK_TRUE(month9.ok()); + CHECK_TRUE(month10.ok()); + CHECK_TRUE(month11.ok()); + CHECK_TRUE(month12.ok()); + + CHECK_EQUAL(1U, unsigned(month1)); + CHECK_EQUAL(2U, unsigned(month2)); + CHECK_EQUAL(3U, unsigned(month3)); + CHECK_EQUAL(4U, unsigned(month4)); + CHECK_EQUAL(5U, unsigned(month5)); + CHECK_EQUAL(6U, unsigned(month6)); + CHECK_EQUAL(7U, unsigned(month7)); + CHECK_EQUAL(8U, unsigned(month8)); + CHECK_EQUAL(9U, unsigned(month9)); + CHECK_EQUAL(10U, unsigned(month10)); + CHECK_EQUAL(11U, unsigned(month11)); + CHECK_EQUAL(12U, unsigned(month12)); + } + + //************************************************************************* + TEST(test_month_comparison_operators) + { + etl::chrono::month month1(1); + etl::chrono::month month2(2); + + CHECK_TRUE(month1 == month1); + CHECK_FALSE(month1 != month1); + CHECK_TRUE(month1 < month2); + CHECK_FALSE(month1 < month1); + CHECK_FALSE(month2 < month1); + CHECK_TRUE(month1 <= month2); + CHECK_TRUE(month1 <= month1); + CHECK_FALSE(month2 <= month1); + CHECK_FALSE(month1 > month2); + CHECK_FALSE(month1 > month1); + CHECK_TRUE(month2 > month1); + CHECK_FALSE(month1 >= month2); + CHECK_TRUE(month1 >= month1); + CHECK_TRUE(month2 >= month1); + +#if ETL_USING_CPP20 + CHECK_TRUE((month1 <=> month1) == 0); + CHECK_TRUE((month1 <=> month2) < 0); + CHECK_TRUE((month2 <=> month1) > 0); +#endif + } + + //************************************************************************* + TEST(test_month_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::month(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } + + //************************************************************************* + TEST(test_month_types) + { + CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); + CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); + CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); + CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); + CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); + CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); + CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); + CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); + CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); + CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); + CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); + CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index c4cbe05d..132160ec 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include @@ -262,6 +263,7 @@ namespace } } +#if ETL_USING_CPP20 //************************************************************************* TEST(test_weekday_minus_weekday) { @@ -283,6 +285,7 @@ namespace CHECK_EQUAL(std_days21.count(), days21.count()); } } +#endif //************************************************************************* TEST(test_min_max_weekday) diff --git a/test/test_chrono_weekday_indexed.cpp b/test/test_chrono_weekday_indexed.cpp index faa55596..e690fc96 100644 --- a/test/test_chrono_weekday_indexed.cpp +++ b/test/test_chrono_weekday_indexed.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include diff --git a/test/test_chrono_weekday_last.cpp b/test/test_chrono_weekday_last.cpp index 09c8f8d6..e2787a2e 100644 --- a/test/test_chrono_weekday_last.cpp +++ b/test/test_chrono_weekday_last.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 1ce125eb..8c275868 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3096,6 +3096,8 @@ + + @@ -7959,6 +7961,7 @@ + @@ -9084,6 +9087,7 @@ + true true diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 69327b6f..1fb6e5fc 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1449,6 +1449,12 @@ ETL\Private + + ETL\Private\chrono + + + ETL\Private\chrono + @@ -3446,6 +3452,9 @@ Tests\Misc + + Tests\Chrono + @@ -3648,6 +3657,9 @@ Tests\Syntax Checks\Source + + Tests\Test Support + diff --git a/test/vs2022/etl_solution_suppressions.cfg b/test/vs2022/etl_solution_suppressions.cfg new file mode 100644 index 00000000..f76caa4c --- /dev/null +++ b/test/vs2022/etl_solution_suppressions.cfg @@ -0,0 +1,4 @@ +[cppcheck] +-i*.cpp +[cppcheck_files] +[cppcheck_includes]