Selaa lähdekoodia

Use Write(byte) overload is used internally when Write(bool) is invoked.

Gert Driesen 11 vuotta sitten
vanhempi
sitoutus
e0a795ee3a

+ 37 - 46
Renci.SshClient/Renci.SshNet.Tests/Classes/Common/SshDataTest.cs

@@ -1,61 +1,52 @@
-using Renci.SshNet.Common;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
-using Renci.SshNet.Tests.Common;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Renci.SshNet.Common;
 
 namespace Renci.SshNet.Tests.Classes.Common
 {
-    /// <summary>
-    ///This is a test class for SshDataTest and is intended
-    ///to contain all SshDataTest Unit Tests
-    ///</summary>
-    [TestClass()]
-    [Ignore] // placeholder for actual test
-    public class SshDataTest : TestBase
+    [TestClass]
+    public class SshDataTest
     {
-        internal virtual SshData CreateSshData()
+        [TestMethod]
+        public void Write_Boolean_False()
         {
-            // TODO: Instantiate an appropriate concrete class.
-            SshData target = null;
-            return target;
-        }
+            var sshData = new MySshData();
+            sshData.Load(new byte[0]);
 
-        /// <summary>
-        ///A test for GetBytes
-        ///</summary>
-        [TestMethod()]
-        public void GetBytesTest()
-        {
-            SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
-            byte[] expected = null; // TODO: Initialize to an appropriate value
-            byte[] actual;
-            actual = target.GetBytes();
-            Assert.AreEqual(expected, actual);
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            sshData.Write(false);
+            Assert.AreEqual((byte) 0, sshData.ReadByte());
+            Assert.IsTrue(sshData.IsEndOfData);
         }
 
-        /// <summary>
-        ///A test for Load
-        ///</summary>
-        [TestMethod()]
-        public void LoadTest()
+        [TestMethod]
+        public void Write_Boolean_True()
         {
-            SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
-            byte[] value = null; // TODO: Initialize to an appropriate value
-            target.Load(value);
-            Assert.Inconclusive("A method that does not return a value cannot be verified.");
+            var sshData = new MySshData();
+            sshData.Load(new byte[0]);
+
+            sshData.Write(true);
+            Assert.AreEqual((byte) 1, sshData.ReadByte());
+            Assert.IsTrue(sshData.IsEndOfData);
         }
 
-        /// <summary>
-        ///A test for IsEndOfData
-        ///</summary>
-        [TestMethod()]
-        public void IsEndOfDataTest()
+        private class MySshData : SshData
         {
-            SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
-            bool actual;
-            actual = target.IsEndOfData;
-            Assert.Inconclusive("Verify the correctness of this test method.");
+            public new void Write(bool data)
+            {
+                base.Write(data);
+            }
+
+            public new byte ReadByte()
+            {
+                return base.ReadByte();
+            }
+
+            protected override void LoadData()
+            {
+            }
+
+            protected override void SaveData()
+            {
+            }
         }
     }
 }

+ 7 - 9
Renci.SshClient/Renci.SshNet/Common/SshData.cs

@@ -202,8 +202,7 @@ namespace Renci.SshNet.Common
         protected ulong ReadUInt64()
         {
             var data = ReadBytes(8);
-            return ((ulong) data[0] << 56 | (ulong) data[1] << 48 | (ulong) data[2] << 40 | (ulong) data[3] << 32 |
-                    (ulong) data[4] << 24 | (ulong) data[5] << 16 | (ulong) data[6] << 8 | data[7]);
+            return ((ulong)data[0] << 56 | (ulong)data[1] << 48 | (ulong)data[2] << 40 | (ulong)data[3] << 32 | (ulong)data[4] << 24 | (ulong)data[5] << 16 | (ulong)data[6] << 8 | data[7]);
         }
 
         /// <summary>
@@ -213,8 +212,7 @@ namespace Renci.SshNet.Common
         protected long ReadInt64()
         {
             var data = ReadBytes(8);
-            return data[0] << 56 | data[1] << 48 | data[2] << 40 | data[3] << 32 | data[4] << 24 | data[5] << 16 |
-                   data[6] << 8 | data[7];
+            return (int)(data[0] << 56 | data[1] << 48 | data[2] << 40 | data[3] << 32 | data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7]);
         }
 
         /// <summary>
@@ -337,14 +335,14 @@ namespace Renci.SshNet.Common
         /// <param name="data">Boolean data to write.</param>
         protected void Write(bool data)
         {
-            Write(data ? 1 : 0);
+            Write(data ? (byte) 1 : (byte) 0);
         }
 
         /// <summary>
         /// Writes uint16 data into internal buffer.
         /// </summary>
         /// <param name="data">uint16 data to write.</param>
-        protected void Write(UInt16 data)
+        protected void Write(ushort data)
         {
             Write(data.GetBytes());
         }
@@ -353,7 +351,7 @@ namespace Renci.SshNet.Common
         /// Writes uint32 data into internal buffer.
         /// </summary>
         /// <param name="data">uint32 data to write.</param>
-        protected void Write(UInt32 data)
+        protected void Write(uint data)
         {
             Write(data.GetBytes());
         }
@@ -362,7 +360,7 @@ namespace Renci.SshNet.Common
         /// Writes uint64 data into internal buffer.
         /// </summary>
         /// <param name="data">uint64 data to write.</param>
-        protected void Write(UInt64 data)
+        protected void Write(ulong data)
         {
             Write(data.GetBytes());
         }
@@ -371,7 +369,7 @@ namespace Renci.SshNet.Common
         /// Writes int64 data into internal buffer.
         /// </summary>
         /// <param name="data">int64 data to write.</param>
-        protected void Write(Int64 data)
+        protected void Write(long data)
         {
             Write(data.GetBytes());
         }