|
| 1 | +/****************************************************************************** |
| 2 | +The MIT License(MIT) |
| 3 | +
|
| 4 | +Embedded Template Library. |
| 5 | +https://github.com/ETLCPP/etl |
| 6 | +https://www.etlcpp.com |
| 7 | +
|
| 8 | +Copyright(c) 2025 BMW AG |
| 9 | +
|
| 10 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | +of this software and associated documentation files(the "Software"), to deal |
| 12 | +in the Software without restriction, including without limitation the rights |
| 13 | +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell |
| 14 | +copies of the Software, and to permit persons to whom the Software is |
| 15 | +furnished to do so, subject to the following conditions : |
| 16 | +
|
| 17 | +The above copyright notice and this permission notice shall be included in all |
| 18 | +copies or substantial portions of the Software. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE |
| 23 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | +SOFTWARE. |
| 27 | +******************************************************************************/ |
| 28 | + |
| 29 | +#include "unit_test_framework.h" |
| 30 | + |
| 31 | +#include "etl/type_list.h" |
| 32 | + |
| 33 | +#include <type_traits> |
| 34 | + |
| 35 | +namespace |
| 36 | +{ |
| 37 | +#if ETL_USING_CPP11 |
| 38 | + SUITE(test_type_list) |
| 39 | + { |
| 40 | + //************************************************************************* |
| 41 | + TEST(test_nth_type) |
| 42 | + { |
| 43 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 44 | + |
| 45 | + CHECK_TRUE((std::is_same<etl::nth_type<0, t1>::type, char>::value)); |
| 46 | + CHECK_TRUE((std::is_same<etl::nth_type<1, t1>::type, int>::value)); |
| 47 | + CHECK_TRUE((std::is_same<etl::nth_type<2, t1>::type, uint32_t>::value)); |
| 48 | + } |
| 49 | + |
| 50 | + //************************************************************************* |
| 51 | + TEST(test_type_list_select) |
| 52 | + { |
| 53 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 54 | + typedef etl::type_list<char, uint32_t> t2; |
| 55 | + |
| 56 | + CHECK_TRUE((std::is_same<etl::type_list_select<t1, 0, 2>::type, t2>::value)); |
| 57 | + } |
| 58 | + |
| 59 | + //************************************************************************* |
| 60 | + TEST(test_type_list_size) |
| 61 | + { |
| 62 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 63 | + typedef etl::type_list<char, uint32_t> t2; |
| 64 | + |
| 65 | + CHECK_EQUAL(etl::type_list_size<t1>::value, 3); |
| 66 | + CHECK_EQUAL(etl::type_list_size<t2>::value, 2); |
| 67 | + } |
| 68 | + |
| 69 | + //************************************************************************* |
| 70 | + TEST(test_type_list_cat) |
| 71 | + { |
| 72 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 73 | + typedef etl::type_list<uint8_t, uint16_t> t2; |
| 74 | + |
| 75 | + typedef etl::type_list<char, int, uint32_t, uint8_t, uint16_t> t_cat1; |
| 76 | + typedef etl::type_list<char, int, uint32_t, uint8_t, bool> t_cat2; |
| 77 | + |
| 78 | + CHECK_TRUE((std::is_same<etl::type_list_cat<t1, t2>::type, t_cat1>::value)); |
| 79 | + CHECK_FALSE((std::is_same<etl::type_list_cat<t1, t2>::type, t_cat2>::value)); |
| 80 | + } |
| 81 | + |
| 82 | + //************************************************************************* |
| 83 | + TEST(test_type_list_contains) |
| 84 | + { |
| 85 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 86 | + typedef etl::type_list<uint8_t, uint16_t> t2; |
| 87 | + typedef etl::type_list<uint16_t> t3; |
| 88 | + typedef etl::type_list<> t4; |
| 89 | + |
| 90 | + CHECK_TRUE((etl::type_list_contains<t1, char>::value)); |
| 91 | + CHECK_FALSE((etl::type_list_contains<t1, uint8_t>::value)); |
| 92 | + CHECK_FALSE((etl::type_list_contains<t2, int>::value)); |
| 93 | + CHECK_TRUE((etl::type_list_contains<t2, uint16_t>::value)); |
| 94 | + CHECK_TRUE((etl::type_list_contains<t3, uint16_t>::value)); |
| 95 | + CHECK_FALSE((etl::type_list_contains<t3, uint32_t>::value)); |
| 96 | + CHECK_FALSE((etl::type_list_contains<t4, uint32_t>::value)); |
| 97 | + |
| 98 | +#if ETL_USING_CPP17 |
| 99 | + CHECK_TRUE((etl::type_list_contains_v<t1, char>)); |
| 100 | + CHECK_FALSE((etl::type_list_contains_v<t1, uint8_t>)); |
| 101 | + CHECK_FALSE((etl::type_list_contains_v<t2, int>)); |
| 102 | + CHECK_TRUE((etl::type_list_contains_v<t2, uint16_t>)); |
| 103 | + CHECK_TRUE((etl::type_list_contains_v<t3, uint16_t>)); |
| 104 | + CHECK_FALSE((etl::type_list_contains_v<t3, uint32_t>)); |
| 105 | + CHECK_FALSE((etl::type_list_contains_v<t4, uint32_t>)); |
| 106 | +#endif |
| 107 | + } |
| 108 | + |
| 109 | + //************************************************************************* |
| 110 | + TEST(test_type_list_index_of) |
| 111 | + { |
| 112 | + typedef etl::type_list<char, int, uint32_t> t1; |
| 113 | + typedef etl::type_list<> t2; |
| 114 | + |
| 115 | + CHECK_EQUAL((etl::type_list_index_of<t1, char>::value), 0); |
| 116 | + CHECK_EQUAL((etl::type_list_index_of<t1, int>::value), 1); |
| 117 | + CHECK_EQUAL((etl::type_list_index_of<t1, uint32_t>::value), 2); |
| 118 | + CHECK_EQUAL((etl::type_list_index_of<t2, uint32_t>::value), etl::npos); |
| 119 | + |
| 120 | +#if ETL_USING_CPP17 |
| 121 | + CHECK_EQUAL((etl::type_list_index_of_v<t1, char>), 0); |
| 122 | + CHECK_EQUAL((etl::type_list_index_of_v<t1, int>), 1); |
| 123 | + CHECK_EQUAL((etl::type_list_index_of_v<t1, uint32_t>), 2); |
| 124 | + CHECK_EQUAL((etl::type_list_index_of_v<t2, uint32_t>), etl::npos); |
| 125 | +#endif |
| 126 | + } |
| 127 | + |
| 128 | + //************************************************************************* |
| 129 | + TEST(test_type_list_max_sizeof_type) |
| 130 | + { |
| 131 | + typedef etl::type_list<char, int16_t, uint32_t> t1; |
| 132 | + typedef etl::type_list<uint8_t, uint16_t> t2; |
| 133 | + typedef etl::type_list<uint32_t> t3; |
| 134 | + typedef etl::type_list<> t4; |
| 135 | + |
| 136 | + CHECK_EQUAL(etl::type_list_max_sizeof_type<t1>::value, 4); |
| 137 | + CHECK_EQUAL(etl::type_list_max_sizeof_type<t2>::value, 2); |
| 138 | + CHECK_EQUAL(etl::type_list_max_sizeof_type<t3>::value, 4); |
| 139 | + CHECK_EQUAL(etl::type_list_max_sizeof_type<t4>::value, 0); |
| 140 | + |
| 141 | +#if ETL_USING_CPP17 |
| 142 | + CHECK_EQUAL(etl::type_list_max_sizeof_type_v<t1>, 4); |
| 143 | + CHECK_EQUAL(etl::type_list_max_sizeof_type_v<t2>, 2); |
| 144 | + CHECK_EQUAL(etl::type_list_max_sizeof_type_v<t3>, 4); |
| 145 | + CHECK_EQUAL(etl::type_list_max_sizeof_type_v<t4>, 0); |
| 146 | +#endif |
| 147 | + } |
| 148 | + |
| 149 | + //************************************************************************* |
| 150 | + TEST(test_type_list_max_alignment) |
| 151 | + { |
| 152 | + typedef etl::type_list<char, int16_t, uint32_t> t1; |
| 153 | + typedef etl::type_list<uint8_t, uint16_t> t2; |
| 154 | + typedef etl::type_list<uint16_t> t3; |
| 155 | + typedef etl::type_list<> t4; |
| 156 | + |
| 157 | + CHECK_EQUAL(etl::type_list_max_alignment<t1>::value, std::alignment_of<uint32_t>::value); |
| 158 | + CHECK_EQUAL(etl::type_list_max_alignment<t2>::value, std::alignment_of<uint16_t>::value); |
| 159 | + CHECK_EQUAL(etl::type_list_max_alignment<t3>::value, std::alignment_of<uint16_t>::value); |
| 160 | + CHECK_EQUAL(etl::type_list_max_alignment<t4>::value, 1); |
| 161 | + |
| 162 | +#if ETL_USING_CPP17 |
| 163 | + CHECK_EQUAL(etl::type_list_max_alignment_v<t1>, std::alignment_of<uint32_t>::value); |
| 164 | + CHECK_EQUAL(etl::type_list_max_alignment_v<t2>, std::alignment_of<uint16_t>::value); |
| 165 | + CHECK_EQUAL(etl::type_list_max_alignment_v<t3>, std::alignment_of<uint16_t>::value); |
| 166 | + CHECK_EQUAL(etl::type_list_max_alignment_v<t4>, 1); |
| 167 | +#endif |
| 168 | + } |
| 169 | + |
| 170 | + }; |
| 171 | +#endif |
| 172 | +} |
0 commit comments