public void OpenRead_WithVariableSizes_Overlapped_CallsApiCorrectly() { var bufferSize = int.Parse((string) TestContext.DataRow["BufferSize"]); var fileSize = int.Parse((string) TestContext.DataRow["FileSize"]); var fixture = DokanOperationsFixture.Instance; var path = fixture.FileName.AsRootedPath(); var testData = DokanOperationsFixture.InitBlockTestData(bufferSize, fileSize); #if LOGONLY fixture.PermitAny(); #else fixture.ExpectCreateFile(path, ReadAccess, ReadShare, FileMode.Open, context: testData); fixture.ExpectReadFileInChunks(path, testData, bufferSize, context: testData, synchronousIo: false); #endif var outputs = NativeMethods.ReadEx(fixture.FileName.AsDriveBasedPath(), bufferSize, testData.Length); #if !LOGONLY for (var i = 0; i < outputs.Length; ++i) { Assert.AreEqual(0, outputs[i].Win32Error, $"Unexpected Win32 error in output {i} for BufferSize={bufferSize}, FileSize={fileSize}"); Assert.AreEqual(NativeMethods.BufferSize(bufferSize, fileSize, i), outputs[i].BytesTransferred, $"Unexpected number of bytes read in output {i} for BufferSize={bufferSize}, FileSize={fileSize}"); Assert.IsTrue(Enumerable.All(outputs[i].Buffer, b => b == (byte) i + 1), $"Unexpected data in output {i} for BufferSize={bufferSize}, FileSize={fileSize}"); } fixture.Verify(); }
public void OpenWrite_WithVariableSizes_Overlapped_CallsApiCorrectly() { var bufferSize = int.Parse((string)TestContext.DataRow["BufferSize"]); var fileSize = int.Parse((string)TestContext.DataRow["FileSize"]); var fixture = DokanOperationsFixture.Instance; var path = fixture.FileName.AsRootedPath(); var testData = DokanOperationsFixture.InitBlockTestData(bufferSize, fileSize); #if LOGONLY fixture.SetupAny(); #else fixture.ExpectCreateFile(path, WriteAccess, WriteShare, FileMode.Open, context: testData); fixture.ExpectSetAllocationSize(path, testData.Length); fixture.ExpectSetEndOfFile(path, testData.Length); #if NETWORK_DRIVE fixture.SetupWriteFileInChunks(path, testData, bufferSize, context: testData, synchronousIo: false); #else fixture.ExpectWriteFileInChunks(path, testData, bufferSize, context: testData); #endif #endif var inputs = Enumerable.Range(0, NativeMethods.NumberOfChunks(bufferSize, fileSize)) .Select( i => new NativeMethods.OverlappedChunk( Enumerable.Repeat((byte)(i + 1), NativeMethods.BufferSize(bufferSize, testData.Length, i)).ToArray())) .ToArray(); NativeMethods.WriteEx(fixture.FileName.AsDriveBasedPath(), bufferSize, testData.Length, inputs); #if !LOGONLY for (var i = 0; i < inputs.Length; ++i) { Assert.AreEqual(0, inputs[i].Win32Error, $"Unexpected Win32 error in input {i} for BufferSize={bufferSize}, FileSize={fileSize}"); Assert.AreEqual(NativeMethods.BufferSize(bufferSize, fileSize, i), inputs[i].BytesTransferred, $"Unexpected number of bytes written in input {i} for BufferSize={bufferSize}, FileSize={fileSize}"); } fixture.Verify(); #endif }
public static void ClassInitialize(TestContext context) { testData = DokanOperationsFixture.InitBlockTestData(FILE_BUFFER_SIZE, 5*FILE_BUFFER_SIZE + 65536); }