mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
* Added compare_message_id * Added new C++11 and up message routing code using a sorted type_list * Renamed compare_message)id to compare_message_id_less * Added documenation for compare_message_id_less Added static asserts for message type template parameters * Added optimisation for contiguous message IDs Added more Doxygen documentation * Added etl::type_list_all_of, etl::type_list_any_of, and etl::type_list_none_of * Added etl::type_list_is_unique * Added common definitions to all router types * Added static_asserts to check message types * Added etl::type_list to etl::nth_type * Added missing 'typename' to type_list nth_type * Added type_list_is_empty * indentation fix * Renamed type_list_prepend & type_list_append to type_list_push_front & type_list_push_back respectively * Added tests for make_index_sequence & make_index_sequence_with_offset * Add more features to etl::type_list (#1307) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Added etl::type_list to etl::observer * Added etl::type_list to etl::nth_type * Added missing 'typename' to type_list nth_type * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Added type_list definitions for nth_type and observer * Added etl::type_list to etl::variant * Updated comments * Addedetl::type~_list to message_router, observer, visitor # Conflicts: # include/etl/observer.h # test/vs2022/etl.vcxproj.filters * Added member type_list type to tuple * Work in progress * Copy changes from other source * Removed unused tests * Fix iter_swap namespace * Add type_list functionality to etl::variant using etl::variant_from_type_list * Add type_list functionality to etl::message_packet using etl::message_packet_from_type_list * Add type_list functionality to etl::message_router using etl::message_router_from_type_list * Add type_list functionality to etl::observer using etl::observer_from_type_list * Add type_list functionality to etl::tuple using etl::tuple_from_type_list * Allow etl::make_index_sequence to be created from an etl::type_list * Add type_list functionality to etl::visitor using etl::visitor_from_type_list * Fix iter_swap namespace * Allow creation of a message_packet with no message types * Allow creation of a message_router with no message types * Updated VS2022 project files * Added missing test files CMakeLists.txt * Fix C++03 compatibility Fixed unused aregument warnings * Synced message_packet generator to updated code * Synced message_router generator to updated code * Synced message_router generator to updated code # Conflicts: # include/etl/generators/message_router_generator.h # include/etl/message_router.h * Fixed missing zero message specialisation for <= C++14 * Fixed missing zero message specialisation for <= C++14 * Fix year_month arithmetic and correct chrono API behavior (#1257) * Fix & add more tests for year_month arithmetic * Minor addtions to previous commit * More missing values to be uninitialized * Update the default constructors to = default and correct default constructor tests accordingly * Fix & add more tests for year_month arithmetic * Minor addtions to previous commit * More missing values to be uninitialized * Update the default constructors to = default and correct default constructor tests accordingly * Restore default constructor behavior for chrono calender * Suppress warnings from std in optimized builds (#1259) When testing with ./run-tests.sh 23 3 10, some warnings from std surfaced which resulted in build errors. * Add template deduction guide for span from vector (#1264) * Create span from vector deduction * Use ivector for deduction. Add vector_ext to test * Add vector pointer to test * Finish tests * Initialize pdata_ext and others * Document how to implement platform specifics (#1262) Some interfaces need to be implemented in every project or platform using the ETL: * etl_get_high_resolution_clock * etl_get_system_clock * etl_get_steady_clock * etl_putchar Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Fix etl::as_bytes for etl::span<const T> (#1266) A missing 'const' in the etl::as_bytes implementation was causing a compile-time error when etl::as_bytes was called on a span of const values. Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Remove some UB in test_vector_non_trivial.cpp (#1268) Some of the tests' UB are detectable by Gcc15 and thus give a compile error due to warnings-as-error flag. Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Update C++26 deprecated constructs to ensure future standard compliance (#1267) * Update C++26 deprecated constructs to ensure future standard compliance I replaced std::is_trivial with a combination of std::is_trivially_default_constructible and std::is_trivially_copyable. Additionally, I added the required comma before the ellipsis in variadic functions to match updated language specifications. * Some additional is_trivial related changes not found directly when compiling tests in C++26 --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Fix return value of get_token_list (#1271) Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Fix etl::tuple template signature error in pair assignment operator (#1265) * Fix etl::tuple template signature error in pair assignment operator * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update etl::tuple to explicitly use etl::pair or std::pair in assignment operator * Added tests for etl::tuple assignment from pair --------- Co-authored-by: Bryton Flecker <bflecker@swe.com> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Remove advance() on static spans (#1281) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Remove advance() on static spans Since the size of a static span is constant, we can't reasonably advance() on it. --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Add missing includes (#1286) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Add missing includes Before this change, the includes needed to be done explicitly by files using basic_string_stream.h, and be included first. This was error prone, especially if includes are reordered (e.g. via the currently defined clang-format rules). --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Move comparison operators of etl::expected to namespace etl (#1287) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Move comparison operators of etl::expected to namespace etl --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Make typed_storage constructor constexpr (#1291) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Make typed_storage constructor constexpr --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Add basic_format_arg constructor for ibasic_string (#1288) * Allow string as format arg * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Added test string escaped * Add temporary string test --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * QR Code for Github * Added etl::visitor_from_type_list * accepts(id) for empty router passes on to a sucessor * Fixed incorrect comment from 'tuple' to 'message_router' * PR review changes * PR review changes * Fixed internal constexptr flag in message_packet * Fixed unused variable in unti test * Added new type_list features Added make_index_sequence_with_offset * Renamed type_list_select_from_sequence to type_list_select_from_index_sequence * Replaced type_list_size<TTypeList>::value with TTypeList::size internally for better clarity. * Added etl::type_list_remove, etl::type_list_remove_if, etl::type_list_unique, etl::type_list_pop_front, etl::type_list_pop_back * Add ref-qualifiers to basic_format_spec (#1292) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * feat: use ref-qualifiers for basic_format_spec Converted the l-value methods to ref-qualified and also added r-value ref-qualified methods. --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Add support for size_t and unsigned long to etl::format (#1290) * Remove AppVeyor build status badge Removed AppVeyor build status badge from README. * Update README.md * Update CONTRIBUTING.md Updated the instructions for contributing. * Fix for issue 1276 "Data corruption in the etl::bip_buffer_spsc_atomic" (#1277) * Reproduce data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Fix data corruption bug in the `etl::bip_buffer_spsc_atomic`. * Add support for size_t and unsigned long to etl::format * Document list of supported types in etl::supported_format_types * Add further types and tests for etl::format --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: Sergei <sergej.shirokov@gmail.com> * Deduce underlying storage size when constructing string_ext from char[]. (#1269) * Deduce underlying storage size when constructing string_ext from char[]. This removes the need for passing sizeof(storage) to the constructor. * Add array constructors for the other string types. - u16string_ext - u32string_ext - u8string_ext - wstring_ext * Add additional constructors to match existing API. * Fix inconsistent test argument order. --------- Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Added etl::type_list_all_of, etl::type_list_any_of, and etl::type_list_none_of * Added etl::type_list_is_unique * Added type_list_is_empty * indentation fix * Fix merge error * Renamed type_list_prepend & type_list_append to type_list_push_front & type_list_push_back respectively * Added tests for make_index_sequence & make_index_sequence_with_offset * Resolve coderabbit review issues * Resolve coderabbit review issues * Resolve coderabbit review issues * Resolve coderabbit review issues * Added etl::type_list_indices_of_type which create an etl::index_sequence of all of the indexes of a specified type in an etl::type_list * Updated comments * Resolve coderabbit review issues Added index_sequence utility to support type_list utilities. Added additional index_sequence utilities for completeness * Added etl::index_sequence_cat, etl::index_sequence_pop_front, etl::index_sequence_pop_back, etl::index_sequence_at * Fix 'unused variable' error in index_sequence tests --------- Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.co.uk> Co-authored-by: Sergei <sergej.shirokov@gmail.com> Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com> Co-authored-by: Bo Rydberg <2945606+bolry@users.noreply.github.com> Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de> Co-authored-by: Mike Bloom <91038685+mike919192@users.noreply.github.com> Co-authored-by: taltenbach <92919739+taltenbach@users.noreply.github.com> Co-authored-by: Bryton Flecker <fleckerbr@gmail.com> Co-authored-by: Bryton Flecker <bflecker@swe.com> Co-authored-by: Drew Rife <drew.rife95@gmail.com> Co-authored-by: Marco Nilsson <marco@zyax.se> * Moved O(1)/O(logN) index search test to get_dispatch_index_from_message_id Updated message_router generator * Fixed C++03 compatibilty * Replaced is_base_of with is_message * Missing 'return' in chrono example * Fixed doxygen comments * Check message inherits from etl::message<> * Copilot & coderabbit review changes Check for no duplicated message IDs Added diagnostic disable Make Message_Id_Start an etl::message_id_t type * Synchronised message_router_generator.h * Modified the "All message IDs must be unique" static_assert to directly use the index_sequence of message IDs Added addition index_sequence utilities to support this change. * Changed Router1 definition to use unordered message ids to check message sorting in message_router * Added has_message_id and compare_message_id_less to message.h * Moved member type definitions to a traits class message_packet, message_types, sorted_message_types * Sync message_router_generator to changes * Fixed C++03 compatibility --------- Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com> Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.co.uk> Co-authored-by: Sergei <sergej.shirokov@gmail.com> Co-authored-by: Bo Rydberg <2945606+bolry@users.noreply.github.com> Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de> Co-authored-by: Mike Bloom <91038685+mike919192@users.noreply.github.com> Co-authored-by: taltenbach <92919739+taltenbach@users.noreply.github.com> Co-authored-by: Bryton Flecker <fleckerbr@gmail.com> Co-authored-by: Bryton Flecker <bflecker@swe.com> Co-authored-by: Drew Rife <drew.rife95@gmail.com> Co-authored-by: Marco Nilsson <marco@zyax.se>
169 lines
6.4 KiB
C++
169 lines
6.4 KiB
C++
/******************************************************************************
|
|
The MIT License(MIT)
|
|
|
|
Embedded Template Library.
|
|
https://github.com/ETLCPP/etl
|
|
https://www.etlcpp.com
|
|
|
|
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 "unit_test_framework.h"
|
|
|
|
#include "etl/message.h"
|
|
|
|
SUITE(test_message)
|
|
{
|
|
//*************************************************************************
|
|
TEST(test_message_traits)
|
|
{
|
|
// imessage
|
|
// ^
|
|
// MessageBase
|
|
// ^
|
|
// etl::message<I, MessageBase>
|
|
// ^
|
|
// Message
|
|
|
|
// | is_imessage | is_message | is_message_type | is_message_base | is_user_message_base
|
|
// imessage | T | T | F | T | F
|
|
// MessageBase | F | T | F | T | T
|
|
// Message | F | T | T | F | F
|
|
// int | F | F | F | F | F
|
|
|
|
struct MessageBase : public etl::imessage {};
|
|
struct Message : public etl::message<1, MessageBase> {};
|
|
|
|
#if ETL_USING_CPP17
|
|
// Is an imessage?
|
|
CHECK_TRUE(etl::is_imessage_v<etl::imessage>);
|
|
CHECK_FALSE(etl::is_imessage_v<MessageBase>);
|
|
CHECK_FALSE(etl::is_imessage_v<Message>);
|
|
CHECK_FALSE(etl::is_imessage_v<int>);
|
|
|
|
// Is an imessage, or derived from imessage?
|
|
CHECK_TRUE(etl::is_message_v<etl::imessage>);
|
|
CHECK_TRUE(etl::is_message_v<MessageBase>);
|
|
CHECK_TRUE(etl::is_message_v<Message>);
|
|
CHECK_FALSE(etl::is_message_v<int>);
|
|
|
|
// Is a concrete message?
|
|
CHECK_FALSE(etl::is_message_type_v<etl::imessage>);
|
|
CHECK_FALSE(etl::is_message_type_v<MessageBase>);
|
|
CHECK_TRUE(etl::is_message_type_v<Message>);
|
|
CHECK_FALSE(etl::is_message_type_v<int>);
|
|
|
|
// Is a message base?
|
|
CHECK_TRUE(etl::is_message_base_v<etl::imessage>);
|
|
CHECK_TRUE(etl::is_message_base_v<MessageBase>);
|
|
CHECK_FALSE(etl::is_message_base_v<Message>);
|
|
CHECK_FALSE(etl::is_message_base_v<int>);
|
|
|
|
// Is a user message base?
|
|
CHECK_FALSE(etl::is_user_message_base_v<etl::imessage>);
|
|
CHECK_TRUE(etl::is_user_message_base_v<MessageBase>);
|
|
CHECK_FALSE(etl::is_user_message_base_v<Message>);
|
|
CHECK_FALSE(etl::is_user_message_base_v<int>);
|
|
#else
|
|
// Is an imessage?
|
|
CHECK_TRUE(etl::is_imessage<etl::imessage>::value);
|
|
CHECK_FALSE(etl::is_imessage<MessageBase>::value);
|
|
CHECK_FALSE(etl::is_imessage<Message>::value);
|
|
CHECK_FALSE(etl::is_imessage<int>::value);
|
|
|
|
// Is an imessage, or derived from imessage?
|
|
CHECK_TRUE(etl::is_message<etl::imessage>::value);
|
|
CHECK_TRUE(etl::is_message<MessageBase>::value);
|
|
CHECK_TRUE(etl::is_message<Message>::value);
|
|
CHECK_FALSE(etl::is_message<int>::value);
|
|
|
|
// Is a concrete message?
|
|
CHECK_FALSE(etl::is_message_type<etl::imessage>::value);
|
|
CHECK_FALSE(etl::is_message_type<MessageBase>::value);
|
|
CHECK_TRUE(etl::is_message_type<Message>::value);
|
|
CHECK_FALSE(etl::is_message_type<int>::value);
|
|
|
|
// Is a message base?
|
|
CHECK_TRUE(etl::is_message_base<etl::imessage>::value);
|
|
CHECK_TRUE(etl::is_message_base<MessageBase>::value);
|
|
CHECK_FALSE(etl::is_message_base<Message>::value);
|
|
CHECK_FALSE(etl::is_message_base<int>::value);
|
|
|
|
// Is a user message base?
|
|
CHECK_FALSE(etl::is_user_message_base<etl::imessage>::value);
|
|
CHECK_TRUE(etl::is_user_message_base<MessageBase>::value);
|
|
CHECK_FALSE(etl::is_user_message_base<Message>::value);
|
|
CHECK_FALSE(etl::is_user_message_base<int>::value);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_message_base_type)
|
|
{
|
|
struct Message1 : public etl::message<1> {};
|
|
|
|
struct MessageBase : public etl::imessage {};
|
|
struct Message2 : public etl::message<2, MessageBase> {};
|
|
|
|
CHECK_TRUE((std::is_same<etl::imessage, Message1::base_type>::value));
|
|
CHECK_TRUE((std::is_same<MessageBase, Message2::base_type>::value));
|
|
|
|
CHECK_FALSE((std::is_same<MessageBase, Message1::base_type>::value));
|
|
CHECK_FALSE((std::is_same<etl::imessage, Message2::base_type>::value));
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_has_message_id)
|
|
{
|
|
struct Message1 : public etl::message<1> {};
|
|
struct Message2 : public etl::message<2> {};
|
|
struct MessageNoID : public etl::imessage {};
|
|
|
|
CHECK_TRUE(etl::has_message_id<Message1>::value);
|
|
CHECK_TRUE(etl::has_message_id<Message2>::value);
|
|
CHECK_FALSE(etl::has_message_id<MessageNoID>::value);
|
|
|
|
#if ETL_USING_CPP17
|
|
CHECK_TRUE(etl::has_message_id_v<Message1>);
|
|
CHECK_TRUE(etl::has_message_id_v<Message2>);
|
|
CHECK_FALSE(etl::has_message_id_v<MessageNoID>);
|
|
#endif
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_message_compare_message_id)
|
|
{
|
|
struct Message1 : public etl::message<1> {};
|
|
struct Message2 : public etl::message<2> {};
|
|
struct MessageNoID : public etl::imessage {};
|
|
|
|
CHECK_TRUE((etl::compare_message_id_less<Message1, Message2>::value));
|
|
CHECK_FALSE((etl::compare_message_id_less<Message2, Message1>::value));
|
|
|
|
// CHECK_FALSE((etl::compare_message_id_less<Message1, MessageNoID>::value)); // Uncomment to trigger static assert.
|
|
|
|
#if ETL_USING_CPP17
|
|
CHECK_TRUE((etl::compare_message_id_less_v<Message1, Message2>));
|
|
CHECK_FALSE((etl::compare_message_id_less_v<Message2, Message1>));
|
|
#endif
|
|
}
|
|
}
|