/
LzwTests.cs
83 lines (67 loc) · 2.85 KB
/
LzwTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using ICSharpCode.SharpZipLib.LZW;
using NUnit.Framework;
using System.IO;
using ICSharpCode.SharpZipLib.Tests.TestSupport;
namespace ICSharpCode.SharpZipLib.Tests.LZW
{
[TestFixture]
public class LzwTestSuite {
//[Test]
//[Category("LZW")]
//public void TestLzw() {
// LzwInputStream str = new LzwInputStream(File.OpenRead("D:\\hour2890.09n.Z"));
// Stream raw = File.OpenRead("D:\\hour2890.09n");
// byte[] data = new byte[1028 * 1028];
// byte[] dataRaw = new byte[1028 * 1028];
// raw.Read(dataRaw, 0, 1028);
// str.Read(data, 0, 1028);
// for (int i = 0; i < 1028; i++) {
// Assert.AreEqual(data[i], dataRaw[i]);
// }
// Stream output = File.Open("D:\\erase.txt", FileMode.CreateNew);
// output.Write(data, 0, 1028);
// output.Close();
// raw.Close();
//}
//[Test]
//[Category("LZW")]
//public void TestStream() {
// using (Stream inStream = new LzwInputStream(File.OpenRead("D:\\hour2890.09n.Z")))
// using (FileStream outStream = File.Create("D:\\hour2890.09n")) {
// byte[] buffer = new byte[4096];
// StreamUtils.Copy(inStream, outStream, buffer);
// }
//}
[Test]
[Category("LZW")]
public void ZeroLengthInputStream() {
LzwInputStream lis = new LzwInputStream(new MemoryStream());
bool exception = false;
try {
lis.ReadByte();
} catch {
exception = true;
}
Assert.IsTrue(exception, "reading from an empty stream should cause an exception");
}
[Test]
[Category("LZW")]
public void InputStreamOwnership() {
TrackedMemoryStream memStream = new TrackedMemoryStream();
LzwInputStream s = new LzwInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
s.Close();
Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");
memStream = new TrackedMemoryStream();
s = new LzwInputStream(memStream);
Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");
s.IsStreamOwner = false;
s.Close();
Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close");
Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close");
}
}
}