67 lines
2.5 KiB
C#
67 lines
2.5 KiB
C#
using System.IO;
|
|
using System.Text;
|
|
using NUnit.Framework;
|
|
|
|
namespace m3uTool.Tests
|
|
{
|
|
[TestFixture]
|
|
public class ProcessStreamWrapperTests : ProgressCallbackTestBase
|
|
{
|
|
private class StdinToStdoutProcess : ProcessStreamWrapper
|
|
{
|
|
public StdinToStdoutProcess(ProcessArguments encOpt, Stream outputStream)
|
|
: base(encOpt, outputStream)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the process executable filename, such as "LAME.EXE", "FAAC.EXE", etc.
|
|
/// </summary>
|
|
/// <value>The process executable filename.</value>
|
|
protected override string ProcessExecutableFilename
|
|
{
|
|
get { return "StdinToStdout.exe"; }
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void ProcessStreamWrapperFunctionalityTest()
|
|
{
|
|
string inputString = File.ReadAllText("testText.txt");
|
|
string writtenString = ""; // string that was written to the process
|
|
|
|
Stream inputStream = new MemoryStream();
|
|
|
|
var sw = new StreamWriter(inputStream, Encoding.Default);
|
|
{
|
|
int writeSize = 127;
|
|
for (int i = 0; i < inputString.Length; i += writeSize)
|
|
{
|
|
// select a substring of characters from the input string
|
|
string substring = inputString.Substring(i,
|
|
(i + writeSize < inputString.Length)
|
|
? writeSize
|
|
: inputString.Length - i);
|
|
sw.Write(substring.ToCharArray(), 0, substring.Length);
|
|
writtenString += substring;
|
|
}
|
|
}
|
|
inputStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
Stream outputStream = new MemoryStream();
|
|
using (var s = new StdinToStdoutProcess(new ProcessArguments(), outputStream))
|
|
{
|
|
s.ProgressCallback = this;
|
|
s.ProcessInput(inputStream);
|
|
}
|
|
|
|
outputStream.Seek(0, SeekOrigin.Begin);
|
|
string outputString;
|
|
using (var sr = new StreamReader(outputStream, Encoding.Default))
|
|
{
|
|
outputString = sr.ReadToEnd();
|
|
}
|
|
Assert.AreEqual(writtenString, outputString);
|
|
}
|
|
}
|
|
} |