Author: siwuzzz
Date: Wed Aug  1 12:38:47 2007
New Revision: 214

Added:
   trunk/clients/cs/src/unittests/gziplivetest.cs
   trunk/clients/cs/src/unittests/gzipstreamtest.cs
Modified:
   trunk/clients/cs/src/VS2003/unittests/unittests.csproj
   trunk/clients/cs/src/core/gzipstream.cs

Log:
src/core/gzipstream.cs:
- Added XML comments

src/VS2003/unittests/unittests.csproj:
- Added GZipStream unit tests
- Added GZip Live Tests

src/unittests/gziplivetest.cs:
- Live test using GZip against a calendar feed

src/unittests/gzipstreamtest.cs:
- GZipStream unit tests

Modified: trunk/clients/cs/src/VS2003/unittests/unittests.csproj
==============================================================================
--- trunk/clients/cs/src/VS2003/unittests/unittests.csproj      (original)
+++ trunk/clients/cs/src/VS2003/unittests/unittests.csproj      Wed Aug  1 
12:38:47 2007
@@ -1,7 +1,7 @@
 <VisualStudioProject>
     <CSHARP
         ProjectType = "Local"
-        ProductVersion = "7.10.6030"
+        ProductVersion = "7.10.3077"
         SchemaVersion = "2.0"
         ProjectGuid = "{22D56E6B-DF29-4675-A655-B33252B7FA4B}"
     >
@@ -115,23 +115,11 @@
                     Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                 />
                 <Reference
-                    Name = "nunit.framework"
-                    AssemblyName = "nunit.framework"
-                    HintPath = "C:\Program Files\NUnit 
2.2\bin\nunit.framework.dll"
-                    AssemblyFolderKey = "hklm\dn\nunit.framework"
-                />
-                <Reference
                     Name = "gbase"
                     Project = "{C9B83904-8002-455C-AA48-C47CDF74F365}"
                     Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                 />
                 <Reference
-                    Name = "nunit.core"
-                    AssemblyName = "nunit.core"
-                    HintPath = "C:\Program Files\NUnit 
2.2.8\bin\nunit.core.dll"
-                    AssemblyFolderKey = "hklm\dn\nunit.framework"
-                />
-                <Reference
                     Name = "System.Web"
                     AssemblyName = "System.Web"
                     HintPath = 
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
@@ -146,6 +134,12 @@
                     Project = "{279D35CE-871A-4C76-B823-A73675EDF191}"
                     Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
                 />
+                <Reference
+                    Name = "nunit.framework"
+                    AssemblyName = "nunit.framework"
+                    HintPath = "C:\Program Files\NUnit 
2.4\bin\nunit.framework.dll"
+                    AssemblyFolderKey = "hkcu\dn\nunit 2.4.0"
+                />
             </References>
         </Build>
         <Files>
@@ -285,6 +279,18 @@
                 <File
                     RelPath = "gbaseutilitiestest.cs"
                     Link = "..\..\unittests\gbase\gbaseutilitiestest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "gziplivetest.cs"
+                    Link = "..\..\unittests\gziplivetest.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "gzipstreamtest.cs"
+                    Link = "..\..\unittests\gzipstreamtest.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
                 />

