mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Added unit tests for new classes
This commit is contained in:
parent
b2b14bac30
commit
585b494aa1
145
test/test_container.cpp
Normal file
145
test/test_container.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../container.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(ContainerTest)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(TestSTLContainer)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
std::list<int> data(SIZE);
|
||||
|
||||
std::list<int>::iterator iBegin = etl::begin(data);
|
||||
CHECK(data.begin() == iBegin);
|
||||
|
||||
std::list<int>::iterator iEnd = etl::end(data);
|
||||
CHECK(data.end() == iEnd);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestConstSTLContainer)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
const std::list<int> data(SIZE);
|
||||
|
||||
std::list<int>::const_iterator iBegin = etl::begin(data);
|
||||
CHECK(data.begin() == iBegin);
|
||||
|
||||
const std::list<int>::const_iterator iEnd = etl::end(data);
|
||||
CHECK(data.end() == iEnd);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCArray)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
int data[SIZE];
|
||||
|
||||
int* iBegin = etl::begin(data);
|
||||
CHECK(&data[0] == iBegin);
|
||||
|
||||
int* iEnd = etl::end(data);
|
||||
CHECK(&data[SIZE] == iEnd);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestConstCArray)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
const int data[SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
const int* const iBegin = etl::begin(data);
|
||||
CHECK(&data[0] == iBegin);
|
||||
|
||||
const int* const iEnd = etl::end(data);
|
||||
CHECK(&data[SIZE] == iEnd);
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestNext)
|
||||
{
|
||||
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
const int* p;
|
||||
|
||||
p = etl::next(std::begin(data));
|
||||
CHECK_EQUAL(data[1], *p);
|
||||
|
||||
p = etl::next(std::begin(data), 1);
|
||||
CHECK_EQUAL(data[1], *p);
|
||||
|
||||
p = etl::next(std::begin(data), 5);
|
||||
CHECK_EQUAL(data[5], *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestPrev)
|
||||
{
|
||||
const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
const int* p;
|
||||
|
||||
p = etl::prev(std::end(data));
|
||||
CHECK_EQUAL(data[9], *p);
|
||||
|
||||
p = etl::prev(std::end(data), 1);
|
||||
CHECK_EQUAL(data[9], *p);
|
||||
|
||||
p = etl::prev(std::end(data), 5);
|
||||
CHECK_EQUAL(data[5], *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestSTLContainerSize)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
std::list<int> data(SIZE);
|
||||
|
||||
size_t runtime_size = etl::size(data);
|
||||
CHECK_EQUAL(SIZE, runtime_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestCArraySize)
|
||||
{
|
||||
const size_t SIZE = 10;
|
||||
int data[SIZE];
|
||||
|
||||
size_t runtime_size = etl::size(data);
|
||||
CHECK_EQUAL(SIZE, runtime_size);
|
||||
|
||||
size_t compiletime_size = sizeof(etl::array_size(data));
|
||||
CHECK_EQUAL(SIZE, compiletime_size);
|
||||
}
|
||||
};
|
||||
}
|
||||
194
test/test_cyclic_value.cpp
Normal file
194
test/test_cyclic_value.cpp
Normal file
@ -0,0 +1,194 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../cyclic_value.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestCyclicValue)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(CompileTimeInitialisation)
|
||||
{
|
||||
etl::cyclic_value<int, 2, 7> value;
|
||||
|
||||
CHECK_EQUAL(2, value);
|
||||
CHECK_EQUAL(2, value.first());
|
||||
CHECK_EQUAL(7, value.last());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(RunTimeInitialisation)
|
||||
{
|
||||
etl::cyclic_value<int> value(2, 7, 1);
|
||||
|
||||
CHECK_EQUAL(2, value);
|
||||
CHECK_EQUAL(2, value.first());
|
||||
CHECK_EQUAL(7, value.last());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(set)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
|
||||
CHECK_EQUAL(2, value);
|
||||
CHECK_EQUAL(2, value.first());
|
||||
CHECK_EQUAL(7, value.last());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(ToFirst)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
++value;
|
||||
value.to_first();
|
||||
|
||||
CHECK_EQUAL(value.first(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(ToLast)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
value.to_last();
|
||||
|
||||
CHECK_EQUAL(value.last(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Increment)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
|
||||
for (int i = value.first(); i <= value.last(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(i, value);
|
||||
++value;
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Decrement)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
value.to_last();
|
||||
|
||||
for (int i = value.last(); i >= value.first(); --i)
|
||||
{
|
||||
CHECK_EQUAL(i, value);
|
||||
--value;
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(IncrementWrap)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
|
||||
int expected[8] = { 2, 3, 4, 5, 6, 7, 2, 3 };
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
CHECK_EQUAL(expected[i], value);
|
||||
++value;
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(DecrementWrap)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7);
|
||||
|
||||
int expected[8] = { 2, 7, 6, 5, 4, 3, 2, 7 };
|
||||
|
||||
for (int i = 0; i > 8; ++i)
|
||||
{
|
||||
CHECK_EQUAL(expected[i], value);
|
||||
--value;
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(NumberOfSteps)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
value.set(2, 7, 1);
|
||||
CHECK_EQUAL(7 - 2 + 1, value.number_of_steps());
|
||||
|
||||
value.set(2, 7, 2);
|
||||
CHECK_EQUAL((7 - 2 + 1) / 2, value.number_of_steps());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(AdvancePositive)
|
||||
{
|
||||
etl::cyclic_value<int, 2, 7, 1> value;
|
||||
|
||||
value.advance(2);
|
||||
|
||||
CHECK_EQUAL(4, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(AdvanceNegative)
|
||||
{
|
||||
etl::cyclic_value<int, 2, 7, 1> value;
|
||||
|
||||
value.to_last();
|
||||
value.advance(-2);
|
||||
|
||||
CHECK_EQUAL(5, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestException)
|
||||
{
|
||||
etl::cyclic_value<int> value;
|
||||
|
||||
CHECK_THROW(value.set(2, 7, 4), etl::cyclic_value_illegal_range_exception);
|
||||
}
|
||||
};
|
||||
}
|
||||
83
test/test_largest.cpp
Normal file
83
test/test_largest.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../largest.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestLargest)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(PODTest)
|
||||
{
|
||||
size_t size;
|
||||
bool type;
|
||||
|
||||
size = etl::largest<char, short, int>::size;
|
||||
type = std::is_same<int, etl::largest<char, short, int>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(int), size);
|
||||
CHECK(type);
|
||||
|
||||
size = etl::largest<int, char, short>::size;
|
||||
type = std::is_same<int, etl::largest<char, short, int>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(int), size);
|
||||
CHECK(type);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(NonPODTest)
|
||||
{
|
||||
size_t size;
|
||||
bool type;
|
||||
|
||||
struct S1 { char a; char b; char c; };
|
||||
struct S2 { char a; short b; char c; };
|
||||
struct S3 { int a; short b; char c; };
|
||||
|
||||
size_t a = sizeof(S1);
|
||||
size_t b = sizeof(S2);
|
||||
size_t c = sizeof(S3);
|
||||
|
||||
size = etl::largest<S1, S2, S3>::size;
|
||||
type = std::is_same<S3, etl::largest<S1, S2, S3>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(S3), size);
|
||||
CHECK(type);
|
||||
|
||||
size = etl::largest<S2, S3, S1>::size;
|
||||
type = std::is_same<S3, etl::largest<S2, S3, S1>::type>::value;
|
||||
|
||||
CHECK_EQUAL(sizeof(S3), size);
|
||||
CHECK(type);
|
||||
}
|
||||
};
|
||||
}
|
||||
51
test/test_numeric.cpp
Normal file
51
test/test_numeric.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../numeric.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestNumeric)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(IOTA)
|
||||
{
|
||||
int data1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int data2[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
etl::iota(std::begin(data2), std::end(data2), 0);
|
||||
|
||||
bool are_same = std::equal(std::begin(data1), std::end(data1), std::begin(data2));
|
||||
|
||||
CHECK(are_same);
|
||||
}
|
||||
};
|
||||
}
|
||||
433
test/test_observer.cpp
Normal file
433
test/test_observer.cpp
Normal file
@ -0,0 +1,433 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../observer.h"
|
||||
|
||||
//*****************************************************************************
|
||||
// Notification1
|
||||
//*****************************************************************************
|
||||
struct Notification1
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Notification2
|
||||
//*****************************************************************************
|
||||
struct Notification2
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Notification3
|
||||
//*****************************************************************************
|
||||
struct Notification3
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Generic notification.
|
||||
//*****************************************************************************
|
||||
template <const int ID>
|
||||
struct Notification
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The observer base type.
|
||||
// Declare what notifications you want to observe and how they are passed to 'notification'.
|
||||
// The Notification1 is passed by value.
|
||||
// The Notification2 is passed by reference.
|
||||
// The Notification3 is passed by const reference.
|
||||
//*****************************************************************************
|
||||
typedef etl::observer<Notification1, Notification2&, const Notification3&> ObserverType;
|
||||
|
||||
//*****************************************************************************
|
||||
// The concrete observable 1 class.
|
||||
//*****************************************************************************
|
||||
class Observable1 : public etl::observable<ObserverType, 2>
|
||||
{
|
||||
public:
|
||||
|
||||
Notification1 data1;
|
||||
Notification2 data2;
|
||||
|
||||
//*********************************
|
||||
// Notify all of the observers.
|
||||
//*********************************
|
||||
void send_notifications()
|
||||
{
|
||||
notify_observers(data1);
|
||||
notify_observers(data2);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The concrete observable 2 class.
|
||||
//*****************************************************************************
|
||||
class Observable2 : public etl::observable<ObserverType, 2>
|
||||
{
|
||||
public:
|
||||
|
||||
Notification3 data3;
|
||||
|
||||
//*********************************
|
||||
// Notify all of the observers.
|
||||
//*********************************
|
||||
void send_notifications()
|
||||
{
|
||||
notify_observers(data3);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The first observer type.
|
||||
// If any one of the overloads is missing or a parameter declaration is incorrect
|
||||
// then the class will be 'abstract' and will not compile.
|
||||
//*****************************************************************************
|
||||
class Observer1 : public ObserverType
|
||||
{
|
||||
public:
|
||||
|
||||
Observer1()
|
||||
: data1_count(0),
|
||||
data2_count(0),
|
||||
data3_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification1 is passed by value.
|
||||
//*******************************************
|
||||
void notification(Notification1 data1)
|
||||
{
|
||||
++data1_count;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification2 is passed by reference.
|
||||
//*******************************************
|
||||
void notification(Notification2& data2)
|
||||
{
|
||||
++data2_count;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification3 is passed by const reference.
|
||||
//*******************************************
|
||||
void notification(const Notification3& data3)
|
||||
{
|
||||
++data3_count;
|
||||
}
|
||||
|
||||
int data1_count;
|
||||
int data2_count;
|
||||
int data3_count;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The second observer type.
|
||||
// If any one of the overloads is missing or a parameter declaration is incorrect
|
||||
// then the class will be 'abstract' and will not compile.
|
||||
//*****************************************************************************
|
||||
class Observer2 : public ObserverType
|
||||
{
|
||||
public:
|
||||
|
||||
Observer2()
|
||||
: data1_count(0),
|
||||
data2_count(0),
|
||||
data3_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification1 is passed by value.
|
||||
//*******************************************
|
||||
void notification(Notification1 data1)
|
||||
{
|
||||
++data1_count;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification2 is passed by reference.
|
||||
//*******************************************
|
||||
void notification(Notification2& data2)
|
||||
{
|
||||
++data2_count;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
// Notification3 is passed by const reference.
|
||||
//*******************************************
|
||||
void notification(const Notification3& data3)
|
||||
{
|
||||
++data3_count;
|
||||
}
|
||||
|
||||
int data1_count;
|
||||
int data2_count;
|
||||
int data3_count;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestObserver)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(Test2Observables2Observers3Notifications)
|
||||
{
|
||||
// The observable objects.
|
||||
Observable1 observable1;
|
||||
Observable2 observable2;
|
||||
|
||||
// The observer objects.
|
||||
Observer1 observer1;
|
||||
Observer2 observer2;
|
||||
|
||||
observable1.add_observer(observer1);
|
||||
|
||||
// Send the notifications.
|
||||
observable1.send_notifications(); // Updates data1 & data2.
|
||||
|
||||
CHECK_EQUAL(1, observer1.data1_count);
|
||||
CHECK_EQUAL(1, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(0, observer2.data1_count);
|
||||
CHECK_EQUAL(0, observer2.data2_count);
|
||||
CHECK_EQUAL(0, observer2.data3_count);
|
||||
|
||||
observable2.send_notifications(); // Updates data3.
|
||||
|
||||
CHECK_EQUAL(1, observer1.data1_count);
|
||||
CHECK_EQUAL(1, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(0, observer2.data1_count);
|
||||
CHECK_EQUAL(0, observer2.data2_count);
|
||||
CHECK_EQUAL(0, observer2.data3_count);
|
||||
|
||||
// Add another observer to both.
|
||||
observable1.add_observer(observer2);
|
||||
observable2.add_observer(observer2);
|
||||
|
||||
// Send the notifications.
|
||||
observable1.send_notifications(); // Updates data1 & data2.
|
||||
|
||||
CHECK_EQUAL(2, observer1.data1_count);
|
||||
CHECK_EQUAL(2, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(1, observer2.data1_count);
|
||||
CHECK_EQUAL(1, observer2.data2_count);
|
||||
CHECK_EQUAL(0, observer2.data3_count);
|
||||
|
||||
observable2.send_notifications(); // Updates data3.
|
||||
|
||||
CHECK_EQUAL(2, observer1.data1_count);
|
||||
CHECK_EQUAL(2, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(1, observer2.data1_count);
|
||||
CHECK_EQUAL(1, observer2.data2_count);
|
||||
CHECK_EQUAL(1, observer2.data3_count);
|
||||
|
||||
observable1.remove_observer(observer1);
|
||||
|
||||
// Send the notifications.
|
||||
observable1.send_notifications(); // Updates data1 & data2.
|
||||
|
||||
CHECK_EQUAL(2, observer1.data1_count);
|
||||
CHECK_EQUAL(2, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(2, observer2.data1_count);
|
||||
CHECK_EQUAL(2, observer2.data2_count);
|
||||
CHECK_EQUAL(1, observer2.data3_count);
|
||||
|
||||
observable2.send_notifications(); // Updates data3.
|
||||
|
||||
CHECK_EQUAL(2, observer1.data1_count);
|
||||
CHECK_EQUAL(2, observer1.data2_count);
|
||||
CHECK_EQUAL(0, observer1.data3_count);
|
||||
|
||||
CHECK_EQUAL(2, observer2.data1_count);
|
||||
CHECK_EQUAL(2, observer2.data2_count);
|
||||
CHECK_EQUAL(2, observer2.data3_count);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test8Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>, Notification<4>, Notification<5>, Notification<6>, Notification<7>, Notification<8>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test7Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>, Notification<4>, Notification<5>, Notification<6>, Notification<7>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test6Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>, Notification<4>, Notification<5>, Notification<6>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test5Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>, Notification<4>, Notification<5>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test4Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>, Notification<4>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test3Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>, Notification<3>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test2Notifications)
|
||||
{
|
||||
typedef etl::observer<Notification<1>, Notification<2>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test1Notification)
|
||||
{
|
||||
typedef etl::observer<Notification<1>> Observer;
|
||||
|
||||
class Observable : public etl::observable<Observer, 1>
|
||||
{
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(TestObserverList)
|
||||
{
|
||||
class Observer : public etl::observer<Notification1>
|
||||
{
|
||||
void notification(Notification1) {}
|
||||
};
|
||||
|
||||
class Observable : public etl::observable<Observer, 4>
|
||||
{
|
||||
};
|
||||
|
||||
Observable observable;
|
||||
|
||||
Observer observer1;
|
||||
Observer observer2;
|
||||
Observer observer3;
|
||||
Observer observer4;
|
||||
Observer observer5;
|
||||
|
||||
observable.add_observer(observer1);
|
||||
CHECK_EQUAL(1, observable.number_of_observers());
|
||||
|
||||
observable.add_observer(observer2);
|
||||
CHECK_EQUAL(2, observable.number_of_observers());
|
||||
|
||||
observable.add_observer(observer3);
|
||||
CHECK_EQUAL(3, observable.number_of_observers());
|
||||
|
||||
observable.add_observer(observer2);
|
||||
CHECK_EQUAL(3, observable.number_of_observers());
|
||||
|
||||
observable.add_observer(observer4);
|
||||
CHECK_EQUAL(4, observable.number_of_observers());
|
||||
|
||||
CHECK_THROW(observable.add_observer(observer5), etl::observer_list_full_exception);
|
||||
|
||||
observable.remove_observer(observer3);
|
||||
CHECK_EQUAL(3, observable.number_of_observers());
|
||||
|
||||
observable.clear_observers();
|
||||
CHECK_EQUAL(0, observable.number_of_observers());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
487
test/test_type_traits.cpp
Normal file
487
test/test_type_traits.cpp
Normal file
@ -0,0 +1,487 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "../type_traits.h"
|
||||
|
||||
// A class to test non-fundamental types.
|
||||
struct Test
|
||||
{
|
||||
int a;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestTypeTraits)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(is_integral)
|
||||
{
|
||||
CHECK(etl::is_integral<bool>::value == std::is_integral<bool>::value);
|
||||
CHECK(etl::is_integral<char>::value == std::is_integral<char>::value);
|
||||
CHECK(etl::is_integral<signed char>::value == std::is_integral<signed char>::value);
|
||||
CHECK(etl::is_integral<unsigned char>::value == std::is_integral<unsigned char>::value);
|
||||
CHECK(etl::is_integral<wchar_t>::value == std::is_integral<wchar_t>::value);
|
||||
CHECK(etl::is_integral<short>::value == std::is_integral<short>::value);
|
||||
CHECK(etl::is_integral<signed short>::value == std::is_integral<signed short>::value);
|
||||
CHECK(etl::is_integral<unsigned short>::value == std::is_integral<unsigned short>::value);
|
||||
CHECK(etl::is_integral<int>::value == std::is_integral<int>::value);
|
||||
CHECK(etl::is_integral<signed int>::value == std::is_integral<signed int>::value);
|
||||
CHECK(etl::is_integral<unsigned int>::value == std::is_integral<unsigned int>::value);
|
||||
CHECK(etl::is_integral<long>::value == std::is_integral<long>::value);
|
||||
CHECK(etl::is_integral<signed long>::value == std::is_integral<signed long>::value);
|
||||
CHECK(etl::is_integral<unsigned long>::value == std::is_integral<unsigned long>::value);
|
||||
CHECK(etl::is_integral<long long>::value == std::is_integral<long long>::value);
|
||||
CHECK(etl::is_integral<signed long long>::value == std::is_integral<signed long long>::value);
|
||||
CHECK(etl::is_integral<unsigned long long>::value == std::is_integral<unsigned long long>::value);
|
||||
CHECK(etl::is_integral<const int>::value == std::is_integral<const int>::value);
|
||||
CHECK(etl::is_integral<volatile int>::value == std::is_integral<volatile int>::value);
|
||||
CHECK(etl::is_integral<const int>::value == std::is_integral<const int>::value);
|
||||
CHECK(etl::is_integral<const volatile int>::value == std::is_integral<const volatile int>::value);
|
||||
CHECK(etl::is_integral<float>::value == std::is_integral<float>::value);
|
||||
CHECK(etl::is_integral<double>::value == std::is_integral<double>::value);
|
||||
CHECK(etl::is_integral<long double>::value == std::is_integral<long double>::value);
|
||||
CHECK(etl::is_integral<Test>::value == std::is_integral<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_signed)
|
||||
{
|
||||
CHECK(etl::is_signed<bool>::value == std::is_signed<bool>::value);
|
||||
CHECK(etl::is_signed<char>::value == std::is_signed<char>::value);
|
||||
CHECK(etl::is_signed<signed char>::value == std::is_signed<signed char>::value);
|
||||
CHECK(etl::is_signed<unsigned char>::value == std::is_signed<unsigned char>::value);
|
||||
CHECK(etl::is_signed<wchar_t>::value == std::is_signed<wchar_t>::value);
|
||||
CHECK(etl::is_signed<short>::value == std::is_signed<short>::value);
|
||||
CHECK(etl::is_signed<signed short>::value == std::is_signed<signed short>::value);
|
||||
CHECK(etl::is_signed<unsigned short>::value == std::is_signed<unsigned short>::value);
|
||||
CHECK(etl::is_signed<int>::value == std::is_signed<int>::value);
|
||||
CHECK(etl::is_signed<signed int>::value == std::is_signed<signed int>::value);
|
||||
CHECK(etl::is_signed<unsigned int>::value == std::is_signed<unsigned int>::value);
|
||||
CHECK(etl::is_signed<long>::value == std::is_signed<long>::value);
|
||||
CHECK(etl::is_signed<signed long>::value == std::is_signed<signed long>::value);
|
||||
CHECK(etl::is_signed<unsigned long>::value == std::is_signed<unsigned long>::value);
|
||||
CHECK(etl::is_signed<long long>::value == std::is_signed<long long>::value);
|
||||
CHECK(etl::is_signed<signed long long>::value == std::is_signed<signed long long>::value);
|
||||
CHECK(etl::is_signed<unsigned long long>::value == std::is_signed<unsigned long long>::value);
|
||||
CHECK(etl::is_signed<const int>::value == std::is_signed<const int>::value);
|
||||
CHECK(etl::is_signed<volatile int>::value == std::is_signed<volatile int>::value);
|
||||
CHECK(etl::is_signed<const int>::value == std::is_signed<const int>::value);
|
||||
CHECK(etl::is_signed<const volatile int>::value == std::is_signed<const volatile int>::value);
|
||||
CHECK(etl::is_signed<float>::value == std::is_signed<float>::value);
|
||||
CHECK(etl::is_signed<double>::value == std::is_signed<double>::value);
|
||||
CHECK(etl::is_signed<long double>::value == std::is_signed<long double>::value);
|
||||
CHECK(etl::is_signed<Test>::value == std::is_signed<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_unsigned)
|
||||
{
|
||||
CHECK(etl::is_unsigned<bool>::value == std::is_unsigned<bool>::value);
|
||||
CHECK(etl::is_unsigned<char>::value == std::is_unsigned<char>::value);
|
||||
CHECK(etl::is_unsigned<signed char>::value == std::is_unsigned<signed char>::value);
|
||||
CHECK(etl::is_unsigned<unsigned char>::value == std::is_unsigned<unsigned char>::value);
|
||||
CHECK(etl::is_unsigned<signed char>::value == std::is_unsigned<signed char>::value);
|
||||
CHECK(etl::is_unsigned<wchar_t>::value == std::is_unsigned<wchar_t>::value);
|
||||
CHECK(etl::is_unsigned<short>::value == std::is_unsigned<short>::value);
|
||||
CHECK(etl::is_unsigned<signed short>::value == std::is_unsigned<signed short>::value);
|
||||
CHECK(etl::is_unsigned<unsigned short>::value == std::is_unsigned<unsigned short>::value);
|
||||
CHECK(etl::is_unsigned<int>::value == std::is_unsigned<int>::value);
|
||||
CHECK(etl::is_unsigned<signed int>::value == std::is_unsigned<signed int>::value);
|
||||
CHECK(etl::is_unsigned<unsigned int>::value == std::is_unsigned<unsigned int>::value);
|
||||
CHECK(etl::is_unsigned<long>::value == std::is_unsigned<long>::value);
|
||||
CHECK(etl::is_unsigned<signed long>::value == std::is_unsigned<signed long>::value);
|
||||
CHECK(etl::is_unsigned<unsigned long>::value == std::is_unsigned<unsigned long>::value);
|
||||
CHECK(etl::is_unsigned<long long>::value == std::is_unsigned<long long>::value);
|
||||
CHECK(etl::is_unsigned<signed long long>::value == std::is_unsigned<signed long long>::value);
|
||||
CHECK(etl::is_unsigned<unsigned long long>::value == std::is_unsigned<unsigned long long>::value);
|
||||
CHECK(etl::is_unsigned<const int>::value == std::is_unsigned<const int>::value);
|
||||
CHECK(etl::is_unsigned<volatile int>::value == std::is_unsigned<volatile int>::value);
|
||||
CHECK(etl::is_unsigned<const int>::value == std::is_unsigned<const int>::value);
|
||||
CHECK(etl::is_unsigned<const volatile int>::value == std::is_unsigned<const volatile int>::value);
|
||||
CHECK(etl::is_unsigned<float>::value == std::is_unsigned<float>::value);
|
||||
CHECK(etl::is_unsigned<double>::value == std::is_unsigned<double>::value);
|
||||
CHECK(etl::is_unsigned<long double>::value == std::is_unsigned<long double>::value);
|
||||
CHECK(etl::is_unsigned<Test>::value == std::is_unsigned<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_floating_point)
|
||||
{
|
||||
CHECK(etl::is_floating_point<bool>::value == std::is_floating_point<bool>::value);
|
||||
CHECK(etl::is_floating_point<char>::value == std::is_floating_point<char>::value);
|
||||
CHECK(etl::is_floating_point<signed char>::value == std::is_floating_point<signed char>::value);
|
||||
CHECK(etl::is_floating_point<unsigned char>::value == std::is_floating_point<unsigned char>::value);
|
||||
CHECK(etl::is_floating_point<wchar_t>::value == std::is_floating_point<wchar_t>::value);
|
||||
CHECK(etl::is_floating_point<short>::value == std::is_floating_point<short>::value);
|
||||
CHECK(etl::is_floating_point<signed short>::value == std::is_floating_point<signed short>::value);
|
||||
CHECK(etl::is_floating_point<unsigned short>::value == std::is_floating_point<unsigned short>::value);
|
||||
CHECK(etl::is_floating_point<int>::value == std::is_floating_point<int>::value);
|
||||
CHECK(etl::is_floating_point<signed int>::value == std::is_floating_point<signed int>::value);
|
||||
CHECK(etl::is_floating_point<unsigned int>::value == std::is_floating_point<unsigned int>::value);
|
||||
CHECK(etl::is_floating_point<long>::value == std::is_floating_point<long>::value);
|
||||
CHECK(etl::is_floating_point<signed long>::value == std::is_floating_point<signed long>::value);
|
||||
CHECK(etl::is_floating_point<unsigned long>::value == std::is_floating_point<unsigned long>::value);
|
||||
CHECK(etl::is_floating_point<long long>::value == std::is_floating_point<long long>::value);
|
||||
CHECK(etl::is_floating_point<signed long long>::value == std::is_floating_point<signed long long>::value);
|
||||
CHECK(etl::is_floating_point<unsigned long long>::value == std::is_floating_point<unsigned long long>::value);
|
||||
CHECK(etl::is_floating_point<const int>::value == std::is_floating_point<const int>::value);
|
||||
CHECK(etl::is_floating_point<volatile int>::value == std::is_floating_point<volatile int>::value);
|
||||
CHECK(etl::is_floating_point<const int>::value == std::is_floating_point<const int>::value);
|
||||
CHECK(etl::is_floating_point<const volatile int>::value == std::is_floating_point<const volatile int>::value);
|
||||
CHECK(etl::is_floating_point<float>::value == std::is_floating_point<float>::value);
|
||||
CHECK(etl::is_floating_point<double>::value == std::is_floating_point<double>::value);
|
||||
CHECK(etl::is_floating_point<long double>::value == std::is_floating_point<long double>::value);
|
||||
CHECK(etl::is_floating_point<Test>::value == std::is_signed<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_pointer)
|
||||
{
|
||||
CHECK(etl::is_pointer<int>::value == std::is_pointer<int>::value);
|
||||
CHECK(etl::is_pointer<int*>::value == std::is_pointer<int*>::value);
|
||||
CHECK(etl::is_pointer<const int*>::value == std::is_pointer<const int*>::value);
|
||||
CHECK(etl::is_pointer<volatile int*>::value == std::is_pointer<volatile int*>::value);
|
||||
CHECK(etl::is_pointer<const volatile int*>::value == std::is_pointer<const volatile int*>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_reference)
|
||||
{
|
||||
CHECK(etl::is_reference<int>::value == std::is_reference<int>::value);
|
||||
CHECK(etl::is_reference<int&>::value == std::is_reference<int&>::value);
|
||||
CHECK(etl::is_reference<const int&>::value == std::is_reference<const int&>::value);
|
||||
CHECK(etl::is_reference<volatile int&>::value == std::is_reference<volatile int&>::value);
|
||||
CHECK(etl::is_reference<const volatile int&>::value == std::is_reference<const volatile int&>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_same)
|
||||
{
|
||||
CHECK((etl::is_same<int, int>::value == std::is_same<int, int>::value));
|
||||
CHECK((etl::is_same<char, int>::value == std::is_same<char, int>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_array)
|
||||
{
|
||||
CHECK(etl::is_array<int>::value == std::is_array<int>::value);
|
||||
CHECK(etl::is_array<int[10]>::value == std::is_array<int[10]>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_pointer)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_pointer<int>::type, std::remove_pointer<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_pointer<int*>::type, std::remove_pointer<int*>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_pointer<const int*>::type, std::remove_pointer<const int*>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_pointer<volatile int*>::type, std::remove_pointer<volatile int*>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_pointer<const volatile int*>::type, std::remove_pointer<const volatile int*>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(add_pointer)
|
||||
{
|
||||
CHECK((std::is_same<etl::add_pointer<int>::type, std::add_pointer<int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_pointer<int*>::type, std::add_pointer<int*>::type>::value));
|
||||
CHECK((std::is_same<etl::add_pointer<const int*>::type, std::add_pointer<const int*>::type>::value));
|
||||
CHECK((std::is_same<etl::add_pointer<volatile int*>::type, std::add_pointer<volatile int*>::type>::value));
|
||||
CHECK((std::is_same<etl::add_pointer<const volatile int*>::type, std::add_pointer<const volatile int*>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_reference)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_reference<int>::type, std::remove_reference<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_reference<int&>::type, std::remove_reference<int&>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_reference<const int&>::type, std::remove_reference<const int&>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_reference<volatile int&>::type, std::remove_reference<volatile int&>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_reference<const volatile int&>::type, std::remove_reference<const volatile int&>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(add_reference)
|
||||
{
|
||||
CHECK((std::is_same<etl::add_reference<int>::type, std::add_reference<int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_reference<int&>::type, std::add_reference<int&>::type>::value));
|
||||
CHECK((std::is_same<etl::add_reference<const int&>::type, std::add_reference<const int&>::type>::value));
|
||||
CHECK((std::is_same<etl::add_reference<volatile int&>::type, std::add_reference<volatile int&>::type>::value));
|
||||
CHECK((std::is_same<etl::add_reference<const volatile int&>::type, std::add_reference<const volatile int&>::type>::value));
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_const)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_const<int>::type, std::remove_const<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_const<const int>::type, std::remove_const<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_const<const volatile int>::type, std::remove_const<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(add_const)
|
||||
{
|
||||
CHECK((std::is_same<etl::add_const<int>::type, std::add_const<int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_const<const int>::type, std::add_const<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_const<const volatile int>::type, std::add_const<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_const)
|
||||
{
|
||||
CHECK(etl::is_const<int>::value == std::is_const<int>::value);
|
||||
CHECK(etl::is_const<const int>::value == std::is_const<const int>::value);
|
||||
CHECK(etl::is_const<const volatile int>::value == std::is_const<const volatile int>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_volatile)
|
||||
{
|
||||
CHECK(etl::is_volatile<int>::value == std::is_volatile<int>::value);
|
||||
CHECK(etl::is_volatile<volatile int>::value == std::is_volatile<volatile int>::value);
|
||||
CHECK(etl::is_volatile<const volatile int>::value == std::is_volatile<const volatile int>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_volatile)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_volatile<int>::type, std::remove_volatile<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_volatile<volatile int>::type, std::remove_volatile<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_volatile<const volatile int>::type, std::remove_volatile<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(add_volatile)
|
||||
{
|
||||
CHECK((std::is_same<etl::add_volatile<int>::type, std::add_volatile<int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_volatile<volatile int>::type, std::add_volatile<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_volatile<const volatile int>::type, std::add_volatile<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_cv)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_cv<int>::type, std::remove_cv<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_cv<const int>::type, std::remove_cv<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_cv<volatile int>::type, std::remove_cv<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_cv<const volatile int>::type, std::remove_cv<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(add_cv)
|
||||
{
|
||||
|
||||
typedef etl::add_cv<int>::type t1;
|
||||
typedef std::add_cv<int>::type t2;
|
||||
|
||||
bool pass = std::is_same<t1, t2>::value;
|
||||
//std::is_same<etl::add_cv<int>::type, std::add_cv<int>::type>::value;
|
||||
|
||||
CHECK(pass);
|
||||
CHECK((std::is_same<etl::add_cv<const int>::type, std::add_cv<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_cv<volatile int>::type, std::add_cv<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::add_cv<const volatile int>::type, std::add_cv<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_arithmetic)
|
||||
{
|
||||
CHECK(etl::is_arithmetic<bool>::value == std::is_arithmetic<bool>::value);
|
||||
CHECK(etl::is_arithmetic<char>::value == std::is_arithmetic<char>::value);
|
||||
CHECK(etl::is_arithmetic<signed char>::value == std::is_arithmetic<signed char>::value);
|
||||
CHECK(etl::is_arithmetic<unsigned char>::value == std::is_arithmetic<unsigned char>::value);
|
||||
CHECK(etl::is_arithmetic<wchar_t>::value == std::is_arithmetic<wchar_t>::value);
|
||||
CHECK(etl::is_arithmetic<short>::value == std::is_arithmetic<short>::value);
|
||||
CHECK(etl::is_arithmetic<signed short>::value == std::is_arithmetic<signed short>::value);
|
||||
CHECK(etl::is_arithmetic<unsigned short>::value == std::is_arithmetic<unsigned short>::value);
|
||||
CHECK(etl::is_arithmetic<int>::value == std::is_arithmetic<int>::value);
|
||||
CHECK(etl::is_arithmetic<signed int>::value == std::is_arithmetic<signed int>::value);
|
||||
CHECK(etl::is_arithmetic<unsigned int>::value == std::is_arithmetic<unsigned int>::value);
|
||||
CHECK(etl::is_arithmetic<long>::value == std::is_arithmetic<long>::value);
|
||||
CHECK(etl::is_arithmetic<signed long>::value == std::is_arithmetic<signed long>::value);
|
||||
CHECK(etl::is_arithmetic<unsigned long>::value == std::is_arithmetic<unsigned long>::value);
|
||||
CHECK(etl::is_arithmetic<long long>::value == std::is_arithmetic<long long>::value);
|
||||
CHECK(etl::is_arithmetic<signed long long>::value == std::is_arithmetic<signed long long>::value);
|
||||
CHECK(etl::is_arithmetic<unsigned long long>::value == std::is_arithmetic<unsigned long long>::value);
|
||||
CHECK(etl::is_arithmetic<const int>::value == std::is_arithmetic<const int>::value);
|
||||
CHECK(etl::is_arithmetic<volatile int>::value == std::is_arithmetic<volatile int>::value);
|
||||
CHECK(etl::is_arithmetic<const int>::value == std::is_arithmetic<const int>::value);
|
||||
CHECK(etl::is_arithmetic<const volatile int>::value == std::is_arithmetic<const volatile int>::value);
|
||||
CHECK(etl::is_arithmetic<float>::value == std::is_arithmetic<float>::value);
|
||||
CHECK(etl::is_arithmetic<double>::value == std::is_arithmetic<double>::value);
|
||||
CHECK(etl::is_arithmetic<long double>::value == std::is_arithmetic<long double>::value);
|
||||
CHECK(etl::is_arithmetic<Test>::value == std::is_arithmetic<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_fundamental)
|
||||
{
|
||||
CHECK(etl::is_fundamental<void>::value == std::is_fundamental<void>::value);
|
||||
CHECK(etl::is_fundamental<bool>::value == std::is_fundamental<bool>::value);
|
||||
CHECK(etl::is_fundamental<char>::value == std::is_fundamental<char>::value);
|
||||
CHECK(etl::is_fundamental<signed char>::value == std::is_fundamental<signed char>::value);
|
||||
CHECK(etl::is_fundamental<unsigned char>::value == std::is_fundamental<unsigned char>::value);
|
||||
CHECK(etl::is_fundamental<wchar_t>::value == std::is_fundamental<wchar_t>::value);
|
||||
CHECK(etl::is_fundamental<short>::value == std::is_fundamental<short>::value);
|
||||
CHECK(etl::is_fundamental<signed short>::value == std::is_fundamental<signed short>::value);
|
||||
CHECK(etl::is_fundamental<unsigned short>::value == std::is_fundamental<unsigned short>::value);
|
||||
CHECK(etl::is_fundamental<int>::value == std::is_fundamental<int>::value);
|
||||
CHECK(etl::is_fundamental<signed int>::value == std::is_fundamental<signed int>::value);
|
||||
CHECK(etl::is_fundamental<unsigned int>::value == std::is_fundamental<unsigned int>::value);
|
||||
CHECK(etl::is_fundamental<long>::value == std::is_fundamental<long>::value);
|
||||
CHECK(etl::is_fundamental<signed long>::value == std::is_fundamental<signed long>::value);
|
||||
CHECK(etl::is_fundamental<unsigned long>::value == std::is_fundamental<unsigned long>::value);
|
||||
CHECK(etl::is_fundamental<long long>::value == std::is_fundamental<long long>::value);
|
||||
CHECK(etl::is_fundamental<signed long long>::value == std::is_fundamental<signed long long>::value);
|
||||
CHECK(etl::is_fundamental<unsigned long long>::value == std::is_fundamental<unsigned long long>::value);
|
||||
CHECK(etl::is_fundamental<const int>::value == std::is_fundamental<const int>::value);
|
||||
CHECK(etl::is_fundamental<volatile int>::value == std::is_fundamental<volatile int>::value);
|
||||
CHECK(etl::is_fundamental<const int>::value == std::is_fundamental<const int>::value);
|
||||
CHECK(etl::is_fundamental<const volatile int>::value == std::is_fundamental<const volatile int>::value);
|
||||
CHECK(etl::is_fundamental<float>::value == std::is_fundamental<float>::value);
|
||||
CHECK(etl::is_fundamental<double>::value == std::is_fundamental<double>::value);
|
||||
CHECK(etl::is_fundamental<long double>::value == std::is_fundamental<long double>::value);
|
||||
CHECK(etl::is_fundamental<Test>::value == std::is_fundamental<Test>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(is_void)
|
||||
{
|
||||
CHECK(etl::is_void<int>::value == std::is_void<int>::value);
|
||||
CHECK(etl::is_void<void>::value == std::is_void<void>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(make_signed)
|
||||
{
|
||||
CHECK((std::is_same<etl::make_signed<char>::type, std::make_signed<char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<signed char>::type, std::make_signed<signed char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<unsigned char>::type, std::make_signed<unsigned char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<wchar_t>::type, std::make_signed<wchar_t>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<short>::type, std::make_signed<short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<signed short>::type, std::make_signed<signed short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<unsigned short>::type, std::make_signed<unsigned short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<int>::type, std::make_signed<int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<signed int>::type, std::make_signed<signed int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<unsigned int>::type, std::make_signed<unsigned int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<long>::type, std::make_signed<long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<signed long>::type, std::make_signed<signed long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<unsigned long>::type, std::make_signed<unsigned long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<long long>::type, std::make_signed<long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<signed long long>::type, std::make_signed<signed long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<unsigned long long>::type, std::make_signed<unsigned long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<const int>::type, std::make_signed<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<volatile int>::type, std::make_signed<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<const int>::type, std::make_signed<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_signed<const volatile int>::type, std::make_signed<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(make_unsigned)
|
||||
{
|
||||
CHECK((std::is_same<etl::make_unsigned<char>::type, std::make_unsigned<char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<signed char>::type, std::make_unsigned<signed char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<unsigned char>::type, std::make_unsigned<unsigned char>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<wchar_t>::type, std::make_unsigned<wchar_t>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<short>::type, std::make_unsigned<short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<signed short>::type, std::make_unsigned<signed short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<unsigned short>::type, std::make_unsigned<unsigned short>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<int>::type, std::make_unsigned<int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<signed int>::type, std::make_unsigned<signed int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<unsigned int>::type, std::make_unsigned<unsigned int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<long>::type, std::make_unsigned<long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<signed long>::type, std::make_unsigned<signed long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<unsigned long>::type, std::make_unsigned<unsigned long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<long long>::type, std::make_unsigned<long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<signed long long>::type, std::make_unsigned<signed long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<unsigned long long>::type, std::make_unsigned<unsigned long long>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<const int>::type, std::make_unsigned<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<volatile int>::type, std::make_unsigned<volatile int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<const int>::type, std::make_unsigned<const int>::type>::value));
|
||||
CHECK((std::is_same<etl::make_unsigned<const volatile int>::type, std::make_unsigned<const volatile int>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(extent)
|
||||
{
|
||||
CHECK((std::is_same<etl::extent<int>::type, std::extent<int>::type>::value));
|
||||
CHECK((std::is_same<etl::extent<int[]>::type, std::extent<int[]>::type>::value));
|
||||
CHECK((std::is_same<etl::extent<int[10]>::type, std::extent<int[10]>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_extent)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_extent<int>::type, std::remove_extent<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_extent<int[]>::type, std::remove_extent<int[]>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_extent<int[10]>::type, std::remove_extent<int[10]>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(remove_all_extents)
|
||||
{
|
||||
CHECK((std::is_same<etl::remove_all_extents<int>::type, std::remove_all_extents<int>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_all_extents<int[10]>::type, std::remove_all_extents<int[10]>::type>::value));
|
||||
CHECK((std::is_same<etl::remove_all_extents<int[10][10]>::type, std::remove_all_extents<int[10][10]>::type>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(rank)
|
||||
{
|
||||
CHECK(etl::rank<int>::value == std::rank<int>::value);
|
||||
CHECK(etl::rank<int[10]>::value == std::rank<int[10]>::value);
|
||||
CHECK(etl::rank<int[10][10]>::value == std::rank<int[10][10]>::value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(alignment_of)
|
||||
{
|
||||
struct Test
|
||||
{
|
||||
int a;
|
||||
char b;
|
||||
float c;
|
||||
};
|
||||
|
||||
CHECK_EQUAL(std::alignment_of<char>::value, etl::alignment_of<char>::value);
|
||||
CHECK_EQUAL(std::alignment_of<unsigned char>::value, etl::alignment_of<unsigned char>::value);
|
||||
CHECK_EQUAL(std::alignment_of<short>::value, etl::alignment_of<short>::value);
|
||||
CHECK_EQUAL(std::alignment_of<unsigned short>::value, etl::alignment_of<unsigned short>::value);
|
||||
CHECK_EQUAL(std::alignment_of<int>::value, etl::alignment_of<int>::value);
|
||||
CHECK_EQUAL(std::alignment_of<unsigned int>::value, etl::alignment_of<unsigned int>::value);
|
||||
CHECK_EQUAL(std::alignment_of<long>::value, etl::alignment_of<long>::value);
|
||||
CHECK_EQUAL(std::alignment_of<unsigned long>::value, etl::alignment_of<unsigned long>::value);
|
||||
CHECK_EQUAL(std::alignment_of<long long>::value, etl::alignment_of<long long>::value);
|
||||
CHECK_EQUAL(std::alignment_of<unsigned long long>::value, etl::alignment_of<unsigned long long>::value);
|
||||
CHECK_EQUAL(std::alignment_of<float>::value, etl::alignment_of<float>::value);
|
||||
CHECK_EQUAL(std::alignment_of<double>::value, etl::alignment_of<double>::value);
|
||||
CHECK_EQUAL(std::alignment_of<Test>::value, etl::alignment_of<Test>::value);
|
||||
}
|
||||
};
|
||||
}
|
||||
831
test/test_vector.cpp
Normal file
831
test/test_vector.cpp
Normal file
@ -0,0 +1,831 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../vector.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestVector)
|
||||
{
|
||||
static const size_t SIZE = 10;
|
||||
|
||||
typedef etl::vector<int, SIZE> Data;
|
||||
typedef std::vector<int> TestData;
|
||||
|
||||
TestData initial_data;
|
||||
TestData less_data;
|
||||
TestData greater_data;
|
||||
TestData shorter_data;
|
||||
TestData different_data;
|
||||
|
||||
//*************************************************************************
|
||||
struct SetupFixture
|
||||
{
|
||||
SetupFixture()
|
||||
{
|
||||
int n[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
int n_less[] = { 0, 1, 2, 3, 3, 5, 6, 7, 8, 9 };
|
||||
int n_greater[] = { 0, 1, 2, 4, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
initial_data.assign(std::begin(n), std::end(n));
|
||||
less_data.assign(std::begin(n_less), std::end(n_less));
|
||||
greater_data.assign(std::begin(n_greater), std::end(n_greater));
|
||||
shorter_data.assign(std::begin(n_greater), std::end(n_greater) - 1);
|
||||
different_data.assign(initial_data.rbegin(), initial_data.rend());
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, DefaultConstructor)
|
||||
{
|
||||
Data data;
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
CHECK(data.empty());
|
||||
CHECK_EQUAL(data.capacity(), SIZE);
|
||||
CHECK_EQUAL(data.max_size(), SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ConstructorSize)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
Data data(INITIAL_SIZE);
|
||||
|
||||
CHECK(data.size() == INITIAL_SIZE);
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ConstructorSizeValue)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const int INITIAL_VALUE = 1;
|
||||
|
||||
std::array<int, INITIAL_SIZE> testData;
|
||||
testData.fill(INITIAL_VALUE);
|
||||
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
CHECK(data.size() == INITIAL_SIZE);
|
||||
CHECK(!data.empty());
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ConstructorRange)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
CHECK(data.size() == SIZE);
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Iterator)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ConstIterator)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
bool isEqual = std::equal(data.cbegin(),
|
||||
data.cend(),
|
||||
testData.cbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ReverseIterator)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
bool isEqual = std::equal(data.rbegin(),
|
||||
data.rend(),
|
||||
testData.rbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ConstReverseIterator)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
bool isEqual = std::equal(data.crbegin(),
|
||||
data.crend(),
|
||||
testData.crbegin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ResizeUp)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
|
||||
Data data(INITIAL_SIZE);
|
||||
data.resize(NEW_SIZE);
|
||||
|
||||
CHECK_EQUAL(data.size(), NEW_SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ResizeUpValue)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 8;
|
||||
const int INITIAL_VALUE = 1;
|
||||
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
data.resize(NEW_SIZE, INITIAL_VALUE);
|
||||
|
||||
std::array<int, NEW_SIZE> testData;
|
||||
testData.fill(INITIAL_VALUE);
|
||||
|
||||
bool isEqual = std::equal(data.begin(), data.end(), testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ResizeExcess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = SIZE + 1;
|
||||
|
||||
Data data(INITIAL_SIZE);
|
||||
|
||||
CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, ResizeDown)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t NEW_SIZE = 2;
|
||||
|
||||
Data data(INITIAL_SIZE);
|
||||
data.resize(NEW_SIZE);
|
||||
|
||||
CHECK_EQUAL(data.size(), NEW_SIZE);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Indexing)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(data[i], testData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, IndexingConst)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
const Data data(testData.begin(), testData.end());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(data[i], testData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Clear)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data(testData.begin(), testData.end());
|
||||
data.clear();
|
||||
|
||||
CHECK_EQUAL(data.size(), size_t(0));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, AssignRange)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
|
||||
Data data;
|
||||
|
||||
data.assign(testData.begin(), testData.end());
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, AssignSizeValue)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const int INITIAL_VALUE = 1;
|
||||
std::array<int, INITIAL_SIZE> testData;
|
||||
testData.fill(INITIAL_VALUE);
|
||||
|
||||
Data data;
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, AssignSizeValueExcess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = SIZE;
|
||||
const size_t EXCESS_SIZE = SIZE + 1;
|
||||
const int INITIAL_VALUE = 1;
|
||||
std::array<int, INITIAL_SIZE> testData;
|
||||
testData.fill(INITIAL_VALUE);
|
||||
|
||||
Data data;
|
||||
|
||||
CHECK_THROW(data.assign(EXCESS_SIZE, INITIAL_VALUE), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionValue)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const int INITIAL_VALUE = 1;
|
||||
const int INSERT_VALUE = 2;
|
||||
|
||||
TestData testData(INITIAL_SIZE, INITIAL_VALUE);
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
data.insert(data.begin() + offset, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INITIAL_VALUE);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
offset = 0;
|
||||
|
||||
data.insert(data.begin() + offset, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INITIAL_VALUE);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
offset = data.size();
|
||||
|
||||
data.insert(data.begin() + offset, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INITIAL_VALUE);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionValueExcess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = SIZE;
|
||||
const int INITIAL_VALUE = 1;
|
||||
const int INSERT_VALUE = 2;
|
||||
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full_exception);
|
||||
|
||||
offset = 0;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full_exception);
|
||||
|
||||
offset = data.size();
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionNValue)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const size_t INSERT_SIZE = 3;
|
||||
const int INITIAL_VALUE = 1;
|
||||
const int INSERT_VALUE = 2;
|
||||
|
||||
TestData testData;
|
||||
Data data;
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
offset = 0;
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
offset = data.size();
|
||||
data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
testData.insert(testData.begin() + offset, INSERT_SIZE, INITIAL_VALUE);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionNValueExcess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = SIZE;
|
||||
const size_t INSERT_SIZE = 4;
|
||||
const int INITIAL_VALUE = 1;
|
||||
const int INSERT_VALUE = 2;
|
||||
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full_exception);
|
||||
|
||||
offset = 0;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full_exception);
|
||||
|
||||
offset = data.size();
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionRange)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const int INITIAL_VALUE = 1;
|
||||
|
||||
TestData testData;
|
||||
Data data;
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
data.insert(data.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
testData.insert(testData.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
offset = 0;
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
data.insert(data.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
testData.insert(testData.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
|
||||
data.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
testData.assign(INITIAL_SIZE, INITIAL_VALUE);
|
||||
offset = data.size();
|
||||
data.insert(data.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
testData.insert(testData.begin() + offset, initial_data.begin(), initial_data.begin() + 3);
|
||||
|
||||
isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, InsertPositionRangeExcess)
|
||||
{
|
||||
const size_t INITIAL_SIZE = 5;
|
||||
const int INITIAL_VALUE = 1;
|
||||
|
||||
Data data(INITIAL_SIZE, INITIAL_VALUE);
|
||||
|
||||
size_t offset = 2;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full_exception);
|
||||
|
||||
offset = 0;
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full_exception);
|
||||
|
||||
offset = data.size();
|
||||
|
||||
CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, PushBack)
|
||||
{
|
||||
TestData testData;
|
||||
Data data;
|
||||
|
||||
for (size_t i = 0; i < SIZE; ++i)
|
||||
{
|
||||
testData.push_back(i);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < SIZE; ++i)
|
||||
{
|
||||
data.push_back(i);
|
||||
}
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, PushBackNull)
|
||||
{
|
||||
TestData testData;
|
||||
Data data;
|
||||
|
||||
testData.push_back(1);
|
||||
|
||||
data.push_back();
|
||||
data[0] = 1;
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, PushBackExcess)
|
||||
{
|
||||
Data data;
|
||||
|
||||
for (size_t i = 0; i < SIZE; ++i)
|
||||
{
|
||||
data.push_back(i);
|
||||
}
|
||||
|
||||
CHECK_THROW(data.push_back(SIZE), etl::vector_full_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, PopBack)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
testData.pop_back();
|
||||
testData.pop_back();
|
||||
|
||||
data.pop_back();
|
||||
data.pop_back();
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, EraseSingle)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
testData.erase(testData.begin() + 2);
|
||||
|
||||
data.erase(data.begin() + 2);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, EraseRange)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
testData.erase(testData.begin() + 2, testData.begin() + 4);
|
||||
|
||||
data.erase(data.begin() + 2, data.begin() + 4);
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
testData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Front)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(data.front()== testData.front());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Back)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(data.back() == testData.back());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Assignment)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
Data otherData;
|
||||
|
||||
otherData = data;
|
||||
|
||||
bool isEqual = std::equal(data.begin(),
|
||||
data.end(),
|
||||
otherData.begin());
|
||||
|
||||
CHECK(isEqual);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, At)
|
||||
{
|
||||
TestData testData(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, AtConst)
|
||||
{
|
||||
const TestData testData(initial_data.begin(), initial_data.end());
|
||||
const Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
for (size_t i = 0; i < data.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(data.at(i), testData.at(i));
|
||||
}
|
||||
|
||||
CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds_exception);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Full)
|
||||
{
|
||||
Data data;
|
||||
data.resize(data.max_size());
|
||||
|
||||
CHECK(data.full());
|
||||
CHECK(!data.empty());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Begin)
|
||||
{
|
||||
Data data(10);
|
||||
const Data constData(10);
|
||||
|
||||
CHECK_EQUAL(data.begin(), std::begin(data));
|
||||
CHECK_EQUAL(constData.begin(), std::begin(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, End)
|
||||
{
|
||||
Data data(10);
|
||||
const Data constData(10);
|
||||
|
||||
CHECK_EQUAL(data.end(), std::end(data));
|
||||
CHECK_EQUAL(constData.end(), std::end(constData));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, Equal)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(initial1 == initial2);
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(!(initial1 == different));
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK(!(shorter == initial1));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, NotEqual)
|
||||
{
|
||||
const Data initial1(initial_data.begin(), initial_data.end());
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK(!(initial1 != initial2));
|
||||
|
||||
const Data different(different_data.begin(), different_data.end());
|
||||
|
||||
CHECK(initial1 != different);
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK(shorter != initial1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, LessThan)
|
||||
{
|
||||
const Data less(less_data.begin(), less_data.end());
|
||||
const Data initial(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK((less < initial) == (less_data < initial_data));
|
||||
|
||||
const Data greater(greater_data.begin(), greater_data.end());
|
||||
|
||||
CHECK((greater < initial) == (greater_data < initial_data));
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK((shorter < initial) == (shorter_data < initial_data));
|
||||
CHECK((initial < shorter) == (initial_data < shorter_data));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, LessThanEqual)
|
||||
{
|
||||
const Data less(less_data.begin(), less_data.end());
|
||||
const Data initial(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK((less <= initial) == (less_data <= initial_data));
|
||||
|
||||
const Data greater(greater_data.begin(), greater_data.end());
|
||||
|
||||
CHECK((greater <= initial) == (greater_data <= initial_data));
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK((shorter <= initial) == (shorter_data <= initial_data));
|
||||
CHECK((initial <= shorter) == (initial_data <= shorter_data));
|
||||
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
CHECK((initial <= initial2) == (initial_data <= initial_data));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, GreaterThan)
|
||||
{
|
||||
const Data less(less_data.begin(), less_data.end());
|
||||
const Data initial(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK((less > initial) == (less_data > initial_data));
|
||||
|
||||
const Data greater(greater_data.begin(), greater_data.end());
|
||||
|
||||
CHECK((greater > initial) == (greater_data > initial_data));
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK((shorter > initial) == (shorter_data > initial_data));
|
||||
CHECK((initial > shorter) == (initial_data > shorter_data));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, GreaterThanEqual)
|
||||
{
|
||||
const Data less(less_data.begin(), less_data.end());
|
||||
const Data initial(initial_data.begin(), initial_data.end());
|
||||
|
||||
CHECK((less >= initial) == (less_data >= initial_data));
|
||||
|
||||
const Data greater(greater_data.begin(), greater_data.end());
|
||||
|
||||
CHECK((greater >= initial) == (greater_data >= initial_data));
|
||||
|
||||
const Data shorter(shorter_data.begin(), shorter_data.end());
|
||||
|
||||
CHECK((shorter >= initial) == (shorter_data >= initial_data));
|
||||
CHECK((initial >= shorter) == (initial_data > shorter_data));
|
||||
|
||||
const Data initial2(initial_data.begin(), initial_data.end());
|
||||
CHECK((initial >= initial2) == (initial_data >= initial_data));
|
||||
}
|
||||
};
|
||||
}
|
||||
719
test/test_visitor.cpp
Normal file
719
test/test_visitor.cpp
Normal file
@ -0,0 +1,719 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
|
||||
Copyright(c) 2014 jwellbelove
|
||||
|
||||
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 <UnitTest++/UnitTest++.h>
|
||||
|
||||
#include "../visitor.h"
|
||||
|
||||
//*****************************************************************************
|
||||
// Pre-declare the data types.
|
||||
//*****************************************************************************
|
||||
class Square;
|
||||
class Circle;
|
||||
class Triangle;
|
||||
|
||||
//*****************************************************************************
|
||||
// What classes do you want the visitors to handle?
|
||||
// Square will be passed by reference.
|
||||
// Circle will be passed by reference.
|
||||
// Triangle will be passed by const reference.
|
||||
//*****************************************************************************
|
||||
typedef etl::visitor<Square, Circle, const Triangle> DrawVisitorType;
|
||||
|
||||
//*****************************************************************************
|
||||
// What classes do you want the visitors to handle?
|
||||
// Square will be passed by reference.
|
||||
// Triangle will be passed by const reference.
|
||||
//*****************************************************************************
|
||||
typedef etl::visitor<Square, const Triangle> LogVisitorType;
|
||||
|
||||
//*****************************************************************************
|
||||
// Square accepts draw & log visitors.
|
||||
//*****************************************************************************
|
||||
class Square : public etl::visitable<DrawVisitorType, LogVisitorType>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(DrawVisitorType& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
void accept(LogVisitorType& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Circle only accepts draw visitors.
|
||||
//*****************************************************************************
|
||||
class Circle : public etl::visitable<DrawVisitorType>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(DrawVisitorType& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Triangle accepts draw & log visitors.
|
||||
//*****************************************************************************
|
||||
class Triangle : public etl::visitable<DrawVisitorType, LogVisitorType>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(DrawVisitorType& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
void accept(LogVisitorType& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// Generic other shapes.
|
||||
//*****************************************************************************
|
||||
template <const int ID, typename TVisitor>
|
||||
class Shape : public etl::visitable<TVisitor>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(TVisitor& visitor)
|
||||
{
|
||||
visitor.visit(*this);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class DrawVisitor : public DrawVisitorType
|
||||
{
|
||||
public:
|
||||
|
||||
DrawVisitor()
|
||||
: square_called(false),
|
||||
circle_called(false),
|
||||
triangle_called(false)
|
||||
{
|
||||
}
|
||||
|
||||
void visit(Square&)
|
||||
{
|
||||
square_called = true;
|
||||
}
|
||||
|
||||
void visit(Circle&)
|
||||
{
|
||||
circle_called = true;
|
||||
}
|
||||
|
||||
void visit(const Triangle&)
|
||||
{
|
||||
triangle_called = true;
|
||||
}
|
||||
|
||||
bool square_called;
|
||||
bool circle_called;
|
||||
bool triangle_called;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
class LogVisitor : public LogVisitorType
|
||||
{
|
||||
public:
|
||||
|
||||
LogVisitor()
|
||||
: square_called(false),
|
||||
circle_called(false),
|
||||
triangle_called(false)
|
||||
{
|
||||
}
|
||||
|
||||
void visit(Square&)
|
||||
{
|
||||
square_called = true;
|
||||
}
|
||||
|
||||
// SHOULD NEVER BE CALLED.
|
||||
void visit(Circle&)
|
||||
{
|
||||
circle_called = true;
|
||||
}
|
||||
|
||||
void visit(const Triangle&)
|
||||
{
|
||||
triangle_called = true;
|
||||
}
|
||||
|
||||
bool square_called;
|
||||
bool circle_called;
|
||||
bool triangle_called;
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
SUITE(TestVisitor)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(TestTwoVisitorsThreeVisitables)
|
||||
{
|
||||
DrawVisitor draw_visitor;
|
||||
LogVisitor log_visitor;
|
||||
|
||||
Square square;
|
||||
Circle circle;
|
||||
Triangle triangle;
|
||||
|
||||
CHECK_EQUAL(false, draw_visitor.square_called);
|
||||
CHECK_EQUAL(false, draw_visitor.circle_called);
|
||||
CHECK_EQUAL(false, draw_visitor.triangle_called);
|
||||
CHECK_EQUAL(false, log_visitor.square_called);
|
||||
CHECK_EQUAL(false, log_visitor.circle_called);
|
||||
CHECK_EQUAL(false, log_visitor.triangle_called);
|
||||
|
||||
square.accept(draw_visitor);
|
||||
square.accept(log_visitor);
|
||||
|
||||
CHECK_EQUAL(true, draw_visitor.square_called);
|
||||
CHECK_EQUAL(false, draw_visitor.circle_called);
|
||||
CHECK_EQUAL(false, draw_visitor.triangle_called);
|
||||
CHECK_EQUAL(true, log_visitor.square_called);
|
||||
CHECK_EQUAL(false, log_visitor.circle_called);
|
||||
CHECK_EQUAL(false, log_visitor.triangle_called);
|
||||
|
||||
circle.accept(draw_visitor);
|
||||
|
||||
CHECK_EQUAL(true, draw_visitor.square_called);
|
||||
CHECK_EQUAL(true, draw_visitor.circle_called);
|
||||
CHECK_EQUAL(false, draw_visitor.triangle_called);
|
||||
CHECK_EQUAL(true, log_visitor.square_called);
|
||||
CHECK_EQUAL(false, log_visitor.circle_called);
|
||||
CHECK_EQUAL(false, log_visitor.triangle_called);
|
||||
|
||||
triangle.accept(draw_visitor);
|
||||
triangle.accept(log_visitor);
|
||||
|
||||
CHECK_EQUAL(true, draw_visitor.square_called);
|
||||
CHECK_EQUAL(true, draw_visitor.circle_called);
|
||||
CHECK_EQUAL(true, draw_visitor.triangle_called);
|
||||
CHECK_EQUAL(true, log_visitor.square_called);
|
||||
CHECK_EQUAL(false, log_visitor.circle_called);
|
||||
CHECK_EQUAL(true, log_visitor.triangle_called);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test1Visitor)
|
||||
{
|
||||
class AShape;
|
||||
class ShapeVisitor1 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class AShape : public etl::visitable<ShapeVisitor1>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(ShapeVisitor1&) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test2Visitor)
|
||||
{
|
||||
class AShape;
|
||||
class ShapeVisitor1 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor2 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class AShape : public etl::visitable<ShapeVisitor1, ShapeVisitor2>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(ShapeVisitor1&) {}
|
||||
void accept(ShapeVisitor2&) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test3Visitor)
|
||||
{
|
||||
class AShape;
|
||||
class ShapeVisitor1 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor2 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor3 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class AShape : public etl::visitable<ShapeVisitor1, ShapeVisitor2, ShapeVisitor3>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(ShapeVisitor1&) {}
|
||||
void accept(ShapeVisitor2&) {}
|
||||
void accept(ShapeVisitor3&) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test4Visitor)
|
||||
{
|
||||
class AShape;
|
||||
class ShapeVisitor1 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor2 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor3 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class ShapeVisitor4 : public etl::visitor<AShape&>
|
||||
{
|
||||
void visit(AShape&) {}
|
||||
};
|
||||
|
||||
class AShape : public etl::visitable<ShapeVisitor1, ShapeVisitor2, ShapeVisitor3, ShapeVisitor4>
|
||||
{
|
||||
public:
|
||||
|
||||
void accept(ShapeVisitor1&) {}
|
||||
void accept(ShapeVisitor2&) {}
|
||||
void accept(ShapeVisitor3&) {}
|
||||
void accept(ShapeVisitor4&) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test1Visitable)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test2Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test3Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test4Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test5Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test6Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test7Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test8Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test9Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test10Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test11Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test12Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor>, Shape<12, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
void visit(Shape<12, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test13Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor>, Shape<12, ShapeVisitor>,
|
||||
Shape<13, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
void visit(Shape<12, ShapeVisitor>) {}
|
||||
void visit(Shape<13, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test14Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor>, Shape<12, ShapeVisitor>,
|
||||
Shape<13, ShapeVisitor>, Shape<14, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
void visit(Shape<12, ShapeVisitor>) {}
|
||||
void visit(Shape<13, ShapeVisitor>) {}
|
||||
void visit(Shape<14, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test15Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor>, Shape<12, ShapeVisitor>,
|
||||
Shape<13, ShapeVisitor>, Shape<14, ShapeVisitor>, Shape<15, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
void visit(Shape<12, ShapeVisitor>) {}
|
||||
void visit(Shape<13, ShapeVisitor>) {}
|
||||
void visit(Shape<14, ShapeVisitor>) {}
|
||||
void visit(Shape<15, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(Test16Visitables)
|
||||
{
|
||||
class ShapeVisitor : public etl::visitor <Shape<1, ShapeVisitor>, Shape<2, ShapeVisitor>, Shape<3, ShapeVisitor>, Shape<4, ShapeVisitor>,
|
||||
Shape<5, ShapeVisitor>, Shape<6, ShapeVisitor>, Shape<7, ShapeVisitor>, Shape<8, ShapeVisitor>,
|
||||
Shape<9, ShapeVisitor>, Shape<10, ShapeVisitor>, Shape<11, ShapeVisitor>, Shape<12, ShapeVisitor>,
|
||||
Shape<13, ShapeVisitor>, Shape<14, ShapeVisitor>, Shape<15, ShapeVisitor>, Shape<16, ShapeVisitor> >
|
||||
{
|
||||
public:
|
||||
|
||||
void visit(Shape<1, ShapeVisitor>) {}
|
||||
void visit(Shape<2, ShapeVisitor>) {}
|
||||
void visit(Shape<3, ShapeVisitor>) {}
|
||||
void visit(Shape<4, ShapeVisitor>) {}
|
||||
void visit(Shape<5, ShapeVisitor>) {}
|
||||
void visit(Shape<6, ShapeVisitor>) {}
|
||||
void visit(Shape<7, ShapeVisitor>) {}
|
||||
void visit(Shape<8, ShapeVisitor>) {}
|
||||
void visit(Shape<9, ShapeVisitor>) {}
|
||||
void visit(Shape<10, ShapeVisitor>) {}
|
||||
void visit(Shape<11, ShapeVisitor>) {}
|
||||
void visit(Shape<12, ShapeVisitor>) {}
|
||||
void visit(Shape<13, ShapeVisitor>) {}
|
||||
void visit(Shape<14, ShapeVisitor>) {}
|
||||
void visit(Shape<15, ShapeVisitor>) {}
|
||||
void visit(Shape<16, ShapeVisitor>) {}
|
||||
};
|
||||
|
||||
// This test just needs to compile without errors.
|
||||
CHECK(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user