Work on unit tests

This commit is contained in:
Nikolaj Olsson 2021-02-02 11:18:11 +01:00
parent bce18c4f55
commit 82175c8e72
3 changed files with 55 additions and 17 deletions

View File

@ -0,0 +1,28 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.Common;
namespace Test.Core
{
[TestClass]
public class UUEncodingTest
{
[TestMethod]
public void ForwardAndBackAgain()
{
var byteArray = new byte[byte.MaxValue];
for (int i = byte.MinValue; i < byte.MaxValue; i++)
{
byteArray[i] = (byte)i;
}
var text = UUEncoding.UUEncode(byteArray);
var newBytes = UUEncoding.UUDecode(text);
Assert.AreEqual(byteArray.Length, newBytes.Length);
for (int i = byte.MinValue; i < byte.MaxValue; i++)
{
Assert.AreEqual(byteArray[i], newBytes[i]);
}
}
}
}

View File

@ -70,29 +70,38 @@ namespace Test.FixCommonErrors
var asm = System.Reflection.Assembly.GetExecutingAssembly();
var stream = asm.GetManifestResourceStream("Test.Dictionaries.en_US.aff");
if (stream != null)
{
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "en_US.aff")))
{
CopyStream(stream, file);
}
}
WriteStream(stream, Path.Combine(dictionaryFolder, "en_US.aff"));
stream = asm.GetManifestResourceStream("Test.Dictionaries.en_US.dic");
if (stream != null)
{
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "en_US.dic")))
{
CopyStream(stream, file);
}
}
WriteStream(stream, Path.Combine(dictionaryFolder, "en_US.dic"));
stream = asm.GetManifestResourceStream("Test.Dictionaries.names.xml");
if (stream != null)
WriteStream(stream, Path.Combine(dictionaryFolder, "names.xml"));
}
private static readonly object WriteStreamLock = new Object();
private static void WriteStream(Stream stream, string fileName)
{
lock (WriteStreamLock)
{
using (Stream file = File.OpenWrite(Path.Combine(dictionaryFolder, "names.xml")))
if (stream != null)
{
CopyStream(stream, file);
if (File.Exists(fileName))
{
try
{
File.Delete(fileName);
}
catch
{
return;
}
}
using (Stream file = File.OpenWrite(fileName))
{
CopyStream(stream, file);
}
}
}
}

View File

@ -61,6 +61,7 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Core\UUEncodingTest.cs" />
<Compile Include="Core\CharUtilsTest.cs" />
<Compile Include="Core\DialogTypeTest.cs" />
<Compile Include="Core\SeJsonParserTest.cs" />