[DEV] finish Array ==> need to validate coverage
This commit is contained in:
parent
8ce4e3dfe3
commit
a2e20519f0
@ -230,9 +230,9 @@ namespace etk {
|
||||
return m_array->get(m_current);
|
||||
}
|
||||
private:
|
||||
Iterator(const Array<ETK_ARRAY_TYPE> * _obj, int32_t _pos):
|
||||
Iterator(const Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE> * _obj, int32_t _pos):
|
||||
m_current(_pos),
|
||||
m_array(const_cast<Array<ETK_ARRAY_TYPE> *>(_obj)) {
|
||||
m_array(const_cast<Array<ETK_ARRAY_TYPE, ETK_ARRAY_SIZE> *>(_obj)) {
|
||||
// nothing to do ...
|
||||
}
|
||||
size_t getCurrent() const {
|
||||
@ -241,7 +241,8 @@ namespace etk {
|
||||
friend class Array;
|
||||
};
|
||||
private:
|
||||
ETK_ARRAY_TYPE m_data[ETK_ARRAY_SIZE]; //!< pointer on the current table of Data (static allocated ==> can not change)
|
||||
uint8_t m_rawData[ETK_ARRAY_SIZE*sizeof(ETK_ARRAY_TYPE)]; //!< pointer on the current table of Data (static allocated ==> can not change)
|
||||
ETK_ARRAY_TYPE* m_data = (ETK_ARRAY_TYPE*)m_rawData; //!< pointer on the current table of Data (static allocated ==> can not change)
|
||||
size_t m_size = 0; //!< Number of element in the buffer
|
||||
const size_t m_allocated = ETK_ARRAY_SIZE; //!< Current allocated size
|
||||
public:
|
||||
|
@ -27,6 +27,7 @@ def get_maintainer():
|
||||
def configure(target, my_module):
|
||||
my_module.add_src_file([
|
||||
'test/main.cpp',
|
||||
'test/ConstructDestruct.cpp',
|
||||
'test/testColor.cpp',
|
||||
'test/testFunction.cpp',
|
||||
'test/testMapUnordered.cpp',
|
||||
|
57
test/ConstructDestruct.cpp
Normal file
57
test/ConstructDestruct.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include <test-debug/debug.hpp>
|
||||
#include "ConstructDestruct.hpp"
|
||||
|
||||
static int32_t isDestroy = 0;
|
||||
|
||||
test::ConstructDestruct::ConstructDestruct(uint32_t _addValue):
|
||||
m_addValue(_addValue) {
|
||||
isDestroy += m_addValue;
|
||||
TEST_DEBUG("Create class " << m_addValue << " isDestroy=" << isDestroy);
|
||||
}
|
||||
|
||||
test::ConstructDestruct::ConstructDestruct(test::ConstructDestruct&& _obj):
|
||||
m_addValue(_obj.m_addValue) {
|
||||
_obj.m_addValue = 0;
|
||||
TEST_DEBUG("move contruction " << m_addValue << " isDestroy=" << isDestroy);
|
||||
}
|
||||
|
||||
test::ConstructDestruct::ConstructDestruct(const test::ConstructDestruct& _obj):
|
||||
m_addValue(_obj.m_addValue) {
|
||||
isDestroy += m_addValue;
|
||||
TEST_DEBUG("copy contruction " << m_addValue << " isDestroy=" << isDestroy);
|
||||
}
|
||||
|
||||
test::ConstructDestruct::~ConstructDestruct() {
|
||||
if (m_addValue == 0) {
|
||||
TEST_DEBUG("Remove class (after move)" << " isDestroy=" << isDestroy);
|
||||
return;
|
||||
}
|
||||
isDestroy -= m_addValue;
|
||||
TEST_DEBUG("Remove Class " << m_addValue << " isDestroy=" << isDestroy);
|
||||
}
|
||||
|
||||
test::ConstructDestruct& test::ConstructDestruct::operator= (test::ConstructDestruct&& _obj) {
|
||||
TEST_DEBUG("move operator " << m_addValue << " isDestroy=" << isDestroy);
|
||||
if (this != &_obj) {
|
||||
etk::swap(m_addValue, _obj.m_addValue);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
test::ConstructDestruct& test::ConstructDestruct::operator= (const test::ConstructDestruct& _obj) {
|
||||
TEST_DEBUG("opr operator " << m_addValue << " isDestroy=" << isDestroy);
|
||||
if (this != &_obj) {
|
||||
m_addValue = _obj.m_addValue;
|
||||
isDestroy += m_addValue;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int32_t test::getIsDestroy() {
|
||||
return isDestroy;
|
||||
}
|
||||
|
||||
void test::resetIsDestroy() {
|
||||
isDestroy = 0;
|
||||
}
|
||||
|
25
test/ConstructDestruct.hpp
Normal file
25
test/ConstructDestruct.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL-2 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
|
||||
namespace test {
|
||||
|
||||
class ConstructDestruct {
|
||||
private:
|
||||
uint32_t m_addValue;
|
||||
public:
|
||||
ConstructDestruct(uint32_t _addValue);
|
||||
ConstructDestruct(ConstructDestruct&& _obj);
|
||||
ConstructDestruct(const ConstructDestruct& _obj);
|
||||
virtual ~ConstructDestruct();
|
||||
ConstructDestruct& operator= (ConstructDestruct&& _obj);
|
||||
ConstructDestruct& operator= (const ConstructDestruct& _obj);
|
||||
};
|
||||
int32_t getIsDestroy();
|
||||
void resetIsDestroy();
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
#include <etk/Array.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etest/etest.hpp>
|
||||
#include "ConstructDestruct.hpp"
|
||||
|
||||
TEST(TestArray, constructor) {
|
||||
// Test contructor value
|
||||
@ -193,83 +194,49 @@ TEST(TestArray, initializationList_2) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint32_t isDestroy = 0;
|
||||
|
||||
class testContructDestruct {
|
||||
private:
|
||||
uint32_t m_addValue;
|
||||
public:
|
||||
testContructDestruct(uint32_t _addValue):
|
||||
m_addValue(_addValue) {
|
||||
isDestroy += m_addValue;
|
||||
TEST_DEBUG("Create class " << m_addValue);
|
||||
}
|
||||
testContructDestruct(testContructDestruct&& _obj):
|
||||
m_addValue(_obj.m_addValue) {
|
||||
_obj.m_addValue = 0;
|
||||
TEST_DEBUG("move contruction " << m_addValue);
|
||||
}
|
||||
virtual ~testContructDestruct() {
|
||||
if (m_addValue == 0) {
|
||||
TEST_DEBUG("Remove class (after move)");
|
||||
return;
|
||||
}
|
||||
TEST_DEBUG("Remove Class " << m_addValue);
|
||||
isDestroy -= m_addValue;
|
||||
}
|
||||
testContructDestruct& operator= (testContructDestruct&& _obj) {
|
||||
TEST_DEBUG("move operator " << m_addValue);
|
||||
if (this != &_obj) {
|
||||
etk::swap(m_addValue, _obj.m_addValue);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(TestArray, destroyElementAtTheCorectMoment) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Array<testContructDestruct, 20> list;
|
||||
list.pushBack(testContructDestruct(55));
|
||||
etk::Array<test::ConstructDestruct, 20> list;
|
||||
list.pushBack(test::ConstructDestruct(55));
|
||||
EXPECT_EQ(list.size(), 1);
|
||||
EXPECT_EQ(isDestroy, 55);
|
||||
EXPECT_EQ(test::getIsDestroy(), 55);
|
||||
auto it = list.erase(list.begin());
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
EXPECT_EQ(list.size(), 0);
|
||||
EXPECT_EQ(it, list.end());
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
|
||||
TEST(TestArray, destroyElementAtTheCorectMoment_2) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Array<testContructDestruct, 20> list;
|
||||
list.pushBack(testContructDestruct(4));
|
||||
list.pushBack(testContructDestruct(30));
|
||||
list.pushBack(testContructDestruct(1000));
|
||||
list.pushBack(testContructDestruct(200));
|
||||
etk::Array<test::ConstructDestruct, 20> list;
|
||||
list.pushBack(test::ConstructDestruct(4));
|
||||
list.pushBack(test::ConstructDestruct(30));
|
||||
list.pushBack(test::ConstructDestruct(1000));
|
||||
list.pushBack(test::ConstructDestruct(200));
|
||||
EXPECT_EQ(list.size(), 4);
|
||||
EXPECT_EQ(isDestroy, 1234);
|
||||
EXPECT_EQ(test::getIsDestroy(), 1234);
|
||||
auto it = list.erase(list.begin());
|
||||
EXPECT_EQ(list.size(), 3);
|
||||
EXPECT_EQ(isDestroy, 1230);
|
||||
EXPECT_EQ(test::getIsDestroy(), 1230);
|
||||
it = list.erase(list.begin()+1);
|
||||
EXPECT_EQ(isDestroy, 230);
|
||||
EXPECT_EQ(test::getIsDestroy(), 230);
|
||||
EXPECT_EQ(list.size(), 2);
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
|
||||
TEST(TestArray, allocateElementAtTheCorectMoment) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Array<testContructDestruct, 20> list;
|
||||
etk::Array<test::ConstructDestruct, 20> list;
|
||||
EXPECT_EQ(list.size(), 0);
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
/*
|
||||
TEST(TestArray, allocateBench) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <etk/Vector.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etest/etest.hpp>
|
||||
#include "ConstructDestruct.hpp"
|
||||
|
||||
TEST(TestVector, constructor) {
|
||||
// Test contructor value
|
||||
@ -193,84 +194,50 @@ TEST(TestVector, initializationList_2) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint32_t isDestroy = 0;
|
||||
|
||||
class testContructDestruct {
|
||||
private:
|
||||
uint32_t m_addValue;
|
||||
public:
|
||||
testContructDestruct(uint32_t _addValue):
|
||||
m_addValue(_addValue) {
|
||||
isDestroy += m_addValue;
|
||||
TEST_DEBUG("Create class " << m_addValue);
|
||||
}
|
||||
testContructDestruct(testContructDestruct&& _obj):
|
||||
m_addValue(_obj.m_addValue) {
|
||||
_obj.m_addValue = 0;
|
||||
TEST_DEBUG("move contruction " << m_addValue);
|
||||
}
|
||||
virtual ~testContructDestruct() {
|
||||
if (m_addValue == 0) {
|
||||
TEST_DEBUG("Remove class (after move)");
|
||||
return;
|
||||
}
|
||||
TEST_DEBUG("Remove Class " << m_addValue);
|
||||
isDestroy -= m_addValue;
|
||||
}
|
||||
testContructDestruct& operator= (testContructDestruct&& _obj) {
|
||||
TEST_DEBUG("move operator " << m_addValue);
|
||||
if (this != &_obj) {
|
||||
etk::swap(m_addValue, _obj.m_addValue);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
TEST(TestVector, destroyElementAtTheCorectMoment) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Vector<testContructDestruct> list;
|
||||
list.pushBack(testContructDestruct(55));
|
||||
etk::Vector<test::ConstructDestruct> list;
|
||||
list.pushBack(test::ConstructDestruct(55));
|
||||
EXPECT_EQ(list.size(), 1);
|
||||
EXPECT_EQ(isDestroy, 55);
|
||||
EXPECT_EQ(test::getIsDestroy(), 55);
|
||||
auto it = list.erase(list.begin());
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
EXPECT_EQ(list.size(), 0);
|
||||
EXPECT_EQ(it, list.end());
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
|
||||
TEST(TestVector, destroyElementAtTheCorectMoment_2) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Vector<testContructDestruct> list;
|
||||
list.pushBack(testContructDestruct(4));
|
||||
list.pushBack(testContructDestruct(30));
|
||||
list.pushBack(testContructDestruct(1000));
|
||||
list.pushBack(testContructDestruct(200));
|
||||
etk::Vector<test::ConstructDestruct> list;
|
||||
list.pushBack(test::ConstructDestruct(4));
|
||||
list.pushBack(test::ConstructDestruct(30));
|
||||
list.pushBack(test::ConstructDestruct(1000));
|
||||
list.pushBack(test::ConstructDestruct(200));
|
||||
EXPECT_EQ(list.size(), 4);
|
||||
EXPECT_EQ(isDestroy, 1234);
|
||||
EXPECT_EQ(test::getIsDestroy(), 1234);
|
||||
auto it = list.erase(list.begin());
|
||||
EXPECT_EQ(list.size(), 3);
|
||||
EXPECT_EQ(isDestroy, 1230);
|
||||
EXPECT_EQ(test::getIsDestroy(), 1230);
|
||||
it = list.erase(list.begin()+1);
|
||||
EXPECT_EQ(isDestroy, 230);
|
||||
EXPECT_EQ(test::getIsDestroy(), 230);
|
||||
EXPECT_EQ(list.size(), 2);
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
|
||||
TEST(TestVector, allocateElementAtTheCorectMoment) {
|
||||
isDestroy = 0;
|
||||
test::resetIsDestroy();
|
||||
{
|
||||
etk::Vector<testContructDestruct> list;
|
||||
etk::Vector<test::ConstructDestruct> list;
|
||||
list.reserve(10);
|
||||
EXPECT_EQ(list.size(), 0);
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
EXPECT_EQ(isDestroy, 0);
|
||||
EXPECT_EQ(test::getIsDestroy(), 0);
|
||||
}
|
||||
/*
|
||||
TEST(TestVector, allocateBench) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <etk/math/Vector2D.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include <etest/etest.hpp>
|
||||
#include "ConstructDestruct.hpp"
|
||||
|
||||
TEST(TestVector2D_f, constructor) {
|
||||
// Test contructor value
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <etest/etest.hpp>
|
||||
#include <etk/math/Vector3D.hpp>
|
||||
#include <test-debug/debug.hpp>
|
||||
#include "ConstructDestruct.hpp"
|
||||
|
||||
#define NAME "etk:Vector3D<float>"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user