private IEnumerable <SkipToBoundaryTestCase> CreateEmptyBufferTestCases() { List <SkipToBoundaryTestCase> testCases = new List <SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LineFeeds, (boundaryString, lineFeed) => { SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in empty buffer.", PayloadFunc = builder => builder.ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return(testCases); }
private IEnumerable <SkipToBoundaryTestCase> CreatePartialBoundaryAtStreamEndTestCases() { List <SkipToBoundaryTestCase> testCases = new List <SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, lineFeed, isEndBoundary) => { // Fill the buffer with 'a' bytes and leave some room for the line feed, // the two dashes and the first byte of the boundary int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int partialBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + 1; int bytesBeforePartialBoundary = BatchReaderStreamBufferWrapper.BufferLength - partialBoundaryLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with partial " + (isEndBoundary ? "end" : "start") + " delimiter at the end of the stream.", PayloadFunc = builder => leadingBoundaryLineFeed ? builder .FillBytes(bytesBeforePartialBoundary, 'a') .LineFeed() .Chars(MemoryStreamBatchPayloadBuilder.BoundaryDelimiter) .Chars(boundaryString[0]) .ResetMemoryStream() : builder .FillBytes(bytesBeforePartialBoundary, 'a') .Chars(MemoryStreamBatchPayloadBuilder.BoundaryDelimiter) .Chars(boundaryString[0]) .ResetMemoryStream(), ExpectedBoundaryFound = false, ExpectedIsEndBoundary = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = partialBoundaryLength, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return(testCases); }
private IEnumerable <SkipToBoundaryTestCase> CreateBoundaryAtTheEndTestCases() { List <SkipToBoundaryTestCase> testCases = new List <SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + boundaryString.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with " + (isEndBoundary ? "end" : "start") + " delimiter at the end.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 1 - endBoundaryLength, 'a') .EndBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(1, 'b') .ResetMemoryStream() : builder // NOTE: we keep 3 bytes at the end of the buffer here since the algorithm always tries // to match the end boundary and otherwise reports a partial match. .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3 - startBoundaryLength, 'a') .StartBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(3, 'b') .ResetMemoryStream(), ExpectedBoundaryFound = true, ExpectedIsEndBoundary = isEndBoundary, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = BatchReaderStreamBufferWrapper.BufferLength - (isEndBoundary ? 1 : 3), NumberOfBytesInBuffer = isEndBoundary ? 1 : 3, } }; testCases.Add(testCase); }); return(testCases); }
private IEnumerable <SkipToBoundaryTestCase> CreateBoundaryAcrossBuffersTestCases() { List <SkipToBoundaryTestCase> testCases = new List <SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + boundaryString.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; int boundaryLength = isEndBoundary ? endBoundaryLength : startBoundaryLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with " + (isEndBoundary ? "end" : "start") + " delimiter across buffer boundaries.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 2, 'a') .EndBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(100, 'b') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 2, 'a') .StartBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(100, 'b') .ResetMemoryStream(), ExpectedBoundaryFound = true, ExpectedIsEndBoundary = isEndBoundary, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = boundaryLength, NumberOfBytesInBuffer = 100, } }; testCases.Add(testCase); }); return(testCases); }
/// <summary> /// Copy constructor. /// </summary> /// <param name="other">The test case instance to copy.</param> public SkipToBoundaryTestCase(SkipToBoundaryTestCase other) : base(other) { this.ExpectedBoundaryFound = other.ExpectedBoundaryFound; this.ExpectedIsEndBoundary = other.ExpectedIsEndBoundary; }
private IEnumerable<SkipToBoundaryTestCase> CreateEmptyBufferTestCases() { List<SkipToBoundaryTestCase> testCases = new List<SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LineFeeds, (boundaryString, lineFeed) => { SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in empty buffer.", PayloadFunc = builder => builder.ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return testCases; }
private IEnumerable <SkipToBoundaryTestCase> CreateNoBoundaryTestCases() { List <SkipToBoundaryTestCase> testCases = new List <SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings.Where(str => str.Length > 1), // excluding '-' boundary string since partials would be the empty string which this test does not handle LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { string almostBoundary = boundaryString.Substring(0, boundaryString.Length - 1); int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + almostBoundary.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; int almostBoundaryLength = isEndBoundary ? endBoundaryLength : startBoundaryLength; // Use a stream where a string similar to the boundary is included SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string in first buffer.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(200, 'a') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream() : builder .FillBytes(200, 'a') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); // Use a stream where a string similar to the boundary exists in the second buffer testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string in second buffer.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength, 'a') .FillBytes(200, 'b') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'c') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength, 'a') .FillBytes(200, 'b') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'c') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); // Use a stream where a string similar to the boundary exists across buffers testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string across buffers.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3, 'a') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3, 'a') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return(testCases); }
private IEnumerable<SkipToBoundaryTestCase> CreatePartialBoundaryAtStreamEndTestCases() { List<SkipToBoundaryTestCase> testCases = new List<SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, lineFeed, isEndBoundary) => { // Fill the buffer with 'a' bytes and leave some room for the line feed, // the two dashes and the first byte of the boundary int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int partialBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + 1; int bytesBeforePartialBoundary = BatchReaderStreamBufferWrapper.BufferLength - partialBoundaryLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with partial " + (isEndBoundary ? "end" : "start") + " delimiter at the end of the stream.", PayloadFunc = builder => leadingBoundaryLineFeed ? builder .FillBytes(bytesBeforePartialBoundary, 'a') .LineFeed() .Chars(MemoryStreamBatchPayloadBuilder.BoundaryDelimiter) .Chars(boundaryString[0]) .ResetMemoryStream() : builder .FillBytes(bytesBeforePartialBoundary, 'a') .Chars(MemoryStreamBatchPayloadBuilder.BoundaryDelimiter) .Chars(boundaryString[0]) .ResetMemoryStream(), ExpectedBoundaryFound = false, ExpectedIsEndBoundary = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = partialBoundaryLength, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return testCases; }
private IEnumerable<SkipToBoundaryTestCase> CreateBoundaryAcrossBuffersTestCases() { List<SkipToBoundaryTestCase> testCases = new List<SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + boundaryString.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; int boundaryLength = isEndBoundary ? endBoundaryLength : startBoundaryLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with " + (isEndBoundary ? "end" : "start") + " delimiter across buffer boundaries.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 2, 'a') .EndBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(100, 'b') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 2, 'a') .StartBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(100, 'b') .ResetMemoryStream(), ExpectedBoundaryFound = true, ExpectedIsEndBoundary = isEndBoundary, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = boundaryLength, NumberOfBytesInBuffer = 100, } }; testCases.Add(testCase); }); return testCases; }
private IEnumerable<SkipToBoundaryTestCase> CreateBoundaryAtTheEndTestCases() { List<SkipToBoundaryTestCase> testCases = new List<SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings, LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + boundaryString.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary " + boundaryString + " with " + (isEndBoundary ? "end" : "start") + " delimiter at the end.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 1 - endBoundaryLength, 'a') .EndBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(1, 'b') .ResetMemoryStream() : builder // NOTE: we keep 3 bytes at the end of the buffer here since the algorithm always tries // to match the end boundary and otherwise reports a partial match. .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3 - startBoundaryLength, 'a') .StartBoundary(boundaryString, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(3, 'b') .ResetMemoryStream(), ExpectedBoundaryFound = true, ExpectedIsEndBoundary = isEndBoundary, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = BatchReaderStreamBufferWrapper.BufferLength - (isEndBoundary ? 1 : 3), NumberOfBytesInBuffer = isEndBoundary ? 1 : 3, } }; testCases.Add(testCase); }); return testCases; }
private IEnumerable<SkipToBoundaryTestCase> CreateNoBoundaryTestCases() { List<SkipToBoundaryTestCase> testCases = new List<SkipToBoundaryTestCase>(); this.CombinatorialEngineProvider.RunCombinations( BoundaryStrings.Where(str => str.Length > 1), // excluding '-' boundary string since partials would be the empty string which this test does not handle LeadingLineFeedForBoundary, WhitespaceCounts, LineFeeds, new bool[] { false, true }, (boundaryString, leadingBoundaryLineFeed, whitespaceCount, lineFeed, isEndBoundary) => { string almostBoundary = boundaryString.Substring(0, boundaryString.Length - 1); int leadingLineFeedLength = leadingBoundaryLineFeed ? lineFeed.Length : 0; int startBoundaryLength = leadingLineFeedLength + BatchReaderStreamTestUtils.TwoDashesLength + almostBoundary.Length + whitespaceCount + lineFeed.Length; int endBoundaryLength = startBoundaryLength + BatchReaderStreamTestUtils.TwoDashesLength; int almostBoundaryLength = isEndBoundary ? endBoundaryLength : startBoundaryLength; // Use a stream where a string similar to the boundary is included SkipToBoundaryTestCase testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string in first buffer.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(200, 'a') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream() : builder .FillBytes(200, 'a') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); // Use a stream where a string similar to the boundary exists in the second buffer testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string in second buffer.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength, 'a') .FillBytes(200, 'b') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'c') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength, 'a') .FillBytes(200, 'b') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'c') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); // Use a stream where a string similar to the boundary exists across buffers testCase = new SkipToBoundaryTestCase(boundaryString, lineFeed) { DebugDescription = "Skip to boundary '" + boundaryString + "' in stream with similar string across buffers.", PayloadFunc = builder => isEndBoundary ? builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3, 'a') .EndBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream() : builder .FillBytes(BatchReaderStreamBufferWrapper.BufferLength - 3, 'a') .StartBoundary(almostBoundary, leadingBoundaryLineFeed, whitespaceCount) .FillBytes(200, 'b') .ResetMemoryStream(), ExpectedIsEndBoundary = false, ExpectedBoundaryFound = false, ExpectedBufferState = new BatchReaderStreamBufferState { ReadPositionInBuffer = 0, NumberOfBytesInBuffer = 0, } }; testCases.Add(testCase); }); return testCases; }