9 using System.Collections;
15 using NUnit.Framework;
23 namespace DotZLibTests
30 public static bool byteArrEqual(
byte[] lhs,
byte[] rhs )
32 if (lhs.Length != rhs.Length)
34 for (
int i = lhs.Length-1;
i >= 0; --
i)
44 public class CircBufferTests
46 #region Circular buffer tests
48 public void SinglePutGet()
50 CircularBuffer
buf =
new CircularBuffer(10);
62 public void BlockPutGet()
64 CircularBuffer
buf =
new CircularBuffer(10);
65 byte[]
arr = {1,2,3,4,5,6,7,8,9,10};
72 byte[] arr2 = (
byte[])
arr.Clone();
74 Assert.IsTrue( Utils.byteArrEqual(
arr,arr2) );
81 public class ChecksumTests
85 public void CRC32_Null()
87 CRC32Checksum
crc32 =
new CRC32Checksum();
90 crc32 =
new CRC32Checksum(1);
93 crc32 =
new CRC32Checksum(556);
98 public void CRC32_Data()
100 CRC32Checksum
crc32 =
new CRC32Checksum();
101 byte[] data = { 1,2,3,4,5,6,7 };
105 crc32 =
new CRC32Checksum();
106 crc32.Update(
"penguin");
109 crc32 =
new CRC32Checksum(1);
110 crc32.Update(
"penguin");
119 public void Adler_Null()
121 AdlerChecksum adler =
new AdlerChecksum();
122 Assert.AreEqual(0, adler.Value);
124 adler =
new AdlerChecksum(1);
125 Assert.AreEqual( 1, adler.Value );
127 adler =
new AdlerChecksum(556);
128 Assert.AreEqual( 556, adler.Value );
132 public void Adler_Data()
134 AdlerChecksum adler =
new AdlerChecksum(1);
135 byte[] data = { 1,2,3,4,5,6,7 };
137 Assert.AreEqual( 0x5b001d, adler.Value );
139 adler =
new AdlerChecksum();
140 adler.Update(
"penguin");
141 Assert.AreEqual(0x0bcf02f6, adler.Value );
143 adler =
new AdlerChecksum(1);
144 adler.Update(
"penguin");
145 Assert.AreEqual(0x0bd602f7, adler.Value);
152 public class InfoTests
156 public void Info_Version()
158 Info
info =
new Info();
159 Assert.AreEqual(
"1.2.12", Info.Version);
169 public class DeflateInflateTests
171 #region Deflate tests
173 public void Deflate_Init()
180 private ArrayList compressedData =
new ArrayList();
183 private ArrayList uncompressedData =
new ArrayList();
186 public void CDataAvail(
byte[] data,
int startIndex,
int count)
189 compressedData.Add(data[
i+startIndex]);
193 public void Deflate_Compress()
195 compressedData.Clear();
197 byte[] testData =
new byte[35000];
198 for (
int i = 0;
i < testData.Length; ++
i)
206 adler1 =
def.Checksum;
211 #region Inflate tests
213 public void Inflate_Init()
215 using (Inflater
inf =
new Inflater())
220 private void DDataAvail(
byte[] data,
int startIndex,
int count)
223 uncompressedData.Add(data[
i+startIndex]);
227 public void Inflate_Expand()
229 uncompressedData.Clear();
231 using (Inflater
inf =
new Inflater())
234 inf.Add((
byte[])compressedData.ToArray(
typeof(
byte)));
236 adler2 =
inf.Checksum;
238 Assert.AreEqual( adler1, adler2 );
244 public class GZipStreamTests
246 #region GZipStream test
248 public void GZipStream_WriteRead()
250 using (GZipStream gzOut =
new GZipStream(
"gzstream.gz",
CompressLevel.Best))
252 BinaryWriter
writer =
new BinaryWriter(gzOut);
258 using (GZipStream gzIn =
new GZipStream(
"gzstream.gz"))
260 BinaryReader
reader =
new BinaryReader(gzIn);
261 string s =
reader.ReadString();
263 double d =
reader.ReadDouble();
RzBinInfo * info(RzBinFile *bf)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
CompressLevel
Defines constants for the available compression levels in zlib
delegate void DataAvailableHandler(byte[] data, int startIndex, int count)
Represents the method that will be called from a codec when new data are available.
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
int inf(FILE *source, FILE *dest)
int def(FILE *source, FILE *dest, int level)
#define Assert(cond, msg)