Modified: trunk/clients/cs/src/core/gzipstream.cs
==============================================================================
--- trunk/clients/cs/src/core/gzipstream.cs     (original)
+++ trunk/clients/cs/src/core/gzipstream.cs     Wed Aug  1 12:38:47 2007
@@ -4,12 +4,16 @@
 
 namespace Google.GData.Client
 {
+    /// <summary>Type of compression to use for the GZipStream. Currently only 
Decompress is supported.</summary>
     public enum CompressionMode
        {
+        /// <summary>Compresses the underlying stream.</summary>
         Compress,
+        /// <summary>Decompresses the underlying stream.</summary>
         Decompress,
        }
 
+    /// <summary>Provides methods and properties used to compress and 
decompress streams.</summary>
     public class GZipStream : Stream
     {
         #region Native const, structs, and defs
@@ -129,27 +133,42 @@
         private byte[]              inputBuffer = new byte[BufferSize];
         private GCHandle            inputBufferHandle;
 
+        /// <summary>Initializes a new instance of the GZipStream class using 
the specified stream and CompressionMode value.</summary>
+        /// <param name="stream">The stream to compress or decompress.</param>
+        /// <param name="mode">One of the CompressionMode values that 
indicates the action to take.</param>
         public GZipStream(Stream stream, CompressionMode mode)
         {
+            if (mode != CompressionMode.Decompress)
+                throw new NotImplementedException("Compression is not 
implemented.");
+
             this.compressedStream = stream;
             this.mode = mode;
 
-            this.inputBufferHandle = GCHandle.Alloc(inputBuffer, 
GCHandleType.Pinned);
-
             this.zstream.zalloc = IntPtr.Zero;
             this.zstream.zfree = IntPtr.Zero;
             this.zstream.opaque = IntPtr.Zero;
 
-            inflateInit2(ref this.zstream, ZLibOpenType.Both, ZLibVersion, 
Marshal.SizeOf(typeof(z_stream)));
+            ZLibReturnCode ret = inflateInit2(ref this.zstream, 
ZLibOpenType.Both, ZLibVersion, Marshal.SizeOf(typeof(z_stream)));
+
+            if (ret != ZLibReturnCode.Ok)
+                throw new ArgumentException("Unable to init ZLib. Return code: 
" + ret.ToString());
+
+            this.inputBufferHandle = GCHandle.Alloc(inputBuffer, 
GCHandleType.Pinned);
         }
 
+        /// <summary>GZipStream destructor. Cleans all allocated 
resources.</summary>
         ~GZipStream()
         {
             inputBufferHandle.Free();
             inflateEnd(ref this.zstream);
         }
 
-        public override int Read(byte[] buffer, int offset, int count)
+        /// <summary>Reads a number of decompressed bytes into the specified 
byte array.</summary>
+        /// <param name="array">The array used to store decompressed 
bytes.</param>
+        /// <param name="offset">The location in the array to begin 
reading.</param>
+        /// <param name="count">The number of bytes decompressed.</param>
+        /// <returns>The number of bytes that were decompressed into the byte 
array. If the end of the stream has been reached, zero or the number of bytes 
read is returned.</returns>
+        public override int Read(byte[] array, int offset, int count)
         {
             if (this.mode == CompressionMode.Compress)
                 throw new NotSupportedException("Can't read on a compress 
stream!");
@@ -177,15 +196,15 @@
                     {
                         case ZLibReturnCode.StreamEnd:
                             exitLoop = true;
-                            Array.Copy(tmpOutputBuffer, 0, buffer, offset, 
count - (int)this.zstream.avail_out);
+                            Array.Copy(tmpOutputBuffer, 0, array, offset, 
count - (int)this.zstream.avail_out);
                             break;
                         case ZLibReturnCode.Ok:
-                            Array.Copy(tmpOutputBuffer, 0, buffer, offset, 
count - (int)this.zstream.avail_out);
+                            Array.Copy(tmpOutputBuffer, 0, array, offset, 
count - (int)this.zstream.avail_out);
                             break;
                         case ZLibReturnCode.MemoryError:
-                            throw new OutOfMemoryException();
+                            throw new OutOfMemoryException("ZLib return code: 
" + result.ToString());
                         default:
-                            throw new Exception("Zlib Return Code: " + 
result.ToString());
+                            throw new Exception("ZLib return code: " + 
result.ToString());
                     }
                 }
 
@@ -197,58 +216,76 @@
             }
         }
 
+        /// <summary>Closes the current stream and releases any resources 
(such as sockets and file handles) associated with the current stream.</summary>
         public override void Close()
         {
             this.compressedStream.Close();
             base.Close();
         }
 
+        /// <summary>Gets a value indicating whether the stream supports 
reading while decompressing a file.</summary>
         public override bool CanRead
         {
             get { return (this.mode == CompressionMode.Decompress ? true : 
false); }
         }
 
+        /// <summary>Gets a value indicating whether the stream supports 
writing.</summary>
         public override bool CanWrite
         {
             get { return (this.mode == CompressionMode.Compress ? true : 
false); }
         }
 
+        /// <summary>Gets a value indicating whether the stream supports 
seeking.</summary>
         public override bool CanSeek
         {
             get { return (false); }
         }
 
+        /// <summary>Gets a reference to the underlying stream.</summary>
         public Stream BaseStream
         {
             get { return (this.compressedStream); }
         }
 
         #region Not yet supported
+        /// <summary>Flushes the contents of the internal buffer of the 
current GZipStream object to the underlying stream.</summary>
         public override void Flush()
         {
-            throw new Exception("The method or operation is not implemented.");
+            throw new NotSupportedException("The method or operation is not 
implemented.");
         }
 
+        /// <summary>This property is not supported and always throws a 
NotSupportedException.</summary>
+        /// <param name="offset">The location in the stream.</param>
+        /// <param name="origin">One of the SeekOrigin values.</param>
+        /// <returns>A long value.</returns>
         public override long Seek(long offset, SeekOrigin origin)
         {
             throw new NotSupportedException();
         }
 
+        /// <summary>This property is not supported and always throws a 
NotSupportedException.</summary>
+        /// <param name="value">The length of the stream.</param>
         public override void SetLength(long value)
         {
             throw new NotSupportedException();
         }
 
-        public override void Write(byte[] buffer, int offset, int count)
+        /// <summary>This property is not supported and always throws a 
NotSupportedException.</summary>
+        /// <param name="array">The array used to store compressed 
bytes.</param>
+        /// <param name="offset">The location in the array to begin 
reading.</param>
+        /// <param name="count">The number of bytes compressed.</param>
+        public override void Write(byte[] array, int offset, int count)
         {
             throw new NotSupportedException("Not yet supported!");
         }
 
+        /// <summary>This property is not supported and always throws a 
NotSupportedException.</summary>
         public override long Length
         {
             get { throw new NotSupportedException(); }
         }
 
+        /// <summary>This property is not supported and always throws a 
NotSupportedException.</summary>
         public override long Position
         {
             get { throw new NotSupportedException(); }

Added: trunk/clients/cs/src/unittests/gziplivetest.cs
==============================================================================
--- (empty file)
+++ trunk/clients/cs/src/unittests/gziplivetest.cs      Wed Aug  1 12:38:47 2007
@@ -0,0 +1,64 @@
+using System;
+using System.IO;
+using System.Xml; 
+using System.Collections;
+using System.Configuration;
+using System.Net; 
+using NUnit.Framework;
+using Google.GData.Client;
+using Google.GData.Client.UnitTests;
+using Google.GData.Extensions;
+using Google.GData.Calendar;
+using Google.GData.AccessControl;
+
+namespace Google.GData.Client.LiveTests
+{
+       /// <summary>
+       /// Summary description for gziplivetest.
+       /// </summary>
+    [TestFixture] 
+    [Category("LiveTest")]
+    public class GZipTestSuite : BaseLiveTestClass
+       {
+        private CalendarService calendarService;
+        private string  calendarUri = "";
+
+               public GZipTestSuite()
+               {
+               }
+
+        public override void InitTest()
+        {
+            base.InitTest();
+            this.calendarService = new CalendarService(null);
+            calendarService.RequestFactory.UseGZip = true;
+        }
+
+        protected override void ReadConfigFile()
+        {
+            base.ReadConfigFile();
+
+            if (unitTestConfiguration.Contains("calendarURI") == true)
+                this.calendarUri = 
(string)unitTestConfiguration["calendarURI"];
+        }
+
+        [Test]
+        public void     TestGZipQuery()
+        {
+            IGDataRequest request = 
this.calendarService.RequestFactory.CreateRequest(GDataRequestType.Query, new 
Uri(calendarUri));
+            Assert.IsTrue(request.UseGZip, "IGDataRequest.UseGZip property 
should be true.");
+
+            request.Credentials = new NetworkCredential(this.userName, 
this.passWord);
+            request.Execute();
+            Assert.IsTrue(request.UseGZip, "IGDataRequest.UseGZip is not true, 
the response was NOT in GZip format.");
+
+            Stream responseStream = request.GetResponseStream();
+            Assert.IsTrue(responseStream != null, "Response stream should not 
be null.");
+            Assert.IsTrue(responseStream is Google.GData.Client.GZipStream, 
"Response stream is not Google.GData.Client.GZipStream.");
+
+            AtomFeed feed = new AtomFeed(new Uri(calendarUri), 
this.calendarService);
+            feed.Parse(request.GetResponseStream(), AlternativeFormat.Atom);
+            Assert.IsTrue(feed.Self != null, "AtomFeed object is not right.");
+        }
+       }
+}

Added: trunk/clients/cs/src/unittests/gzipstreamtest.cs
==============================================================================
--- (empty file)
+++ trunk/clients/cs/src/unittests/gzipstreamtest.cs    Wed Aug  1 12:38:47 2007
@@ -0,0 +1,106 @@
+using System;
+using System.Text;
+using System.Xml;
+using System.IO;
+
+using Google.GData.Client;
+
+using NUnit.Framework;
+
+namespace Google.GData.Client.UnitTests
+{
+       /// <summary>
+       /// Summary description for gziptest.
+       /// </summary>
+    [TestFixture]
+    public class GZipStreamTest : BaseTestClass
+       {
+        private const string    Data = "Google.GData.Client.GZipStream";
+        private const string    Base64GZipData = 
"H4sIAEDbsEYAA3PPz0/PSdVzd0ksSdRzzslMzSvRc4/KLAguKUpNzAUAg1++Bx4AAAA=";
+
+        private byte[]          compressedData;
+
+               public GZipStreamTest()
+               {
+               }
+
+        public override void InitTest()
+        {
+            base.InitTest();
+            this.compressedData = Convert.FromBase64String(Base64GZipData);
+        }
+
+        [Test]
+        public void TestInit()
+        {
+            Stream      baseStream = new MemoryStream();
+            GZipStream  gzipStream = new GZipStream(baseStream, 
CompressionMode.Decompress);
+
+            Assert.AreSame(baseStream, gzipStream.BaseStream);
+
+            gzipStream.Close();
+        }
+
+        [Test]
+        public void TestDecompress()
+        {
+            Stream      baseStream = new MemoryStream(this.compressedData);
+            GZipStream  gzipStream = new GZipStream(baseStream, 
CompressionMode.Decompress);
+
+            StreamReader reader = new StreamReader(gzipStream);
+
+            string  data = reader.ReadToEnd();
+
+            Assert.AreEqual(Data, data);
+
+            gzipStream.Close();
+        }
+
+        [Test]
+        public void TestDestructor()
+        {
+            using (GZipStream stream = new GZipStream(new MemoryStream(), 
CompressionMode.Decompress))
+            {
+            }
+        }
+
+        [Test]
+        public void TestProperties()
+        {
+            Stream      baseStream = new MemoryStream(this.compressedData);
+            GZipStream  gzipStream = new GZipStream(baseStream, 
CompressionMode.Decompress);
+
+            Assert.IsTrue(gzipStream.CanRead);
+            Assert.IsFalse(gzipStream.CanWrite);
+            Assert.IsFalse(gzipStream.CanSeek);
+
+            try { long i = gzipStream.Length; }
+            catch (NotSupportedException) {}
+
+            try { long i = gzipStream.Position; }
+            catch (NotSupportedException) {}
+
+            try { gzipStream.Position = 0; }
+            catch (NotSupportedException) {}
+        }
+
+        [Test]
+        public void TestNotSupported()
+        {
+            Stream      baseStream = new MemoryStream(this.compressedData);
+            GZipStream  gzipStream = new GZipStream(baseStream, 
CompressionMode.Decompress);
+
+            try { gzipStream.Write(null, 0, 0); }
+            catch (NotSupportedException) {}
+
+            try { gzipStream.Flush(); }
+            catch (NotSupportedException) {}
+
+            try { gzipStream.Seek(0, SeekOrigin.Begin); }
+            catch (NotSupportedException) {}
+
+            try { gzipStream.SetLength(0); }
+            catch (NotSupportedException) {}
+        }
+       }
+}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Data API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to