diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ff5f59..c4817a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,10 +157,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${COMPILED_BINARIES_DIR}/lib) # == PACKAGING == # =============== -if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - # make package only if BofStd is the main project (not a submodule) - include(packaging.cmake) -endif() +include(packaging.cmake) + # ======================= # == POPULATE PROJECTS == # ======================= diff --git a/lib/include/bofstd/bofcircularbuffer.h b/lib/include/bofstd/bofcircularbuffer.h index 4db111d..d66d7b5 100644 --- a/lib/include/bofstd/bofcircularbuffer.h +++ b/lib/include/bofstd/bofcircularbuffer.h @@ -114,6 +114,7 @@ class BofCircularBuffer uint32_t GetNbElementLocked() const; uint32_t GetCapacity() const; uint32_t GetNbFreeElement(); + BOFERR SetOverWriteMode(bool _Overwrite_B); uint32_t GetMaxLevel() const; bool IsBufferOverflow(); void Reset(); @@ -125,7 +126,8 @@ class BofCircularBuffer BOFERR Peek(DataType *_pData, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pIndexOf_U32, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell BOFERR PeekFromPop(uint32_t _RelativeIndexFromPop_U32, DataType *_pData, bool *_pLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell BOFERR PeekByIndex(uint32_t _AbsoluteIndex_U32, DataType *_pData, bool *_pLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell); - BOFERR Skip(bool *_pLocked_B); + //_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space + BOFERR Skip(DataType *_pData, bool _SignalIfNeeded_B, uint32_t *_pIndexOf_U32, DataType **_ppStorage, bool *_pLocked_B); BOFERR UnlockPop(uint32_t _AbsoluteIndex_U32); bool IsLocked(uint32_t _AbsoluteIndex_U32); bool IsEntryFree(uint32_t _AbsoluteIndex_U32, bool *_pIsLocked_B, DataType **_ppStorage); //_ppStorage is mainly used in mCircularBufferParam_X.PopLockMode_B to provide write access to the locked storage cell @@ -298,6 +300,12 @@ uint32_t BofCircularBuffer::GetNbFreeElement() return Rts_U32; } +template +BOFERR BofCircularBuffer::SetOverWriteMode(bool _Overwrite_B) +{ + mCircularBufferParam_X.Overwrite_B = _Overwrite_B; + return BOF_ERR_NO_ERROR; +} template uint32_t BofCircularBuffer::GetMaxLevel() const { @@ -380,6 +388,12 @@ BOFERR BofCircularBuffer::Push(const DataType *_pData, uint32_t _Block if (mNbElementInBuffer_U32 > mCircularBufferParam_X.NbMaxElement_U32) { mNbElementInBuffer_U32 = mCircularBufferParam_X.NbMaxElement_U32; // mCircularBufferParam_X.Overwrite_B + BOF_ASSERT(mPushIndex_U32 == mPopIndex_U32) + mPopIndex_U32++; + if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32) + { + mPopIndex_U32 = 0; + } mOverflow_B = true; } } @@ -487,6 +501,12 @@ BOFERR BofCircularBuffer::PushForNextPop(const DataType *_pData, bool if (mNbElementInBuffer_U32 > mCircularBufferParam_X.NbMaxElement_U32) { mNbElementInBuffer_U32 = mCircularBufferParam_X.NbMaxElement_U32; // mCircularBufferParam_X.Overwrite_B + BOF_ASSERT(mPushIndex_U32 == mPopIndex_U32) + mPopIndex_U32++; + if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32) + { + mPopIndex_U32 = 0; + } mOverflow_B = true; } } @@ -822,8 +842,9 @@ BOFERR BofCircularBuffer::PeekByIndex(uint32_t _AbsoluteIndex_U32, Dat return Rts_E; } +//_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space template -BOFERR BofCircularBuffer::Skip(bool *_pIsLocked_B) +BOFERR BofCircularBuffer::Skip(DataType *_pData, bool _SignalIfNeeded_B, uint32_t *_pIndexOf_U32, DataType **_ppStorage, bool *_pLocked_B) { BOFERR Rts_E; @@ -835,9 +856,9 @@ BOFERR BofCircularBuffer::Skip(bool *_pIsLocked_B) BOF_ASSERT(mNbElementLockedInBuffer_U32 <= mNbElementInBuffer_U32); if (mNbElementInBuffer_U32 - mNbElementLockedInBuffer_U32) { - if (_pIsLocked_B) + if (_pLocked_B) { - *_pIsLocked_B = mpLock_U8[mPopIndex_U32] ? true : false; + *_pLocked_B = mpLock_U8[mPopIndex_U32] ? true : false; } if (mpLock_U8[mPopIndex_U32] == 0) { @@ -846,6 +867,18 @@ BOFERR BofCircularBuffer::Skip(bool *_pIsLocked_B) mNbElementInBuffer_U32--; BOF_ASSERT(mPopIndex_U32 < mCircularBufferParam_X.NbMaxElement_U32); + if (_pIndexOf_U32) + { + *_pIndexOf_U32 = mPopIndex_U32; + } + if (_pData) + { + *_pData = mpData_T[mPopIndex_U32]; + } + if (_ppStorage) + { + *_ppStorage = &mpData_T[mPopIndex_U32]; + } mPopIndex_U32++; if (mPopIndex_U32 >= mCircularBufferParam_X.NbMaxElement_U32) { @@ -853,7 +886,10 @@ BOFERR BofCircularBuffer::Skip(bool *_pIsLocked_B) } if (mCircularBufferParam_X.Blocking_B) //&& (_BlockingTimeouItInMs_U32)) { - Rts_E = SignalReadWrite(); + if (_SignalIfNeeded_B) + { + Rts_E = SignalReadWrite(); + } } } else diff --git a/lib/include/bofstd/bofhttprequest.h b/lib/include/bofstd/bofhttprequest.h index 83ca999..a85b52c 100644 --- a/lib/include/bofstd/bofhttprequest.h +++ b/lib/include/bofstd/bofhttprequest.h @@ -57,6 +57,9 @@ enum BOF_HTTP_REQUEST_TYPE BOF_HTTP_REQUEST_OPTIONS, BOF_HTTP_REQUEST_CONNECT, BOF_HTTP_REQUEST_TRACE, + BOF_HTTP_REQUEST_DBG_ECHO, //For user Debug Echo function + BOF_HTTP_REQUEST_MAX, + }; /// @brief This class implements an http request parser. /// Cf BofHttpRequest @@ -155,6 +158,8 @@ class BOFSTD_EXPORT BofHttpRequest /// @remarks Different operator. bool operator!=(const BofHttpRequest &_rOther_O) const; + static BOF_HTTP_REQUEST_TYPE S_RequestType(const char *_pRequest_c); + static std::string S_RequestString(BOF_HTTP_REQUEST_TYPE _Method_E); /// @brief Check if the http request instance is well formed. /// @return true if the http request is valid. /// @remarks None diff --git a/lib/include/bofstd/bofpot.h b/lib/include/bofstd/bofpot.h index 35be9cd..042c464 100644 --- a/lib/include/bofstd/bofpot.h +++ b/lib/include/bofstd/bofpot.h @@ -1022,11 +1022,34 @@ template void BofPot::Reset() { BOFERR Sts_E; + uint32_t i_U32; + DataType *pData_X; BOF_POT_LOCK(Sts_E); if (Sts_E == BOF_ERR_NO_ERROR) { mLevelMax_U32 = 0; + mpFirstPotElementToTryForGet_X = mpPotDataStorage_X; + mNumberOfElementOutOfThePot_U32=0; + pData_X = mpPotDataStorage_X; + + if (mPotParam_X.MagicNumber_U32) + { + for (i_U32 = 0; i_U32 < mPotParam_X.PotCapacity_U32; i_U32++, pData_X++) + { + *(uint32_t *)pData_X = 0; + } + } + else + { + if (mpInUseElementList_U8) + { + for (i_U32 = 0; i_U32 < mPotParam_X.PotCapacity_U32; i_U32++) + { + mpInUseElementList_U8[i_U32] = 0x00; + } + } + } BOF_POT_UNLOCK() } } diff --git a/lib/include/bofstd/bofrawcircularbuffer.h b/lib/include/bofstd/bofrawcircularbuffer.h index ea0b786..c370799 100644 --- a/lib/include/bofstd/bofrawcircularbuffer.h +++ b/lib/include/bofstd/bofrawcircularbuffer.h @@ -22,6 +22,7 @@ #pragma once #include +#include BEGIN_BOF_NAMESPACE() @@ -29,8 +30,12 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM { bool MultiThreadAware_B; /*! true if the object is used in a multi threaded application (use mCs)*/ uint32_t BufferSizeInByte_U32; /*! Specifies the maximum number of byte inside inside the queue*/ - uint32_t NbMaxSlot_U32; /*! Specifies the maximum number of buffer inside the queue (if 0 the whole BufferSizeInByte_U32 can be used)*/ + bool SlotMode_B; /* If true, the mpData_U8 buffer of BufferSizeInByte_U32 will be divided by NbMaxBufferEntry_U32 and each slot will be BufferSizeInByte_U32/NbMaxBufferEntry_U32 */ + uint32_t NbMaxBufferEntry_U32; /*! Specifies the maximum number of buffer which will be tracked inside the mpData_U8 buffer of BufferSizeInByte_U32*/ uint8_t *pData_U8; /*! Pointer to queue storage buffer used to record queue element*/ + bool Overwrite_B; /*! true if new data overwritte the oldest one when the queue is full. */ + bool Blocking_B; + BOF_RAW_CIRCULAR_BUFFER_PARAM() { Reset(); @@ -40,8 +45,11 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM { MultiThreadAware_B = false; BufferSizeInByte_U32 = 0; - NbMaxSlot_U32 = 0; + SlotMode_B = false; + NbMaxBufferEntry_U32 = 0; pData_U8 = nullptr; + Overwrite_B = false; + Blocking_B = false; } }; @@ -50,54 +58,70 @@ struct BOF_RAW_CIRCULAR_BUFFER_PARAM * Raw Circular buffer class * * Description - * This class manages a circular byte buffer instance. Each entry in the circular buffer is - * preceded by a 32 bits value containing the length of the payload: - * - * L1: | L2: | ... | Ln: + * This class manages a circular byte buffer instance. For each entry in the circular buffer, there is an entry in + * in std::unique_ptr> mpuSlotCollection. + * BOF_RAW_BUFFER describes a buffer portion inside the global mpData_U8 buffer * - * The effective range of this value is [1,0x7FFFFFFF]. When bit 31 is set, this location has been - * reserved (locked) by LockBuffer and it will be filled by UnlockLockBuffer which will clear the bit 31 - * When this bit is set PopBuffer will fail even if the state of the buffer seems to be ready for pop - * operation. PushBuffer can continue to work + * mpData_U8: | | ... | * - * The filling of the buffer is controlled by BufferCapacity_U32 and NbMaxBuffer_U32 + * The filling of the buffer is controlled by SlotMode_B, NbMaxBufferEntry_U32 and BufferSizeInByte_U32 * - * BufferCapacity_U32 gives the number of byte allocated to store the list of buffers + * BufferSizeInByte_U32 gives the number of byte allocated to store the list of buffers * - * Each pushed buffer is stored one after each other if NbMaxBuffer_U32 is 0. In this case - * the buffer capacity is optimized used in term of memory - * L1:L2:...Ln: + * Each pushed buffer is stored one after each other if SlotMode_B is false up to a maximum of NbMaxBufferEntry_U32 + * pending entries which must be Poped out to be able to use the rest of the buffer. * - * If NbMaxBuffer_U32 is different from 0, each buffer will be stored in a slot of - * BufferCapacity_U32/NbMaxBuffer_U32 bytes. This will gives slot of equal size inside the + * If SlotMode_B is true, each buffer will be stored in a slot of + * BufferSizeInByte_U32/NbMaxBufferEntry_U32 bytes. This will gives slot of equal size inside the * circular buffer which contains variable size buffer array from 1 to - * (BufferCapacity_U32/NbMaxBuffer_U32) bytes length. In this cas the BufferCapacity_U32 is - * increased by (NbMaxBuffer_U32*sizeof(uint32_t)) to be able to store the extra buffer 32 bits value - * containing the length of the payload - * L1: L2: ...Ln: + * (BufferSizeInByte_U32/NbMaxBufferEntry_U32) bytes length. + * + * ...Ln: * <--------SlotSize--------><--------SlotSize-------->...<--------SlotSize--------> - * - * See Also - * None + * + * Each entry in the buffer list can be read partially byte per byte up to the size of the length of this entry. + * Data can also be appended part by part if you call SetAppendMode(true), do not forget to call SetAppendMode(false) + * when the data is considered as completly full */ - +struct BOF_RAW_BUFFER +{ + uint32_t IndexInBuffer_U32; //Index of the first data byte (pData_U8[0]) inside the global mpData_U8 buffer. + uint32_t SlotEmpySpace_U32; //Number of not used byte in slot when pushed + uint32_t Size1_U32; //Number of byte from pData1_U8 to the end op the buffer (no Size2_U32 for slotmode) + uint8_t *pData1_U8; //Pointer to data corresponding to Size1_U32 (no pData2_U8 for SlotMode_B) + uint32_t Size2_U32; //In non slot mode, data may be spreaded accross the end of the buffer, this one contains the number of byte from mpData_U8[0] to the end of the buffer + uint8_t *pData2_U8; //Pointer to data corresponding to Size1_U32 (no Size2_U32 for SlotMode_B) + BOF_RAW_BUFFER() + { + Reset(); + } + void Reset() + { + IndexInBuffer_U32 = 0; + SlotEmpySpace_U32 = 0; + Size1_U32 = 0; + pData1_U8 = nullptr; + Size2_U32 = 0; + pData2_U8 = nullptr; + } +}; class BOFSTD_EXPORT BofRawCircularBuffer { private: BOF_RAW_CIRCULAR_BUFFER_PARAM mRawCircularBufferParam_X; - uint32_t mNbSlot_U32; /*! Current number of buffer stored inside the raw queue */ - // uint32_t mNbMaxSlot_U32; /*! Maximum number of buffer which can be stored inside the queue. If it is 0, the whole buffer size is used to store a maximum number of buffer otherwise of constant slot size - // is used to store variable buffer length (see class comment) */ - uint32_t mSlotSize_U32; /*! if mNbMaxSlot_U32 != 0 this is the slot size which is used to store variable buffer length (adjusted mNbElementInBuffer_U32/mNbMaxBuffer_U32 (see class comment) otherwize 0 */ - bool mDataPreAllocated_B; /*! true if mpData_U8 is provided by the caller (!! if mNbMaxBuffer_U32 is different from zero, extra storage is needed to record lenth of each slot (see class comment) */ - uint8_t *mpData_U8; /*! Pointer to queue storage buffer used to record queue element*/ - uint32_t mPushIndex_U32; /*! Current position of the write index inside the queue*/ - uint32_t mPopIndex_U32; /*! Current position of the read index inside the queue*/ - // uint32_t mBufferCapacity_U32; /*! The maximum number of element inside the queue*/ - uint32_t mNbElementInBuffer_U32; /*! Current number of element inside the queue*/ - uint32_t mLevelMax_U32; /*! Contains the maximum buffer fill level. This one is reset by the GetMaxLevel method*/ - BOF_MUTEX mRawCircularBufferMtx_X; /*! Provide a serialized access to shared resources in a multi threaded environment*/ - BOFERR mErrorCode_E; + uint32_t mSlotSize_U32 = 0; /*! if SlotMode_B this is the slot size which is used to store variable buffer length (adjusted BufferSizeInByte_U32/mNbElementInBuffer_U32 */ + bool mDataPreAllocated_B=false; /*! true if mpData_U8 is provided by the caller */ + uint8_t *mpData_U8=nullptr; /*! Pointer to queue storage buffer used to record queue element*/ + uint32_t mLevelMax_U32=0; /*! Contains the maximum buffer fill level. This one is reset by the GetMaxLevel method*/ + BOF_MUTEX mRawCircularBufferMtx_X; /*! Provide a serialized access to shared resources in a multi threaded environment*/ + BOFERR mErrorCode_E=BOF_ERR_NO_ERROR; + bool mOverflow_B=false; /*! true if data overflow has occured. Reset to false by IsBufferOverflow*/ + bool mAppendMode_B=false; /*! true if we are in append mode */ + std::unique_ptr> mpuBufferCollection = nullptr; + BOF_RAW_BUFFER mRawBufferToPush_X; + uint32_t mCrtBufferRemain_U32 = 0; + uint8_t *mpCrtBufferHead_U8 = nullptr; + uint8_t *mpCrtBufferEnd_U8 = nullptr; public: BofRawCircularBuffer(const BOF_RAW_CIRCULAR_BUFFER_PARAM &_rRawCircularBufferParam_X); @@ -112,23 +136,26 @@ class BOFSTD_EXPORT BofRawCircularBuffer bool IsEmpty(); bool IsFull(); uint32_t GetSlotSize(); - uint32_t GetNbElement(); - uint32_t GetCapacity(); + uint32_t GetNbElement(uint32_t *_pSizeOfFirst_U32); + uint32_t GetCapacity(uint32_t *_pTotalSize_U32); uint32_t GetMaxLevel(); void Reset(); - uint32_t GetNbFreeElement(); - BOFERR PushBuffer(uint32_t _Nb_U32, const uint8_t *_pData_U8); - BOFERR PopBuffer(uint32_t *_pNbMax_U32, uint8_t *_pData_U8); - BOFERR Peek(uint32_t _Index_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8); - BOFERR Skip(); - BOFERR LockBuffer(uint32_t _Nb_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8); - BOFERR UnlockBuffer(const uint8_t *_pLockedBuffer_U8, uint32_t _Nb_U32); + uint32_t GetNbFreeElement(uint32_t *_pRemainingSize_U32); + BOFERR SetOverWriteMode(bool _Overwrite_B); + BOFERR SetAppendMode(uint32_t _BlockingTimeouItInMs_U32, bool _Append_B); + bool IsBufferOverflow(); + BOFERR PushBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8); + BOFERR PopBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8); + BOFERR Peek(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8); + //Need to call Skip after GetBufferPtr + BOFERR GetBufferPtr(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8); + //_SignalIfNeeded_B:: sometime you skip just to process OverWrite mode, in this case do not signal free space + BOFERR Skip(bool _SignalIfNeeded_B, bool *_pLocked_B); private: - uint32_t ReadNbHeader(uint32_t *_pPopIndex_U32); //Lock is not taken to avoid recursive mutex - BOFERR WriteNbHeader(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32); //Lock is not taken to avoid recursive mutex - BOFERR ReadPayload(uint32_t *_pPopIndex_U32, uint32_t _Nb_U32, uint8_t *_pData_U8); //Lock is not taken to avoid recursive mutex - BOFERR WritePayload(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8); //Lock is not taken to avoid recursive mutex + BOFERR PushRawBuffer(uint32_t _BlockingTimeouItInMs_U32); + BOFERR UpdatePushRawBuffer(uint32_t _Size_U32, const uint8_t *_pData_U8); + BOFERR PopOrPeekBuffer(bool _Pop_B, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8); }; END_BOF_NAMESPACE() \ No newline at end of file diff --git a/lib/include/bofstd/bofsocketos.h b/lib/include/bofstd/bofsocketos.h index 0952211..21828fd 100644 --- a/lib/include/bofstd/bofsocketos.h +++ b/lib/include/bofstd/bofsocketos.h @@ -309,6 +309,14 @@ struct BOF_SOCKET_ADDRESS *pIp_U8++ = static_cast(_Ip4_U32); } SocketType_E = _SocketType_E; + if (SocketType_E == BOF_SOCK_TYPE::BOF_SOCK_TCP) + { + Protocol_S = "tcp"; + } + if (SocketType_E == BOF_SOCK_TYPE::BOF_SOCK_UDP) + { + Protocol_S = "udp"; + } } void Inc(int32_t _Inc_S32) diff --git a/lib/include/bofstd/bofsocketthread.h b/lib/include/bofstd/bofsocketthread.h index ee51cbe..3b8b4ce 100644 --- a/lib/include/bofstd/bofsocketthread.h +++ b/lib/include/bofstd/bofsocketthread.h @@ -240,7 +240,7 @@ class BOFSTD_EXPORT BofSocketThread : public BofThread BOFERR CancelSocketOperation(uint32_t _TimeOut_U32); BOFERR ClearSocketOperation(); BOFERR ResetSocketOperation(); - + uint32_t GetIoDefaultTimeout() const; BofSocket *GetListeningSocket(); BofSocket *GetSocket(); const BOF_SOCKET_OPERATION_PARAM &GetCurrentOpParam(); diff --git a/lib/include/bofstd/bofstd.h b/lib/include/bofstd/bofstd.h index 970b58d..e96fa66 100644 --- a/lib/include/bofstd/bofstd.h +++ b/lib/include/bofstd/bofstd.h @@ -135,6 +135,10 @@ struct BOF_SIZE }; #define BOF_PI 3.14159265358979323846 +#define BOF_SQAURE_2 1.41421356237309504880 +#define BOF_EULER_NUMBER 2.71828182845904523536 +#define BOF_EULER_CONSTANT 0.57721566490153286060 + #define BOF_HANDLE uintptr_t // typedef void *BOF_HANDLE; // #define BOF_INVALID_HANDLE_VALUE ((BOF_HANDLE)-1) diff --git a/lib/include/bofstd/bofsystem.h b/lib/include/bofstd/bofsystem.h index 00e7347..8e1e9f7 100644 --- a/lib/include/bofstd/bofsystem.h +++ b/lib/include/bofstd/bofsystem.h @@ -239,7 +239,7 @@ struct BOF_BUFFER } return pRts_U8; } - uint8_t *Seek(uint64_t _Offset_U64, uint64_t &_rRemain_U64) + uint8_t *SeekAbs(uint64_t _Offset_U64, uint64_t &_rRemain_U64) { uint8_t *pRts_U8 = nullptr; @@ -247,7 +247,22 @@ struct BOF_BUFFER if (_Offset_U64 <= Size_U64) { Offset_U64 = _Offset_U64; - _rRemain_U64 = Size_U64 - _Offset_U64; + _rRemain_U64 = Size_U64 - Offset_U64; + pRts_U8 = &pData_U8[Offset_U64]; + } + return pRts_U8; + } + uint8_t *SeekRel(int64_t _Amount_S64, uint64_t &_rRemain_U64) + { + uint8_t *pRts_U8 = nullptr; + uint64_t NewOffset_U64; + + std::lock_guard Lock(Mtx); + NewOffset_U64 = Offset_U64 + _Amount_S64; + if (NewOffset_U64 <= Size_U64) + { + Offset_U64 = NewOffset_U64; + _rRemain_U64 = Size_U64 - Offset_U64; pRts_U8 = &pData_U8[Offset_U64]; } return pRts_U8; diff --git a/lib/src/bofdatetime.cpp b/lib/src/bofdatetime.cpp index 04ab5fe..83abba6 100644 --- a/lib/src/bofdatetime.cpp +++ b/lib/src/bofdatetime.cpp @@ -98,7 +98,7 @@ void BofDateTime::ClearDate() mYear_U16 = 0; mMonth_U8 = 0; mDay_U8 = 0; - mIsValid_B = false; + //No it is a Datetime with no valid data for example mIsValid_B = false; } void BofDateTime::ClearTime() { diff --git a/lib/src/boffs.cpp b/lib/src/boffs.cpp index 4879e2f..fc79a55 100644 --- a/lib/src/boffs.cpp +++ b/lib/src/boffs.cpp @@ -1115,7 +1115,7 @@ BOFERR Bof_CopyFile(bool _OverwriteIfExists_B, const BofPath &_rSrcPath, const B if (CreateOut_B) { Rts_E = BOF_ERR_CREATE; - std::ofstream Ofs(_rDstPath.FullPathName(false).c_str(), std::ios::trunc); + std::ofstream Ofs(_rDstPath.FullPathName(false).c_str(), std::ios::trunc| std::ios_base::binary); if (Ofs) { Ofs << Ifs.rdbuf(); diff --git a/lib/src/bofhttprequest.cpp b/lib/src/bofhttprequest.cpp index 39d1efc..8fdcf15 100644 --- a/lib/src/bofhttprequest.cpp +++ b/lib/src/bofhttprequest.cpp @@ -40,6 +40,7 @@ static BOF::BofEnum S_BofHttpRequestTypeEnumConverter( {BOF_HTTP_REQUEST_OPTIONS,"OPTIONS"}, {BOF_HTTP_REQUEST_CONNECT,"CONNECT"}, {BOF_HTTP_REQUEST_TRACE, "TRACE"}, + {BOF_HTTP_REQUEST_DBG_ECHO, "DBGECHO89ABCDEF"}, //No _ and must be (LWS_PRE-1) long for lws optim }, BOF_HTTP_REQUEST_UNKNOWN); @@ -151,6 +152,31 @@ bool BofHttpRequest::operator!=(const BofHttpRequest &_rOther_O) const { return !(*this == _rOther_O); } +BOF_HTTP_REQUEST_TYPE BofHttpRequest::S_RequestType(const char *_pRequest_c) +{ + BOF_HTTP_REQUEST_TYPE Rts_E = BOF_HTTP_REQUEST_TYPE::BOF_HTTP_REQUEST_UNKNOWN; + uint32_t i_U32; + const char *pRequestEnum_c; + + if (_pRequest_c) + { + for (i_U32 = BOF_HTTP_REQUEST_TYPE::BOF_HTTP_REQUEST_GET; i_U32 < BOF_HTTP_REQUEST_TYPE::BOF_HTTP_REQUEST_MAX; i_U32++) + { + pRequestEnum_c = S_BofHttpRequestTypeEnumConverter.ToString((BOF_HTTP_REQUEST_TYPE)i_U32).c_str(); + if (!strncmp(pRequestEnum_c, _pRequest_c, strlen(pRequestEnum_c))) + { + Rts_E= (BOF_HTTP_REQUEST_TYPE)i_U32; + break; + } + } + } + return Rts_E; +} + +std::string BofHttpRequest::S_RequestString(BOF_HTTP_REQUEST_TYPE _Method_E) +{ + return S_BofHttpRequestTypeEnumConverter.ToString(_Method_E); +} bool BofHttpRequest::IsValid() const { diff --git a/lib/src/bofrawcircularbuffer.cpp b/lib/src/bofrawcircularbuffer.cpp index 462fc72..1404fc5 100644 --- a/lib/src/bofrawcircularbuffer.cpp +++ b/lib/src/bofrawcircularbuffer.cpp @@ -34,118 +34,64 @@ BEGIN_BOF_NAMESPACE() Bof_UnlockMutex(mRawCircularBufferMtx_X); \ } -/*! - * Description - * This is the constructor of a CircularBuffer - * - * Parameters - * _pRawCircularBufferParam_X: Specifies the object creation parameters and contains the retuned values. - * - * Returns - * None - * - * Remarks - * None - * - * See Also - * ~BofRawCircularBuffer - */ +#define DBG_RAW_BUFFER_INFO(pUser, pRaw) \ + { \ + printf("%-28.28s Base %p Crt %p Used %06d Rem %06d/%06d Psh Indx %06d SltNot %06d Sz.Ptr %06d/%p %06d/%p\n", pUser, mpData_U8, mpCrtBufferHead_U8, \ + mRawCircularBufferParam_X.BufferSizeInByte_U32 - mCrtBufferRemain_U32, mCrtBufferRemain_U32, mRawCircularBufferParam_X.BufferSizeInByte_U32, \ + (pRaw)->IndexInBuffer_U32, (pRaw)->SlotEmpySpace_U32, (pRaw)->Size1_U32, (pRaw)->pData1_U8, (pRaw)->Size2_U32, (pRaw)->pData2_U8); \ + } BofRawCircularBuffer::BofRawCircularBuffer(const BOF_RAW_CIRCULAR_BUFFER_PARAM &_rRawCircularBufferParam_X) { - mRawCircularBufferParam_X = _rRawCircularBufferParam_X; - mNbSlot_U32 = 0; - mSlotSize_U32 = 0; - mNbElementInBuffer_U32 = 0; - mpData_U8 = nullptr; - mPushIndex_U32 = 0; - mPopIndex_U32 = 0; - mLevelMax_U32 = 0; + BOF_CIRCULAR_BUFFER_PARAM CircularBufferParam_X; + mRawCircularBufferParam_X = _rRawCircularBufferParam_X; mErrorCode_E = BOF_ERR_TOO_SMALL; - if (mRawCircularBufferParam_X.BufferSizeInByte_U32) + if ((mRawCircularBufferParam_X.BufferSizeInByte_U32) && (mRawCircularBufferParam_X.NbMaxBufferEntry_U32)) { - mErrorCode_E = _rRawCircularBufferParam_X.MultiThreadAware_B ? Bof_CreateMutex("BofCircularBuffer", false, false, mRawCircularBufferMtx_X) : BOF_ERR_NO_ERROR; + mErrorCode_E = _rRawCircularBufferParam_X.MultiThreadAware_B ? Bof_CreateMutex("BofRawCircularBuffer", false, false, mRawCircularBufferMtx_X) : BOF_ERR_NO_ERROR; if (mErrorCode_E == BOF_ERR_NO_ERROR) { if (_rRawCircularBufferParam_X.pData_U8) { mDataPreAllocated_B = true; mpData_U8 = _rRawCircularBufferParam_X.pData_U8; - - if (mRawCircularBufferParam_X.NbMaxSlot_U32) - { - if ((mRawCircularBufferParam_X.BufferSizeInByte_U32 - (mRawCircularBufferParam_X.NbMaxSlot_U32 * sizeof(uint32_t))) % mRawCircularBufferParam_X.NbMaxSlot_U32) - { - mErrorCode_E = BOF_ERR_WRONG_SIZE; - } - else - { - mSlotSize_U32 = (mRawCircularBufferParam_X.BufferSizeInByte_U32 - (mRawCircularBufferParam_X.NbMaxSlot_U32 * static_cast(sizeof(uint32_t)))) / mRawCircularBufferParam_X.NbMaxSlot_U32; - - if (!mSlotSize_U32) - { - mErrorCode_E = BOF_ERR_WRONG_SIZE; - } - } - } } else { - if (mRawCircularBufferParam_X.NbMaxSlot_U32) + mDataPreAllocated_B = false; + mpData_U8 = new uint8_t[mRawCircularBufferParam_X.BufferSizeInByte_U32]; + if (mpData_U8 == nullptr) { - if (mRawCircularBufferParam_X.BufferSizeInByte_U32 % mRawCircularBufferParam_X.NbMaxSlot_U32) - { - mErrorCode_E = BOF_ERR_WRONG_SIZE; - } - else - { - mSlotSize_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32 / mRawCircularBufferParam_X.NbMaxSlot_U32; - - if (!mSlotSize_U32) - { - mErrorCode_E = BOF_ERR_WRONG_SIZE; - } - else - { - mRawCircularBufferParam_X.BufferSizeInByte_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32 + (mRawCircularBufferParam_X.NbMaxSlot_U32 * static_cast(sizeof(uint32_t))); // Space needed by length header - } - } + mErrorCode_E = BOF_ERR_ENOMEM; } - - if (mErrorCode_E == BOF_ERR_NO_ERROR) + } + if (mErrorCode_E == BOF_ERR_NO_ERROR) + { + mSlotSize_U32 = mRawCircularBufferParam_X.SlotMode_B ? (mRawCircularBufferParam_X.BufferSizeInByte_U32 / mRawCircularBufferParam_X.NbMaxBufferEntry_U32) : 0; + mRawBufferToPush_X.Reset(); + mCrtBufferRemain_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32; + mpCrtBufferHead_U8 = mpData_U8; + mRawBufferToPush_X.pData1_U8 = mpCrtBufferHead_U8; + mpCrtBufferEnd_U8 = &mpData_U8[mRawCircularBufferParam_X.BufferSizeInByte_U32]; + + mErrorCode_E = BOF_ERR_ENOMEM; + CircularBufferParam_X.MultiThreadAware_B = false; // Controled by the mutex of BofRawCircularBuffer + CircularBufferParam_X.NbMaxElement_U32 = mRawCircularBufferParam_X.NbMaxBufferEntry_U32; + CircularBufferParam_X.pData = nullptr; + CircularBufferParam_X.Overwrite_B = false; + CircularBufferParam_X.Blocking_B = _rRawCircularBufferParam_X.Blocking_B; + CircularBufferParam_X.PopLockMode_B = false; + mpuBufferCollection = std::make_unique>(CircularBufferParam_X); + if (mpuBufferCollection) { - mDataPreAllocated_B = false; - mpData_U8 = new uint8_t[mRawCircularBufferParam_X.BufferSizeInByte_U32]; - - if (mpData_U8 == nullptr) - { - mErrorCode_E = BOF_ERR_ENOMEM; - } + mErrorCode_E = mpuBufferCollection->LastErrorCode(); } } } } } -/*! - * Description - * This is the destructor of the Circular buffer structure. It releases all - * the resources allocated dynamically by the object - * - * Parameters - * None - * - * Returns - * None - * - * Remarks - * None - * - * See Also - * BofRawCircularBuffer - */ - BofRawCircularBuffer::~BofRawCircularBuffer() { if (!mDataPreAllocated_B) @@ -155,149 +101,75 @@ BofRawCircularBuffer::~BofRawCircularBuffer() Bof_DestroyMutex(mRawCircularBufferMtx_X); } +void BofRawCircularBuffer::Reset() +{ + BOFERR Sts_E; + + BOF_RAW_CIRCULAR_BUFFER_LOCK(Sts_E); + if (Sts_E == BOF_ERR_NO_ERROR) + { + mLevelMax_U32 = 0; + mOverflow_B = false; + mAppendMode_B = false; + mpuBufferCollection->Reset(); + mRawBufferToPush_X.Reset(); + mRawBufferToPush_X.pData1_U8 = mpData_U8; + mCrtBufferRemain_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32; + mpCrtBufferHead_U8 = mpData_U8; + BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); + } +} + BOFERR BofRawCircularBuffer::LastErrorCode() { return mErrorCode_E; } + bool BofRawCircularBuffer::IsEmpty() { - return mNbElementInBuffer_U32 == 0; -} -bool BofRawCircularBuffer::IsFull() -{ - return GetNbFreeElement() == 0; + bool Rts_B; + + Rts_B = mpuBufferCollection->IsEmpty(); + return Rts_B; } + uint32_t BofRawCircularBuffer::GetSlotSize() { return mSlotSize_U32; } -uint32_t BofRawCircularBuffer::GetNbElement() -{ - return mSlotSize_U32 ? mNbSlot_U32 : mNbElementInBuffer_U32; -} -uint32_t BofRawCircularBuffer::GetCapacity() -{ - return mSlotSize_U32 ? mRawCircularBufferParam_X.NbMaxSlot_U32 : mRawCircularBufferParam_X.BufferSizeInByte_U32; -} -uint32_t BofRawCircularBuffer::GetMaxLevel() -{ - return mLevelMax_U32; -} -/*! - * Description - * This function stores a byte buffer of _Nb_U32 byte long inside the circular buffer. - * - * Parameters - * _Nb_U32: Specify the number of byte to push inside the container - * _pData_UB: Specifies the data byte stream to store in the circular buffer. - * - * Returns - * uint32_t: BOF_ERR_NO_ERROR if the operation is successful - * - * Remarks - * a uint32_t containing the number of bytes pushed is inserted before the data buffer for Pop operation - * - * See Also - * Pop - */ -BOFERR BofRawCircularBuffer::PushBuffer(uint32_t _Nb_U32, const uint8_t *_pData_U8) -{ - BOFERR Rts_E = BOF_ERR_EINVAL; - bool EnoughSpace_B; - if ((_Nb_U32) && (_Nb_U32 < 0x80000000) && (_pData_U8)) // Bit 31 is used to signal locked zone - { - BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); - if (Rts_E == BOF_ERR_NO_ERROR) - { - if (mSlotSize_U32) - { - EnoughSpace_B = ((mNbSlot_U32 < mRawCircularBufferParam_X.NbMaxSlot_U32) && (_Nb_U32 <= mSlotSize_U32)); - } - else - { - EnoughSpace_B = ((mNbElementInBuffer_U32 + _Nb_U32 + sizeof(uint32_t)) <= mRawCircularBufferParam_X.BufferSizeInByte_U32); - } +bool BofRawCircularBuffer::IsFull() +{ + bool Rts_B; - if (EnoughSpace_B) - { - WriteNbHeader(nullptr, _Nb_U32); - Rts_E = WritePayload(nullptr, _Nb_U32, _pData_U8); - } - else - { - Rts_E = BOF_ERR_FULL; - } - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); - } - } - return Rts_E; + Rts_B = mpuBufferCollection->IsFull(); + return Rts_B; } -/*! - * Description - * This function removes a data byte buffer (up to '*_pNbMax_U32 long) from the circular buffer. - * - * Parameters - * _pNbMax_U32: Specify the maximum number of element to pop and \returns the real number of data poped - * _pData_U8: \Returns the data read from the circular buffer. - * - * Returns - * uint32_t: BOF_ERR_NO_ERROR if the operation is successful - * - * Remarks - * None - * - * See Also - * Push - */ -BOFERR BofRawCircularBuffer::PopBuffer(uint32_t *_pNbMax_U32, uint8_t *_pData_U8) +uint32_t BofRawCircularBuffer::GetNbElement(uint32_t *_pSizeOfFirst_U32) { - BOFERR Rts_E = BOF_ERR_EINVAL; - uint32_t Nb_U32, PopIndex_U32; + uint32_t Rts_U32, PopIndex_U32; + BOF_RAW_BUFFER RawBuffer_X; - if ((_pNbMax_U32) && (_pData_U8)) + if (_pSizeOfFirst_U32) { - BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); - if (Rts_E == BOF_ERR_NO_ERROR) + if (IsEmpty()) { - if (mNbSlot_U32) - { - PopIndex_U32 = mPopIndex_U32; - Nb_U32 = ReadNbHeader(&PopIndex_U32); - - if (Nb_U32 & 0x80000000) // Bit 31 is used to signal locked zone - { - Rts_E = BOF_ERR_NOT_AVAILABLE; - Nb_U32 = 0; - } - else - { - if (Nb_U32 <= *_pNbMax_U32) - { - mNbElementInBuffer_U32 -= static_cast(sizeof(uint32_t)); - mPopIndex_U32 = PopIndex_U32; - Rts_E = ReadPayload(nullptr, Nb_U32, _pData_U8); - } - else - { - Rts_E = BOF_ERR_TOO_SMALL; - } - } - } - else + *_pSizeOfFirst_U32 = 0; + } + else + { + if (mpuBufferCollection->Peek(&RawBuffer_X, 0, nullptr, nullptr) == BOF_ERR_NO_ERROR) { - Rts_E = BOF_ERR_EMPTY; - Nb_U32 = 0; + *_pSizeOfFirst_U32 = RawBuffer_X.Size1_U32 + RawBuffer_X.Size2_U32; } - *_pNbMax_U32 = Nb_U32; - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } } - return Rts_E; + Rts_U32 = mpuBufferCollection->GetNbElement(); + return Rts_U32; } -uint32_t BofRawCircularBuffer::GetNbFreeElement() +uint32_t BofRawCircularBuffer::GetNbFreeElement(uint32_t *_pRemainingSize_U32) { uint32_t Rts_U32 = 0; BOFERR Sts_E; @@ -305,547 +177,491 @@ uint32_t BofRawCircularBuffer::GetNbFreeElement() BOF_RAW_CIRCULAR_BUFFER_LOCK(Sts_E); if (Sts_E == BOF_ERR_NO_ERROR) { - if (mSlotSize_U32) + Rts_U32 = mpuBufferCollection->GetNbFreeElement(); + if (_pRemainingSize_U32) { - Rts_U32 = mRawCircularBufferParam_X.NbMaxSlot_U32 - mNbSlot_U32; - } - else - { - Rts_U32 = ((mRawCircularBufferParam_X.BufferSizeInByte_U32 - mNbElementInBuffer_U32) > static_cast(sizeof(uint32_t))) ? mRawCircularBufferParam_X.BufferSizeInByte_U32 - mNbElementInBuffer_U32 - static_cast(sizeof(uint32_t)) : 0; + *_pRemainingSize_U32 = mCrtBufferRemain_U32; } BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } return Rts_U32; } -void BofRawCircularBuffer::Reset() +uint32_t BofRawCircularBuffer::GetCapacity(uint32_t *_pTotalSize_U32) { - BOFERR Sts_E; + uint32_t Rts_U32; - BOF_RAW_CIRCULAR_BUFFER_LOCK(Sts_E); - if (Sts_E == BOF_ERR_NO_ERROR) + Rts_U32 = mpuBufferCollection->GetCapacity(); + if (_pTotalSize_U32) { - mLevelMax_U32 = 0; - mPushIndex_U32 = 0; - mPopIndex_U32 = 0; - mNbElementInBuffer_U32 = 0; - mNbSlot_U32 = 0; + *_pTotalSize_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32; + } + return Rts_U32; +} - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); +uint32_t BofRawCircularBuffer::GetMaxLevel() +{ + uint32_t Rts_U32; + + Rts_U32 = mSlotSize_U32 ? mpuBufferCollection->GetMaxLevel() : mLevelMax_U32; + return Rts_U32; +} + +BOFERR BofRawCircularBuffer::SetOverWriteMode(bool _Overwrite_B) +{ + mRawCircularBufferParam_X.Overwrite_B = _Overwrite_B; + return BOF_ERR_NO_ERROR; +} + +BOFERR BofRawCircularBuffer::SetAppendMode(uint32_t _BlockingTimeouItInMs_U32, bool _Append_B) +{ + BOFERR Rts_E = BOF_ERR_NO_ERROR; + // uint8_t pData_U8[8]; + + if ((mAppendMode_B) && (_Append_B == false)) // We leave the append mode->unlock growing buffer + { + // Rts_E = UpdatePushRawBuffer(0, pData_U8); + // if (Rts_E == BOF_ERR_NO_ERROR) + { + Rts_E = PushRawBuffer(_BlockingTimeouItInMs_U32); + } } + mAppendMode_B = _Append_B; + return Rts_E; } -BOFERR BofRawCircularBuffer::Peek(uint32_t _Index_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8) +bool BofRawCircularBuffer::IsBufferOverflow() +{ + bool Rts_B = mOverflow_B; + mOverflow_B = false; + return Rts_B; +} + +BOFERR BofRawCircularBuffer::LockRawCircularBuffer() +{ + BOFERR Rts_E = BOF_ERR_BAD_TYPE; + + if (mRawCircularBufferParam_X.MultiThreadAware_B) + { + Rts_E = Bof_LockMutex(mRawCircularBufferMtx_X); + } + return Rts_E; +} + +BOFERR BofRawCircularBuffer::UnlockRawCircularBuffer() +{ + BOFERR Rts_E = BOF_ERR_BAD_TYPE; + + if (mRawCircularBufferParam_X.MultiThreadAware_B) + { + Rts_E = Bof_UnlockMutex(mRawCircularBufferMtx_X); + } + return Rts_E; +} + +// Buffer is protected and all param are checked by caller +BOFERR BofRawCircularBuffer::UpdatePushRawBuffer(uint32_t _Size_U32, const uint8_t *_pData_U8) { BOFERR Rts_E = BOF_ERR_EINVAL; - uint32_t Nb_U32, PopIndex_U32, j_U32; + uint32_t Nb1_U32, Nb2_U32, Index_U32; - if ((_pNbMax_U32) && (_pData_U8)) + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + BOF_ASSERT(_Size_U32 <= mCrtBufferRemain_U32); + if ((_pData_U8) && (_Size_U32 <= mCrtBufferRemain_U32)) { - BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); - if (Rts_E == BOF_ERR_NO_ERROR) + if (mRawBufferToPush_X.Size2_U32) { - if ((mNbSlot_U32) && (_Index_U32 < mNbSlot_U32)) + BOF_ASSERT(mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size2_U32 + _Size_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + if (mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size2_U32 + _Size_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32) { - PopIndex_U32 = mPopIndex_U32; - - if (_Index_U32) - { - for (j_U32 = 0; j_U32 < _Index_U32; j_U32++) - { - Nb_U32 = ReadNbHeader(&PopIndex_U32); + memcpy(&mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size2_U32], _pData_U8, _Size_U32); + BOF_ASSERT(mpCrtBufferHead_U8 == &mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size2_U32]); + mCrtBufferRemain_U32 -= _Size_U32; + mpCrtBufferHead_U8 += _Size_U32; + mRawBufferToPush_X.Size2_U32 += _Size_U32; + Rts_E = BOF_ERR_NO_ERROR; + } + } + else + { + Rts_E = BOF_ERR_NO_ERROR; + Index_U32 = mRawBufferToPush_X.IndexInBuffer_U32 + _Size_U32; + if (Index_U32 > mRawCircularBufferParam_X.BufferSizeInByte_U32) + { + Nb1_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32 - (mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size1_U32); + memcpy(&mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size1_U32], _pData_U8, Nb1_U32); + BOF_ASSERT(mpCrtBufferHead_U8 == &mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size1_U32]); - if (Nb_U32 & 0x80000000) // Bit 31 is used to signal locked zone - { - Nb_U32 &= 0x7FFFFFFF; // Bit 31 is used to signal locked zone - } + Nb2_U32 = _Size_U32 - Nb1_U32; + memcpy(&mpData_U8[0 + 0], &_pData_U8[Nb1_U32], Nb2_U32); - if (mSlotSize_U32) - { - PopIndex_U32 += mSlotSize_U32; - } - else - { - PopIndex_U32 = ((PopIndex_U32 + Nb_U32) % mRawCircularBufferParam_X.BufferSizeInByte_U32); - } + mCrtBufferRemain_U32 -= (Nb1_U32 + Nb2_U32); + mpCrtBufferHead_U8 = &mpData_U8[Nb1_U32]; - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - } - } - Nb_U32 = ReadNbHeader(&PopIndex_U32); + mRawBufferToPush_X.Size1_U32 = mRawCircularBufferParam_X.BufferSizeInByte_U32 - mRawBufferToPush_X.IndexInBuffer_U32; + mRawBufferToPush_X.pData2_U8 = mpData_U8; + mRawBufferToPush_X.Size2_U32 = Nb2_U32; // (Index_U32 - mRawCircularBufferParam_X.BufferSizeInByte_U32); - if (Nb_U32 & 0x80000000) // Bit 31 is used to signal locked zone - { - Rts_E = BOF_ERR_NOT_AVAILABLE; - Nb_U32 = 0; - } - else - { - // In peek mode we can 'read' less than Nb_U32 as we do not modify buffer control val - if (Nb_U32 > *_pNbMax_U32) - { - Nb_U32 = *_pNbMax_U32; - } - Rts_E = ReadPayload(&PopIndex_U32, Nb_U32, _pData_U8); - } + BOF_ASSERT(Nb2_U32 == (Index_U32 - mRawCircularBufferParam_X.BufferSizeInByte_U32)); } else { - Rts_E = BOF_ERR_EMPTY; - Nb_U32 = 0; + memcpy(&mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size1_U32], _pData_U8, _Size_U32); + BOF_ASSERT(mpCrtBufferHead_U8 == &mpData_U8[mRawBufferToPush_X.IndexInBuffer_U32 + mRawBufferToPush_X.Size1_U32]); + + mCrtBufferRemain_U32 -= _Size_U32; + mpCrtBufferHead_U8 += _Size_U32; + + mRawBufferToPush_X.Size1_U32 += _Size_U32; + } + BOF_ASSERT(mpCrtBufferHead_U8 <= mpCrtBufferEnd_U8); + if (mpCrtBufferHead_U8 >= mpCrtBufferEnd_U8) + { + BOF_ASSERT(mpCrtBufferHead_U8 == mpCrtBufferEnd_U8); + mpCrtBufferHead_U8 = mpData_U8; } - *_pNbMax_U32 = Nb_U32; - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } + + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); } return Rts_E; } -BOFERR BofRawCircularBuffer::Skip() +// Buffer is protected and all param are checked by caller +BOFERR BofRawCircularBuffer::PushRawBuffer(uint32_t _BlockingTimeouItInMs_U32) { - BOFERR Rts_E; - uint32_t Nb_U32, PopIndex_U32; + BOFERR Rts_E = BOF_ERR_EINVAL; + uint32_t Nb_U32; - BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + + Nb_U32 = (mRawBufferToPush_X.Size1_U32 + mRawBufferToPush_X.Size2_U32); + if (mSlotSize_U32) + { + mRawBufferToPush_X.SlotEmpySpace_U32 = mSlotSize_U32 - Nb_U32; // For partial read of slot + BOF_ASSERT(mRawBufferToPush_X.SlotEmpySpace_U32 <= mSlotSize_U32); + } + Rts_E = mpuBufferCollection->Push(&mRawBufferToPush_X, _BlockingTimeouItInMs_U32, nullptr); + BOF_ASSERT(Rts_E == BOF_ERR_NO_ERROR); if (Rts_E == BOF_ERR_NO_ERROR) { - if (mNbSlot_U32) + if (mSlotSize_U32) { - PopIndex_U32 = mPopIndex_U32; - Nb_U32 = ReadNbHeader(&PopIndex_U32); - - if (Nb_U32 & 0x80000000) // Bit 31 is used to signal locked zone + mCrtBufferRemain_U32 -= mRawBufferToPush_X.SlotEmpySpace_U32; + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + mpCrtBufferHead_U8 += mRawBufferToPush_X.SlotEmpySpace_U32; + if (mpCrtBufferHead_U8 >= mpCrtBufferEnd_U8) { - Rts_E = BOF_ERR_NOT_AVAILABLE; - } - else - { - mNbElementInBuffer_U32 -= static_cast(sizeof(uint32_t)); - mPopIndex_U32 = PopIndex_U32; - Rts_E = ReadPayload(nullptr, Nb_U32, nullptr); + BOF_ASSERT(mpCrtBufferHead_U8 == mpCrtBufferEnd_U8); + mpCrtBufferHead_U8 = mpData_U8; } } else { - Rts_E = BOF_ERR_EMPTY; + if (Nb_U32 > mLevelMax_U32) + { + mLevelMax_U32 = Nb_U32; + } } - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); + mRawBufferToPush_X.Reset(); + mRawBufferToPush_X.IndexInBuffer_U32 = mpCrtBufferHead_U8 - mpData_U8; + mRawBufferToPush_X.pData1_U8 = mpCrtBufferHead_U8; } + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + return Rts_E; } -BOFERR BofRawCircularBuffer::LockBuffer(uint32_t _Nb_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8) +BOFERR BofRawCircularBuffer::PushBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8) { BOFERR Rts_E = BOF_ERR_EINVAL; - uint32_t Nb_U32; bool EnoughSpace_B; + uint32_t Nb_U32, IndexOf_U32; + //char pHeader_c[128]; + bool IsLocked_B; + BOF_RAW_BUFFER RawBuffer_X, *pRawBuffer_X; - if ((_Nb_U32) && (_pNb1_U32) && (_ppData1_U8) && (_pNb2_U32) && (_ppData2_U8)) + if ((_Nb_U32) && (_pData_U8)) { - *_pNb1_U32 = 0; - *_ppData1_U8 = nullptr; - *_pNb2_U32 = 0; - *_ppData2_U8 = nullptr; - BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); if (Rts_E == BOF_ERR_NO_ERROR) { - if (mSlotSize_U32) - { - EnoughSpace_B = ((mNbSlot_U32 < mRawCircularBufferParam_X.NbMaxSlot_U32) && (_Nb_U32 <= mSlotSize_U32)); - } - else - { - EnoughSpace_B = ((mNbElementInBuffer_U32 + _Nb_U32 + sizeof(uint32_t)) <= mRawCircularBufferParam_X.BufferSizeInByte_U32); - } + //sprintf(pHeader_c, "PushBuffer Start: Nb %d ", _Nb_U32); + //DBG_RAW_BUFFER_INFO(pHeader_c, &mRawBufferToPush_X); + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + EnoughSpace_B = (_Nb_U32 <= mCrtBufferRemain_U32); if (EnoughSpace_B) { - WriteNbHeader(nullptr, _Nb_U32 | 0x80000000); // Bit 31 is used to signal locked zone (PopBuffer) - *_ppData1_U8 = &mpData_U8[mPushIndex_U32]; - if (mSlotSize_U32) { - *_pNb1_U32 = _Nb_U32; + if (mAppendMode_B) + { + EnoughSpace_B = ((_Nb_U32 + mRawBufferToPush_X.Size1_U32 + mRawBufferToPush_X.Size2_U32) <= mSlotSize_U32); + } + else + { + EnoughSpace_B = (_Nb_U32 <= mSlotSize_U32); + } } else { - Nb_U32 = (mRawCircularBufferParam_X.BufferSizeInByte_U32 - mPushIndex_U32); - - if (Nb_U32 >= _Nb_U32) + if (IsFull()) //we have only a limitted amound of entries { - *_pNb1_U32 = _Nb_U32; + EnoughSpace_B = false; + } + } + } + if ((!EnoughSpace_B) && (!mAppendMode_B) && (mRawCircularBufferParam_X.Overwrite_B)) + { + if (mSlotSize_U32) + { + EnoughSpace_B = (_Nb_U32 <= mSlotSize_U32); + } + else + { + EnoughSpace_B = (_Nb_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + } + if (EnoughSpace_B) + { + if (mSlotSize_U32) + { + // Not BofRawCircularBuffer::Skip + Rts_E = mpuBufferCollection->Skip(&RawBuffer_X, false, &IndexOf_U32, &pRawBuffer_X, &IsLocked_B); // Remove oldest buffer so we have new storage space + if (Rts_E == BOF_ERR_NO_ERROR) + { + mCrtBufferRemain_U32 = mSlotSize_U32; + } } else { - *_ppData2_U8 = &mpData_U8[0]; - *_pNb1_U32 = Nb_U32; - *_pNb2_U32 = _Nb_U32 - Nb_U32; + do + { + // Not BofRawCircularBuffer::Skip + Rts_E = mpuBufferCollection->Skip(&RawBuffer_X, false, &IndexOf_U32, &pRawBuffer_X, &IsLocked_B); // Remove oldest bufferS so we have new storage space + if (Rts_E == BOF_ERR_NO_ERROR) + { + mCrtBufferRemain_U32 += (RawBuffer_X.Size1_U32 + RawBuffer_X.Size2_U32); + } + } while ((Rts_E == BOF_ERR_NO_ERROR) && (mCrtBufferRemain_U32 < _Nb_U32)); } + BOF_ASSERT(mCrtBufferRemain_U32 >= _Nb_U32); + mOverflow_B = true; } + } - if (WritePayload(nullptr, _Nb_U32, nullptr) == 0) - { - Rts_E = BOF_ERR_NO_ERROR; - } - else + if (EnoughSpace_B) + { + if (Rts_E == BOF_ERR_NO_ERROR) { - Rts_E = BOF_ERR_WRITE; + Rts_E = UpdatePushRawBuffer(_Nb_U32, _pData_U8); + BOF_ASSERT(Rts_E == BOF_ERR_NO_ERROR); + if (!mAppendMode_B) + { + Rts_E = PushRawBuffer(_BlockingTimeouItInMs_U32); + } } } else { - Rts_E = BOF_ERR_FULL; + Rts_E = BOF_ERR_TOO_BIG; } - BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } + //DBG_RAW_BUFFER_INFO("PushBuffer End:", &mRawBufferToPush_X); + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + + BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } return Rts_E; } -BOFERR BofRawCircularBuffer::UnlockBuffer(const uint8_t *_pLockedBuffer_U8, uint32_t _Nb_U32) // , const uint8_t *_pData_U8) +BOFERR BofRawCircularBuffer::PopOrPeekBuffer(bool _Pop_B, uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8) { BOFERR Rts_E = BOF_ERR_EINVAL; - uint32_t PopIndex_U32, PushIndex_U32, Nb_U32; + uint32_t Size_U32, NbToRead_U32, NbRead_U32, IndexOf_U32; + BOF_RAW_BUFFER RawBuffer_X, *pRawBuffer_X; + bool IsLocked_B, PartialRead_B; + //char pHeader_c[128]; - if ((_Nb_U32) && (_pLockedBuffer_U8)) + if (_pNbMax_U32) { - if ((_pLockedBuffer_U8 >= mpData_U8) && (_pLockedBuffer_U8 < &mpData_U8[mRawCircularBufferParam_X.BufferSizeInByte_U32]) && ((_pLockedBuffer_U8 + _Nb_U32) <= &mpData_U8[mRawCircularBufferParam_X.BufferSizeInByte_U32])) + NbRead_U32 = 0; + if ((*_pNbMax_U32) && (_pData_U8)) { BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); if (Rts_E == BOF_ERR_NO_ERROR) { - PopIndex_U32 = static_cast(_pLockedBuffer_U8 - mpData_U8 - sizeof(uint32_t)); - PushIndex_U32 = PopIndex_U32; - Nb_U32 = ReadNbHeader(&PopIndex_U32); // Bit 31 is used to signal locked zone: Written by LockBuffer + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); - if (Nb_U32 & 0x80000000) + if (!IsEmpty()) { - Nb_U32 &= 0x7FFFFFFF; // Bit 31 is used to signal locked zone - - if (_Nb_U32 <= Nb_U32) // Normally they should be equal... + Rts_E = mpuBufferCollection->Peek(&RawBuffer_X, _BlockingTimeouItInMs_U32, nullptr, &pRawBuffer_X); + BOF_ASSERT(Rts_E == BOF_ERR_NO_ERROR); + if (Rts_E == BOF_ERR_NO_ERROR) { - Rts_E = WriteNbHeader(&PushIndex_U32, - Nb_U32); // Write Nb_U32 and not _Nb_U32 because all other var control have been computed by LockBuffer based on this value... - // Rts_U32 = WritePayload(&PushIndex_U32, _Nb_U32, _pData_U8); - } - else - { - Rts_E = BOF_ERR_WRONG_SIZE; + //sprintf(pHeader_c, _Pop_B ? "PopBuffer Start: Nb %d " : "PeekBuffer Start: Nb %d ", *_pNbMax_U32); + //DBG_RAW_BUFFER_INFO(pHeader_c, pRawBuffer_X); + + NbToRead_U32 = RawBuffer_X.Size1_U32 + RawBuffer_X.Size2_U32; + PartialRead_B = false; + if (NbToRead_U32 > *_pNbMax_U32) + { + NbToRead_U32 = *_pNbMax_U32; + PartialRead_B = true; + } + NbRead_U32 = 0; + if (NbToRead_U32) + { + if (RawBuffer_X.Size1_U32) + { + Size_U32 = (RawBuffer_X.Size1_U32 > NbToRead_U32) ? NbToRead_U32 : RawBuffer_X.Size1_U32; + + memcpy(_pData_U8, RawBuffer_X.pData1_U8, Size_U32); + pRawBuffer_X->Size1_U32 -= Size_U32; + pRawBuffer_X->pData1_U8 += Size_U32; + NbToRead_U32 -= Size_U32; + NbRead_U32 += Size_U32; + } + } + if (NbToRead_U32) + { + if (RawBuffer_X.Size2_U32) + { + BOF_ASSERT(RawBuffer_X.pData2_U8); + + Size_U32 = (RawBuffer_X.Size2_U32 > NbToRead_U32) ? NbToRead_U32 : RawBuffer_X.Size2_U32; + + memcpy(&_pData_U8[NbRead_U32], RawBuffer_X.pData2_U8, Size_U32); + pRawBuffer_X->Size2_U32 -= Size_U32; + pRawBuffer_X->pData2_U8 += Size_U32; + NbToRead_U32 -= Size_U32; + NbRead_U32 += Size_U32; + } + } + if (PartialRead_B) + { + mCrtBufferRemain_U32 += NbRead_U32; + } + else if (_Pop_B) + { + // Not BofRawCircularBuffer::Skip + Rts_E = mpuBufferCollection->Skip(&RawBuffer_X, true, &IndexOf_U32, &pRawBuffer_X, &IsLocked_B); // Remove oldest bufferS so we have new storage space + BOF_ASSERT(Rts_E == BOF_ERR_NO_ERROR); + if (Rts_E == BOF_ERR_NO_ERROR) + { + mCrtBufferRemain_U32 += NbRead_U32; + if (mSlotSize_U32) + { + mCrtBufferRemain_U32 += RawBuffer_X.SlotEmpySpace_U32; + } + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + // NO !! mpCrtBufferHead_U8 += NbRead_U32; + } + } + //DBG_RAW_BUFFER_INFO(_Pop_B ? "PopBuffer End:" : "PeekBuffer End:", pRawBuffer_X); } } else { - Rts_E = BOF_ERR_NOT_AVAILABLE; + Rts_E = BOF_ERR_EMPTY; } + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); + BOF_ASSERT(mpCrtBufferHead_U8 >= mpData_U8); + BOF_ASSERT(mpCrtBufferHead_U8 < mpCrtBufferEnd_U8); + BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); - } - } - } + } // if (Rts_E == BOF_ERR_NO_ERROR) + } // if (_pData_U8) + *_pNbMax_U32 = NbRead_U32; + } // if (_pNbMax_U32) return Rts_E; } -// if _pPopIndex_U32 is not null we do not update circular buffer control var and we return the new popIndex value to the caller -uint32_t BofRawCircularBuffer::ReadNbHeader(uint32_t *_pPopIndex_U32) +BOFERR BofRawCircularBuffer::PopBuffer(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8) { - uint32_t Rts_U32, PopIndex_U32; - //Lock is not taken to avoid recursive mutex - // No security check (private fct caller has checked everything) - if (_pPopIndex_U32) - { - PopIndex_U32 = *_pPopIndex_U32; - } - else - { - PopIndex_U32 = mPopIndex_U32; - } - Rts_U32 = ((uint32_t)(mpData_U8[PopIndex_U32]) << 24); - PopIndex_U32++; - - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - - Rts_U32 |= ((uint32_t)(mpData_U8[PopIndex_U32]) << 16); - PopIndex_U32++; - - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - - Rts_U32 |= ((uint32_t)(mpData_U8[PopIndex_U32]) << 8); - PopIndex_U32++; - - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - - Rts_U32 |= ((uint32_t)(mpData_U8[PopIndex_U32])); - PopIndex_U32++; - - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - - if (_pPopIndex_U32) - { - *_pPopIndex_U32 = PopIndex_U32; - } - else - { - mPopIndex_U32 = PopIndex_U32; - mNbElementInBuffer_U32 -= static_cast(sizeof(uint32_t)); - } - return Rts_U32; + BOFERR Rts_E = PopOrPeekBuffer(true, _BlockingTimeouItInMs_U32, _pNbMax_U32, _pData_U8); + return Rts_E; } -BOFERR BofRawCircularBuffer::WriteNbHeader(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32) +BOFERR BofRawCircularBuffer::Peek(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNbMax_U32, uint8_t *_pData_U8) { - BOFERR Rts_E = BOF_ERR_NO_ERROR; - uint32_t PushIndex_U32; - //Lock is not taken to avoid recursive mutex - // No security check (private fct caller has checked everything) - if (_pPushIndex_U32) - { - PushIndex_U32 = *_pPushIndex_U32; - } - else - { - PushIndex_U32 = mPushIndex_U32; - } - mpData_U8[PushIndex_U32] = (uint8_t)(_Nb_U32 >> 24); - PushIndex_U32++; - - if (PushIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PushIndex_U32 = 0; - } - - mpData_U8[PushIndex_U32] = (uint8_t)(_Nb_U32 >> 16); - PushIndex_U32++; - - if (PushIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PushIndex_U32 = 0; - } - - mpData_U8[PushIndex_U32] = (uint8_t)(_Nb_U32 >> 8); - PushIndex_U32++; - - if (PushIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PushIndex_U32 = 0; - } - - mpData_U8[PushIndex_U32] = (uint8_t)(_Nb_U32); - PushIndex_U32++; - - if (PushIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PushIndex_U32 = 0; - } - - if (_pPushIndex_U32) - { - *_pPushIndex_U32 = PushIndex_U32; - } - else - { - mPushIndex_U32 = PushIndex_U32; - mNbElementInBuffer_U32 += static_cast(sizeof(uint32_t)); - } - + BOFERR Rts_E = PopOrPeekBuffer(false, _BlockingTimeouItInMs_U32, _pNbMax_U32, _pData_U8); return Rts_E; } -BOFERR BofRawCircularBuffer::ReadPayload(uint32_t *_pPopIndex_U32, uint32_t _Nb_U32, uint8_t *_pData_U8) +// Need to call Skip after GetBufferPtr +BOFERR BofRawCircularBuffer::GetBufferPtr(uint32_t _BlockingTimeouItInMs_U32, uint32_t *_pNb1_U32, uint8_t **_ppData1_U8, uint32_t *_pNb2_U32, uint8_t **_ppData2_U8) { - BOFERR Rts_E = BOF_ERR_NO_ERROR; - uint32_t Nb_U32, PopIndex_U32, NbElementInBuffer_U32; - //Lock is not taken to avoid recursive mutex - // No security check (private fct caller has checked everything) - if (_pPopIndex_U32) - { - PopIndex_U32 = *_pPopIndex_U32; - } - else - { - PopIndex_U32 = mPopIndex_U32; - mNbSlot_U32--; - } - NbElementInBuffer_U32 = mNbElementInBuffer_U32; + BOFERR Rts_E = BOF_ERR_EINVAL; + BOF_RAW_BUFFER RawBuffer_X, *pRawBuffer_X; - if (mSlotSize_U32) + if ((_pNb1_U32) && (_ppData1_U8) && (_pNb2_U32) && (_ppData2_U8)) { - if (_pData_U8) - { - memcpy(_pData_U8, &mpData_U8[PopIndex_U32], _Nb_U32); - } - PopIndex_U32 += mSlotSize_U32; - NbElementInBuffer_U32 -= mSlotSize_U32; - } - else - { - Nb_U32 = (mRawCircularBufferParam_X.BufferSizeInByte_U32 - PopIndex_U32); - - if (Nb_U32 >= _Nb_U32) - { - if (_pData_U8) - { - memcpy(_pData_U8, &mpData_U8[PopIndex_U32], _Nb_U32); - } - PopIndex_U32 += _Nb_U32; - } - else + *_pNb1_U32 = 0; + *_ppData1_U8 = mpData_U8; + *_pNb2_U32 = 0; + *_ppData2_U8 = nullptr; + BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); + if (Rts_E == BOF_ERR_NO_ERROR) { - // Copy from the end of the buffer - if (_pData_U8) + if (!IsEmpty()) { - memcpy(_pData_U8, &mpData_U8[PopIndex_U32], Nb_U32); - - // Copy the remaining byte from the beginning of the buffer - _pData_U8 += Nb_U32; - Nb_U32 = _Nb_U32 - Nb_U32; - memcpy(_pData_U8, &mpData_U8[0], Nb_U32); + Rts_E = mpuBufferCollection->Peek(&RawBuffer_X, _BlockingTimeouItInMs_U32, nullptr, &pRawBuffer_X); + BOF_ASSERT(Rts_E == BOF_ERR_NO_ERROR); + if (Rts_E == BOF_ERR_NO_ERROR) + { + *_pNb1_U32 = RawBuffer_X.Size1_U32; + *_ppData1_U8 = RawBuffer_X.pData1_U8; + *_pNb2_U32 = RawBuffer_X.Size2_U32; + *_ppData2_U8 = RawBuffer_X.pData2_U8; + } } else { - Nb_U32 = _Nb_U32 - Nb_U32; + //no as we want to return mpData_U8 as container's base pointer Rts_E = BOF_ERR_EMPTY; } - PopIndex_U32 = Nb_U32; + BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } - NbElementInBuffer_U32 -= _Nb_U32; - } - - if (PopIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PopIndex_U32 = 0; - } - - if (_pPopIndex_U32) - { - *_pPopIndex_U32 = PopIndex_U32; - } - else - { - mPopIndex_U32 = PopIndex_U32; - mNbElementInBuffer_U32 = NbElementInBuffer_U32; } return Rts_E; } -// if _pData_U8 is null we just reserve (lock) a buffer for later use (LockBuffer) -// if _pPushIndex_U32 not null, Data is pushed from *_pPushIndex_U32 (Push Locked Buffer) -BOFERR BofRawCircularBuffer::WritePayload(uint32_t *_pPushIndex_U32, uint32_t _Nb_U32, const uint8_t *_pData_U8) +BOFERR BofRawCircularBuffer::Skip(bool _SignalIfNeeded_B, bool *_pLocked_B) { - BOFERR Rts_E = BOF_ERR_NO_ERROR; - uint32_t Nb_U32, PushIndex_U32, NbElementInBuffer_U32; - //Lock is not taken to avoid recursive mutex - // No security check (private fct caller has checked everything) - if (_pPushIndex_U32) - { - PushIndex_U32 = *_pPushIndex_U32; - } - else - { - PushIndex_U32 = mPushIndex_U32; - mNbSlot_U32++; - } - NbElementInBuffer_U32 = mNbElementInBuffer_U32; - - if (mSlotSize_U32) - { - if (_pData_U8) - { - memcpy(&mpData_U8[PushIndex_U32], _pData_U8, _Nb_U32); - } - PushIndex_U32 += mSlotSize_U32; - NbElementInBuffer_U32 += mSlotSize_U32; + BOFERR Rts_E; + uint32_t IndexOf_U32; + BOF_RAW_BUFFER RawBuffer_X, *pRawBuffer_X; - if (mNbSlot_U32 > mLevelMax_U32) - { - mLevelMax_U32 = mNbSlot_U32; - } - } - else + BOF_RAW_CIRCULAR_BUFFER_LOCK(Rts_E); + if (Rts_E == BOF_ERR_NO_ERROR) { - Nb_U32 = (mRawCircularBufferParam_X.BufferSizeInByte_U32 - PushIndex_U32); - - if (Nb_U32 >= _Nb_U32) - { - if (_pData_U8) - { - memcpy(&mpData_U8[PushIndex_U32], _pData_U8, _Nb_U32); - } - PushIndex_U32 += _Nb_U32; - } - else + Rts_E = mpuBufferCollection->Skip(&RawBuffer_X, _SignalIfNeeded_B, &IndexOf_U32, &pRawBuffer_X, _pLocked_B); + if (Rts_E == BOF_ERR_NO_ERROR) { - // Copy to the end of the buffer - if (_pData_U8) - { - memcpy(&mpData_U8[PushIndex_U32], _pData_U8, Nb_U32); - - // Copy the remaining byte at the beginning of the buffer - _pData_U8 += Nb_U32; - } - Nb_U32 = _Nb_U32 - Nb_U32; - - if (_pData_U8) + mCrtBufferRemain_U32 += (RawBuffer_X.Size1_U32 + RawBuffer_X.Size2_U32); + if (mSlotSize_U32) { - memcpy(&mpData_U8[0], _pData_U8, Nb_U32); + mCrtBufferRemain_U32 += mRawBufferToPush_X.SlotEmpySpace_U32; } - PushIndex_U32 = Nb_U32; - } - NbElementInBuffer_U32 += _Nb_U32; - - if (NbElementInBuffer_U32 > mLevelMax_U32) - { - mLevelMax_U32 = NbElementInBuffer_U32; + BOF_ASSERT(mCrtBufferRemain_U32 <= mRawCircularBufferParam_X.BufferSizeInByte_U32); } - } - - if (PushIndex_U32 >= mRawCircularBufferParam_X.BufferSizeInByte_U32) - { - PushIndex_U32 = 0; - } - - if (_pPushIndex_U32) - { - *_pPushIndex_U32 = PushIndex_U32; - } - else - { - mNbElementInBuffer_U32 = NbElementInBuffer_U32; - mPushIndex_U32 = PushIndex_U32; - } - return Rts_E; -} -BOFERR BofRawCircularBuffer::LockRawCircularBuffer() -{ - BOFERR Rts_E = BOF_ERR_BAD_TYPE; - - if (mRawCircularBufferParam_X.MultiThreadAware_B) - { - Rts_E = Bof_LockMutex(mRawCircularBufferMtx_X); + BOF_RAW_CIRCULAR_BUFFER_UNLOCK(); } return Rts_E; } -BOFERR BofRawCircularBuffer::UnlockRawCircularBuffer() -{ - BOFERR Rts_E = BOF_ERR_BAD_TYPE; - if (mRawCircularBufferParam_X.MultiThreadAware_B) - { - Rts_E = Bof_UnlockMutex(mRawCircularBufferMtx_X); - } - return Rts_E; -} END_BOF_NAMESPACE() \ No newline at end of file diff --git a/lib/src/bofsocket.cpp b/lib/src/bofsocket.cpp index c4d132a..b5b81a4 100644 --- a/lib/src/bofsocket.cpp +++ b/lib/src/bofsocket.cpp @@ -1321,8 +1321,7 @@ BOFERR BofSocket::V_ReadData(uint32_t _TimeoutInMs_U32, uint32_t &_rNb_U32, uint Nb_U32 = static_cast(recvfrom(mSocket, reinterpret_cast(_pBuffer_U8), static_cast(Size), 0, reinterpret_cast(&mDstIpAddress_X.IpV4Address_X), &Len_i)); } } - if (static_cast(Nb_U32) > - 0) // https://stackoverflow.com/questions/2416944/can-read-function-on-a-connected-socket-return-zero-bytes: No, you should consider -1 as an error and 0 as a normal disconnect, and close the socket in either case. � + if (static_cast(Nb_U32) > 0) // https://stackoverflow.com/questions/2416944/can-read-function-on-a-connected-socket-return-zero-bytes: No, you should consider -1 as an error and 0 as a normal disconnect, and close the socket in either case. � { _rNb_U32 = Nb_U32; Rts_E = BOF_ERR_NO_ERROR; @@ -2067,7 +2066,7 @@ BOFERR BofSocket::SetReadTimeout(uint32_t _TimeoutInMs_U32) #if defined(_WIN32) PollStatus_i = WSAPoll(&Fds_X, 1, _TimeoutInMs_U32); // == 1); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) #else - PollStatus_i = poll(&Fds_X, 1, _TimeoutInMs_U32); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) + PollStatus_i = poll(&Fds_X, 1, _TimeoutInMs_U32); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) #endif if (PollStatus_i > 0) { @@ -2155,7 +2154,7 @@ BOFERR BofSocket::SetReadOrWriteTimeout(uint32_t _TimeoutInMs_U32, bool &_ReadDa #if defined(_WIN32) PollStatus_i = WSAPoll(&Fds_X, 1, _TimeoutInMs_U32); // == 1); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) #else - PollStatus_i = poll(&Fds_X, 1, _TimeoutInMs_U32); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) + PollStatus_i = poll(&Fds_X, 1, _TimeoutInMs_U32); // Better than select (==1 can also be BOF_POLL_ERR, BOF_POLL_HUP, or BOF_POLL_NVAL) #endif if (PollStatus_i > 0) { diff --git a/lib/src/bofsocketos.cpp b/lib/src/bofsocketos.cpp index cf2b2b4..5b19419 100644 --- a/lib/src/bofsocketos.cpp +++ b/lib/src/bofsocketos.cpp @@ -1822,10 +1822,11 @@ BOFERR Bof_ResolveIpAddress(const std::string &_rIpAddress_S, BOF_SOCKET_ADDRESS _rIpAddress_X.IpV4Address_X.sin_family = 0; Rts_E = BOF_ERR_FORMAT; PosEop = _rIpAddress_S.find("://"); - + Protocol_S = ""; if (PosEop != std::string::npos) { Protocol_S = _rIpAddress_S.substr(0, PosEop); + _rIpAddress_X.Protocol_S = Protocol_S; if (Protocol_S == "tcp") { Type_E = BOF_SOCK_TYPE::BOF_SOCK_TCP; @@ -1876,6 +1877,7 @@ BOFERR Bof_ResolveIpAddress(const std::string &_rIpAddress_S, BOF_SOCKET_ADDRESS { Rts_E = Bof_IpAddressToSocketAddress(Interface_S, _rInterfaceIpAddress_X); _rInterfaceIpAddress_X.SocketType_E = Type_E; + _rInterfaceIpAddress_X.Protocol_S = Protocol_S; } } @@ -1885,6 +1887,7 @@ BOFERR Bof_ResolveIpAddress(const std::string &_rIpAddress_S, BOF_SOCKET_ADDRESS { Rts_E = Bof_IpAddressToSocketAddress(Address_S, _rIpAddress_X); _rIpAddress_X.SocketType_E = Type_E; + _rIpAddress_X.Protocol_S = Protocol_S; } } } diff --git a/lib/src/bofsocketthread.cpp b/lib/src/bofsocketthread.cpp index ca0968b..9c9f65d 100644 --- a/lib/src/bofsocketthread.cpp +++ b/lib/src/bofsocketthread.cpp @@ -18,6 +18,8 @@ BEGIN_BOF_NAMESPACE() constexpr uint32_t PUSH_POP_TIMEOUT = 150; // Global To for getting command out of incoming queue, in ListeningMode_B it is half of the To specified for listen constexpr uint32_t DEF_IO_TIMEOUT = 2000; +#define SOCK_IO_DBG(pFormat,...) {printf("%d: " pFormat,Bof_GetMsTickCount(), __VA_ARGS__);} + BofSocketThread::BofSocketThread(const BOF_SOCKET_THREAD_PARAM &_rSocketThreadParam_X) : BofThread() { @@ -44,7 +46,7 @@ BofSocketThread::BofSocketThread(const BOF_SOCKET_THREAD_PARAM &_rSocketThreadPa mpuSocketOperationResultCollection = std::make_unique>(CircularBufferParam_X); if ((mpuSocketOperationResultCollection) && (mpuSocketOperationParamCollection->LastErrorCode() == BOF_ERR_NO_ERROR)) { - // printf("%d: Launch\n", BOF::Bof_GetMsTickCount()); + // SOCK_IO_DBG("Launch\n"); Sts_E = LaunchBofProcessingThread(mSocketThreadParam_X.Name_S, false, 0, mSocketThreadParam_X.ThreadSchedulerPolicy_E, mSocketThreadParam_X.ThreadPriority_E, 0, 2000, 0); BOF_ASSERT(Sts_E == BOF_ERR_NO_ERROR); Sts_B = IsThreadRunning(100); @@ -58,11 +60,11 @@ BofSocketThread::~BofSocketThread() BOF_SOCKET_EXIT_PARAM Param_X; uint32_t OpTicket_U32; // First this and after destructor of BofThread - // printf("%d: ProgramSocketOperation exit cmd\n", BOF::Bof_GetMsTickCount()); + // SOCK_IO_DBG("ProgramSocketOperation exit cmd\n"); BOFERR e = ProgramSocketOperation(PUSH_POP_TIMEOUT, Param_X, OpTicket_U32); if (e != BOF_ERR_NO_ERROR) { - // printf("%d: ProgramSocketOperation rts %d\n", BOF::Bof_GetMsTickCount(), e); + // SOCK_IO_DBG("ProgramSocketOperation rts %d\n", e); } // Must kill the thread from here and not in the BofThread destructor because between both destructor, all mem var of BofSocketThread will disappear (unique pointer) DestroyBofProcessingThread("~BofSocketThread"); @@ -80,7 +82,7 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT; Param_X.Exit_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - // printf("BOF_SOCKET_OPERATION_EXIT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); + // SOCK_IO_DBG("BOF_SOCKET_OPERATION_EXIT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -105,7 +107,7 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN; Param_X.Listen_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - // printf("BOF_SOCKET_OPERATION_LISTEN %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); + // SOCK_IO_DBG("BOF_SOCKET_OPERATION_LISTEN %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -129,7 +131,7 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT; Param_X.Connect_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - // printf("BOF_SOCKET_OPERATION_CONNECT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); + // SOCK_IO_DBG("BOF_SOCKET_OPERATION_CONNECT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -153,7 +155,7 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ; Param_X.Read_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - printf("BOF_SOCKET_OPERATION_READ %s PushErr %s Ticket %d Op %d Buf %d:%p NbElem %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E, _rParam_X.Nb_U32, _rParam_X.pBuffer_U8, mpuSocketOperationParamCollection->GetNbElement()); + SOCK_IO_DBG("BOF_SOCKET_OPERATION_READ %s PushErr %s Ticket %d Op %d Buf %d:%p NbElem %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E, _rParam_X.Nb_U32, _rParam_X.pBuffer_U8, mpuSocketOperationParamCollection->GetNbElement()); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -177,7 +179,7 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE; Param_X.Write_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - printf("BOF_SOCKET_OPERATION_WRITE %s PushErr %s Ticket %d Op %d Buf %d:%p Soc %p NbElem %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E, _rParam_X.Nb_U32, _rParam_X.pBuffer_U8, Param_X.Write_X.pSocket_O, mpuSocketOperationParamCollection->GetNbElement()); + SOCK_IO_DBG("BOF_SOCKET_OPERATION_WRITE %s PushErr %s Ticket %d Op %d Buf %d:%p Soc %p NbElem %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E, _rParam_X.Nb_U32, _rParam_X.pBuffer_U8, Param_X.Write_X.pSocket_O, mpuSocketOperationParamCollection->GetNbElement()); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -199,11 +201,11 @@ BOFERR BofSocketThread::ProgramSocketOperation(uint32_t _TimeOut_U32, BOF_SOCKET BOF_INC_TICKET_NUMBER(mTicket_U32); Param_X.TimeOut_U32 = _TimeOut_U32; Param_X.Timer_U32 = BOF::Bof_GetMsTickCount(); - // printf("================> Tim %d\n", Param_X.Timer_U32); + // SOCK_IO_DBG("================> Tim %d\n", Param_X.Timer_U32); Param_X.Operation_E = BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT; Param_X.Disconnect_X = _rParam_X; Rts_E = mpuSocketOperationParamCollection->Push(&Param_X, PUSH_POP_TIMEOUT, nullptr); - // printf("BOF_SOCKET_OPERATION_DISCONNECT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); + // SOCK_IO_DBG("BOF_SOCKET_OPERATION_DISCONNECT %s Err %s Ticket %d Op %d\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), Param_X.Ticket_U32, Param_X.Operation_E); if (Rts_E == BOF_ERR_NO_ERROR) { _rOpTicket_U32 = Param_X.Ticket_U32; @@ -222,23 +224,23 @@ BOFERR BofSocketThread::GetSocketOperationResult(uint32_t _TimeOut_U32, BOF_SOCK _rOperationResult_X.Reset(); Rts_E = mpuSocketOperationResultCollection->Pop(&_rOperationResult_X, _TimeOut_U32, nullptr, nullptr); - printf("BOF_SOCKET_OPERATION_GET_RESULT %s Err %s Ticket %d Op %d Sts %s\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), _rOperationResult_X.OpTicket_U32, _rOperationResult_X.Operation_E, BOF::Bof_ErrorCode(_rOperationResult_X.Sts_E)); + SOCK_IO_DBG("BOF_SOCKET_OPERATION_GET_RESULT %s Err %s Ticket %d Op %d Sts %s\n", mSocketThreadParam_X.Name_S.c_str(), BOF::Bof_ErrorCode(Rts_E), _rOperationResult_X.OpTicket_U32, _rOperationResult_X.Operation_E, BOF::Bof_ErrorCode(_rOperationResult_X.Sts_E)); return Rts_E; } uint32_t BofSocketThread::NumberOfOperationWaiting() { - // printf("NumberOfOperationPending %d\n", mpuSocketOperationParamCollection->GetNbElement()); + // SOCK_IO_DBG("NumberOfOperationPending %d\n", mpuSocketOperationParamCollection->GetNbElement()); return mpuSocketOperationParamCollection->GetNbElement(); } bool BofSocketThread::IsOperationPending() { - // printf("NumberOfOperationPending %d\n", mpuSocketOperationParamCollection->GetNbElement()); + // SOCK_IO_DBG("NumberOfOperationPending %d\n", mpuSocketOperationParamCollection->GetNbElement()); return mOperationPending_B; // only cleared by ClearSocketOperation or CancelSocketOperation } uint32_t BofSocketThread::NumberOfResultPending() { - // printf("NumberOfResultPending %d\n", mpuSocketOperationResultCollection->GetNbElement()); + // SOCK_IO_DBG("NumberOfResultPending %d\n", mpuSocketOperationResultCollection->GetNbElement()); return mpuSocketOperationResultCollection->GetNbElement(); } BOFERR BofSocketThread::CancelSocketOperation(uint32_t _TimeOut_U32) @@ -285,6 +287,11 @@ BOFERR BofSocketThread::ResetSocketOperation() return Rts_E; } +uint32_t BofSocketThread::GetIoDefaultTimeout() const +{ + return DEF_IO_TIMEOUT; +} + BofSocket *BofSocketThread::CreateTcpSocket(BOF::BOF_IPV4_ADDR_U32 &_rSrcIpAddr_X, uint16_t _SrcPort_U16, uint32_t _NbMaxClient_U32) // 0 for normal socket !=0 for listening one _Listen_B) { BofSocket *pRts_O; @@ -376,25 +383,25 @@ BOFERR BofSocketThread::V_OnProcessing() PollTimeout_U32 = PUSH_POP_TIMEOUT; // Will be changed if we goes in ListeningMode_B do { - // printf("%d: Alive Wait %s for %d Bal %d ListenMode %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), PollTimeout_U32, BofThread::S_BofThreadBalance(), ListeningMode_B); + // SOCK_IO_DBG("Alive Wait %s for %d Bal %d ListenMode %d\n", mSocketThreadParam_X.Name_S.c_str(), PollTimeout_U32, BofThread::S_BofThreadBalance(), ListeningMode_B); // Use Peek instead of Pop to use the queue length as an io pending flag (pop is made at the end of the command exec) Rts_E = mpuSocketOperationParamCollection->Peek(&mCurrentOpParam_X, PollTimeout_U32, nullptr, nullptr); if ((Rts_E != BOF_ERR_ETIMEDOUT) && (Rts_E != BOF_ERR_NO_ERROR)) { - // printf("%d: End of Wait rts %d cmd %d\n", BOF::Bof_GetMsTickCount(), Rts_E, mCurrentOpParam_X.Operation_E); + // SOCK_IO_DBG("End of Wait rts %d cmd %d\n", Rts_E, mCurrentOpParam_X.Operation_E); } // Check if a new cmd has been received or just command timeout on the queue NewCommandRcv_B = (Rts_E == BOF_ERR_NO_ERROR); if ((NewCommandRcv_B) || (ListeningMode_B)) { - // printf("%d: %s Alive Wait err %d ListenMode %d NewCmd %d Op %d Ticket %d To %d NbP %d NbR %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), Rts_E, ListeningMode_B, NewCommandRcv_B, mCurrentOpParam_X.Operation_E, mCurrentOpParam_X.Ticket_U32, + // SOCK_IO_DBG("%s Alive Wait err %d ListenMode %d NewCmd %d Op %d Ticket %d To %d NbP %d NbR %d\n", mSocketThreadParam_X.Name_S.c_str(), Rts_E, ListeningMode_B, NewCommandRcv_B, mCurrentOpParam_X.Operation_E, mCurrentOpParam_X.Ticket_U32, // mCurrentOpParam_X.TimeOut_U32, mpuSocketOperationParamCollection->GetNbElement(), mpuSocketOperationResultCollection->GetNbElement()); First init of operation param Result_X.Reset(); Result_X.Sts_E = BOF_ERR_NO_ERROR; Result_X.Operation_E = mCurrentOpParam_X.Operation_E; Result_X.OpTicket_U32 = mCurrentOpParam_X.Ticket_U32; - Result_X.Time_U32 = BOF::Bof_ElapsedMsTime(mCurrentOpParam_X.Timer_U32); - + Result_X.Time_U32 = BOF::Bof_ElapsedMsTime(mCurrentOpParam_X.Timer_U32); //Time to get the command in processing thread + mCurrentOpParam_X.Timer_U32 = BOF::Bof_GetMsTickCount(); //Restart op timer to have the time to execute this one // So ListeningMode_B is perhaps true, but nevertheless a new command must be processed SendResult_B = false; if (NewCommandRcv_B) @@ -408,7 +415,7 @@ BOFERR BofSocketThread::V_OnProcessing() switch (mCurrentOpParam_X.Operation_E) { case BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT: - // printf("%d: BOF_SOCKET_OPERATION_EXIT\n", BOF::Bof_GetMsTickCount()); + // SOCK_IO_DBG("BOF_SOCKET_OPERATION_EXIT\n"); Result_X.Sts_E = BOF_ERR_CANCEL; // To skip if below Rts_E = BOF_ERR_CANCEL; // To exit loop here and in BofThread: break; @@ -424,7 +431,7 @@ BOFERR BofSocketThread::V_OnProcessing() } if ((pIoSocket_O) && (mCurrentOpParam_X.Read_X.pBuffer_U8)) { - printf("BOF_SOCKET_OPERATION_READ IoBuf %d:%p Ticket %d Op %d START on %s\n", mCurrentOpParam_X.Read_X.Nb_U32, mCurrentOpParam_X.Read_X.pBuffer_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, pIoSocket_O->ToString().c_str()); + SOCK_IO_DBG("BOF_SOCKET_OPERATION_READ IoBuf %d:%p Ticket %d Op %d START on %s\n", mCurrentOpParam_X.Read_X.Nb_U32, mCurrentOpParam_X.Read_X.pBuffer_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, pIoSocket_O->ToString().c_str()); Total_U32 = mCurrentOpParam_X.Read_X.Nb_U32; pBuffer_U8 = mCurrentOpParam_X.Read_X.pBuffer_U8; Result_X.pSocket_O = pIoSocket_O; @@ -446,7 +453,7 @@ BOFERR BofSocketThread::V_OnProcessing() } if ((pIoSocket_O) && (mCurrentOpParam_X.Write_X.pBuffer_U8)) { - printf("BOF_SOCKET_OPERATION_WRITE IoBuf %d:%p Ticket %d Op %d START on %s\n", mCurrentOpParam_X.Write_X.Nb_U32, mCurrentOpParam_X.Write_X.pBuffer_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, pIoSocket_O->ToString().c_str()); + SOCK_IO_DBG("BOF_SOCKET_OPERATION_WRITE IoBuf %d:%p Ticket %d Op %d START on %s\n", mCurrentOpParam_X.Write_X.Nb_U32, mCurrentOpParam_X.Write_X.pBuffer_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, pIoSocket_O->ToString().c_str()); Total_U32 = mCurrentOpParam_X.Write_X.Nb_U32; pBuffer_U8 = mCurrentOpParam_X.Write_X.pBuffer_U8; Result_X.pSocket_O = pIoSocket_O; @@ -543,7 +550,7 @@ BOFERR BofSocketThread::V_OnProcessing() Result_X.Sts_E = BOF_ERR_NO_CLIENT; } // Just to detect DISCONNECT extra command on listening for ever thread - // printf("%d: Alive Listen Wait %s for %d Bal %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), ListenTimeout_U32, BofThread::S_BofThreadBalance()); + // SOCK_IO_DBG("%d: Alive Listen Wait %s for %d Bal %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), ListenTimeout_U32, BofThread::S_BofThreadBalance()); pClient = mSocketThreadParam_X.pListeningSocket_O->V_Listen(ListenTimeout_U32, ""); if (pClient) { @@ -565,8 +572,8 @@ BOFERR BofSocketThread::V_OnProcessing() } } } - // printf("----listen------------------------------------->id=%d\n", ListenTicketId_U32); - // printf("%d: Alive Listen Wait end %p SndRes %d\n", BOF::Bof_GetMsTickCount(), pClient, SendResult_B); + // SOCK_IO_DBG("----listen------------------------------------->id=%d\n", ListenTicketId_U32); + // SOCK_IO_DBG("%d: Alive Listen Wait end %p SndRes %d\n", BOF::Bof_GetMsTickCount(), pClient, SendResult_B); break; case BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT: @@ -603,34 +610,17 @@ BOFERR BofSocketThread::V_OnProcessing() case BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ: Size_U32 = Remain_U32; Result_X.Sts_E = pIoSocket_O->V_ReadData(mSocketThreadParam_X.SubPacketTimeout_U32, /*mCurrentOpParam_X.TimeOut_U32*/ Size_U32, pCrtBuf_U8); // To be able to cancel a very long socket operation (read,write,..) we split it in segment of max mSocketThreadParam_X.SubPacketTimeout_U32 ms - // printf("%d: Read: Total %d Size %d Remain %d Sts %d\n", Bof_GetMsTickCount(), Total_U32, Size_U32, Remain_U32, Result_X.Sts_E); + //SOCK_IO_DBG("BOF_SOCKET_OPERATION_READ LstIoBuf %d:%p Ticket %d Op %d END Sts %s Sz %d Rem %d\n", Size_U32, pCrtBuf_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, Bof_ErrorCode(Result_X.Sts_E), Size_U32, Remain_U32 - Size_U32); Delta_U32 = Bof_ElapsedMsTime(Start_U32); KBPerS_U32 = Delta_U32 ? (Size_U32 * 1000) / (Delta_U32 * 1024) : 99999999; - if ((Result_X.Sts_E) || (Size_U32 == Remain_U32)) - { - printf("BOF_SOCKET_OPERATION_READ LstIoBuf %d:%p Ticket %d Op %d END Sts %s Delta %d Sz %d KB/S %d Rem %d\n", Size_U32, pCrtBuf_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, Bof_ErrorCode(Result_X.Sts_E), Delta_U32, Size_U32, KBPerS_U32, Remain_U32 - Size_U32); - } - if ((Result_X.Sts_E == BOF_ERR_ETIMEDOUT) && (Size_U32)) - { - printf("BOF_SOCKET_OPERATION_READ Timeout cancelled as we rx some byte (%d)\n", Size_U32); - Result_X.Sts_E = BOF_ERR_NO_ERROR; - } break; case BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE: Size_U32 = Remain_U32; Result_X.Sts_E = pIoSocket_O->V_WriteData(mSocketThreadParam_X.SubPacketTimeout_U32, /*mCurrentOpParam_X.TimeOut_U32*/ Size_U32, pCrtBuf_U8); // To be able to cancel a very long socket operation (read,write,..) we split it in segment of max mSocketThreadParam_X.SubPacketTimeout_U32 ms + //SOCK_IO_DBG("BOF_SOCKET_OPERATION_WRITE LstIoBuf %d:%p Ticket %d Op %d END Sts %s Sz %d Rem %d\n", Size_U32, pCrtBuf_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, Bof_ErrorCode(Result_X.Sts_E), Size_U32, Remain_U32 - Size_U32); Delta_U32 = Bof_ElapsedMsTime(Start_U32); KBPerS_U32 = Delta_U32 ? (Size_U32 * 1000) / (Delta_U32 * 1024) : 99999999; - if ((Result_X.Sts_E) || (Size_U32 == Remain_U32)) - { - printf("BOF_SOCKET_OPERATION_WRITE LstIoBuf %d:%p Ticket %d Op %d END Sts %s Delta %d Sz %d KB/S %d Rem %d\n", Size_U32, pCrtBuf_U8, mCurrentOpParam_X.Ticket_U32, mCurrentOpParam_X.Operation_E, Bof_ErrorCode(Result_X.Sts_E), Delta_U32, Size_U32, KBPerS_U32, Remain_U32 - Size_U32); - } - if ((Result_X.Sts_E == BOF_ERR_ETIMEDOUT) && (Size_U32)) - { - printf("BOF_SOCKET_OPERATION_WRITE Timeout cancelled as we tx some byte (%d)\n", Size_U32); - Result_X.Sts_E = BOF_ERR_NO_ERROR; - } break; case BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT: @@ -647,7 +637,7 @@ BOFERR BofSocketThread::V_OnProcessing() Result_X.pSocket_O = mSocketThreadParam_X.pSocket_O; BOF_SAFE_DELETE(mSocketThreadParam_X.pSocket_O); } - // printf("B==>S_BofSocketBalance %d S_BofThreadBalance %d\n", BOF::BofSocket::S_BofSocketBalance(), BOF::BofThread::S_BofThreadBalance()); + // SOCK_IO_DBG("B==>S_BofSocketBalance %d S_BofThreadBalance %d\n", BOF::BofSocket::S_BofSocketBalance(), BOF::BofThread::S_BofThreadBalance()); break; default: @@ -656,16 +646,28 @@ BOFERR BofSocketThread::V_OnProcessing() Remain_U32 -= Size_U32; pCrtBuf_U8 += Size_U32; - Result_X.Time_U32 = BOF::Bof_ElapsedMsTime(mCurrentOpParam_X.Timer_U32); if (Result_X.Time_U32 > mCurrentOpParam_X.TimeOut_U32) { - printf("Op %d TIMEOUT %d > %d\n !!!", mCurrentOpParam_X.Operation_E, Result_X.Time_U32, mCurrentOpParam_X.TimeOut_U32); - Result_X.Sts_E = BOF_ERR_ETIMEDOUT; + SendResult_B = true; + SOCK_IO_DBG("BofSocketThread: Op %d Ticket %d TIMEOUT %d > %d Sts %d !!!\n", mCurrentOpParam_X.Operation_E, mCurrentOpParam_X.Ticket_U32, Result_X.Time_U32, mCurrentOpParam_X.TimeOut_U32, Result_X.Sts_E); + if ((mCurrentOpParam_X.Operation_E == BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ) || (mCurrentOpParam_X.Operation_E == BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE)) + { + if ((Result_X.Sts_E == BOF_ERR_ETIMEDOUT) && (Remain_U32 != Total_U32)) + { + SOCK_IO_DBG("BOF_SOCKET_OPERATION_READ/BOF_SOCKET_OPERATION_WRITE Timeout cancelled as we rx or tx some byte (%d/%d)\n", Remain_U32, Total_U32); + Result_X.Sts_E = BOF_ERR_NO_ERROR; + break; + } + } + else + { + Result_X.Sts_E = BOF_ERR_ETIMEDOUT; + } } if (mCancel_B) { - // printf("inner loop exit %d snd %d rem %d sts %d cancel %d op %d tck %d\n", IsThreadLoopMustExit(), SendResult_B, Remain_U32, Result_X.Sts_E, mCancel_B.load(), Result_X.Operation_E, Result_X.OpTicket_U32); + // SOCK_IO_DBG("inner loop exit %d snd %d rem %d sts %d cancel %d op %d tck %d\n", IsThreadLoopMustExit(), SendResult_B, Remain_U32, Result_X.Sts_E, mCancel_B.load(), Result_X.Operation_E, Result_X.OpTicket_U32); } } while ((!IsThreadLoopMustExit()) && (!mCancel_B) && (Remain_U32) && (Result_X.Sts_E == BOF_ERR_NO_ERROR)); if (mCancel_B) @@ -683,7 +685,7 @@ BOFERR BofSocketThread::V_OnProcessing() { Sts_E = mSocketThreadParam_X.Callback(mCurrentOpParam_X.Ticket_U32, Sts_E); } - // printf("%d: %s Alive Push Op %d Sts %s/%s Bal %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), Result_X.Operation_E, BOF::Bof_ErrorCode(Sts_E), BOF::Bof_ErrorCode(Result_X.Sts_E), BofThread::S_BofThreadBalance()); + // SOCK_IO_DBG("%d: %s Alive Push Op %d Sts %s/%s Bal %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), Result_X.Operation_E, BOF::Bof_ErrorCode(Sts_E), BOF::Bof_ErrorCode(Result_X.Sts_E), BofThread::S_BofThreadBalance()); } } // if ((NewCommandRcv_B) || (ListeningMode_B)) if (NewCommandRcv_B) @@ -696,26 +698,18 @@ BOFERR BofSocketThread::V_OnProcessing() } if (mCancel_B) { - // printf("%d: %s Alive Cancel nb op %d res %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), IsThreadLoopMustExit(), mpuSocketOperationParamCollection->GetNbElement(), mpuSocketOperationResultCollection->GetNbElement()); - + // SOCK_IO_DBG("%d: %s Alive Cancel nb op %d res %d\n", BOF::Bof_GetMsTickCount(), mSocketThreadParam_X.Name_S.c_str(), IsThreadLoopMustExit(), mpuSocketOperationParamCollection->GetNbElement(), mpuSocketOperationResultCollection->GetNbElement()); mpuSocketOperationParamCollection->Reset(); mpuSocketOperationResultCollection->Reset(); mCancel_B = false; Bof_SignalEvent(mCancelEvent_X, 0); } } while ((!IsThreadLoopMustExit()) && ((Rts_E == BOF_ERR_NO_ERROR) || (!NewCommandRcv_B))); - /* - if (mSocketThreadParam_X.pListeningSocket_O == mSocketThreadParam_X.pSocket_O) - { - if (mSocketThreadParam_X.pSocket_O) - { - } - } - */ + BOF_SAFE_DELETE(mSocketThreadParam_X.pListeningSocket_O); BOF_SAFE_DELETE(mSocketThreadParam_X.pSocket_O); - // printf("%d: Exit with Rts %d sts %d Name %s Bal %d\n", BOF::Bof_GetMsTickCount(), Rts_E, Result_X.Sts_E, mSocketThreadParam_X.Name_S.c_str(), BofThread::S_BofThreadBalance()); + // SOCK_IO_DBG("%d: Exit with Rts %d sts %d Name %s Bal %d\n", BOF::Bof_GetMsTickCount(), Rts_E, Result_X.Sts_E, mSocketThreadParam_X.Name_S.c_str(), BofThread::S_BofThreadBalance()); return Rts_E; } END_BOF_NAMESPACE() diff --git a/lib/src/bofstring.cpp b/lib/src/bofstring.cpp index 10a19e2..1709193 100644 --- a/lib/src/bofstring.cpp +++ b/lib/src/bofstring.cpp @@ -643,7 +643,6 @@ int64_t Bof_StrToBin(uint8_t _Base_U8, const char *_pStr_c) // An optional prefix indicating octal or hexadecimal base("0" or "0x" / "0X" respectively) // A sequence of decimal digits(if no base prefix was specified) or either octal or hexadecimal digits if a specific prefix is present Rts_S64 = strtoll(_pStr_c, &p_c, _Base_U8); - return (Rts_S64); } diff --git a/lib/src/bofsystem.cpp b/lib/src/bofsystem.cpp index d7dac7f..916dba5 100644 --- a/lib/src/bofsystem.cpp +++ b/lib/src/bofsystem.cpp @@ -1719,7 +1719,7 @@ static void *S_ThreadLauncher(void *_pThreadContext) pThread_X->ThreadRunning_B = false; S_BofThreadBalance--; // Bof_ErrorCode can fail does to app shudown (static initializer) - printf("%d: End of thread '%s' BAL %d, ExitCode %d MustStop %d\n", Bof_GetMsTickCount(), pThread_X->Name_S.c_str(), S_BofThreadBalance.load(), pThread_X->ThreadExitCode_E, pThread_X->ThreadMustStop_B.load()); + printf("%d: S_ThreadLauncher End of thread '%s' BAL %d, ExitCode %d MustStop %d\n", Bof_GetMsTickCount(), pThread_X->Name_S.c_str(), S_BofThreadBalance.load(), pThread_X->ThreadExitCode_E, pThread_X->ThreadMustStop_B.load()); } return pRts; @@ -1883,6 +1883,7 @@ BOFERR Bof_StopThread(BOF_THREAD &_rThread_X) if (Rts_E == BOF_ERR_NO_ERROR) { _rThread_X.Reset(); + _rThread_X.ThreadMustStop_B = true; } return Rts_E; } diff --git a/lib/src/bofthread.cpp b/lib/src/bofthread.cpp index a9ac9f5..14aceac 100644 --- a/lib/src/bofthread.cpp +++ b/lib/src/bofthread.cpp @@ -868,19 +868,22 @@ void BofThread::BofThread_Thread() } } - if (Sts_E == BOF_ERR_NO_ERROR) + if (!mThreadMustStop_B) { - LockThreadCriticalSection(" BofThread::BofThread_Thread"); - // printf("%d: V_ONPROCESSING START mThreadLoopMustExit_B %d %s BAL %d\n", BOF::Bof_GetMsTickCount(), mThreadLoopMustExit_B.load(), mName_S.c_str(), S_BofThreadBalance()); - // Any other error code different from BOF_ERR_NO_ERROR will exit the tread loop - // Returning BOF_ERR_EXIT_THREAD will exit the thread loop with an exit code of BOF_ERR_NO_ERROR - // Thread will be stopped if someone calls DestroyBofProcessingThread or destroy the object - Sts_E = V_OnProcessing(); - UnlockThreadCriticalSection(); - if (Sts_E == BOF_ERR_EXIT_THREAD) + if (Sts_E == BOF_ERR_NO_ERROR) { - Sts_E = BOF_ERR_NO_ERROR; - break; + LockThreadCriticalSection(" BofThread::BofThread_Thread"); + // printf("%d: V_ONPROCESSING START mThreadLoopMustExit_B %d %s BAL %d\n", BOF::Bof_GetMsTickCount(), mThreadLoopMustExit_B.load(), mName_S.c_str(), S_BofThreadBalance()); + // Any other error code different from BOF_ERR_NO_ERROR will exit the tread loop + // Returning BOF_ERR_EXIT_THREAD will exit the thread loop with an exit code of BOF_ERR_NO_ERROR + // Thread will be stopped if someone calls DestroyBofProcessingThread or destroy the object + Sts_E = V_OnProcessing(); + UnlockThreadCriticalSection(); + if (Sts_E == BOF_ERR_EXIT_THREAD) + { + Sts_E = BOF_ERR_NO_ERROR; + break; + } } } // printf("%d: V_ONPROCESSING WHILE mThreadLoopMustExit_B %d Sts %d\n", BOF::Bof_GetMsTickCount(), mThreadLoopMustExit_B.load(), Sts_E); @@ -890,7 +893,7 @@ void BofThread::BofThread_Thread() Sts_E = Bof_SignalEvent(mThreadExitEvent_X, 0); S_mBofThreadBalance--; // Bof_ErrorCode can fail does to app shudown (static initializer) - printf("%d: End of thread '%s' BAL %d, ExitCode %d MustStop %d\n", Bof_GetMsTickCount(), mThreadParam_X.Name_S.c_str(), S_mBofThreadBalance.load(), Sts_E, mThreadMustStop_B.load()); + printf("%d: BofThread_Thread End of thread '%s' BAL %d, ExitCode %d MustStop %d\n", Bof_GetMsTickCount(), mThreadParam_X.Name_S.c_str(), S_mBofThreadBalance.load(), Sts_E, mThreadMustStop_B.load()); // BOF_ASSERT(Sts_E == BOF_ERR_NO_ERROR); } int BofThread::S_BofThreadBalance() diff --git a/lib/src/bofuart.cpp b/lib/src/bofuart.cpp index 6bf60ab..b82a501 100644 --- a/lib/src/bofuart.cpp +++ b/lib/src/bofuart.cpp @@ -166,7 +166,8 @@ BofUart::BofUart(const BOF_UART_PARAM &_rUartParam_X) BofRawCircularBufferParam_X.Reset(); BofRawCircularBufferParam_X.MultiThreadAware_B = true; BofRawCircularBufferParam_X.BufferSizeInByte_U32 = mUartParam_X.BaseChannelParam_X.SndBufferSize_U32; - BofRawCircularBufferParam_X.NbMaxSlot_U32 = 0; + BofRawCircularBufferParam_X.SlotMode_B = false; + BofRawCircularBufferParam_X.NbMaxBufferEntry_U32 = 128; BofRawCircularBufferParam_X.pData_U8 = nullptr; mpTxData_O = new BofRawCircularBuffer(BofRawCircularBufferParam_X); @@ -690,7 +691,7 @@ BOFERR BofUart::V_GetStatus(BOF_COM_CHANNEL_STATUS &_rStatus_X) if (ClearCommError(mId_h, &Error_DW, &Status_X)) { _rStatus_X.NbIn_U32 = Status_X.cbInQue; - Nb_U32 = mpTxData_O ? mpTxData_O->GetNbElement() : 0; + Nb_U32 = mpTxData_O ? mpTxData_O->GetNbElement(nullptr) : 0; _rStatus_X.NbOut_U32 = (Nb_U32 > Status_X.cbOutQue) ? Nb_U32 : Status_X.cbOutQue; Rts_E = BOF_ERR_NO_ERROR; } @@ -993,7 +994,7 @@ BOFERR BofUart::ReadUntilString(uint32_t _TimeOut_U32, uint32_t &_rNb_U32, uint8 BOFERR BofUart::V_WriteData(uint32_t /*_TimeOut_U32*/, uint32_t &_rNb_U32, const uint8_t *pBuffer_U8) { BOFERR Rts_E = BOF_ERR_WRITE; - uint32_t Nb_U32; + uint32_t Nb_U32, RemainingSize_U32; if ((mOpen_B) && (pBuffer_U8)) { @@ -1008,9 +1009,9 @@ BOFERR BofUart::V_WriteData(uint32_t /*_TimeOut_U32*/, uint32_t &_rNb_U32, const } else { - if (mpTxData_O->GetNbFreeElement() >= Nb_U32) + if ((mpTxData_O->GetNbFreeElement(&RemainingSize_U32)) && (RemainingSize_U32 >= Nb_U32)) { - if (mpTxData_O->PushBuffer(Nb_U32, pBuffer_U8) == BOF_ERR_NO_ERROR) + if (mpTxData_O->PushBuffer(false, Nb_U32, pBuffer_U8) == BOF_ERR_NO_ERROR) { #if defined(_WIN32) if (SignalThreadWakeUpEvent()) @@ -1104,7 +1105,7 @@ BOFERR BofUart::V_OnProcessing() Finish_B = true; NbMax_U32 = sizeof(pData_U8); - if ((mpTxData_O) && (mpTxData_O->PopBuffer(&NbMax_U32, pData_U8) == BOF_ERR_NO_ERROR)) + if ((mpTxData_O) && (mpTxData_O->PopBuffer(0,&NbMax_U32, pData_U8) == BOF_ERR_NO_ERROR)) { Rts_E = BOF_ERR_WRITE; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a611d8b..4c00a0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -252,12 +252,12 @@ if(MEMORYCHECK_SUPPRESSIONS_FILE) file(APPEND ${MEMORYCHECK_SUPPRESSIONS_FILE} ${CONTENT}) endif() -# message("ut_bofstd: Create data dir " ${COMPILED_BINARIES_DIR} "/bin/data") -# file(MAKE_DIRECTORY ${COMPILED_BINARIES_DIR}/bin/data) #Ut under linux from vscode -# foreach(Filename ${DATA_FILES}) -# message("ut_bofstd: Copy " ${Filename} " to " ${COMPILED_BINARIES_DIR} "/bin/data") -# file(COPY ${Filename} DESTINATION ${COMPILED_BINARIES_DIR}/bin/data) -# endforeach() +message("ut_bofstd: Create data dir " ${COMPILED_BINARIES_DIR} "/bin/data") +file(MAKE_DIRECTORY ${COMPILED_BINARIES_DIR}/bin/data) #Ut under linux from vscode +foreach(Filename ${DATA_FILES}) + message("ut_bofstd: Copy " ${Filename} " to " ${COMPILED_BINARIES_DIR} "/bin/data") + file(COPY ${Filename} DESTINATION ${COMPILED_BINARIES_DIR}/bin/data) +endforeach() install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${COMPILED_BINARIES_DIR}/bin FILES_MATCHING PATTERN "*") install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bofstd-runtime FILES_MATCHING PATTERN "*") diff --git a/tests/data/shell_script_1.bof b/tests/data/shell_script_1.bof index 2eb7072..b556776 100644 --- a/tests/data/shell_script_1.bof +++ b/tests/data/shell_script_1.bof @@ -4,5 +4,5 @@ ? si(0, false, true) ls(false,false,false) -exec(../data/shell_script_2.bof) +exec(../../binaries/bin/data/shell_script_2.bof) q diff --git a/tests/src/main.cpp b/tests/src/main.cpp index 6fd6a4b..9edda39 100644 --- a/tests/src/main.cpp +++ b/tests/src/main.cpp @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) //::testing::GTEST_FLAG(filter) = "Fs_Test.*"; //::testing::GTEST_FLAG(filter) = "Guid_Test.*"; //::testing::GTEST_FLAG(filter) = "JsonParser_Test.*"; + //::testing::GTEST_FLAG(filter) = "JsonWriter_Test.*"; //::testing::GTEST_FLAG(filter) = "Logger_Test.*"; //::testing::GTEST_FLAG(filter) = "NaryTreeKv_Test.*"; //::testing::GTEST_FLAG(filter) = "Path_Test.*"; @@ -119,10 +120,10 @@ int main(int argc, char *argv[]) //::testing::GTEST_FLAG(filter) = "Process_Test.*"; //::testing::GTEST_FLAG(filter) = "Queue_Test.*"; //::testing::GTEST_FLAG(filter) = "RamDb_Test.*"; - //::testing::GTEST_FLAG(filter) = "RawCircularBufferNoSlotsize_Test.*"; - //::testing::GTEST_FLAG(filter) = "RawCircularBufferWithSlotsize_Test.*"; + //::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.*"; + //::testing::GTEST_FLAG(filter) = "RawCircularBufferInSlotMode_Test.*"; //::testing::GTEST_FLAG(filter) = "Shell_Test.*"; - //::testing::GTEST_FLAG(filter) = "SocketOs_Test.ListAndSetupInterface"; //*"; + //::testing::GTEST_FLAG(filter) = "SocketOs_Test.*"; //::testing::GTEST_FLAG(filter) = "SocketTcp_Test.*"; //::testing::GTEST_FLAG(filter) = "SocketUdp_Test.*"; //::testing::GTEST_FLAG(filter) = "SockIo_Client_Server_Test.*"; @@ -132,18 +133,22 @@ int main(int argc, char *argv[]) ////::testing::GTEST_FLAG(filter) = "stringformatter a fixer.*"; //::testing::GTEST_FLAG(filter) = "System_Test.*"; //::testing::GTEST_FLAG(filter) = "Threading_Test.*"; + //::testing::GTEST_FLAG(filter) = "BofThreadPool_Test.*"; //::testing::GTEST_FLAG(filter) = "Timecode_Test.*"; //::testing::GTEST_FLAG(filter) = "Uart_Test.*"; //::testing::GTEST_FLAG(filter) = "Uri_Test.*"; //::testing::GTEST_FLAG(filter) = "XmlParser_Test.*"; // Use these one + //::testing::GTEST_FLAG(filter) = "SockIo_Test.*"; //::testing::GTEST_FLAG(filter) = "JsonParser_Test.*:XmlWriter_Test.*"; - //::testing::GTEST_FLAG(filter) = "CmdLineParser_Test.*:Uri_Test.*"; + //::testing::GTEST_FLAG(filter) = "CmdLineParser_Test.*:U7ri_Test.*"; //::testing::GTEST_FLAG(filter) = "Threading_Test.MultiThreadWithoutMutex"; //::testing::GTEST_FLAG(filter) = "System_Test.Rational"; - //::testing::GTEST_FLAG(filter) = "BofThreadPool_Test.*"; - //::testing::GTEST_FLAG(filter) = "Path_Test.*"; + //::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.FillWrapOverwrite"; + //::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.*:CircularBuffer_Test.*:RawCircularBufferInSlotMode_Test.*"; + //::testing::GTEST_FLAG(filter) = "RawCircularBufferNoSlotsize_Test.LoopByteBuffer"; + //::testing::GTEST_FLAG(filter) = "RawCircularBuffer_Test.*:RawCircularBufferInSlotMode_Test.*"; // std::string CrtDir_S; // BOF::Bof_GetCurrentDirectory(CrtDir_S); // printf("-CrtDir_S->%s\n", CrtDir_S.c_str()); @@ -165,10 +170,10 @@ int main(int argc, char *argv[]) /* * WINDOWS -[==========] 174 tests from 46 test suites ran. (82449 ms total) -[ PASSED ] 174 tests. +[==========] 189 tests from 48 test suites ran. (108823 ms total) +[ PASSED ] 189 tests. - YOU HAVE 7 DISABLED TESTS + YOU HAVE 3 DISABLED TESTS LINUX: diff --git a/tests/src/ut_jsonparserwriter.cpp b/tests/src/ut_jsonparserwriter.cpp index c017311..8f02ccd 100644 --- a/tests/src/ut_jsonparserwriter.cpp +++ b/tests/src/ut_jsonparserwriter.cpp @@ -114,7 +114,7 @@ TEST(JsonParser_Test, JsonTypeNative) Json::CharReaderBuilder JsonReader; JSONCPP_STRING JsonErr; - Ifs.open("./data/jsonparser.json"); + Ifs.open("../../binaries/bin/data/jsonparser.json"); JsonReader["collectComments"] = true; if (!parseFromStream(JsonReader, Ifs, &Root, &JsonErr)) { @@ -184,7 +184,7 @@ TEST(JsonParser_Test, JsonType) S_JsonType_X.Reset(); Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/jsonparser.json"; + Path = CrtDir + "../../binaries/bin/data/jsonparser.json"; // printf("crtdir %s Jsonpath is %s\n", CrtDir.FullPathName(false).c_str(), Path.FullPathName(false).c_str()); EXPECT_EQ(Bof_ReadFile(Path, JsonData_S), BOF_ERR_NO_ERROR); @@ -425,7 +425,8 @@ TEST(JsonParser_Test, Json) S_AppParamJson_X.Reset(); Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/jsonparser.json"; + Path = CrtDir + "../../binaries/bin/data/jsonparser.json"; + EXPECT_EQ(Bof_ReadFile(Path, JsonData_S), BOF_ERR_NO_ERROR); pBofJsonParser_O = new BofJsonParser(JsonData_S); @@ -525,7 +526,7 @@ TEST(JsonWriter_Test, Json) // memset(&S_AppParam_X, 0, sizeof(S_AppParam_X) ); Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/jsonparser.json"; + Path = CrtDir + "../../binaries/bin/data/jsonparser.json"; EXPECT_EQ(Bof_ReadFile(Path, JsonData_S), BOF_ERR_NO_ERROR); pBofJsonParser_O = new BofJsonParser(JsonData_S); diff --git a/tests/src/ut_logger.cpp b/tests/src/ut_logger.cpp index ecd146f..765d239 100644 --- a/tests/src/ut_logger.cpp +++ b/tests/src/ut_logger.cpp @@ -28,7 +28,7 @@ #include "gtestrunner.h" // To use a test fixture, derive from testing::Test class -class TestLogger : public testing::Test +class Logger_Test : public testing::Test { public: // Per-test-case set-up. Called before the first test in this test case. @@ -45,21 +45,21 @@ class TestLogger : public testing::Test /*** Factory functions called at the beginning/end of each test case **********/ -void TestLogger::SetUpTestCase() +void Logger_Test::SetUpTestCase() { } -void TestLogger::TearDownTestCase() +void Logger_Test::TearDownTestCase() { } /*** Factory functions called at the beginning/end of each test *****************/ -void TestLogger::SetUp() +void Logger_Test::SetUp() { } -void TestLogger::TearDown() +void Logger_Test::TearDown() { } @@ -227,7 +227,7 @@ enum DBG_FLAG_MASK : uint32_t BOF_DBG_ERROR = 0x40000000 /*! Display error */ }; -TEST_F(TestLogger, LoggerInit) +TEST_F(Logger_Test, LoggerInit) { uint32_t i_U32, Mask_U32; std::vector LogMaskNames_S{/*0*/ "INIT", "INFO", "", "", "", "", "", "", /*8*/ "", "", "", "", "", "", "", "", /*16*/ "", "", "", "", "", "", "", "", /*24*/ "", "", "", "", "", "", "ALWAYS", "ERROR"}; @@ -387,7 +387,7 @@ TEST_F(Logger_Test, LoggerMultiSink) } #endif -TEST_F(TestLogger, LogAlways) +TEST_F(Logger_Test, LogAlways) { constexpr const char *MFS_LOGGER_MAINCHANNEL = "Mfs"; uint32_t Mask_U32, i_U32; @@ -433,7 +433,7 @@ TEST_F(TestLogger, LogAlways) Bof_MsSleep(100); } -TEST_F(TestLogger, LoggerMultiChannel) +TEST_F(Logger_Test, LoggerMultiChannel) { BOFERR Sts_E; BofLogger &rBofLog = BofLogger::S_Instance(); @@ -491,6 +491,9 @@ TEST_F(TestLogger, LoggerMultiChannel) Bof_MsSleep(500); // 24/03/23 10:59:15:664 C LogChannel7 00000774 Log 00000305 uint32_t OneLineSize_U32 = 8 + 1 + 12 + 1 + 1 + 1 + static_cast(strlen(S_LogChannelList[0].ChannelName_S.c_str())) + 1 + 8 + 1 + 3 + 1 + 8 + 1; +#if defined(_WIN32) + OneLineSize_U32++; //\r\n instead of \n +#endif uint32_t FileSize_U32 = (j_U32 * OneLineSize_U32); EXPECT_EQ(Bof_GetFileSize(S_LogChannelList[0].FileLogPath), FileSize_U32); EXPECT_LE(Bof_GetFileSize(S_LogChannelList[1].FileLogPath), MAXLOGSIZEINBYTE); @@ -498,7 +501,12 @@ TEST_F(TestLogger, LoggerMultiChannel) uint32_t LinePerFile_U32 = MAXLOGSIZEINBYTE / OneLineSize_U32; uint32_t NbLineInCurrentFile_U32 = j_U32 % LinePerFile_U32; // 24/03/23 11:02:33:065 C LogChannel3 00000628 Log 00000273 - uint32_t RotatingSize_U32 = NbLineInCurrentFile_U32 * (8 + 1 + 12 + 1 + 1 + 1 + static_cast(strlen(S_LogChannelList[2].ChannelName_S.c_str())) + 1 + 8 + 1 + 3 + 1 + 8 + 1); + OneLineSize_U32 = (8 + 1 + 12 + 1 + 1 + 1 + static_cast(strlen(S_LogChannelList[2].ChannelName_S.c_str())) + 1 + 8 + 1 + 3 + 1 + 8 + 1); +#if defined(_WIN32) + OneLineSize_U32++; //\r\n instead of \n +#endif + uint32_t RotatingSize_U32 = NbLineInCurrentFile_U32 * OneLineSize_U32; + // printf("%d %d %d\n", Bof_GetFileSize(S_LogChannelList[2].FileLogPath), RotatingSize_U32, RotatingSize_U32 + 1); EXPECT_LE(RotatingSize_U32, Bof_GetFileSize(S_LogChannelList[2].FileLogPath)); EXPECT_LE(Bof_GetFileSize(S_LogChannelList[2].FileLogPath), RotatingSize_U32 + 2); diff --git a/tests/src/ut_rawcircularbuffer.cpp b/tests/src/ut_rawcircularbuffer.cpp index d251831..3c3970d 100644 --- a/tests/src/ut_rawcircularbuffer.cpp +++ b/tests/src/ut_rawcircularbuffer.cpp @@ -24,12 +24,77 @@ USE_BOF_NAMESPACE() -#define NBPUSHSAMESIZE 16 +constexpr uint32_t RAW_BUF_SIZE = 0x1000; +constexpr uint32_t RAW_MAX_BUFFER_ENTRY = 16; -class RawCircularBufferNoSlotsize_Test : public testing::Test +bool FillBuffer(uint8_t *_pData_U8, uint32_t _Offset_U32, uint32_t _Len_U32, int8_t _Step_S8, uint32_t _Tag_U32) +{ + bool Rts_B = false; + uint32_t i_U32; + uint8_t Val_U8; + + if ((_pData_U8) && (_Offset_U32 <= RAW_BUF_SIZE) && (_Len_U32 <= RAW_BUF_SIZE) && (_Len_U32 >= 4) && ((_Len_U32 + _Offset_U32) <= RAW_BUF_SIZE)) + { + Rts_B = true; + _pData_U8 = &_pData_U8[_Offset_U32]; + *(uint32_t *)_pData_U8 = _Tag_U32; + _pData_U8 += 4; + _Len_U32 -= 4; + Val_U8 = _Step_S8; + + for (i_U32 = 0; i_U32 < _Len_U32; i_U32++) + { + *_pData_U8++ = Val_U8; + Val_U8 += _Step_S8; + } + } + return Rts_B; +} +bool ClearBuffer(uint8_t *_pData_U8, uint32_t _Offset_U32, uint32_t _Len_U32, uint8_t _Val_U8) +{ + bool Rts_B = false; + uint32_t i_U32; + + if ((_pData_U8) && (_Offset_U32 <= RAW_BUF_SIZE) && (_Len_U32 <= RAW_BUF_SIZE) && (_Len_U32 >= 4) && ((_Len_U32 + _Offset_U32) <= RAW_BUF_SIZE)) + { + Rts_B = true; + _pData_U8 = &_pData_U8[_Offset_U32]; + memset(_pData_U8, _Val_U8, _Len_U32); + } + return Rts_B; +} +bool CheckBuffer(uint8_t *_pData_U8, uint32_t _Offset_U32, uint32_t _Len_U32, int8_t _Step_S8, uint32_t _Tag_U32) +{ + bool Rts_B = false; + uint32_t i_U32; + uint8_t Val_U8; + + if ((_pData_U8) && (_Offset_U32 <= RAW_BUF_SIZE) && (_Len_U32 <= RAW_BUF_SIZE) && (_Len_U32 >= 4) && ((_Len_U32 + _Offset_U32) <= RAW_BUF_SIZE)) + { + _pData_U8 = &_pData_U8[_Offset_U32]; + if (*(uint32_t *)_pData_U8 == _Tag_U32) + { + _pData_U8 += 4; + _Len_U32 -= 4; + Val_U8 = _Step_S8; + + for (i_U32 = 0; i_U32 < _Len_U32; i_U32++) + { + if (*_pData_U8++ != Val_U8) + { + break; + } + Val_U8 += _Step_S8; + } + Rts_B = (i_U32 == _Len_U32); + } + } + return Rts_B; +} +class RawCircularBuffer_Test : public testing::Test { public: - RawCircularBufferNoSlotsize_Test() + RawCircularBuffer_Test() : mpBofRawCircularBuffer_O(nullptr) { } @@ -47,416 +112,398 @@ class RawCircularBufferNoSlotsize_Test : public testing::Test BofRawCircularBuffer *mpBofRawCircularBuffer_O; BOF_RAW_CIRCULAR_BUFFER_PARAM mBofRawCircularBufferParam_X; + uint8_t *mpData_U8 = nullptr; private: }; /*** Factory functions called at the beginning/end of each test case **********/ -void RawCircularBufferNoSlotsize_Test::SetUpTestCase() +void RawCircularBuffer_Test::SetUpTestCase() { } -void RawCircularBufferNoSlotsize_Test::TearDownTestCase() +void RawCircularBuffer_Test::TearDownTestCase() { } -void RawCircularBufferNoSlotsize_Test::SetUp() +void RawCircularBuffer_Test::SetUp() { mBofRawCircularBufferParam_X.Reset(); mBofRawCircularBufferParam_X.MultiThreadAware_B = true; - mBofRawCircularBufferParam_X.BufferSizeInByte_U32 = 0x1000; - mBofRawCircularBufferParam_X.NbMaxSlot_U32 = 0; + mBofRawCircularBufferParam_X.BufferSizeInByte_U32 = RAW_BUF_SIZE; + mBofRawCircularBufferParam_X.SlotMode_B = false; + mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 = RAW_MAX_BUFFER_ENTRY; mBofRawCircularBufferParam_X.pData_U8 = nullptr; mpBofRawCircularBuffer_O = new BofRawCircularBuffer(mBofRawCircularBufferParam_X); EXPECT_TRUE(mpBofRawCircularBuffer_O != nullptr); EXPECT_TRUE(mpBofRawCircularBuffer_O->LastErrorCode() == BOF_ERR_NO_ERROR); + mpData_U8 = new uint8_t[RAW_BUF_SIZE]; + ASSERT_TRUE(mpBofRawCircularBuffer_O != nullptr); } -void RawCircularBufferNoSlotsize_Test::TearDown() +void RawCircularBuffer_Test::TearDown() { BOF_SAFE_DELETE(mpBofRawCircularBuffer_O); EXPECT_TRUE(mpBofRawCircularBuffer_O == nullptr); } -TEST_F(RawCircularBufferNoSlotsize_Test, ByteBuffer) +TEST_F(RawCircularBuffer_Test, BasicPushPop) { - uint32_t Nb_U32, i_U32, Index_U32, Size_U32; - BOFERR Sts_E; - bool Sts_B; - uint8_t pData_U8[0x1000]; - uint32_t pNb1_U32[8], pNb2_U32[8]; - uint8_t *ppData1_U8[8], *ppData2_U8[8]; - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32 - sizeof(uint32_t), Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(0, Nb_U32); - - for (i_U32 = 0; i_U32 < sizeof(pData_U8); i_U32++) - { - pData_U8[i_U32] = (uint8_t)i_U32; - } + uint32_t SizeOfFirst_U32, Size_U32, TotalSize_U32, RemainingSize_U32, WriteSize_U32, Tag_U32 = 0xDEADAA55; + + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetMaxLevel()); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetSlotSize(), 0); + WriteSize_U32 = (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32)); + + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, nullptr)); + EXPECT_EQ(0, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, nullptr)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(0, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32)); + + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 0, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 10, nullptr)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 0, nullptr)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32, mpData_U8)); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32)); + + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(WriteSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - WriteSize_U32, RemainingSize_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, nullptr)); + EXPECT_EQ(0, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, nullptr)); - Size_U32 = 10; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(nullptr, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(nullptr, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); + Size_U32 = RAW_BUF_SIZE; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(WriteSize_U32, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); EXPECT_EQ(0, Size_U32); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(0, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(10, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(0, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32)); - Index_U32 = 0; - Size_U32 = 10; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_FALSE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, Size_U32 + sizeof(uint32_t)); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.BufferSizeInByte_U32 - Size_U32 - sizeof(uint32_t) - sizeof(uint32_t)); // 1 uint32_t for size and another one for next push - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, Size_U32 + sizeof(uint32_t)); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), WriteSize_U32); - Index_U32 = 0; - Size_U32 = 9; - memset(&pData_U8[Index_U32], 0, Size_U32); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(10, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32)); - Index_U32 = 0; - Size_U32 = 10; - memset(&pData_U8[Index_U32], 0, Size_U32); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(10, Size_U32); - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, 0); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.BufferSizeInByte_U32 - sizeof(uint32_t)); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, Size_U32 + sizeof(uint32_t)); - - for (i_U32 = 0; i_U32 < Size_U32; i_U32++) - { - EXPECT_EQ(pData_U8[i_U32], (uint8_t)i_U32); - } + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32, mpData_U8)); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(WriteSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - WriteSize_U32, RemainingSize_U32); - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE) - sizeof(uint32_t); + mpBofRawCircularBuffer_O->Reset(); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 0); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); +} - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) - { - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Size_U32; - } - Index_U32 = 0; +TEST_F(RawCircularBuffer_Test, PartialPop) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, Size_U32, RemainingSize_U32, WriteSize_U32, Tag_U32 = 0xDEADAA55; - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_FALSE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_TRUE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, sizeof(pData_U8)); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, 0); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, sizeof(pData_U8)); + WriteSize_U32 = (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 4, mpData_U8)); - mpBofRawCircularBuffer_O->Reset(); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(mBofRawCircularBufferParam_X.BufferSizeInByte_U32 - sizeof(uint32_t), Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(0, Nb_U32); - - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Nb_U32 = Size_U32 * 2; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32, mpData_U8)); - mpBofRawCircularBuffer_O->Reset(); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(3, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(WriteSize_U32 / 4, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 3, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - (WriteSize_U32 / 4) - (WriteSize_U32 / 2) - WriteSize_U32, RemainingSize_U32); - // push - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE) - sizeof(uint32_t); - - Nb_U32 = Size_U32; // 1 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 2; // 2-3 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 4; // 4-7 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32; // 8 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - EXPECT_NE((int)Index_U32, 0); - - memset(pData_U8, 0, sizeof(pData_U8)); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); + Size_U32 = WriteSize_U32 * 2; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(WriteSize_U32 / 4, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32 / 4, 1, Tag_U32 - 3)); + + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(2, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(WriteSize_U32 / 2, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 2, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - (WriteSize_U32 / 2) - WriteSize_U32, RemainingSize_U32); + + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); Index_U32 = 0; - // pop - Nb_U32 = Size_U32 * 8; // 1 - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 1); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 8; // 2-3 - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 2); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 8; // 4-7 - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 4); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 8; // 8 - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 1); - Index_U32 += Nb_U32; - - for (i_U32 = 0; i_U32 < Size_U32; i_U32++) + for (i_U32 = 0; i_U32 < 8; i_U32++) { - EXPECT_EQ(pData_U8[i_U32], (uint8_t)i_U32); + Size_U32 = WriteSize_U32 / 2 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(WriteSize_U32 / 2 / 8, Size_U32); + Index_U32 += Size_U32; } + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32 / 2, 1, Tag_U32 - 2)); - // Skip - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE) - sizeof(uint32_t); - - Nb_U32 = Size_U32; // 1 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 2; // 2-3 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 4; // 4-7 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32; // 8 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - EXPECT_NE((int)Index_U32, 0); - - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - - // Peek - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE) - sizeof(uint32_t); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(WriteSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - WriteSize_U32, RemainingSize_U32); - Nb_U32 = Size_U32; // 1 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - - Nb_U32 = Size_U32 * 2; // 2-3 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); + Index_U32 = 0; + for (i_U32 = 0; i_U32 < 8; i_U32++) + { + Size_U32 = WriteSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(WriteSize_U32 / 8, Size_U32); + Index_U32 += Size_U32; + } + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32 - 1)); + + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), WriteSize_U32); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); +} - Nb_U32 = Size_U32 * 4; // 4-7 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; +TEST_F(RawCircularBuffer_Test, PushAppend) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, Size_U32, WriteSize_U32, Tag_U32 = 0xDEADAA55; - Nb_U32 = Size_U32; // 8 - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; + WriteSize_U32 = (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, false)); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); Index_U32 = 0; - Nb_U32 = Size_U32 * 8; - Sts_E = mpBofRawCircularBuffer_O->Peek(0, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 1); - - Nb_U32 = Size_U32 * 8; - Sts_E = mpBofRawCircularBuffer_O->Peek(1, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 2); - - Nb_U32 = Size_U32 * 8; - Sts_E = mpBofRawCircularBuffer_O->Peek(2, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 4); - - Nb_U32 = Size_U32 * 8; - Sts_E = mpBofRawCircularBuffer_O->Peek(3, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 1); - - Nb_U32 = Size_U32 * 8; - Sts_E = mpBofRawCircularBuffer_O->Peek(4, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); - - // Lock/Unlock + for (i_U32 = 0; i_U32 < 8; i_U32++) + { + Size_U32 = WriteSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(Size_U32, (WriteSize_U32 / 8)); + Index_U32 += Size_U32; + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), Size_U32); + EXPECT_EQ((i_U32 + 1), mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, Size_U32); + } mpBofRawCircularBuffer_O->Reset(); - + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, true)); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); Index_U32 = 0; - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Size_U32, &pNb1_U32[0], &ppData1_U8[0], &pNb2_U32[0], &ppData2_U8[0]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Size_U32, pNb1_U32[0]); - EXPECT_EQ(0, pNb2_U32[0]); - EXPECT_TRUE(ppData1_U8[0] != nullptr); - EXPECT_TRUE(ppData2_U8[0] == nullptr); - - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, pData_U8); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Size_U32, &pNb1_U32[1], &ppData1_U8[1], &pNb2_U32[1], &ppData2_U8[1]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Size_U32, pNb1_U32[1]); - EXPECT_EQ(0, pNb2_U32[1]); - EXPECT_TRUE(ppData1_U8[1] != nullptr); - EXPECT_TRUE(ppData2_U8[1] == nullptr); - - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ((Size_U32 + sizeof(uint32_t)) * 3, Nb_U32); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); - - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[0], Nb_U32); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); + for (i_U32 = 0; i_U32 < 8; i_U32++) + { + Size_U32 = WriteSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(Size_U32, (WriteSize_U32 / 8)); + Index_U32 += Size_U32; + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 0); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, 0); + } + Size_U32 = WriteSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, false)); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), WriteSize_U32 + (WriteSize_U32 / 8)); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 + (WriteSize_U32 / 8)); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); + Size_U32 = WriteSize_U32; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(WriteSize_U32, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32 - 1)); +} - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); +TEST_F(RawCircularBuffer_Test, Fill) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, Size_U32, WriteSize_U32, Tag_U32 = 0xDEADAA55; - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[0], Size_U32); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); + WriteSize_U32 = (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); + mpBofRawCircularBuffer_O->SetOverWriteMode(false); + for (i_U32 = 0; i_U32 < (RAW_MAX_BUFFER_ENTRY * 2); i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + if (i_U32 >= RAW_MAX_BUFFER_ENTRY) + { + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 / 2); + } + else + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); + EXPECT_EQ(i_U32 + 1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 / 2); + } + } + mpBofRawCircularBuffer_O->Reset(); + mpBofRawCircularBuffer_O->SetOverWriteMode(true); + for (i_U32 = 0; i_U32 < (RAW_MAX_BUFFER_ENTRY * 2); i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + if (i_U32 >= RAW_MAX_BUFFER_ENTRY) + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 / 2); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsBufferOverflow()); + } + else + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); + EXPECT_EQ(i_U32 + 1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 / 2); + if (i_U32 == (RAW_MAX_BUFFER_ENTRY - 1)) + { + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsFull()); + } + else + { + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + } + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsBufferOverflow()); + } + } +} - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[1], Size_U32); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); +TEST_F(RawCircularBuffer_Test, FillWrapOverwrite) +{ + uint32_t i_U32, j_U32,Index_U32, SizeOfFirst_U32, Size_U32, Nb_U32, Nb1_U32, Nb2_U32, WriteSize_U32, WrapAt_U32, LastLen_U32, Tag_U32 = 0xDEADAA55; + uint8_t *pBaseData_U8, *pData1_U8, *pData2_U8; + bool IsLocked; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); + WriteSize_U32 = ((RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY)/2); + mpBofRawCircularBuffer_O->SetOverWriteMode(true); + for (i_U32 = WriteSize_U32; i_U32 < (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); i_U32++) + { + mpBofRawCircularBuffer_O->Reset(); + Nb_U32 = (RAW_BUF_SIZE / WriteSize_U32) + 1; + LastLen_U32 = (RAW_BUF_SIZE % WriteSize_U32); + WrapAt_U32 = LastLen_U32 ? (RAW_BUF_SIZE/ WriteSize_U32):0; + for (j_U32 = 0; j_U32 < Nb_U32; j_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, (int8_t)(j_U32+1), Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32, mpData_U8)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->GetBufferPtr(0, &Nb1_U32, &pData1_U8, &Nb2_U32, &pData2_U8)); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + //printf("i %d/%d j %02d/%02d szof %d ws %d b1 %03d:%p b2 %03d:%p\n", i_U32, (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY), j_U32, Nb_U32, SizeOfFirst_U32, WriteSize_U32, Nb1_U32, pData1_U8, Nb2_U32, pData2_U8); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, WriteSize_U32, 0)); + Size_U32 = WriteSize_U32; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(WriteSize_U32, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, WriteSize_U32, (int8_t)(j_U32 + 1), Tag_U32 - 1)); + EXPECT_EQ(WriteSize_U32, (Nb1_U32 + Nb2_U32)); + EXPECT_TRUE(pData1_U8 != nullptr); + if (WrapAt_U32) + { + if (j_U32 == WrapAt_U32) + { + EXPECT_EQ(LastLen_U32, Nb1_U32); + EXPECT_EQ(WriteSize_U32 -LastLen_U32, Nb2_U32); + EXPECT_TRUE(pData2_U8 != nullptr); + } + else + { + EXPECT_EQ(WriteSize_U32, Nb1_U32); + EXPECT_EQ(0, Nb2_U32); + EXPECT_TRUE(pData2_U8 == nullptr); + } + } + else + { + EXPECT_EQ(WriteSize_U32, Nb1_U32); + EXPECT_EQ(0, Nb2_U32); + EXPECT_TRUE(pData2_U8 == nullptr); + } + } //for (j_U32 = 0; j_U32 < (RAW_MAX_BUFFER_ENTRY * 2); j_U32++) + WriteSize_U32++; + } // for (i_U32 = 0; i_U32 < (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); i_U32++) +} - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); +TEST_F(RawCircularBuffer_Test, GetPtrSkip) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, Size_U32, Nb1_U32, Nb2_U32, WriteSize_U32, Tag_U32 = 0xDEADAA55; + uint8_t *pBaseData_U8, *pData1_U8, *pData2_U8; + bool IsLocked; - mpBofRawCircularBuffer_O->Reset(); + WriteSize_U32 = (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->GetBufferPtr(0, &Nb1_U32, &pBaseData_U8, &Nb2_U32, &pData2_U8)); + EXPECT_EQ(Nb1_U32, 0); + EXPECT_TRUE(pBaseData_U8 != nullptr); + EXPECT_EQ(Nb2_U32, 0); + EXPECT_TRUE(pData2_U8 == nullptr); - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, pData_U8); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Nb_U32 = mBofRawCircularBufferParam_X.BufferSizeInByte_U32 - Size_U32 - static_cast(sizeof(uint32_t)) - static_cast(sizeof(uint32_t)) - 16; - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Nb_U32, &pNb1_U32[0], &ppData1_U8[0], &pNb2_U32[0], &ppData2_U8[0]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, pNb1_U32[0]); - EXPECT_EQ(0, pNb2_U32[0]); - EXPECT_TRUE(ppData1_U8[0] != nullptr); - EXPECT_TRUE(ppData2_U8[0] == nullptr); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Nb_U32 = Size_U32 + 16; - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Nb_U32, &pNb1_U32[1], &ppData1_U8[1], &pNb2_U32[1], &ppData2_U8[1]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(16 - sizeof(uint32_t), pNb1_U32[1]); - EXPECT_EQ(Size_U32 + sizeof(uint32_t), pNb2_U32[1]); - EXPECT_TRUE(ppData1_U8[1] != nullptr); - EXPECT_TRUE(ppData2_U8[1] != nullptr); - - Nb_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); - EXPECT_EQ(0, Nb_U32); + Index_U32 = 0; + for (i_U32 = 0; i_U32 < RAW_MAX_BUFFER_ENTRY; i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, WriteSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, WriteSize_U32 / 2, mpData_U8)); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, WriteSize_U32 / 2); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->GetBufferPtr(0, &Nb1_U32, &pData1_U8, &Nb2_U32, &pData2_U8)); + + EXPECT_EQ(Nb1_U32, WriteSize_U32 / 2); + EXPECT_TRUE(pData1_U8 == &pBaseData_U8[Index_U32]); + EXPECT_EQ(Nb2_U32, 0); + EXPECT_TRUE(pData2_U8 == nullptr); + ASSERT_TRUE(CheckBuffer(pData1_U8, 0, Nb1_U32, 1, Tag_U32 - 1)); + + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->Skip(true, &IsLocked)); + EXPECT_FALSE(IsLocked); + + Index_U32 += Nb1_U32; + } + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), WriteSize_U32 / 2); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); } -class RawCircularBufferWithSlotsize_Test : public testing::Test + +class RawCircularBufferInSlotMode_Test : public testing::Test { public: - RawCircularBufferWithSlotsize_Test() + RawCircularBufferInSlotMode_Test() : mpBofRawCircularBuffer_O(nullptr) { } @@ -474,314 +521,342 @@ class RawCircularBufferWithSlotsize_Test : public testing::Test BofRawCircularBuffer *mpBofRawCircularBuffer_O; BOF_RAW_CIRCULAR_BUFFER_PARAM mBofRawCircularBufferParam_X; + uint8_t *mpData_U8 = nullptr; private: }; -/*** Factory functions called at the beginning/end of each test case **********/ - -void RawCircularBufferWithSlotsize_Test::SetUpTestCase() -{ -} - -void RawCircularBufferWithSlotsize_Test::TearDownTestCase() -{ -} - -void RawCircularBufferWithSlotsize_Test::SetUp() +void RawCircularBufferInSlotMode_Test::SetUp() { mBofRawCircularBufferParam_X.Reset(); mBofRawCircularBufferParam_X.MultiThreadAware_B = true; - mBofRawCircularBufferParam_X.BufferSizeInByte_U32 = 0x1000; - mBofRawCircularBufferParam_X.NbMaxSlot_U32 = NBPUSHSAMESIZE; + mBofRawCircularBufferParam_X.BufferSizeInByte_U32 = RAW_BUF_SIZE; // 0x1000; + mBofRawCircularBufferParam_X.SlotMode_B = true; + mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 = RAW_MAX_BUFFER_ENTRY; + mBofRawCircularBufferParam_X.pData_U8 = nullptr; mpBofRawCircularBuffer_O = new BofRawCircularBuffer(mBofRawCircularBufferParam_X); - EXPECT_TRUE(mpBofRawCircularBuffer_O != nullptr); - EXPECT_TRUE(mpBofRawCircularBuffer_O->LastErrorCode() == BOF_ERR_NO_ERROR); + ASSERT_TRUE(mpBofRawCircularBuffer_O != nullptr); + ASSERT_TRUE(mpBofRawCircularBuffer_O->LastErrorCode() == BOF_ERR_NO_ERROR); + mpData_U8 = new uint8_t[RAW_BUF_SIZE]; + ASSERT_TRUE(mpBofRawCircularBuffer_O != nullptr); } -void RawCircularBufferWithSlotsize_Test::TearDown() +void RawCircularBufferInSlotMode_Test::TearDown() { BOF_SAFE_DELETE(mpBofRawCircularBuffer_O); - EXPECT_TRUE(mpBofRawCircularBuffer_O == nullptr); + ASSERT_TRUE(mpBofRawCircularBuffer_O == nullptr); + BOF_SAFE_DELETE_ARRAY(mpData_U8); + ASSERT_TRUE(mpData_U8 == nullptr); } -TEST_F(RawCircularBufferWithSlotsize_Test, CheckByteBuffer) +/*** Factory functions called at the beginning/end of each test case **********/ +void RawCircularBufferInSlotMode_Test::SetUpTestCase() { - uint32_t Nb_U32, i_U32, Index_U32, Size_U32; - BOFERR Sts_E; - bool Sts_B; - uint8_t pData_U8[0x1000]; - uint32_t pNb1_U32[8], pNb2_U32[8]; - uint8_t *ppData1_U8[8], *ppData2_U8[8]; - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(0, Nb_U32); - - for (i_U32 = 0; i_U32 < sizeof(pData_U8); i_U32++) - { - pData_U8[i_U32] = (uint8_t)i_U32; - } +} + +void RawCircularBufferInSlotMode_Test::TearDownTestCase() +{ +} - Size_U32 = 10; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(nullptr, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(nullptr, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); +TEST_F(RawCircularBufferInSlotMode_Test, BasicPushPop) +{ + uint32_t SizeOfFirst_U32, SlotSize_U32, Size_U32, TotalSize_U32, RemainingSize_U32, Tag_U32 = 0xDEADAA55; + + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetMaxLevel()); + SlotSize_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); + EXPECT_EQ(SlotSize_U32, (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY)); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32)); + + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, nullptr)); + EXPECT_EQ(0, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, nullptr)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); EXPECT_EQ(0, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32)); + + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 0, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 10, nullptr)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, 0, nullptr)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32, mpData_U8)); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32)); + + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SlotSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - SlotSize_U32, RemainingSize_U32); + + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, mpData_U8)); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, nullptr)); + EXPECT_EQ(0, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, nullptr, nullptr)); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(0, pData_U8); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(10, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(0, nullptr); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, SlotSize_U32, 0)); + Size_U32 = RAW_BUF_SIZE; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(SlotSize_U32, Size_U32); + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(0, Size_U32); - Index_U32 = 0; - Size_U32 = 10; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_FALSE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, 1); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.NbMaxSlot_U32 - 1); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, 1); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32)); - Index_U32 = 0; - Size_U32 = 9; - memset(&pData_U8[Index_U32], 0, Size_U32); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(10, Size_U32); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); - Index_U32 = 0; - Size_U32 = 10; - memset(&pData_U8[Index_U32], 0, Size_U32); - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(10, Size_U32); - - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, 0); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.NbMaxSlot_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, 1); - - for (i_U32 = 0; i_U32 < Size_U32; i_U32++) - { - EXPECT_EQ(pData_U8[i_U32], (uint8_t)i_U32); - } + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 1); - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32)); - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) - { - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Size_U32; - } - Index_U32 = 0; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32, mpData_U8)); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SlotSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - SlotSize_U32, RemainingSize_U32); - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_FALSE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_TRUE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.NbMaxSlot_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(Nb_U32, 0); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(Nb_U32, mBofRawCircularBufferParam_X.NbMaxSlot_U32); + mpBofRawCircularBuffer_O->Reset(); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 0); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetCapacity(&TotalSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, TotalSize_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); +} - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); +TEST_F(RawCircularBufferInSlotMode_Test, PartialPop) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, SlotSize_U32, Size_U32, RemainingSize_U32, Tag_U32 = 0xDEADAA55; - mpBofRawCircularBuffer_O->Reset(); + SlotSize_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); + EXPECT_EQ(SlotSize_U32, (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY)); - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); - Sts_B = mpBofRawCircularBuffer_O->IsFull(); - EXPECT_FALSE(Sts_B); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetCapacity(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetNbFreeElement(); - EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxSlot_U32, Nb_U32); - Nb_U32 = mpBofRawCircularBuffer_O->GetMaxLevel(); - EXPECT_EQ(0, Nb_U32); - - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Nb_U32 = Size_U32 * 2; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 4, mpData_U8)); - mpBofRawCircularBuffer_O->Reset(); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); - // push - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32, mpData_U8)); - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) - { - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; - } - memset(pData_U8, 0, sizeof(pData_U8)); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(3, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SlotSize_U32 / 4, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 3, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - SlotSize_U32 - SlotSize_U32 - SlotSize_U32, RemainingSize_U32); + + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, SlotSize_U32, 0)); + Size_U32 = SlotSize_U32 * 2; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(SlotSize_U32 / 4, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32 / 4, 1, Tag_U32 - 3)); + + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(2, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SlotSize_U32 / 2, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 2, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - SlotSize_U32 - SlotSize_U32, RemainingSize_U32); + + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, SlotSize_U32, 0)); Index_U32 = 0; - // pop - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) - { - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32 * 1); - Index_U32 += Nb_U32; - } - for (i_U32 = 0; i_U32 < Size_U32; i_U32++) + for (i_U32 = 0; i_U32 < 8; i_U32++) { - EXPECT_EQ(pData_U8[i_U32], (uint8_t)i_U32); + Size_U32 = SlotSize_U32 / 2 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(SlotSize_U32 / 2 / 8, Size_U32); + Index_U32 += Size_U32; } + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32 / 2, 1, Tag_U32 - 2)); - // Skip - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SlotSize_U32, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32 - 1, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE - SlotSize_U32, RemainingSize_U32); - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, SlotSize_U32, 0)); + Index_U32 = 0; + for (i_U32 = 0; i_U32 < 8; i_U32++) { - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; + Size_U32 = SlotSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(SlotSize_U32 / 8, Size_U32); + Index_U32 += Size_U32; } + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32 - 1)); + + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 3); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); + EXPECT_EQ(mBofRawCircularBufferParam_X.NbMaxBufferEntry_U32, mpBofRawCircularBuffer_O->GetNbFreeElement(&RemainingSize_U32)); + EXPECT_EQ(RAW_BUF_SIZE, RemainingSize_U32); +} - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) - { - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - } - Sts_E = mpBofRawCircularBuffer_O->Skip(); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - Sts_B = mpBofRawCircularBuffer_O->IsEmpty(); - EXPECT_TRUE(Sts_B); +TEST_F(RawCircularBufferInSlotMode_Test, PushAppend) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, SlotSize_U32, Size_U32, Tag_U32 = 0xDEADAA55; - // Peek - Index_U32 = 0; - Size_U32 = (sizeof(pData_U8) / NBPUSHSAMESIZE); + SlotSize_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); + EXPECT_EQ(SlotSize_U32, (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY)); - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, false)); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + Index_U32 = 0; + for (i_U32 = 0; i_U32 < 8; i_U32++) { - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - Index_U32 += Nb_U32; + Size_U32 = SlotSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(Size_U32, (SlotSize_U32 / 8)); + Index_U32 += Size_U32; + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), i_U32 + 1); + EXPECT_EQ(i_U32 + 1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, Size_U32); } - + mpBofRawCircularBuffer_O->Reset(); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, true)); + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); Index_U32 = 0; - for (i_U32 = 0; i_U32 < NBPUSHSAMESIZE; i_U32++) + for (i_U32 = 0; i_U32 < 8; i_U32++) { - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->Peek(i_U32, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Nb_U32, Size_U32); + Size_U32 = SlotSize_U32 / 8; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + EXPECT_EQ(Size_U32, (SlotSize_U32 / 8)); + Index_U32 += Size_U32; + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 0); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, 0); } + Size_U32 = SlotSize_U32 / 8; + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, Size_U32, &mpData_U8[Index_U32])); + + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->SetAppendMode(0, false)); + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 1); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32); + ASSERT_TRUE(ClearBuffer(mpData_U8, 0, SlotSize_U32, 0)); + Size_U32 = SlotSize_U32; + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PopBuffer(0, &Size_U32, mpData_U8)); + EXPECT_EQ(SlotSize_U32, Size_U32); + ASSERT_TRUE(CheckBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32 - 1)); +} - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->Peek(i_U32, &Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); +TEST_F(RawCircularBufferInSlotMode_Test, Fill) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, SlotSize_U32, Size_U32, Tag_U32 = 0xDEADAA55; - // Lock/Unlock + SlotSize_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); + EXPECT_EQ(SlotSize_U32, (RAW_BUF_SIZE / RAW_MAX_BUFFER_ENTRY)); + mpBofRawCircularBuffer_O->SetOverWriteMode(false); + for (i_U32 = 0; i_U32 < (RAW_MAX_BUFFER_ENTRY * 2); i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + if (i_U32 >= RAW_MAX_BUFFER_ENTRY) + { + EXPECT_NE(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32 / 2); + } + else + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); + EXPECT_EQ(i_U32 + 1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32 / 2); + } + } mpBofRawCircularBuffer_O->Reset(); + mpBofRawCircularBuffer_O->SetOverWriteMode(true); + for (i_U32 = 0; i_U32 < (RAW_MAX_BUFFER_ENTRY * 2); i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + if (i_U32 >= RAW_MAX_BUFFER_ENTRY) + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); + EXPECT_EQ(RAW_MAX_BUFFER_ENTRY, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32 / 2); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsBufferOverflow()); + } + else + { + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); + EXPECT_EQ(i_U32 + 1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32 / 2); + if (i_U32 == (RAW_MAX_BUFFER_ENTRY - 1)) + { + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsFull()); + } + else + { + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + } + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsBufferOverflow()); + } + } +} - Index_U32 = 0; - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Size_U32, &pNb1_U32[0], &ppData1_U8[0], &pNb2_U32[0], &ppData2_U8[0]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Size_U32, pNb1_U32[0]); - EXPECT_EQ(0, pNb2_U32[0]); - EXPECT_TRUE(ppData1_U8[0] != nullptr); - EXPECT_TRUE(ppData2_U8[0] == nullptr); - - Sts_E = mpBofRawCircularBuffer_O->PushBuffer(Size_U32, pData_U8); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->LockBuffer(Size_U32, &pNb1_U32[1], &ppData1_U8[1], &pNb2_U32[1], &ppData2_U8[1]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(Size_U32, pNb1_U32[1]); - EXPECT_EQ(0, pNb2_U32[1]); - EXPECT_TRUE(ppData1_U8[1] != nullptr); - EXPECT_TRUE(ppData2_U8[1] == nullptr); - - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(3, Nb_U32); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); - - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[0], Nb_U32); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - EXPECT_EQ(0, Nb_U32); - - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[0], Size_U32); - EXPECT_NE(BOF_ERR_NO_ERROR, Sts_E); - - Sts_E = mpBofRawCircularBuffer_O->UnlockBuffer(ppData1_U8[1], Size_U32); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); - - Nb_U32 = Size_U32; - Sts_E = mpBofRawCircularBuffer_O->PopBuffer(&Nb_U32, &pData_U8[Index_U32]); - EXPECT_EQ(BOF_ERR_NO_ERROR, Sts_E); +TEST_F(RawCircularBufferInSlotMode_Test, GetPtrSkip) +{ + uint32_t i_U32, Index_U32, SizeOfFirst_U32, SlotSize_U32, Size_U32, Nb1_U32, Nb2_U32, Tag_U32 = 0xDEADAA55; + uint8_t *pBaseData_U8, *pData1_U8, *pData2_U8; + bool IsLocked; - Nb_U32 = mpBofRawCircularBuffer_O->GetNbElement(); - EXPECT_EQ(0, Nb_U32); + SlotSize_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->GetBufferPtr(0, &Nb1_U32, &pBaseData_U8, &Nb2_U32, &pData2_U8)); + EXPECT_EQ(Nb1_U32, 0); + EXPECT_TRUE(pBaseData_U8 != nullptr); + EXPECT_EQ(Nb2_U32, 0); + EXPECT_TRUE(pData2_U8 == nullptr); - Nb_U32 = mpBofRawCircularBuffer_O->GetSlotSize(); - EXPECT_EQ(Size_U32, Nb_U32); + Index_U32 = 0; + for (i_U32 = 0; i_U32 < RAW_MAX_BUFFER_ENTRY; i_U32++) + { + ASSERT_TRUE(FillBuffer(mpData_U8, 0, SlotSize_U32, 1, Tag_U32++)); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->PushBuffer(0, SlotSize_U32 / 2, mpData_U8)); + EXPECT_EQ(1, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(SizeOfFirst_U32, SlotSize_U32 / 2); + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->GetBufferPtr(0, &Nb1_U32, &pData1_U8, &Nb2_U32, &pData2_U8)); + + EXPECT_EQ(Nb1_U32, SlotSize_U32 / 2); + EXPECT_TRUE(pData1_U8 == &pBaseData_U8[Index_U32]); + EXPECT_EQ(Nb2_U32, 0); + EXPECT_TRUE(pData2_U8 == nullptr); + ASSERT_TRUE(CheckBuffer(pData1_U8, 0, Nb1_U32, 1, Tag_U32 - 1)); + + EXPECT_EQ(BOF_ERR_NO_ERROR, mpBofRawCircularBuffer_O->Skip(true, &IsLocked)); + EXPECT_FALSE(IsLocked); + + Index_U32 += SlotSize_U32; + } + EXPECT_EQ(mpBofRawCircularBuffer_O->GetMaxLevel(), 1); + EXPECT_TRUE(mpBofRawCircularBuffer_O->IsEmpty()); + EXPECT_FALSE(mpBofRawCircularBuffer_O->IsFull()); + EXPECT_EQ(0, mpBofRawCircularBuffer_O->GetNbElement(&SizeOfFirst_U32)); + EXPECT_EQ(0, SizeOfFirst_U32); } \ No newline at end of file diff --git a/tests/src/ut_shell.cpp b/tests/src/ut_shell.cpp index 3f7ad9b..e8a816e 100644 --- a/tests/src/ut_shell.cpp +++ b/tests/src/ut_shell.cpp @@ -252,8 +252,8 @@ TEST(Shell_Test, Shell) BOF::BOFPARAMETER(nullptr, "", "Specify the ShowExtension_B parameter", "", "", BOF::BOFPARAMETER_ARG_FLAG::CMDLINE_LONGOPT_NEED_ARG, BOF_PARAM_DEF_VARIABLE(S_MyShellArg_X.ShowExtension_B, BOOL, 0, 0))), BOF_ERR_NO_ERROR); - EXPECT_NE(Shell.ExecScript("../data/shell_script_1.dontexist"), BOF_ERR_NO_ERROR); - EXPECT_EQ(Shell.ExecScript("../data/shell_script_1.bof"), BOF_ERR_NO_ERROR); + EXPECT_NE(Shell.ExecScript("../../binaries/bin/data/shell_script_1.dontexist"), BOF_ERR_NO_ERROR); + EXPECT_EQ(Shell.ExecScript("../../binaries/bin/data/shell_script_1.bof"), BOF_ERR_NO_ERROR); Shell.Execute("si(0, false, true)"); // Shell.Interpreter("?"); } diff --git a/tests/src/ut_socketos.cpp b/tests/src/ut_socketos.cpp index 06aaa39..f02fc73 100644 --- a/tests/src/ut_socketos.cpp +++ b/tests/src/ut_socketos.cpp @@ -49,9 +49,9 @@ void TestSocketAddress(bool _IsIpV6_B) Ip_S = IpAddress_X.ToString(false, false); EXPECT_STREQ(Ip_S.c_str(), "1.2.3.4"); Ip_S = IpAddress_X.ToString(true, false); - EXPECT_STREQ(Ip_S.c_str(), "???://1.2.3.4"); + EXPECT_STREQ(Ip_S.c_str(), "://1.2.3.4"); Ip_S = IpAddress_X.ToString(true, true); - EXPECT_STREQ(Ip_S.c_str(), "???://1.2.3.4:8765"); + EXPECT_STREQ(Ip_S.c_str(), "://1.2.3.4:8765"); pIpAddress_X[0].Set(_IsIpV6_B, BOF_SOCK_TYPE::BOF_SOCK_TCP, 1, 2, 3, 4, 1234); pIpAddress_X[1].Set(_IsIpV6_B, BOF_SOCK_TYPE::BOF_SOCK_UDP, 0, 0, 0, 0, 4321); @@ -218,7 +218,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_EQ(Sts_E, BOF_ERR_NO_ERROR); EXPECT_EQ(IpAddress_X.SocketType_E, BOF_SOCK_TYPE::BOF_SOCK_UNKNOWN); Ip_S = Bof_SocketAddressToString(IpAddress_X, true, true); - EXPECT_EQ(Ip_S, "???://1.2.3.4:0"); + EXPECT_EQ(Ip_S, "://1.2.3.4:0"); Sts_E = Bof_IpAddressToSocketAddress("1.2.3.4:", IpAddress_X); EXPECT_NE(Sts_E, BOF_ERR_NO_ERROR); @@ -296,9 +296,9 @@ void TestSocketAddress(bool _IsIpV6_B) } Ip_S = Bof_SocketAddressToString(ListOfIp_X[0], true, false); #if defined(_WIN32) - EXPECT_EQ(Ip_S, "???://204.79.197.203"); + EXPECT_EQ(Ip_S, "://204.79.197.203"); #else - EXPECT_EQ(Ip_S, "???://204.79.197.203"); + EXPECT_EQ(Ip_S, "://204.79.197.203"); #endif #endif @@ -320,7 +320,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_EQ(IpAddress_X.IpV4Address_X.sin_port, 0); } Ip_S = Bof_SocketAddressToString(IpAddress_X, true, true); - EXPECT_EQ(Ip_S, "???://1.2.3.4:0"); + EXPECT_EQ(Ip_S, "://1.2.3.4:0"); Sts_E = Bof_IpAddressToSocketAddress("1.2.3.4:", IpAddress_X); EXPECT_NE(Sts_E, BOF_ERR_NO_ERROR); @@ -401,7 +401,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_EQ(IpAddress_X.IpV4Address_X.sin_port, 0); } Ip_S = Bof_SocketAddressToString(IpAddress_X, true, false); - EXPECT_EQ(Ip_S, "???://204.79.197.203"); + EXPECT_EQ(Ip_S, "://204.79.197.203"); #endif // Bof_IpAddressToSocketAddress @@ -516,7 +516,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_STREQ(IpAddressComponent_X.User_S.c_str(), "john.doe"); EXPECT_STREQ(IpAddressComponent_X.Password_S.c_str(), "password"); Ip_S = Bof_SocketAddressToString(IpAddressComponent_X.Ip_X, true, true); - EXPECT_EQ(Ip_S, "???://1.2.3.4:5"); + EXPECT_EQ(Ip_S, "bha://1.2.3.4:5"); Sts_E = Bof_SplitIpAddress("bha://john.doe@1.2.3.4:5", IpAddressComponent_X); EXPECT_EQ(Sts_E, BOF_ERR_NO_ERROR); @@ -526,7 +526,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_STREQ(IpAddressComponent_X.User_S.c_str(), "john.doe"); EXPECT_STREQ(IpAddressComponent_X.Password_S.c_str(), ""); Ip_S = Bof_SocketAddressToString(IpAddressComponent_X.Ip_X, true, true); - EXPECT_EQ(Ip_S, "???://1.2.3.4:5"); + EXPECT_EQ(Ip_S, "bha://1.2.3.4:5"); Sts_E = Bof_SplitIpAddress("bha://john.doe@1.2.3.4", IpAddressComponent_X); EXPECT_EQ(Sts_E, BOF_ERR_NO_ERROR); @@ -536,7 +536,7 @@ void TestSocketAddress(bool _IsIpV6_B) EXPECT_STREQ(IpAddressComponent_X.User_S.c_str(), "john.doe"); EXPECT_STREQ(IpAddressComponent_X.Password_S.c_str(), ""); Ip_S = Bof_SocketAddressToString(IpAddressComponent_X.Ip_X, true, true); - EXPECT_EQ(Ip_S, "???://1.2.3.4:0"); + EXPECT_EQ(Ip_S, "bha://1.2.3.4:0"); Sts_E = Bof_SplitIpAddress("udp://193.169.2.3:0>john.doe:password@1.2.3.4:123", InterfaceIpAddressComponent_X, IpAddressComponent_X); EXPECT_EQ(Sts_E, BOF_ERR_NO_ERROR); @@ -567,20 +567,20 @@ void TestSocketAddress(bool _IsIpV6_B) Ip_S = Bof_SocketAddressToString(InterfaceIpAddress_X, true, true); if (_IsIpV6_B) { - EXPECT_EQ(Ip_S, "???://[::]:0"); + EXPECT_EQ(Ip_S, "://[::]:0"); } else { - EXPECT_EQ(Ip_S, "???://0.0.0.0:0"); + EXPECT_EQ(Ip_S, "://0.0.0.0:0"); } Ip_S = Bof_BuildIpAddress(InterfaceIpAddress_X, IpAddress_X); if (_IsIpV6_B) { - EXPECT_EQ(Ip_S, "???://[::]:0>192.168.1.1:1234"); + EXPECT_EQ(Ip_S, "://[::]:0>192.168.1.1:1234"); } else { - EXPECT_EQ(Ip_S, "???://0.0.0.0:0>192.168.1.1:1234"); + EXPECT_EQ(Ip_S, "://0.0.0.0:0>192.168.1.1:1234"); } if (_IsIpV6_B) @@ -605,9 +605,9 @@ void TestSocketAddress(bool _IsIpV6_B) Sts_E = Bof_ResolveIpAddress("pgm://192.168.10.1:1235>239.192.1.1:5555", InterfaceIpAddress_X, IpAddress_X); EXPECT_EQ(Sts_E, BOF_ERR_NO_ERROR); Ip_S = Bof_SocketAddressToString(InterfaceIpAddress_X, true, true); - EXPECT_EQ(Ip_S, "???://192.168.10.1:1235"); + EXPECT_EQ(Ip_S, "pgm://192.168.10.1:1235"); Ip_S = Bof_SocketAddressToString(IpAddress_X, true, true); - EXPECT_EQ(Ip_S, "???://239.192.1.1:5555"); + EXPECT_EQ(Ip_S, "pgm://239.192.1.1:5555"); if (_IsIpV6_B) { diff --git a/tests/src/ut_sockio.cpp b/tests/src/ut_sockio.cpp index f3bd7b8..ed95a2b 100644 --- a/tests/src/ut_sockio.cpp +++ b/tests/src/ut_sockio.cpp @@ -26,7 +26,7 @@ #define MAX_NB_CLIENT_SESSION 2 // 64 #define MAX_IO_SIZE (128 * 1024) //(1 * 1024 * 1024) #define DEFAULT_LISTENING_PORT 60000 -#define DEFAULT_INTER_PROCESS_TIMEOUT 250 // Listen timeout is 100 Ms +//#define DefIoTimeout_U32 250 // Listen timeout is 100 Ms #define MAX_NB_OP_PENDING 1 #define MAX_NB_CLIENT_SESSION 2 // 64 @@ -113,7 +113,7 @@ TEST(SockIo_Test, ListenConnectDisconnect) BOF::BOF_SOCKET_LISTEN_PARAM ListenParam_X; BOF::BOF_SOCKET_CONNECT_PARAM ConnectParam_X; BOF::BOF_SOCKET_DISCONNECT_PARAM DisconnectParam_X; - uint32_t i_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32; + uint32_t i_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, DefIoTimeout_U32; std::unique_ptr puSocketThreadServer; std::unique_ptr puSocketThreadSession; std::unique_ptr puSocketThreadClient; @@ -124,7 +124,6 @@ TEST(SockIo_Test, ListenConnectDisconnect) EXPECT_EQ(BOF::BofThread::S_BofThreadBalance(), 0); Start_U32 = BOF::Bof_GetMsTickCount(); - // Create server listening thread SocketThreadParam_X.Name_S = "SockIo_Lis_0"; // for ut under qemu/docker do not use fifo scheduler @@ -139,10 +138,11 @@ TEST(SockIo_Test, ListenConnectDisconnect) ListenParam_X.NbMaxClient_U32 = 3; ListenParam_X.SrcIpAddr_X = BOF::BOF_IPV4_ADDR_U32(127, 0, 0, 1); ListenParam_X.SrcPort_U16 = DEFAULT_LISTENING_PORT; - // Timeout of listen must be at least half of DEFAULT_INTER_PROCESS_TIMEOUT - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DEFAULT_INTER_PROCESS_TIMEOUT*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + // Timeout of listen must be at least half of DefIoTimeout_U32 + DefIoTimeout_U32 = puSocketThreadServer->GetIoDefaultTimeout(); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DefIoTimeout_U32*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -176,9 +176,9 @@ TEST(SockIo_Test, ListenConnectDisconnect) { Timer_U32 = BOF::Bof_GetMsTickCount(); // Connect client to server - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1 + (i_U32 * 2)); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -188,7 +188,7 @@ TEST(SockIo_Test, ListenConnectDisconnect) // EXPECT_NE(ClientOperationResult_X.Time_U32, 0); // Get server session creation param: answer posted due to connect event - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32 + i_U32 + 1); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -212,9 +212,9 @@ TEST(SockIo_Test, ListenConnectDisconnect) // Disconnect client DisconnectParam_X.Unused_U32 = 0; // ClientOperationResult_X.pSocket_O; - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1 + (i_U32 * 2) + 1); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -226,9 +226,9 @@ TEST(SockIo_Test, ListenConnectDisconnect) // Disconnect session DisconnectParam_X.Unused_U32 = 0; // ServerOperationResult_X.pSocket_O; - EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -251,9 +251,9 @@ TEST(SockIo_Test, ListenConnectDisconnect) } // Disconnect server DisconnectParam_X.Unused_U32 = 0; // pListenSocket_O; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -275,7 +275,7 @@ TEST(SockIo_Test, ListenMultipleConnect) BOF::BOF_SOCKET_CONNECT_PARAM ConnectParam_X; BOF::BOF_SOCKET_DISCONNECT_PARAM DisconnectParam_X; BOF::BOF_SOCKET_EXIT_PARAM ExitParam_X; - uint32_t i_U32, j_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32; + uint32_t i_U32, j_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32, DefIoTimeout_U32; std::unique_ptr puSocketThreadServer; std::unique_ptr puSocketThreadClient; std::unique_ptr puSocketThreadSession; @@ -314,11 +314,12 @@ TEST(SockIo_Test, ListenMultipleConnect) ListenParam_X.NbMaxClient_U32 = 3; ListenParam_X.SrcIpAddr_X = BOF::BOF_IPV4_ADDR_U32(127, 0, 0, 1); ListenParam_X.SrcPort_U16 = DEFAULT_LISTENING_PORT; + DefIoTimeout_U32 = puSocketThreadServer->GetIoDefaultTimeout(); - // Timeout of listen must be at least half of DEFAULT_INTER_PROCESS_TIMEOUT - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DEFAULT_INTER_PROCESS_TIMEOUT*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + // Timeout of listen must be at least half of DefIoTimeout_U32 + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DefIoTimeout_U32*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -350,10 +351,10 @@ TEST(SockIo_Test, ListenMultipleConnect) ASSERT_TRUE(puSocketThreadClient != nullptr); // Connect client to server - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1); ClientOperationResult_X.Reset(); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -366,7 +367,7 @@ TEST(SockIo_Test, ListenMultipleConnect) // EXPECT_EQ(BOF::BofThread::S_BofThreadBalance(), NbThread_U32); // Get server session creation param: answer posted due to connect event - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32 + j_U32 + 1); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -399,9 +400,9 @@ TEST(SockIo_Test, ListenMultipleConnect) { DisconnectParam_X.Reset(); DisconnectParam_X.Unused_U32 = 0; // ClientOperationResult_X.pSocket_O; - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -419,9 +420,9 @@ TEST(SockIo_Test, ListenMultipleConnect) { DisconnectParam_X.Reset(); DisconnectParam_X.Unused_U32 = 0; // ServerOperationResult_X.pSocket_O; - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -439,10 +440,10 @@ TEST(SockIo_Test, ListenMultipleConnect) // Disconnect server DisconnectParam_X.Reset(); DisconnectParam_X.Unused_U32 = 0; // pListenSocket_O; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, DisconnectParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, DisconnectParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_DISCONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); @@ -460,9 +461,9 @@ TEST(SockIo_Test, ListenMultipleConnect) { ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 3); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -479,9 +480,9 @@ TEST(SockIo_Test, ListenMultipleConnect) { ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -495,9 +496,9 @@ TEST(SockIo_Test, ListenMultipleConnect) // Leave listen threads ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 3); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -534,7 +535,7 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) BOF::BOF_SOCKET_WRITE_PARAM WriteParam_X; BOF::BOF_SOCKET_DISCONNECT_PARAM DisconnectParam_X; BOF::BOF_SOCKET_EXIT_PARAM ExitParam_X; - uint32_t i_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, ClientOpTicket_U32, SessionOpTicket_U32; + uint32_t i_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, ClientOpTicket_U32, SessionOpTicket_U32, DefIoTimeout_U32; std::unique_ptr puSocketThreadServer; std::unique_ptr puSocketThreadClient; std::unique_ptr puSocketThreadSession; @@ -564,11 +565,12 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) ListenParam_X.NbMaxClient_U32 = 3; ListenParam_X.SrcIpAddr_X = BOF::BOF_IPV4_ADDR_U32(127, 0, 0, 1); ListenParam_X.SrcPort_U16 = DEFAULT_LISTENING_PORT; + DefIoTimeout_U32 = puSocketThreadServer->GetIoDefaultTimeout(); - // Timeout of listen must be at least half of DEFAULT_INTER_PROCESS_TIMEOUT - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DEFAULT_INTER_PROCESS_TIMEOUT*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + // Timeout of listen must be at least half of DefIoTimeout_U32 + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DefIoTimeout_U32*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -597,9 +599,9 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) ASSERT_TRUE(puSocketThreadClient != nullptr); // Connect client to server - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -610,7 +612,7 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) // Get server session creation param: answer posted due to connect event ServerOperationResult_X.Reset(); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32 + 1); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -644,32 +646,32 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) // BOFERR e = puSocketThreadClient->GetSocket()->V_WriteData(1000, WriteParam_X.Nb_U32, WriteParam_X.pBuffer_U8); // BOF::BofSocket *p = puSocketThreadServer->GetSocket(); // BOFERR e = puSocketThreadServer->GetSocket()->V_WriteData(1000, WriteParam_X.Nb_U32, WriteParam_X.pBuffer_U8); - EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, WriteParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DefIoTimeout_U32, WriteParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + i_U32); - EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(SessionOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(SessionOperationResult_X.Size_U32, WriteParam_X.Nb_U32); EXPECT_EQ(SessionOperationResult_X.pBuffer_U8, WriteParam_X.pBuffer_U8); - EXPECT_LT(SessionOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_LT(SessionOperationResult_X.Time_U32, DefIoTimeout_U32); memset(pBuffer_U8, 0, sizeof(pBuffer_U8)); ReadParam_X.Reset(); ReadParam_X.pSocket_O = nullptr; ReadParam_X.Nb_U32 = strlen(pWelcome_c); ReadParam_X.pBuffer_U8 = pBuffer_U8; - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ReadParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ReadParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + i_U32); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(ClientOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(ClientOperationResult_X.Size_U32, ReadParam_X.Nb_U32); EXPECT_EQ(ClientOperationResult_X.pBuffer_U8, ReadParam_X.pBuffer_U8); - EXPECT_LT(ClientOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_LT(ClientOperationResult_X.Time_U32, DefIoTimeout_U32); EXPECT_STREQ(pWelcome_c, (char *)ReadParam_X.pBuffer_U8); Delta_U32 = BOF::Bof_ElapsedMsTime(Timer_U32); @@ -687,9 +689,9 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + i_U32); // Sesion 0 is used to test error just above - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -702,9 +704,9 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + i_U32); // Sesion 0 is used to test error just above - EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSession->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -716,9 +718,9 @@ TEST(SockIo_Test, DISABLED_ListenReadWrite) // Leave listen thread ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -742,7 +744,7 @@ TEST(SockIo_Test, ReadWrite) BOF::BOF_SOCKET_WRITE_PARAM WriteParam_X; BOF::BOF_SOCKET_DISCONNECT_PARAM DisconnectParam_X; BOF::BOF_SOCKET_EXIT_PARAM ExitParam_X; - uint32_t i_U32, j_U32, k_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32; + uint32_t i_U32, j_U32, k_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32, DefIoTimeout_U32; std::unique_ptr puSocketThreadServer; std::unique_ptr puSocketThreadClient; std::unique_ptr puSocketThreadSession; @@ -775,11 +777,12 @@ TEST(SockIo_Test, ReadWrite) ListenParam_X.NbMaxClient_U32 = 3; ListenParam_X.SrcIpAddr_X = BOF::BOF_IPV4_ADDR_U32(127, 0, 0, 1); ListenParam_X.SrcPort_U16 = DEFAULT_LISTENING_PORT; + DefIoTimeout_U32 = puSocketThreadServer->GetIoDefaultTimeout(); - // Timeout of listen must be at least half of DEFAULT_INTER_PROCESS_TIMEOUT - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DEFAULT_INTER_PROCESS_TIMEOUT*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + // Timeout of listen must be at least half of DefIoTimeout_U32 + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DefIoTimeout_U32*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -820,9 +823,9 @@ TEST(SockIo_Test, ReadWrite) ASSERT_TRUE(puSocketThreadClient != nullptr); // Connect client to server - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -836,7 +839,7 @@ TEST(SockIo_Test, ReadWrite) // Get server session creation param: answer posted due to connect event ServerOperationResult_X.Reset(); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32 + j_U32 + 1); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -878,7 +881,7 @@ TEST(SockIo_Test, ReadWrite) WriteParam_X.pSocket_O = nullptr; WriteParam_X.Nb_U32 = MAX_IO_SIZE; WriteParam_X.pBuffer_U8 = pTxBuffer_U8[j_U32]; - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + i_U32); memset(pRxBuffer_U8[j_U32], 0, MAX_IO_SIZE); @@ -886,25 +889,25 @@ TEST(SockIo_Test, ReadWrite) ReadParam_X.pSocket_O = nullptr; ReadParam_X.Nb_U32 = MAX_IO_SIZE; ReadParam_X.pBuffer_U8 = pRxBuffer_U8[j_U32]; - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + i_U32); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(ClientOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(ClientOperationResult_X.Size_U32, MAX_IO_SIZE); EXPECT_EQ(ClientOperationResult_X.pBuffer_U8, pTxBuffer_U8[j_U32]); - EXPECT_LT(ClientOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_LT(ClientOperationResult_X.Time_U32, DefIoTimeout_U32); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(SessionOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(SessionOperationResult_X.Size_U32, MAX_IO_SIZE); EXPECT_EQ(SessionOperationResult_X.pBuffer_U8, pRxBuffer_U8[j_U32]); - EXPECT_LT(SessionOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_LT(SessionOperationResult_X.Time_U32, DefIoTimeout_U32); for (k_U32 = 0; k_U32 < MAX_IO_SIZE; k_U32++) { @@ -932,7 +935,7 @@ TEST(SockIo_Test, ReadWrite) WriteParam_X.pSocket_O = nullptr; WriteParam_X.Nb_U32 = MAX_IO_SIZE; WriteParam_X.pBuffer_U8 = pTxBuffer_U8[j_U32]; - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + MAX_NB_TEST_LOOP); memset(pRxBuffer_U8[j_U32], 0, MAX_IO_SIZE); @@ -940,34 +943,34 @@ TEST(SockIo_Test, ReadWrite) ReadParam_X.pSocket_O = nullptr; ReadParam_X.Nb_U32 = MAX_IO_SIZE + 1; ReadParam_X.pBuffer_U8 = pRxBuffer_U8[j_U32]; - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + MAX_NB_TEST_LOOP); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_WRITE); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(ClientOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(ClientOperationResult_X.Size_U32, MAX_IO_SIZE); EXPECT_EQ(ClientOperationResult_X.pBuffer_U8, pTxBuffer_U8[j_U32]); - EXPECT_LT(ClientOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_LT(ClientOperationResult_X.Time_U32, DefIoTimeout_U32); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT * 1.5f, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32 * 1.5f, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_READ); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); - EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_ETIMEDOUT); + EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); EXPECT_NE(SessionOperationResult_X.pSocket_O, nullptr); EXPECT_EQ(SessionOperationResult_X.Size_U32, MAX_IO_SIZE); EXPECT_EQ(SessionOperationResult_X.pBuffer_U8, pRxBuffer_U8[j_U32]); - EXPECT_GE(SessionOperationResult_X.Time_U32, DEFAULT_INTER_PROCESS_TIMEOUT); + EXPECT_GE(SessionOperationResult_X.Time_U32, DefIoTimeout_U32); // Leave client threads for (j_U32 = 0; j_U32 < MAX_NB_CLIENT_SESSION; j_U32++) { ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + MAX_NB_TEST_LOOP + ((j_U32 == 0) ? 1 : 0)); // Sesion 0 is used to test error just above - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -986,9 +989,9 @@ TEST(SockIo_Test, ReadWrite) { ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + MAX_NB_TEST_LOOP + ((j_U32 == 0) ? 1 : 0)); // Sesion 0 is used to test error just above - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -1006,9 +1009,9 @@ TEST(SockIo_Test, ReadWrite) // Leave listen threads ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -1032,7 +1035,7 @@ TEST(SockIo_Test, CancelReadWrite) BOF::BOF_SOCKET_WRITE_PARAM WriteParam_X; BOF::BOF_SOCKET_DISCONNECT_PARAM DisconnectParam_X; BOF::BOF_SOCKET_EXIT_PARAM ExitParam_X; - uint32_t i_U32, j_U32, k_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32; + uint32_t i_U32, j_U32, k_U32, Timer_U32, Start_U32, Delta_U32, Max_U32, ServerOpTicket_U32, SessionOpTicket_U32, ClientOpTicket_U32, NbThread_U32, DefIoTimeout_U32; std::unique_ptr puSocketThreadServer; std::unique_ptr puSocketThreadClient; std::unique_ptr puSocketThreadSession; @@ -1065,11 +1068,12 @@ TEST(SockIo_Test, CancelReadWrite) ListenParam_X.NbMaxClient_U32 = 3; ListenParam_X.SrcIpAddr_X = BOF::BOF_IPV4_ADDR_U32(127, 0, 0, 1); ListenParam_X.SrcPort_U16 = DEFAULT_LISTENING_PORT; + DefIoTimeout_U32 = puSocketThreadServer->GetIoDefaultTimeout(); - // Timeout of listen must be at least half of DEFAULT_INTER_PROCESS_TIMEOUT - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DEFAULT_INTER_PROCESS_TIMEOUT*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + // Timeout of listen must be at least half of DefIoTimeout_U32 + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(100 /*DefIoTimeout_U32*/, ListenParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_LISTEN); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -1110,9 +1114,9 @@ TEST(SockIo_Test, CancelReadWrite) ASSERT_TRUE(puSocketThreadClient != nullptr); // Connect client to server - EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->ProgramSocketOperation(DefIoTimeout_U32, ConnectParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 1); - EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClient->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -1126,7 +1130,7 @@ TEST(SockIo_Test, CancelReadWrite) // Get server session creation param: answer posted due to connect event ServerOperationResult_X.Reset(); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_CONNECT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32 + j_U32 + 1); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_NO_ERROR); @@ -1164,17 +1168,17 @@ TEST(SockIo_Test, CancelReadWrite) // EXPECT_EQ(BOF::BofThread::S_BofThreadBalance(), NbThread_U32); for (j_U32 = 0; j_U32 < MAX_NB_CLIENT_SESSION; j_U32++) { - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->CancelSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT * 2), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->CancelSocketOperation(DefIoTimeout_U32 * 2), BOF_ERR_NO_ERROR); WriteParam_X.Reset(); WriteParam_X.pSocket_O = nullptr; WriteParam_X.Nb_U32 = MAX_IO_SIZE; WriteParam_X.pBuffer_U8 = pTxBuffer_U8[j_U32]; EXPECT_FALSE(puSocketThreadClientCollection[j_U32]->IsOperationPending()); EXPECT_EQ(puSocketThreadClientCollection[j_U32]->NumberOfOperationWaiting(), 0); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, WriteParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_TRUE(puSocketThreadClientCollection[j_U32]->IsOperationPending()); EXPECT_EQ(puSocketThreadClientCollection[j_U32]->NumberOfOperationWaiting(), 1); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->CancelSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT * 2), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->CancelSocketOperation(DefIoTimeout_U32 * 2), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOpTicket_U32, 2 + i_U32); memset(pRxBuffer_U8[j_U32], 0, MAX_IO_SIZE); @@ -1184,10 +1188,10 @@ TEST(SockIo_Test, CancelReadWrite) ReadParam_X.pBuffer_U8 = pRxBuffer_U8[j_U32]; EXPECT_FALSE(puSocketThreadSessionCollection[j_U32]->IsOperationPending()); EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->NumberOfOperationWaiting(), 0); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ReadParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_TRUE(puSocketThreadSessionCollection[j_U32]->IsOperationPending()); EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->NumberOfOperationWaiting(), 1); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->CancelSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT * 2), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->CancelSocketOperation(DefIoTimeout_U32 * 2), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOpTicket_U32, 1 + i_U32); EXPECT_FALSE(puSocketThreadClientCollection[j_U32]->IsOperationPending()); @@ -1195,15 +1199,15 @@ TEST(SockIo_Test, CancelReadWrite) EXPECT_FALSE(puSocketThreadSessionCollection[j_U32]->IsOperationPending()); EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->NumberOfOperationWaiting(), 0); - EXPECT_NE(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); - EXPECT_NE(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_NE(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_NE(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); } Delta_U32 = BOF::Bof_ElapsedMsTime(Timer_U32); if (Delta_U32 > Max_U32) { Max_U32 = Delta_U32; } - EXPECT_LT(Delta_U32, 4000); + EXPECT_LT(Delta_U32, 10000); if ((Delta_U32 > 3600) || ((i_U32 % 50) == 0)) { printf("%d: Iter %d Delta %d Max is %d ms\n", BOF::Bof_GetMsTickCount(), i_U32, Delta_U32, Max_U32); @@ -1219,10 +1223,10 @@ TEST(SockIo_Test, CancelReadWrite) ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; EXPECT_EQ(puSocketThreadClientCollection[j_U32]->NumberOfResultPending(), 0); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ClientOpTicket_U32), BOF_ERR_NO_ERROR); // EXPECT_EQ(puSocketThreadClientCollection[j_U32]->NumberOfResultPending(), 1); EXPECT_EQ(ClientOpTicket_U32, 2 + MAX_NB_TEST_LOOP); - EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ClientOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadClientCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, ClientOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ClientOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ClientOperationResult_X.OpTicket_U32, ClientOpTicket_U32); EXPECT_EQ(ClientOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -1242,10 +1246,10 @@ TEST(SockIo_Test, CancelReadWrite) ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->NumberOfResultPending(), 0); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, SessionOpTicket_U32), BOF_ERR_NO_ERROR); // EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->NumberOfResultPending(), 1); EXPECT_EQ(SessionOpTicket_U32, 1 + MAX_NB_TEST_LOOP); - EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, SessionOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadSessionCollection[j_U32]->GetSocketOperationResult(DefIoTimeout_U32, SessionOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(SessionOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(SessionOperationResult_X.OpTicket_U32, SessionOpTicket_U32); EXPECT_EQ(SessionOperationResult_X.Sts_E, BOF_ERR_CANCEL); @@ -1263,9 +1267,9 @@ TEST(SockIo_Test, CancelReadWrite) // Leave listen threads ExitParam_X.Reset(); ExitParam_X.Unused_U32 = 0; - EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DEFAULT_INTER_PROCESS_TIMEOUT, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->ProgramSocketOperation(DefIoTimeout_U32, ExitParam_X, ServerOpTicket_U32), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOpTicket_U32, 2); - EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DEFAULT_INTER_PROCESS_TIMEOUT, ServerOperationResult_X), BOF_ERR_NO_ERROR); + EXPECT_EQ(puSocketThreadServer->GetSocketOperationResult(DefIoTimeout_U32, ServerOperationResult_X), BOF_ERR_NO_ERROR); EXPECT_EQ(ServerOperationResult_X.Operation_E, BOF::BOF_SOCKET_OPERATION::BOF_SOCKET_OPERATION_EXIT); EXPECT_EQ(ServerOperationResult_X.OpTicket_U32, ServerOpTicket_U32); EXPECT_EQ(ServerOperationResult_X.Sts_E, BOF_ERR_CANCEL); diff --git a/tests/src/ut_string.cpp b/tests/src/ut_string.cpp index 2289f1d..b130201 100644 --- a/tests/src/ut_string.cpp +++ b/tests/src/ut_string.cpp @@ -27,8 +27,8 @@ USE_BOF_NAMESPACE() TEST(String_Test, StrToBin) { - EXPECT_EQ(Bof_StrToBin(1, "111"), 0); - EXPECT_EQ(Bof_StrToBin(60, "111"), 0); +//Trig an assert in c lib EXPECT_EQ(Bof_StrToBin(1, "111"), 0); +//Trig an assert in c lib EXPECT_EQ(Bof_StrToBin(60, "111"), 0); EXPECT_EQ(Bof_StrToBin(10, "0x111"), 0); EXPECT_EQ(Bof_StrToBin(0, "111"), 111); diff --git a/tests/src/ut_system.cpp b/tests/src/ut_system.cpp index d8874b0..6d2808d 100644 --- a/tests/src/ut_system.cpp +++ b/tests/src/ut_system.cpp @@ -79,10 +79,10 @@ TEST(System_Test, Buffer) EXPECT_EQ(pAllocData_U8[BUFFER_SIZE + i_U32], static_cast(255 - i_U32)); } - pIo_U8 = OtherBuffer_X.Seek(BUFFER_SIZE * 4, RemainToRead_U64); + pIo_U8 = OtherBuffer_X.SeekAbs(BUFFER_SIZE * 4, RemainToRead_U64); EXPECT_EQ(pIo_U8, nullptr); - pIo_U8 = OtherBuffer_X.Seek(BUFFER_SIZE * 2, RemainToRead_U64); + pIo_U8 = OtherBuffer_X.SeekAbs(BUFFER_SIZE * 2, RemainToRead_U64); EXPECT_NE(pIo_U8, nullptr); EXPECT_EQ(RemainToRead_U64, 32); EXPECT_EQ(OtherBuffer_X.RemainToRead(), 32); @@ -317,8 +317,8 @@ TEST(System_Test, DumpMemoryZone) DumpMemoryZoneParam_X.pMemoryZone = &pMemoryZone_U8[23]; DumpMemoryZoneParam_X.VirtualOffset_S64 = 0xABCDEF01; Dmp_S = Bof_DumpMemoryZone(DumpMemoryZoneParam_X); - Out_S = Bof_Sprintf("ABCDEF01 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 ????????? !\"#$%%&%sABCDEF11 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 '()*+,-./0123456%sABCDEF21 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 " - "789:;<=>?@ABCDEF%sABCDEF31 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 GHIJKLMNOPQRSTUV\n"); + Out_S = Bof_Sprintf("ABCDEF01 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 ????????? !\"#$%%&\nABCDEF11 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 '()*+,-./0123456\nABCDEF21 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 " + "789:;<=>?@ABCDEF\nABCDEF31 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 GHIJKLMNOPQRSTUV\n"); EXPECT_STREQ(Out_S.c_str(), Dmp_S.c_str()); DumpMemoryZoneParam_X.NbItemToDump_U32 = 18; @@ -349,7 +349,7 @@ TEST(System_Test, DumpMemoryZone) DumpMemoryZoneParam_X.GenerateVirtualOffset = false; DumpMemoryZoneParam_X.GenerateAsciiData_B = false; Dmp_S = Bof_DumpMemoryZone(DumpMemoryZoneParam_X); - Out_S = Bof_Sprintf("0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,%s0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11, \n"); + Out_S = Bof_Sprintf("0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,\n0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11, \n"); EXPECT_STREQ(Out_S.c_str(), Dmp_S.c_str()); DumpMemoryZoneParam_X.pMemoryZone = &pMemoryZone_U8[64]; @@ -377,7 +377,7 @@ TEST(System_Test, DumpMemoryZone) DumpMemoryZoneParam_X.ReverseEndianness_B = true; DumpMemoryZoneParam_X.AccessSize_E = BOF_ACCESS_SIZE::BOF_ACCESS_SIZE_16; Dmp_S = Bof_DumpMemoryZone(DumpMemoryZoneParam_X); - Out_S = Bof_Sprintf("0x%016llX 0x0001 0x0203 0x0405 0x0607 0x0809 0x0A0B 0x0C0D 0x0E0F ????????????????%s0x%016llX 0x1011 0x1213 ???? \n", reinterpret_cast(pMemoryZone_U8), reinterpret_cast(pMemoryZone_U8 + 16)); + Out_S = Bof_Sprintf("0x%016llX 0x0001 0x0203 0x0405 0x0607 0x0809 0x0A0B 0x0C0D 0x0E0F ????????????????\n0x%016llX 0x1011 0x1213 ???? \n", reinterpret_cast(pMemoryZone_U8), reinterpret_cast(pMemoryZone_U8 + 16)); EXPECT_STREQ(Out_S.c_str(), Dmp_S.c_str()); DumpMemoryZoneParam_X.NbItemToDump_U32 = 5; diff --git a/tests/src/ut_xmlparserwriter.cpp b/tests/src/ut_xmlparserwriter.cpp index b39c158..b55d521 100644 --- a/tests/src/ut_xmlparserwriter.cpp +++ b/tests/src/ut_xmlparserwriter.cpp @@ -100,7 +100,7 @@ TEST(XmlParser_Test, Xml) S_AppParamXml_X.Reset(); Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/xmlparser.xml"; + Path = CrtDir + "../../binaries/bin/data/xmlparser.xml"; printf("-->%s\n", Path.ToString(false).c_str()); EXPECT_EQ(Bof_ReadFile(Path, XmlData_S), BOF_ERR_NO_ERROR); @@ -149,7 +149,7 @@ TEST(XmlParser_Test, XmlVector) S_AppParamVector_X.Reset(); // Should be /home/bha/bld/Tge2-Debug/bofstd/tests/data/xmlvectorparser.xml Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/xmlvectorparser.xml"; + Path = CrtDir + "../../binaries/bin/data/xmlvectorparser.xml"; EXPECT_EQ(Bof_ReadFile(Path, XmlData_S), BOF_ERR_NO_ERROR); pBofXmlParser_O = new BofXmlParser(XmlData_S); @@ -177,7 +177,7 @@ TEST(XmlWriter_Test, XmlVector) S_AppParamVector_X.Reset(); Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/xmlvectorparser.xml"; + Path = CrtDir + "../../binaries/bin/data/xmlvectorparser.xml"; // printf("Crtdir %s path %s\n", CrtDir.FullPathName(false).c_str(), Path.FullPathName(false).c_str()); ASSERT_EQ(Bof_ReadFile(Path, XmlData_S), BOF_ERR_NO_ERROR); @@ -282,7 +282,7 @@ TEST(XmlWriter_Test, Xml) S_AppParamXml_X.Reset(); // Should be /home/bha/bld/Tge2-Debug/bofstd/tests/data/xmlparser.xml Bof_GetCurrentDirectory(CrtDir); - Path = CrtDir + "../data/xmlparser.xml"; + Path = CrtDir + "../../binaries/bin/data/xmlparser.xml"; printf("-->%s\n", Path.ToString(false).c_str()); EXPECT_EQ(Bof_ReadFile(Path, XmlData_S), BOF_ERR_NO_ERROR); @@ -293,994 +293,7 @@ TEST(XmlWriter_Test, Xml) Sts_i = BofXmlWriter_O.FromByte("\r\n\r\n", S_pOptionXml_X, XmlOut_S); EXPECT_EQ(Sts_i, 0); -#if defined(_WIN32) - std::string Res_S = "\r\n" - "\r\n" - "\r\n" - "192.168.1.21\r\n" - "2000\r\n" - "ssh\r\n" - "/tmp/\r\n" - "root\r\n" - "a\r\n" - "b.harmel@gmail.com\r\n" - "b.harmel\r\n" - "OnBings\r\n" - "D:\\SysGCC\\\r\n" - "D:\\cloudstation\\pro\\vsmake-project-template\\\r\n" - "\r\n" - "\r\n" - "Gambardella, Matthew\r\n" - "XML Developer's Guide\r\n" - "Computer\r\n" - "44.950001\r\n" - "AZ\r\n" - "2016-05-26\r\n" - "\r\n" - "\t\t\t\tAn in-depth look at creating applications\r\n" - "\t\t\t\twith XML.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Ralls, Kim\r\n" - "Midnight Rain\r\n" - "Fantasy\r\n" - "5.950000\r\n" - "QS\r\n" - "2000-12-16\r\n" - "\r\n" - "\t\t\t\tA former architect battles corporate zombies,\r\n" - "\t\t\t\tan evil sorceress, and her own childhood to become queen\r\n" - "\t\t\t\tof the world.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Corets, Eva\r\n" - "Maeve Ascendant\r\n" - "Fantasy\r\n" - "5.950000\r\n" - "WX\r\n" - "2000-11-17\r\n" - "\r\n" - "\t\t\t\tAfter the collapse of a nanotechnology\r\n" - "\t\t\t\tsociety in England, the young survivors lay the\r\n" - "\t\t\t\tfoundation for a new society.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Corets, Eva\r\n" - "Oberon's Legacy\r\n" - "Fantasy\r\n" - "5.950000\r\n" - "\r\n" - "2001-03-10\r\n" - "\r\n" - "\t\t\t\tIn post-apocalypse England, the mysterious\r\n" - "\t\t\t\tagent known only as Oberon helps to create a new life\r\n" - "\t\t\t\tfor the inhabitants of London. Sequel to Maeve\r\n" - "\t\t\t\tAscendant.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Corets, Eva\r\n" - "The Sundered Grail\r\n" - "Fantasy\r\n" - "5.950000\r\n" - "\r\n" - "2001-09-10\r\n" - "\r\n" - "\t\t\t\tThe two daughters of Maeve, half-sisters,\r\n" - "\t\t\t\tbattle one another for control of England. Sequel to\r\n" - "\t\t\t\tOberon's Legacy.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Randall, Cynthia\r\n" - "Lover Birds\r\n" - "Romance\r\n" - "4.950000\r\n" - "\r\n" - "2000-09-02\r\n" - "\r\n" - "\t\t\t\tWhen Carla meets Paul at an ornithology\r\n" - "\t\t\t\tconference, tempers fly as feathers get ruffled.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Thurman, Paula\r\n" - "Splish Splash\r\n" - "Romance\r\n" - "4.950000\r\n" - "\r\n" - "2000-11-02\r\n" - "\r\n" - "\t\t\t\tA deep sea diver finds true love twenty\r\n" - "\t\t\t\tthousand leagues beneath the sea.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Knorr, Stefan\r\n" - "Creepy Crawlies\r\n" - "Horror\r\n" - "4.950000\r\n" - "\r\n" - "2000-12-06\r\n" - "\r\n" - "\t\t\t\tAn anthology of horror stories about roaches,\r\n" - "\t\t\t\tcentipedes, scorpions and other insects.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Kress, Peter\r\n" - "Paradox Lost\r\n" - "Science Fiction\r\n" - "6.950000\r\n" - "\r\n" - "2000-11-02\r\n" - "\r\n" - "\t\t\t\tAfter an inadvertant trip through a Heisenberg\r\n" - "\t\t\t\tUncertainty Device, James Salway discovers the problems\r\n" - "\t\t\t\tof being quantum.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "O'Brien, Tim\r\n" - "Microsoft .NET: The Programming Bible\r\n" - "Computer\r\n" - "36.950001\r\n" - "\r\n" - "2000-12-09\r\n" - "\r\n" - "\t\t\t\tMicrosoft's .NET initiative is explored in\r\n" - "\t\t\t\tdetail in this deep programmer's reference.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "O'Brien, Tim\r\n" - "MSXML3: A Comprehensive Guide\r\n" - "Computer\r\n" - "36.950001\r\n" - "\r\n" - "2000-12-01\r\n" - "\r\n" - "\t\t\t\tThe Microsoft MSXML3 parser is covered in\r\n" - "\t\t\t\tdetail, with attention to XML DOM interfaces, XSLT processing,\r\n" - "\t\t\t\tSAX and more.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "Galos, Mike\r\n" - "Visual Studio 7: A Comprehensive Guide\r\n" - "Computer\r\n" - "49.950001\r\n" - "\r\n" - "2001-04-16\r\n" - "\r\n" - "\t\t\t\tMicrosoft Visual Studio 7 is explored in depth,\r\n" - "\t\t\t\tlooking at how Visual Basic, Visual C++, C#, and ASP+ are\r\n" - "\t\t\t\tintegrated into a comprehensive development\r\n" - "\t\t\t\tenvironment.\r\n" - "\t\t\t\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "0.000000\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n" - "1\r\n" - "2\r\n" - "3\r\n" - "\r\n" - "\r\n" - "4\r\n" - "5\r\n" - "6\r\n" - "\r\n" - "\r\n" - "7\r\n" - "8\r\n" - "9\r\n" - "\r\n" - "\r\n" - "10\r\n" - "11\r\n" - "12\r\n" - "\r\n" - "\r\n" - "\r\n" - "\r\n"; -#else + std::string Res_S = "\r\n" "\r\n" "\r\n" @@ -2222,7 +1235,6 @@ TEST(XmlWriter_Test, Xml) "\r\n" "\r\n" "\r\n"; -#endif #if 0 // To track issue but crash when there is no problem const char *p = XmlOut_S.c_str();