Index: src/libchcore/OverlappedCallbacks.cpp =================================================================== diff -u -r734408890246965d47e6bbf2c2978371269dd1fd -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/OverlappedCallbacks.cpp (.../OverlappedCallbacks.cpp) (revision 734408890246965d47e6bbf2c2978371269dd1fd) +++ src/libchcore/OverlappedCallbacks.cpp (.../OverlappedCallbacks.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -51,7 +51,7 @@ if (pBuffer->HasError()) pQueue->AddFailedReadBuffer(pBuffer); else - pQueue->AddFullBuffer(pBuffer); + pQueue->AddFinishedReadBuffer(pBuffer); } VOID CALLBACK OverlappedWriteCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) Index: src/libchcore/TOverlappedReader.cpp =================================================================== diff -u -r685d0da3259dd94327ee8d644a88c155585b8249 -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) +++ src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -106,7 +106,7 @@ return pBuffer; } - void TOverlappedReader::AddFullBuffer(TOverlappedDataBuffer* pBuffer) + void TOverlappedReader::AddFinishedReadBuffer(TOverlappedDataBuffer* pBuffer) { if (!pBuffer) throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); @@ -132,6 +132,18 @@ } } + TOverlappedDataBuffer* TOverlappedReader::GetFinishedReadBuffer() + { + if(m_bReleaseMode) + return nullptr; + + TOverlappedDataBuffer* pBuffer = m_spFullBuffers->Pop(); + if(pBuffer) + pBuffer->SetParam(this); + + return pBuffer; + } + TOrderedBufferQueuePtr TOverlappedReader::GetFinishedQueue() const { return m_spFullBuffers; Index: src/libchcore/TOverlappedReader.h =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/TOverlappedReader.h (.../TOverlappedReader.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TOverlappedReader.h (.../TOverlappedReader.h) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -43,7 +43,8 @@ void AddFailedReadBuffer(TOverlappedDataBuffer* pBuffer); TOverlappedDataBuffer* GetFailedReadBuffer(); - void AddFullBuffer(TOverlappedDataBuffer* pBuffer); + void AddFinishedReadBuffer(TOverlappedDataBuffer* pBuffer); + TOverlappedDataBuffer* GetFinishedReadBuffer(); TOrderedBufferQueuePtr GetFinishedQueue() const; Index: src/libchcore/Tests/OverlappedCallbacksTests.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/OverlappedCallbacksTests.cpp (.../OverlappedCallbacksTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/Tests/OverlappedCallbacksTests.cpp (.../OverlappedCallbacksTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -4,7 +4,8 @@ #include "../OverlappedCallbacks.h" #include "../TOverlappedMemoryPool.h" #include "../../liblogger/TLogFileData.h" -#include "../TOverlappedReaderWriter.h" +#include "../TOverlappedReader.h" +#include "../TOverlappedWriter.h" using namespace chcore; Index: src/libchcore/Tests/TOverlappedDataBufferTests.cpp =================================================================== diff -u -rbef894e38e5c1486824787cf8c47a87a0828b228 -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/TOverlappedDataBufferTests.cpp (.../TOverlappedDataBufferTests.cpp) (revision bef894e38e5c1486824787cf8c47a87a0828b228) +++ src/libchcore/Tests/TOverlappedDataBufferTests.cpp (.../TOverlappedDataBufferTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -2,9 +2,8 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" #include "../TOverlappedDataBuffer.h" -#include "../TOverlappedReaderWriter.h" #include "../../liblogger/TLogFileData.h" -#include "../OverlappedCallbacks.h" +#include "../TCoreException.h" using namespace chcore; Index: src/libchcore/Tests/TOverlappedMemoryPoolTests.cpp =================================================================== diff -u -r3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9 -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/TOverlappedMemoryPoolTests.cpp (.../TOverlappedMemoryPoolTests.cpp) (revision 3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9) +++ src/libchcore/Tests/TOverlappedMemoryPoolTests.cpp (.../TOverlappedMemoryPoolTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -2,10 +2,124 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" #include "../TOverlappedMemoryPool.h" +#include "../../liblogger/TLogFileData.h" +#include "../TOverlappedDataBuffer.h" +#include "../TCoreException.h" using namespace chcore; -TEST(TOverlappedMemoryPoolTests, DefaultTest) +TEST(TOverlappedReaderTests, AllocatingConstructor_CheckBufferSizes) { - TOverlappedMemoryPool memoryPool; + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TBufferListPtr spBufferList = spBuffers->GetBufferList(); + + EXPECT_EQ(3, spBufferList->GetCount()); + + EXPECT_EQ(32768, spBufferList->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBufferList->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBufferList->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBufferList->Pop()); } + +TEST(TOverlappedReaderTests, ReinitializeBuffer_FailsWithBuffersInUse) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + spBuffers->GetBufferList()->Pop(); + + EXPECT_THROW(spBuffers->ReinitializeBuffers(3, 65536), TCoreException); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_ZeroLengthBuffers) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + + EXPECT_THROW(spBuffers->ReinitializeBuffers(3, 0), TCoreException); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_SameSizeSameCount) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + spBuffers->ReinitializeBuffers(3, 32768); + + EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); + EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); + + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBuffers->GetBufferList()->Pop()); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_IncreaseSize) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + spBuffers->ReinitializeBuffers(3, 65536); + + EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); + EXPECT_EQ(65536, spBuffers->GetSingleBufferSize()); + + EXPECT_EQ(65536, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(65536, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(65536, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBuffers->GetBufferList()->Pop()); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_DecreaseSize) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 65536)); + spBuffers->ReinitializeBuffers(3, 32768); + + EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); + EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); + + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBuffers->GetBufferList()->Pop()); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_IncreaseCount) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + spBuffers->ReinitializeBuffers(5, 32768); + + EXPECT_EQ(5, spBuffers->GetTotalBufferCount()); + EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); + + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBuffers->GetBufferList()->Pop()); +} + +TEST(TOverlappedReaderTests, ReinitializeBuffer_DecreaseCount) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(5, 32768)); + spBuffers->ReinitializeBuffers(3, 32768); + + EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); + EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); + + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(32768, spBuffers->GetBufferList()->Pop()->GetBufferSize()); + EXPECT_EQ(nullptr, spBuffers->GetBufferList()->Pop()); +} Index: src/libchcore/Tests/TOverlappedReaderTests.cpp =================================================================== diff -u -r3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9 -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/TOverlappedReaderTests.cpp (.../TOverlappedReaderTests.cpp) (revision 3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9) +++ src/libchcore/Tests/TOverlappedReaderTests.cpp (.../TOverlappedReaderTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -1,13 +1,216 @@ #include "stdafx.h" #include "gtest/gtest.h" #include "gmock/gmock.h" +#include "../TOverlappedDataBuffer.h" +#include "../TCoreException.h" +#include "../../liblogger/TLogFileData.h" +#include "../GTestMacros.h" +#include "../TOverlappedMemoryPool.h" #include "../TOverlappedReader.h" using namespace chcore; -TEST(TOverlappedReaderTests, DefaultTest) +TEST(TOverlappedReaderTests, DefaultConstructor_SanityTest) { logger::TLogFileDataPtr spLogData(std::make_shared()); - TBufferListPtr spQueue(std::make_shared()); - TOverlappedReader reader(spLogData, spQueue, 0, 4096); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + EXPECT_EQ(nullptr, tReader.GetEmptyBuffer()); + EXPECT_EQ(nullptr, tReader.GetFailedReadBuffer()); + + EXPECT_NE(nullptr, tReader.GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReader.GetEventReadFinishedHandle()); + EXPECT_NE(nullptr, tReader.GetEventReadFailedHandle()); + + EXPECT_TIMEOUT(tReader.GetEventReadPossibleHandle()); + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); + EXPECT_TIMEOUT(tReader.GetEventReadFailedHandle()); + + EXPECT_FALSE(tReader.IsDataSourceFinished()); } + +TEST(TOverlappedReaderTests, AllocatingConstructor_SanityTest) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + EXPECT_TIMEOUT(tReader.GetEventReadFailedHandle()); + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); + + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_EQ(nullptr, tReader.GetEmptyBuffer()); + + EXPECT_EQ(nullptr, tReader.GetFailedReadBuffer()); + EXPECT_FALSE(tReader.IsDataSourceFinished()); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(TOverlappedReaderTests, GetEmptyBuffer) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + + EXPECT_NE(nullptr, tReader.GetEmptyBuffer()); + EXPECT_TIMEOUT(tReader.GetEventReadPossibleHandle()); + + EXPECT_EQ(nullptr, tReader.GetEmptyBuffer()); +} + +TEST(TOverlappedReaderTests, AddEmptyBuffer) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + TOverlappedDataBuffer* pBuffers[ 3 ] = { tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer() }; + + EXPECT_TIMEOUT(tReader.GetEventReadPossibleHandle()); + + tReader.AddEmptyBuffer(pBuffers[ 0 ], false); + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + + tReader.AddEmptyBuffer(pBuffers[ 1 ], false); + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); + + tReader.AddEmptyBuffer(pBuffers[ 2 ], false); + EXPECT_SIGNALED(tReader.GetEventReadPossibleHandle()); +} + +TEST(TOverlappedReaderTests, AddEmptyBuffer_Null) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + EXPECT_THROW(tReader.AddEmptyBuffer(nullptr, false), TCoreException); + EXPECT_THROW(tReader.AddEmptyBuffer(nullptr, true), TCoreException); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(TOverlappedReaderTests, AddFullBuffer_GetFullBuffer) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + TOverlappedDataBuffer* pBuffer = tReader.GetEmptyBuffer(); + + tReader.AddFinishedReadBuffer(pBuffer); + EXPECT_SIGNALED(tReader.GetEventReadFinishedHandle()); + + EXPECT_NE(nullptr, tReader.GetFinishedReadBuffer()); + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); +} + +TEST(TOverlappedReaderTests, GetFullBuffer_WrongOrder) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + TOverlappedDataBuffer* pBuffers[ 3 ] = { tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer() }; + + tReader.AddFinishedReadBuffer(pBuffers[ 1 ]); + EXPECT_EQ(nullptr, tReader.GetFinishedReadBuffer()); + + tReader.AddFinishedReadBuffer(pBuffers[ 2 ]); + EXPECT_EQ(nullptr, tReader.GetFinishedReadBuffer()); + + tReader.AddFinishedReadBuffer(pBuffers[ 0 ]); + EXPECT_NE(nullptr, tReader.GetFinishedReadBuffer()); +} + +TEST(TOverlappedReaderTests, AddFullBuffer_HandlingSrcEof) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + TOverlappedDataBuffer* pBuffers[ 3 ] = { tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer() }; + + pBuffers[ 1 ]->SetLastPart(true); + + tReader.AddFinishedReadBuffer(pBuffers[ 0 ]); + EXPECT_FALSE(tReader.IsDataSourceFinished()); + + tReader.AddFinishedReadBuffer(pBuffers[ 1 ]); + EXPECT_TRUE(tReader.IsDataSourceFinished()); +} + +TEST(TOverlappedReaderTests, AddFullBuffer_Null) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + + EXPECT_THROW(tReader.AddFinishedReadBuffer(nullptr), TCoreException); +} + +TEST(TOverlappedReaderTests, AddFullBuffer_SameBufferTwice) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + TOverlappedDataBuffer* pBuffer = tReader.GetEmptyBuffer(); + + pBuffer->InitForRead(0, 1280); + pBuffer->SetBytesTransferred(1230); + pBuffer->SetStatusCode(0); + + tReader.AddFinishedReadBuffer(pBuffer); + EXPECT_THROW(tReader.AddFinishedReadBuffer(pBuffer), TCoreException); +} + +TEST(TOverlappedReaderTests, GetFullBuffer_AddFullBuffer_OutOfOrder) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + + TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); + TOverlappedReader tReader(spLogData, spBuffers->GetBufferList(), 0, 4096); + TOverlappedDataBuffer* pBuffers[ 3 ] = { tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer(), tReader.GetEmptyBuffer() }; + + pBuffers[ 0 ]->InitForRead(0, 1000); + pBuffers[ 0 ]->SetBytesTransferred(1000); + pBuffers[ 0 ]->SetStatusCode(0); + + pBuffers[ 1 ]->InitForRead(1000, 1200); + pBuffers[ 1 ]->SetBytesTransferred(1200); + pBuffers[ 1 ]->SetStatusCode(0); + + pBuffers[ 2 ]->InitForRead(2200, 1400); + pBuffers[ 2 ]->SetBytesTransferred(800); + pBuffers[ 2 ]->SetStatusCode(0); + pBuffers[ 2 ]->SetLastPart(true); + + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); + + tReader.AddFinishedReadBuffer(pBuffers[ 1 ]); + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); + + tReader.AddFinishedReadBuffer(pBuffers[ 2 ]); + EXPECT_TIMEOUT(tReader.GetEventReadFinishedHandle()); + + tReader.AddFinishedReadBuffer(pBuffers[ 0 ]); + EXPECT_SIGNALED(tReader.GetEventReadFinishedHandle()); +} Index: src/libchcore/Tests/TOverlappedReaderWriterTests.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/TOverlappedReaderWriterTests.cpp (.../TOverlappedReaderWriterTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/Tests/TOverlappedReaderWriterTests.cpp (.../TOverlappedReaderWriterTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -1,495 +1,8 @@ #include "stdafx.h" #include "gtest/gtest.h" #include "gmock/gmock.h" -#include "../TOverlappedReaderWriter.h" #include "../TOverlappedDataBuffer.h" #include "../TCoreException.h" #include "../../liblogger/TLogFileData.h" #include "../GTestMacros.h" - -using namespace chcore; - -TEST(TOverlappedReaderWriterTests, DefaultConstructor_SanityTest) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_EQ(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); -// EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); - - EXPECT_EQ(0, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(0, spBuffers->GetSingleBufferSize()); -} - -TEST(TOverlappedReaderWriterTests, AllocatingConstructor_SanityTest) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); -// EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); -} - -TEST(TOverlappedReaderWriterTests, AllocatingConstructor_CheckBufferSizes) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - - EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[2]->GetBufferSize()); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_FailsWithBuffersInUse) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - tReaderWriter.GetReader()->GetEmptyBuffer(); - - EXPECT_THROW(spBuffers->ReinitializeBuffers(3, 65536), TCoreException); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_ZeroLengthBuffers) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_THROW(spBuffers->ReinitializeBuffers(3, 0), TCoreException); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_SameSizeSameCount) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - spBuffers->ReinitializeBuffers(3, 32768); - - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - - EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[2]->GetBufferSize()); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_IncreaseSize) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - spBuffers->ReinitializeBuffers(3, 65536); - - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(65536, spBuffers->GetSingleBufferSize()); - - EXPECT_EQ(65536, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(65536, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(65536, pBuffers[2]->GetBufferSize()); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_DecreaseSize) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 65536)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - spBuffers->ReinitializeBuffers(3, 32768); - - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - - EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[2]->GetBufferSize()); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_IncreaseCount) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - spBuffers->ReinitializeBuffers(5, 32768); - - EXPECT_EQ(5, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - - TOverlappedDataBuffer* pBuffers[5] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[2]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[3]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[4]->GetBufferSize()); -} - -TEST(TOverlappedReaderWriterTests, ReinitializeBuffer_DecreaseCount) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(5, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - spBuffers->ReinitializeBuffers(3, 32768); - - EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); - EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); - EXPECT_EQ(32768, pBuffers[2]->GetBufferSize()); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -TEST(TOverlappedReaderWriterTests, GetEmptyBuffer) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); - EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - EXPECT_EQ(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); -} - -TEST(TOverlappedReaderWriterTests, AddEmptyBuffer) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[0], false); - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[1], false); - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - - tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[2], false); - EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); -} - -TEST(TOverlappedReaderWriterTests, AddEmptyBuffer_Null) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_THROW(tReaderWriter.GetReader()->AddEmptyBuffer(nullptr, false), TCoreException); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -TEST(TOverlappedReaderWriterTests, AddFullBuffer_GetFullBuffer) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffer); - EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - - tReaderWriter.GetWriter()->GetWriteBuffer(); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); -} - -TEST(TOverlappedReaderWriterTests, GetFullBuffer_WrongOrder) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); -} - -TEST(TOverlappedReaderWriterTests, AddFullBuffer_HandlingSrcEof) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[1]->SetLastPart(true); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); - EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); - EXPECT_TRUE(tReaderWriter.GetReader()->IsDataSourceFinished()); -} - -TEST(TOverlappedReaderWriterTests, AddFullBuffer_HandlingDstEof) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[2]->SetLastPart(true); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); - - tReaderWriter.GetWriter()->GetWriteBuffer(); -// EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); - - tReaderWriter.GetWriter()->GetWriteBuffer(); -// EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); - - // getting the last buffer (marked as eof) causes setting the data-writing-finished flag - tReaderWriter.GetWriter()->GetWriteBuffer(); -// EXPECT_TRUE(tReaderWriter.IsDataWritingFinished()); -} - -TEST(TOverlappedReaderWriterTests, AddFullBuffer_Null) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_THROW(tReaderWriter.GetReader()->AddFullBuffer(nullptr), TCoreException); -} - -TEST(TOverlappedReaderWriterTests, AddFullBuffer_SameBufferTwice) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); - - pBuffer->InitForRead(0, 1280); - pBuffer->SetBytesTransferred(1230); - pBuffer->SetStatusCode(0); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffer); - EXPECT_THROW(tReaderWriter.GetReader()->AddFullBuffer(pBuffer), TCoreException); -} - -TEST(TOverlappedReaderWriterTests, GetFullBuffer_AddFullBuffer_OutOfOrder) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[0]->InitForRead(0, 1000); - pBuffers[0]->SetBytesTransferred(1000); - pBuffers[0]->SetStatusCode(0); - - pBuffers[1]->InitForRead(1000, 1200); - pBuffers[1]->SetBytesTransferred(1200); - pBuffers[1]->SetStatusCode(0); - - pBuffers[2]->InitForRead(2200, 1400); - pBuffers[2]->SetBytesTransferred(800); - pBuffers[2]->SetStatusCode(0); - pBuffers[2]->SetLastPart(true); - - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - - tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); - EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// -TEST(TOverlappedReaderWriterTests, AddFinishedBuffer_OutOfOrder_Signals) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[0]->InitForRead(0, 1000); - pBuffers[0]->SetBytesTransferred(1000); - pBuffers[0]->SetStatusCode(0); - - pBuffers[1]->InitForRead(1000, 1200); - pBuffers[1]->SetBytesTransferred(1200); - pBuffers[1]->SetStatusCode(0); - - pBuffers[2]->InitForRead(2200, 1400); - pBuffers[2]->SetBytesTransferred(800); - pBuffers[2]->SetStatusCode(0); - pBuffers[2]->SetLastPart(true); - - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); - EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); -} - -TEST(TOverlappedReaderWriterTests, GetFinishedBuffer_Signals) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[0]->InitForRead(0, 4096); - pBuffers[0]->SetBytesTransferred(4096); - pBuffers[0]->SetStatusCode(0); - - pBuffers[1]->InitForRead(4096, 4096); - pBuffers[1]->SetBytesTransferred(4096); - pBuffers[1]->SetStatusCode(0); - - pBuffers[2]->InitForRead(8192, 4096); - pBuffers[2]->SetBytesTransferred(800); - pBuffers[2]->SetStatusCode(0); - pBuffers[2]->SetLastPart(true); - - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); - - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); - EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); - EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - - pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); - EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); -} - -TEST(TOverlappedReaderWriterTests, GetFinishedBuffer_WrongOrder) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - - pBuffers[0]->InitForRead(0, 1000); - pBuffers[0]->SetBytesTransferred(1000); - pBuffers[0]->SetStatusCode(0); - - pBuffers[1]->InitForRead(1000, 1200); - pBuffers[1]->SetBytesTransferred(1200); - pBuffers[1]->SetStatusCode(0); - - pBuffers[2]->InitForRead(2200, 1400); - pBuffers[2]->SetBytesTransferred(800); - pBuffers[2]->SetStatusCode(0); - pBuffers[2]->SetLastPart(true); - - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); - EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); -} - -TEST(TOverlappedReaderWriterTests, AddFinishedBuffer_Null) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - - EXPECT_THROW(tReaderWriter.GetWriter()->AddFinishedBuffer(nullptr), TCoreException); -} - -TEST(TOverlappedReaderWriterTests, AddFinishedBuffer_SameBufferTwice) -{ - logger::TLogFileDataPtr spLogData(std::make_shared()); - - TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); - TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); - tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffer); - EXPECT_THROW(tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffer), TCoreException); -} +#include "../TOverlappedMemoryPool.h" Index: src/libchcore/Tests/TOverlappedWriterTests.cpp =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rdcbfdc95eedacd24d8b1d78fa507029ce12a5a63 --- src/libchcore/Tests/TOverlappedWriterTests.cpp (.../TOverlappedWriterTests.cpp) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/Tests/TOverlappedWriterTests.cpp (.../TOverlappedWriterTests.cpp) (revision dcbfdc95eedacd24d8b1d78fa507029ce12a5a63) @@ -2,14 +2,40 @@ #include "gtest/gtest.h" #include "gmock/gmock.h" #include "../TOverlappedWriter.h" +#include "../GTestMacros.h" using namespace chcore; -TEST(TOverlappedWriterTests, DefaultTest) +TEST(TOverlappedWriterTests, DefaultConstructor_SanityTest) { logger::TLogFileDataPtr spLogData(std::make_shared()); + + TBufferListPtr spEmptyBuffers(std::make_shared()); TOrderedBufferQueuePtr spQueue(std::make_shared(0)); + TOverlappedWriter tWriter(spLogData, spQueue, 0, spEmptyBuffers); + + EXPECT_EQ(nullptr, tWriter.GetWriteBuffer()); + EXPECT_EQ(nullptr, tWriter.GetFailedWriteBuffer()); + EXPECT_EQ(nullptr, tWriter.GetFinishedBuffer()); + + EXPECT_NE(nullptr, tWriter.GetEventWritePossibleHandle()); + EXPECT_NE(nullptr, tWriter.GetEventWriteFailedHandle()); + EXPECT_NE(nullptr, tWriter.GetEventWriteFinishedHandle()); + + EXPECT_TIMEOUT(tWriter.GetEventWritePossibleHandle()); + EXPECT_TIMEOUT(tWriter.GetEventWriteFailedHandle()); + EXPECT_TIMEOUT(tWriter.GetEventWriteFinishedHandle()); +} + +TEST(TOverlappedWriterTests, AllocatingConstructor_SanityTest) +{ + logger::TLogFileDataPtr spLogData(std::make_shared()); + TBufferListPtr spEmptyBuffers(std::make_shared()); + TOrderedBufferQueuePtr spQueue(std::make_shared(0)); + TOverlappedWriter tWriter(spLogData, spQueue, 0, spEmptyBuffers); - TOverlappedWriter writer(spLogData, spQueue, 0, spEmptyBuffers); + EXPECT_TIMEOUT(tWriter.GetEventWritePossibleHandle()); + EXPECT_TIMEOUT(tWriter.GetEventWriteFailedHandle()); + EXPECT_TIMEOUT(tWriter.GetEventWriteFinishedHandle()); }