Index: src/libchcore/Tests/TOverlappedDataBufferTests.cpp =================================================================== diff -u -radf2d680643ef85665b042e03fed274ab8f11180 -r4160fe7ef4661c482d974476fa02eaadf1877d5b --- src/libchcore/Tests/TOverlappedDataBufferTests.cpp (.../TOverlappedDataBufferTests.cpp) (revision adf2d680643ef85665b042e03fed274ab8f11180) +++ src/libchcore/Tests/TOverlappedDataBufferTests.cpp (.../TOverlappedDataBufferTests.cpp) (revision 4160fe7ef4661c482d974476fa02eaadf1877d5b) @@ -130,3 +130,156 @@ EXPECT_EQ(123, buffer.GetFilePosition()); } + +/////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(TOverlappedDataBufferTests, InitForRead) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.SetRequestedDataSize(123); + buffer.SetFilePosition(1); + buffer.SetRealDataSize(120); + buffer.SetLastPart(true); + buffer.SetErrorCode(54); + buffer.SetStatusCode(3); + buffer.SetBytesTransferred(12); + + buffer.InitForRead(320, 600); + + EXPECT_EQ(600, buffer.GetRequestedDataSize()); + EXPECT_EQ(320, buffer.GetFilePosition()); + EXPECT_EQ(0, buffer.GetRealDataSize()); + EXPECT_EQ(false, buffer.IsLastPart()); + EXPECT_EQ(0, buffer.GetErrorCode()); + EXPECT_EQ(0, buffer.GetStatusCode()); + EXPECT_EQ(0, buffer.GetBytesTransferred()); +} + +TEST(TOverlappedDataBufferTests, InitForWrite) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.SetRequestedDataSize(123); + buffer.SetFilePosition(1); + buffer.SetRealDataSize(120); + buffer.SetLastPart(true); + buffer.SetErrorCode(54); + buffer.SetStatusCode(3); + buffer.SetBytesTransferred(12); + + buffer.InitForWrite(); + + EXPECT_EQ(0, buffer.GetErrorCode()); + EXPECT_EQ(0, buffer.GetStatusCode()); + EXPECT_EQ(0, buffer.GetBytesTransferred()); +} + +TEST(TOverlappedDataBufferTests, Reset) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.SetRequestedDataSize(123); + buffer.SetFilePosition(1); + buffer.SetRealDataSize(120); + buffer.SetLastPart(true); + buffer.SetErrorCode(54); + buffer.SetStatusCode(3); + buffer.SetBytesTransferred(12); + + buffer.Reset(); + + EXPECT_EQ(0, buffer.GetRequestedDataSize()); + EXPECT_EQ(0, buffer.GetFilePosition()); + EXPECT_EQ(0, buffer.GetRealDataSize()); + EXPECT_EQ(false, buffer.IsLastPart()); + EXPECT_EQ(0, buffer.GetErrorCode()); + EXPECT_EQ(0, buffer.GetStatusCode()); + EXPECT_EQ(0, buffer.GetBytesTransferred()); +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(TOverlappedDataBufferTests, RequeueAsEmpty) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.RequeueAsEmpty(); + + EXPECT_EQ(queue.GetEmptyBuffer(), &buffer); +} + +TEST(TOverlappedDataBufferTests, RequeueAsFull) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.RequeueAsFull(); + + EXPECT_EQ(queue.GetFullBuffer(), &buffer); +} + +TEST(TOverlappedDataBufferTests, RequeueAsFinished) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.RequeueAsFinished(); + + EXPECT_EQ(queue.GetFinishedBuffer(), &buffer); +} +/////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(TOverlappedDataBufferTests, OverlappedReadCompleted_Success) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.InitForRead(0, 1024); + buffer.SetStatusCode(0); + buffer.SetBytesTransferred(234); + + OverlappedReadCompleted(ERROR_SUCCESS, 234, &buffer); + + EXPECT_TRUE(buffer.IsLastPart()); + EXPECT_EQ(ERROR_SUCCESS, buffer.GetErrorCode()); + EXPECT_EQ(234, buffer.GetRealDataSize()); + + EXPECT_EQ(queue.GetFullBuffer(), &buffer); +} + +TEST(TOverlappedDataBufferTests, OverlappedReadCompleted_Failure) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.InitForRead(0, 1024); + buffer.SetStatusCode(0); + buffer.SetBytesTransferred(0); + + OverlappedReadCompleted(ERROR_ACCESS_DENIED, 0, &buffer); + + EXPECT_FALSE(buffer.IsLastPart()); + EXPECT_EQ(ERROR_ACCESS_DENIED, buffer.GetErrorCode()); + EXPECT_EQ(0, buffer.GetRealDataSize()); + + EXPECT_EQ(queue.GetFullBuffer(), &buffer); +} + +TEST(TOverlappedDataBufferTests, OverlappedWriteCompleted_Success) +{ + TOverlappedDataBufferQueue queue; + TOverlappedDataBuffer buffer(16384, &queue); + + buffer.InitForRead(0, 1024); + buffer.SetStatusCode(0); + buffer.SetBytesTransferred(234); + buffer.SetLastPart(true); + buffer.SetRealDataSize(234); + + OverlappedWriteCompleted(ERROR_SUCCESS, 234, &buffer); + + EXPECT_EQ(ERROR_SUCCESS, buffer.GetErrorCode()); + EXPECT_EQ(queue.GetFinishedBuffer(), &buffer); +}