Skip to content

Commit

Permalink
Added tests for message base_type
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Mar 5, 2024
1 parent c6dc700 commit de6e6ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/etl/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace etl
};

//***************************************************************************
/// Is T derived from etl::message<>
/// Is T an etl::message<> or derived from etl::message<>
//***************************************************************************
template <typename T>
struct is_message_type : public etl::bool_constant<etl::is_base_of<etl::message_tag, typename etl::remove_cvref<T>::type>::value>
Expand All @@ -225,7 +225,7 @@ namespace etl
};

//***************************************************************************
/// Is T a user defined base of etl::message<T>
/// Is T a user defined base of etl::message<T> and not an etl::imessage
//***************************************************************************
template <typename T>
struct is_user_message_base : public etl::bool_constant<etl::is_message_base<T>::value && !is_imessage<T>::value>
Expand Down
15 changes: 15 additions & 0 deletions test/test_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,19 @@ SUITE(test_message)
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_v<etl::imessage, Message1::base_type>));
CHECK_TRUE((std::is_same_v<MessageBase, Message2::base_type>));

CHECK_FALSE((std::is_same_v<MessageBase, Message1::base_type>));
CHECK_FALSE((std::is_same_v<etl::imessage, Message2::base_type>));
}
};

0 comments on commit de6e6ab

Please sign in to comment.