From a2e20519f0161efc8656515de67c9b3f9cc8c95b Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 19 Jun 2018 07:16:00 +0200 Subject: [PATCH] [DEV] finish Array ==> need to validate coverage --- etk/Array.hpp | 7 ++-- lutin_etk-test.py | 1 + test/ConstructDestruct.cpp | 57 +++++++++++++++++++++++++++++ test/ConstructDestruct.hpp | 25 +++++++++++++ test/testArray.cpp | 75 +++++++++++--------------------------- test/testVector.cpp | 75 +++++++++++--------------------------- test/testVector2_f.cpp | 1 + test/testVector3_f.cpp | 1 + 8 files changed, 131 insertions(+), 111 deletions(-) create mode 100644 test/ConstructDestruct.cpp create mode 100644 test/ConstructDestruct.hpp diff --git a/etk/Array.hpp b/etk/Array.hpp index 0b71e6b..b9206ea 100644 --- a/etk/Array.hpp +++ b/etk/Array.hpp @@ -230,9 +230,9 @@ namespace etk { return m_array->get(m_current); } private: - Iterator(const Array * _obj, int32_t _pos): + Iterator(const Array * _obj, int32_t _pos): m_current(_pos), - m_array(const_cast *>(_obj)) { + m_array(const_cast *>(_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: diff --git a/lutin_etk-test.py b/lutin_etk-test.py index 6423336..784ccba 100644 --- a/lutin_etk-test.py +++ b/lutin_etk-test.py @@ -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', diff --git a/test/ConstructDestruct.cpp b/test/ConstructDestruct.cpp new file mode 100644 index 0000000..c60679c --- /dev/null +++ b/test/ConstructDestruct.cpp @@ -0,0 +1,57 @@ +#include +#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; +} + diff --git a/test/ConstructDestruct.hpp b/test/ConstructDestruct.hpp new file mode 100644 index 0000000..d867000 --- /dev/null +++ b/test/ConstructDestruct.hpp @@ -0,0 +1,25 @@ +/** + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL-2 (see license file) + */ +#pragma once + +#include + +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(); +} diff --git a/test/testArray.cpp b/test/testArray.cpp index 54532f1..67db011 100644 --- a/test/testArray.cpp +++ b/test/testArray.cpp @@ -9,6 +9,7 @@ #include #include #include +#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 list; - list.pushBack(testContructDestruct(55)); + etk::Array 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 list; - list.pushBack(testContructDestruct(4)); - list.pushBack(testContructDestruct(30)); - list.pushBack(testContructDestruct(1000)); - list.pushBack(testContructDestruct(200)); + etk::Array 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 list; + etk::Array 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) { diff --git a/test/testVector.cpp b/test/testVector.cpp index c1b9186..ce739e0 100644 --- a/test/testVector.cpp +++ b/test/testVector.cpp @@ -9,6 +9,7 @@ #include #include #include +#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 list; - list.pushBack(testContructDestruct(55)); + etk::Vector 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 list; - list.pushBack(testContructDestruct(4)); - list.pushBack(testContructDestruct(30)); - list.pushBack(testContructDestruct(1000)); - list.pushBack(testContructDestruct(200)); + etk::Vector 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 list; + etk::Vector 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) { diff --git a/test/testVector2_f.cpp b/test/testVector2_f.cpp index 7e73cd3..aaa41e2 100644 --- a/test/testVector2_f.cpp +++ b/test/testVector2_f.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "ConstructDestruct.hpp" TEST(TestVector2D_f, constructor) { // Test contructor value diff --git a/test/testVector3_f.cpp b/test/testVector3_f.cpp index 2420c39..cff53b3 100644 --- a/test/testVector3_f.cpp +++ b/test/testVector3_f.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "ConstructDestruct.hpp" #define NAME "etk:Vector3D"