#pragma once BEGIN_TEST_MOCKS_NAMESPACE template RingBuffer::RingBuffer() : mWriteHead(mData) , mReadHead(mData) { memset(mData, DataType(0), Size * sizeof(DataType)); } template RingBuffer::~RingBuffer() { } // ----------------------------------------------------------------------------- template int RingBuffer::getLength() const { if (mReadHead == mWriteHead) { return 0; } else if (mWriteHead > mReadHead) { return int(mWriteHead - mReadHead); } else { return int(mWriteHead - mData) + Size - int(mReadHead - mData); } } template bool RingBuffer::isEmpty() const { return mReadHead == mWriteHead; } // ----------------------------------------------------------------------------- template void RingBuffer::write(DataType inData) { *mWriteHead++ = inData; if (mWriteHead >= mData + Size) { mWriteHead = mData; } } template void RingBuffer::write(const DataType* inData, int inSize) { for (int i = 0; i < inSize; ++i) { write(inData[i]); } } template void RingBuffer::clear() { memset(mData, DataType(0), Size * sizeof(DataType)); mReadHead = mData; mWriteHead = mData; } // ----------------------------------------------------------------------------- template DataType RingBuffer::peek() const { return *mReadHead; } template DataType RingBuffer::read() { const DataType data = *mReadHead++; if (mReadHead >= mData + Size) { mReadHead = mData; } return data; } template void RingBuffer::read(DataType* outData, int inSize) { for (int i = 0; i < inSize; ++i) { outData[i] = read(); } } // ============================================================================= template SerialMock::SerialMock() { } template SerialMock::~SerialMock() { } // ----------------------------------------------------------------------------- template void SerialMock::begin(int inBaudrate) { mBaudrate = inBaudrate; mTxBuffer.clear(); mRxBuffer.clear(); } template int SerialMock::available() const { return mRxBuffer.getLength(); } template void SerialMock::write(uint8_t inData) { mTxBuffer.write(inData); } template uint8_t SerialMock::read() { return mRxBuffer.read(); } // ----------------------------------------------------------------------------- template void SerialMock::moveTxToRx() { mRxBuffer.clear(); const int size = mTxBuffer.getSize(); for (int i = 0; i < size; ++i) { mRxBuffer.write(mTxBuffer.read()); } } END_TEST_MOCKS_NAMESPACE