[DEBUG] test software and buffer

This commit is contained in:
Edouard DUPIN 2013-10-09 21:49:40 +02:00
parent 63906e9b77
commit 15f270da8a
2 changed files with 64 additions and 92 deletions

View File

@ -59,11 +59,10 @@ namespace etk
* @param[in] _count Minimum request size of the Buffer
*/
Buffer(int32_t _count = 0) :
m_data(NULL),
m_allocated(0),
m_gapStart(0),
m_gapEnd(GAP_SIZE_MIN)
{
m_data(NULL),
m_allocated(0),
m_gapStart(0),
m_gapEnd(GAP_SIZE_MIN) {
changeAllocation(_count+GAP_SIZE_MIN);
}
/**
@ -71,11 +70,10 @@ namespace etk
* @param[in] _obj Buffer that might be copy
*/
Buffer(const etk::Buffer& _obj) :
m_data(NULL),
m_allocated(_obj.m_allocated),
m_gapStart(_obj.m_gapStart),
m_gapEnd(_obj.m_gapEnd)
{
m_data(NULL),
m_allocated(_obj.m_allocated),
m_gapStart(_obj.m_gapStart),
m_gapEnd(_obj.m_gapEnd) {
// allocate all same data
m_data = (int8_t *)malloc( m_allocated * sizeof(int8_t) );
TK_ASSERT(NULL!=m_data, "Error in data allocation");
@ -85,8 +83,7 @@ namespace etk
/**
* @brief Destructor of the current Class
*/
~Buffer(void)
{
~Buffer(void) {
if (m_data != NULL) {
free(m_data);
}
@ -100,8 +97,7 @@ namespace etk
* @param[in,out] _file Pointer on the file where data might be writed
* @return true if OK / false if an error occured
*/
bool dumpIn(etk::FSNode& _file)
{
bool dumpIn(etk::FSNode& _file) {
if (false == _file.fileOpenWrite()) {
return false;
}
@ -117,8 +113,7 @@ namespace etk
* @param[in,out] _myFile Pointer on the file where data might be read
* @return true if OK / false if an error occured
*/
bool dumpFrom(etk::FSNode& _file)
{
bool dumpFrom(etk::FSNode& _file) {
if (false == _file.fileOpenRead()) {
return false;
}
@ -150,8 +145,7 @@ namespace etk
* @param[in] _obj Buffer that might be copy
* @return reference on the curent re-copy vector
*/
etk::Buffer& operator=(const etk::Buffer& _obj)
{
etk::Buffer& operator=(const etk::Buffer& _obj) {
if( this != &_obj ) // avoid copy to itself
{
if (NULL!=m_data) {
@ -176,8 +170,7 @@ namespace etk
* @param[in] _pos Position in the buffer.
* @return Element at the request pos.
*/
int8_t operator[] (int32_t _pos) const
{
int8_t operator[] (int32_t _pos) const {
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing");
if (_pos < m_gapStart) {
return m_data[_pos];
@ -190,8 +183,7 @@ namespace etk
* @param[in] _pos Desired position read
* @return Reference on the Element
*/
int8_t& get(int32_t _pos) const
{
int8_t& get(int32_t _pos) const {
TK_ASSERT(0 <= _pos || _pos < size(), "try to read an element non existing");
if (_pos < m_gapStart) {
return m_data[_pos];
@ -219,8 +211,7 @@ namespace etk
* @param[in] _nbElement Number of element needed.
* @return The data requested
*/
etk::Vector<int8_t> get(int32_t _pos, int32_t _nbElement)
{
etk::Vector<int8_t> get(int32_t _pos, int32_t _nbElement) {
etk::Vector<int8_t> tmpBuffer;
tmpBuffer.clear();
if (_pos < m_gapStart) {
@ -239,8 +230,7 @@ namespace etk
* @brief Add at the Last position of the Vector
* @param[in] _item Element to add at the end of vector
*/
void pushBack(const int8_t& _item)
{
void pushBack(const int8_t& _item) {
insert(size(), _item);
}
/**
@ -248,11 +238,10 @@ namespace etk
* @param[in] _pos Position where data might be inserted
* @param[in] _items Data that might be inserted.
*/
void insert(int32_t _pos, const int8_t& _item)
{
void insert(int32_t _pos, const int8_t& _item) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << Size());
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size());
return;
}
if( 0 == gapSize() ) {
@ -281,8 +270,7 @@ namespace etk
* @param[in] _pos Position where data might be inserted
* @param[in] _items Data that might be inserted.
*/
void insert(int32_t _pos, etk::Vector<int8_t>& _items)
{
void insert(int32_t _pos, etk::Vector<int8_t>& _items) {
insert(_pos, _items.dataPointer(), _items.size());
}
/**
@ -291,8 +279,7 @@ namespace etk
* @param[in] _items Data that might be inserted. (no need of '\0')
* @param[in] _nbElement number of element to insert
*/
void insert(int32_t _pos, int8_t* _items, int32_t _nbElement)
{
void insert(int32_t _pos, int8_t* _items, int32_t _nbElement) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="<<size());
@ -317,8 +304,7 @@ namespace etk
* @param[in] _pos The first element to remove.
* @param[in] _items Data that might be inserted.
*/
void replace(int32_t _pos, const int8_t& _item)
{
void replace(int32_t _pos, const int8_t& _item) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="<<size());
@ -337,8 +323,7 @@ namespace etk
* @param[in] _nbRemoveElement number of element to remove.
* @param[in] _items Data that might be inserted.
*/
void replace(int32_t _pos, int32_t _nbRemoveElement, etk::Vector<int8_t>& _items)
{
void replace(int32_t _pos, int32_t _nbRemoveElement, etk::Vector<int8_t>& _items) {
replace(_pos, _nbRemoveElement, _items.dataPointer(), _items.size());
}
/**
@ -348,8 +333,7 @@ namespace etk
* @param[in] _items Data that might be inserted.
* @param[in] _nbElement Number of element that might be added.
*/
void replace(int32_t _pos, int32_t _nbRemoveElement, int8_t* _items, int32_t _nbElement)
{
void replace(int32_t _pos, int32_t _nbRemoveElement, int8_t* _items, int32_t _nbElement) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="<<size());
@ -376,8 +360,7 @@ namespace etk
* @param[in] _pos The first element to remove
* @param[in] _nbRemoveElement number of element to remove
*/
void remove(int32_t _pos, int32_t _nbRemoveElement = 1)
{
void remove(int32_t _pos, int32_t _nbRemoveElement = 1) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize="<<size());
@ -403,8 +386,7 @@ namespace etk
/**
* @brief Remove the last element of the Buffer.
*/
void popBack(void)
{
void popBack(void) {
if (size()>0) {
remove( size() );
}
@ -412,8 +394,7 @@ namespace etk
/**
* @brief Clean all the data in the buffer.
*/
void clear(void)
{
void clear(void) {
remove(0, size() );
}
/**
@ -421,16 +402,14 @@ namespace etk
* @param[in] _realElementPosition Real position in the buffer (only use in the ITERATOR)
* @return Reference on the Element
*/
int8_t& getDirect(int32_t _realElementPosition)
{
int8_t& getDirect(int32_t _realElementPosition) {
return m_data[_realElementPosition];
};
/**
* @brief Get the number of element in the vector
* @return The number requested
*/
int32_t size(void) const
{
int32_t size(void) const {
return m_allocated - gapSize();
};
private:
@ -438,8 +417,7 @@ namespace etk
* @brief Change the current allocation to the corect one (depend on the current size)
* @param[in] _newSize Minimum number of element needed
*/
void changeAllocation(int32_t _newSize)
{
void changeAllocation(int32_t _newSize) {
// set the minimal size to 1
if(_newSize <= 0) {
_newSize = 1;
@ -468,9 +446,8 @@ namespace etk
* @return false The operation can not be proccesed.
* @return true The operation done correctly.
*/
bool gapMove(int32_t _pos)
{
if( _pos > Size()
bool gapMove(int32_t _pos) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size());
return false;
@ -492,8 +469,7 @@ namespace etk
* @return false The operation can not be proccesed.
* @return true The operation done correctly.
*/
bool gapResize(int32_t _pos, int32_t _newGapLen)
{
bool gapResize(int32_t _pos, int32_t _newGapLen) {
if( _pos > size()
|| _pos < 0 ) {
TK_ERROR("Request higher than buffer size : pos=" << _pos << " bufferSize=" << size());
@ -540,15 +516,13 @@ namespace etk
* @brief Get the current gap size.
* @return The number of element in the gap
*/
int32_t gapSize(void) const
{
int32_t gapSize(void) const {
return m_gapEnd - m_gapStart;
}
/**
* @brief Control if the writing gap is not too big (automatic resize the buffer).
*/
void gapCheckMaxSize(void)
{
void gapCheckMaxSize(void) {
if(gapSize() > GAP_SIZE_MAX) {
int32_t currentSize = size();
// Change the gap Size

View File

@ -45,7 +45,7 @@ void testUString(void)
int64_t kkk=((int64_t)1)<<iii;
etk::UString plop(kkk, etk::UString::printModeDecimal);
TK_DEBUG(" test : " << plop);
int64_t resTest = plop.ToInt32();
int64_t resTest = plop.toInt32();
TK_DEBUG(" test : " << resTest);
}
@ -60,16 +60,16 @@ void testHash(void)
{
TK_INFO("==> Start test of Hach table");
etk::Hash<etk::UString> testData;
testData.Add("TEST", "testData");
testData.Add("TEST", "testData333");
testData.Add("TEST2", "22222222222222222");
testData.Add("TEST4", "4444444444444444444");
testData.Add("TEST3", "3333333333");
testData.Add("TEST1", "11111111111");
testData.Add("TEST55", "555555555555555((((5555");
TK_INFO(" count =" << testData.Size());
for (int32_t iii=0; iii< testData.Size(); iii++) {
TK_INFO(" id=" << iii << " key='" << testData.GetKey(iii) << "' val='" << testData.GetValue(iii) << "'");
testData.add("TEST", "testData");
testData.add("TEST", "testData333");
testData.add("TEST2", "22222222222222222");
testData.add("TEST4", "4444444444444444444");
testData.add("TEST3", "3333333333");
testData.add("TEST1", "11111111111");
testData.add("TEST55", "555555555555555((((5555");
TK_INFO(" count =" << testData.size());
for (int32_t iii=0; iii< testData.size(); iii++) {
TK_INFO(" id=" << iii << " key='" << testData.getKey(iii) << "' val='" << testData.getValue(iii) << "'");
}
TK_INFO(" direct acces at the key key='TEST4' val='" << testData["TEST4"] << "'");
TK_INFO("==> End test of Hach table");
@ -83,38 +83,36 @@ void testFSNode(void)
TK_INFO("********************************************");
TK_INFO("** Filename=\"" << fileName << "\"");
TK_INFO("********************************************");
TK_INFO(" GetNameFolder() =\"" <<myNodeTest1.GetNameFolder() << "\"");
TK_INFO(" GetName() =\"" <<myNodeTest1.GetName() << "\"");
TK_INFO(" GetNameFile() =\"" <<myNodeTest1.GetNameFile() << "\"");
TK_INFO(" GetRelativeFolder() =\"" <<myNodeTest1.GetRelativeFolder() << "\"");
TK_INFO(" exist =" <<myNodeTest1.Exist());
if (true==myNodeTest1.Exist()) {
TK_INFO(" GetNameFolder() =\"" <<myNodeTest1.getNameFolder() << "\"");
TK_INFO(" GetName() =\"" <<myNodeTest1.getName() << "\"");
TK_INFO(" GetNameFile() =\"" <<myNodeTest1.getNameFile() << "\"");
TK_INFO(" GetRelativeFolder() =\"" <<myNodeTest1.getRelativeFolder() << "\"");
TK_INFO(" exist =" <<myNodeTest1.exist());
if (true==myNodeTest1.exist()) {
TK_ERROR(" ==> remove the file ==> bad for the test");
} else {
TK_INFO(" Display time when file does not exist :");
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.TimeCreatedString() << "\"");
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.TimeModifiedString() << "\"");
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.TimeAccessedString() << "\"");
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.timeCreatedString() << "\"");
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.timeModifiedString() << "\"");
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.timeAccessedString() << "\"");
}
myNodeTest1.Touch();
if (false==myNodeTest1.Exist()) {
myNodeTest1.touch();
if (false==myNodeTest1.exist()) {
TK_ERROR(" ==> Error, can not create the file ....");
} else {
TK_INFO(" Display time when file does exist :");
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.TimeCreatedString() << "\"");
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.TimeModifiedString() << "\"");
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.TimeAccessedString() << "\"");
TK_INFO(" TimeCreatedString() =\"" <<myNodeTest1.timeCreatedString() << "\"");
TK_INFO(" TimeModifiedString() =\"" <<myNodeTest1.timeModifiedString() << "\"");
TK_INFO(" TimeAccessedString() =\"" <<myNodeTest1.timeAccessedString() << "\"");
}
// Try remove the file :
myNodeTest1.Remove();
if (true==myNodeTest1.Exist()) {
myNodeTest1.remove();
if (true==myNodeTest1.exist()) {
TK_ERROR(" ==> The file might be removed ==> but it is not the case ...");
} else {
TK_INFO(" ==> The file is removed");
}
TK_INFO("********************************************");
TK_INFO("==> Stop test of FSNode");
}
@ -122,8 +120,8 @@ void testFSNode(void)
void testArchive(void)
{
TK_INFO("==> Start test of archive");
etk::Archive* tmpArchive = etk::Archive::Load("testzip.zip");
tmpArchive->Display();
etk::Archive* tmpArchive = etk::Archive::load("testzip.zip");
tmpArchive->display();
TK_INFO("==> End test of archive");
}
@ -151,7 +149,7 @@ void testDimension(void)
int main(int argc, const char *argv[])
{
// the only one init for etk:
GeneralDebugSetLevel(etk::LOG_LEVEL_VERBOSE);
debug::setGeneralLevel(etk::LOG_LEVEL_VERBOSE);
//testVector();
//testUniChar();
//testUString();