mirror of
https://github.com/ETLCPP/etl.git
synced 2026-05-01 03:19:10 +08:00
* Move __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS before `#include <stdint.h>`. (#601) Macros must be defined before first include of stdint.h. Else they have no effect. * Replace ETL_COMPILER_ICCAVR by ETL_COMPILER_IAR. (#602) The current definition mechanism for ETL_COMPILER_ICCAVR does not work. Both IAR compilers, for ARM and AVR define `__IAR_SYSTEMS_ICC__`. Thus `ETL_COMPILER_TYPE_DETECTED` will be defined in line before ETL_COMPILER_ICCAVR is defined. This switch will never be entered. Currently I see no reason for differentiating both compilers (`__ICCARM__` and `__ICCAVR__`). The condition for the IAR compiler platform (`__IAR_SYSTEMS_ICC__`) is sufficient (combined with <C++11 detection). At the moment ETL_COMPILER_ICCAVR is used as a switch condition for using `#pragma push_macro`. But actually IAR ARM and IAR AVR have no such macro defined. ETL_COMPILER_IAR is defined for both compilers. Thus the switch condition is replaced with ETL_COMPILER_IAR. * Fix 'maybe-uninitialized' g++ error on macos (#600) * Add documentation to the pair class * Add test directory to the EXAMPLE_PATH * Update .gitignore - Remove duplicate entries - Add doxygen output directories * Add Select1st and Select2nd functors * Merge select1st and select2nd into utility.h Co-authored-by: David Hebbeker <dhebbeker@users.noreply.github.com>
233 lines
5.6 KiB
C++
233 lines
5.6 KiB
C++
/******************************************************************************
|
|
The MIT License(MIT)
|
|
|
|
Embedded Template Library.
|
|
https://github.com/ETLCPP/etl
|
|
https://www.etlcpp.com
|
|
|
|
Copyright(c) 2014 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 <vector>
|
|
#include <ostream>
|
|
|
|
#include "etl/fixed_iterator.h"
|
|
|
|
template <typename TIterator>
|
|
std::ostream& operator << (std::ostream& os, const etl::fixed_iterator<TIterator>& fi)
|
|
{
|
|
os << TIterator(fi);
|
|
|
|
return os;
|
|
}
|
|
|
|
namespace
|
|
{
|
|
SUITE(test_fixed_iterator)
|
|
{
|
|
//*************************************************************************
|
|
TEST(test_default_constructor)
|
|
{
|
|
etl::fixed_iterator<const int*> fi;
|
|
|
|
CHECK_EQUAL((const int*)0, fi);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_copy_constructor)
|
|
{
|
|
int a{};
|
|
|
|
etl::fixed_iterator<const int*> fi1(&a);
|
|
etl::fixed_iterator<const int*> fi2(fi1);
|
|
|
|
CHECK_EQUAL(fi1, fi2);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_constructor)
|
|
{
|
|
int a{};
|
|
|
|
etl::fixed_iterator<const int*> fi(&a);
|
|
|
|
CHECK_EQUAL(&a, fi);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_make)
|
|
{
|
|
int a{};
|
|
|
|
etl::fixed_iterator<const int*> fi = &a;
|
|
|
|
CHECK_EQUAL(&a, fi);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_increment)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
++fi;
|
|
fi++;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_member_dereference_operator)
|
|
{
|
|
struct Test
|
|
{
|
|
int a;
|
|
int b;
|
|
} test = { 1, 2 };
|
|
|
|
etl::fixed_iterator<Test*> fi(&test);
|
|
|
|
CHECK_EQUAL(test.a, fi->a);
|
|
CHECK_EQUAL(test.b, fi->b);
|
|
|
|
*fi = { 3, 4 };
|
|
|
|
CHECK_EQUAL(test.a, fi->a);
|
|
CHECK_EQUAL(test.b, fi->b);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_conversion_operator)
|
|
{
|
|
int a{};
|
|
|
|
etl::fixed_iterator<const int*> fi(&a);
|
|
|
|
CHECK_EQUAL(&a, fi);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_operator_plus_equals)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
fi += 1;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_operator_plus)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
fi = fi + 1;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_decrement)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
--fi;
|
|
fi--;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_operator_minus_equals)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
fi -= 1;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_operator_minus)
|
|
{
|
|
int compare[] = { 1, 2, 3, 4 };
|
|
|
|
etl::fixed_iterator<const int*> fi = &compare[1];
|
|
|
|
for (int i = 0; i < 10; ++i)
|
|
{
|
|
CHECK_EQUAL(compare[1], *fi);
|
|
fi = fi - 1;
|
|
}
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_assignment)
|
|
{
|
|
int a{};
|
|
int b{};
|
|
|
|
etl::fixed_iterator<int*> fi = &a;
|
|
fi = &b;
|
|
|
|
CHECK_EQUAL(&b, fi);
|
|
|
|
fi = &a;
|
|
|
|
CHECK_EQUAL(&a, fi);
|
|
}
|
|
|
|
//*************************************************************************
|
|
TEST(test_equality)
|
|
{
|
|
int a{};
|
|
int b{};
|
|
|
|
etl::fixed_iterator<int*> fi1 = &a;
|
|
etl::fixed_iterator<int*> fi2 = &a;
|
|
etl::fixed_iterator<int*> fi3 = &b;
|
|
|
|
CHECK(fi1 == fi2);
|
|
CHECK(fi1 != fi3);
|
|
}
|
|
};
|
|
}
|