Skip to content

Commit 2f7e1f5

Browse files
committed
Add initial simple LZW tests.
1 parent 405fdd6 commit 2f7e1f5

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/Lzw/LzwTests.cs

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

0 commit comments

Comments
 (0)