Skip to content

Commit e0a795e

Browse files
committed
Use Write(byte) overload is used internally when Write(bool) is invoked.
1 parent d9b9e03 commit e0a795e

File tree

2 files changed

+44
-55
lines changed

2 files changed

+44
-55
lines changed
Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,52 @@
1-
using Renci.SshNet.Common;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
3-
using System;
4-
using Renci.SshNet.Tests.Common;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Renci.SshNet.Common;
53

64
namespace Renci.SshNet.Tests.Classes.Common
75
{
8-
/// <summary>
9-
///This is a test class for SshDataTest and is intended
10-
///to contain all SshDataTest Unit Tests
11-
///</summary>
12-
[TestClass()]
13-
[Ignore] // placeholder for actual test
14-
public class SshDataTest : TestBase
6+
[TestClass]
7+
public class SshDataTest
158
{
16-
internal virtual SshData CreateSshData()
9+
[TestMethod]
10+
public void Write_Boolean_False()
1711
{
18-
// TODO: Instantiate an appropriate concrete class.
19-
SshData target = null;
20-
return target;
21-
}
12+
var sshData = new MySshData();
13+
sshData.Load(new byte[0]);
2214

23-
/// <summary>
24-
///A test for GetBytes
25-
///</summary>
26-
[TestMethod()]
27-
public void GetBytesTest()
28-
{
29-
SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
30-
byte[] expected = null; // TODO: Initialize to an appropriate value
31-
byte[] actual;
32-
actual = target.GetBytes();
33-
Assert.AreEqual(expected, actual);
34-
Assert.Inconclusive("Verify the correctness of this test method.");
15+
sshData.Write(false);
16+
Assert.AreEqual((byte) 0, sshData.ReadByte());
17+
Assert.IsTrue(sshData.IsEndOfData);
3518
}
3619

37-
/// <summary>
38-
///A test for Load
39-
///</summary>
40-
[TestMethod()]
41-
public void LoadTest()
20+
[TestMethod]
21+
public void Write_Boolean_True()
4222
{
43-
SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
44-
byte[] value = null; // TODO: Initialize to an appropriate value
45-
target.Load(value);
46-
Assert.Inconclusive("A method that does not return a value cannot be verified.");
23+
var sshData = new MySshData();
24+
sshData.Load(new byte[0]);
25+
26+
sshData.Write(true);
27+
Assert.AreEqual((byte) 1, sshData.ReadByte());
28+
Assert.IsTrue(sshData.IsEndOfData);
4729
}
4830

49-
/// <summary>
50-
///A test for IsEndOfData
51-
///</summary>
52-
[TestMethod()]
53-
public void IsEndOfDataTest()
31+
private class MySshData : SshData
5432
{
55-
SshData target = CreateSshData(); // TODO: Initialize to an appropriate value
56-
bool actual;
57-
actual = target.IsEndOfData;
58-
Assert.Inconclusive("Verify the correctness of this test method.");
33+
public new void Write(bool data)
34+
{
35+
base.Write(data);
36+
}
37+
38+
public new byte ReadByte()
39+
{
40+
return base.ReadByte();
41+
}
42+
43+
protected override void LoadData()
44+
{
45+
}
46+
47+
protected override void SaveData()
48+
{
49+
}
5950
}
6051
}
6152
}

Renci.SshClient/Renci.SshNet/Common/SshData.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ protected uint ReadUInt32()
202202
protected ulong ReadUInt64()
203203
{
204204
var data = ReadBytes(8);
205-
return ((ulong) data[0] << 56 | (ulong) data[1] << 48 | (ulong) data[2] << 40 | (ulong) data[3] << 32 |
206-
(ulong) data[4] << 24 | (ulong) data[5] << 16 | (ulong) data[6] << 8 | data[7]);
205+
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]);
207206
}
208207

209208
/// <summary>
@@ -213,8 +212,7 @@ protected ulong ReadUInt64()
213212
protected long ReadInt64()
214213
{
215214
var data = ReadBytes(8);
216-
return data[0] << 56 | data[1] << 48 | data[2] << 40 | data[3] << 32 | data[4] << 24 | data[5] << 16 |
217-
data[6] << 8 | data[7];
215+
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]);
218216
}
219217

220218
/// <summary>
@@ -337,14 +335,14 @@ protected void Write(byte data)
337335
/// <param name="data">Boolean data to write.</param>
338336
protected void Write(bool data)
339337
{
340-
Write(data ? 1 : 0);
338+
Write(data ? (byte) 1 : (byte) 0);
341339
}
342340

343341
/// <summary>
344342
/// Writes uint16 data into internal buffer.
345343
/// </summary>
346344
/// <param name="data">uint16 data to write.</param>
347-
protected void Write(UInt16 data)
345+
protected void Write(ushort data)
348346
{
349347
Write(data.GetBytes());
350348
}
@@ -353,7 +351,7 @@ protected void Write(UInt16 data)
353351
/// Writes uint32 data into internal buffer.
354352
/// </summary>
355353
/// <param name="data">uint32 data to write.</param>
356-
protected void Write(UInt32 data)
354+
protected void Write(uint data)
357355
{
358356
Write(data.GetBytes());
359357
}
@@ -362,7 +360,7 @@ protected void Write(UInt32 data)
362360
/// Writes uint64 data into internal buffer.
363361
/// </summary>
364362
/// <param name="data">uint64 data to write.</param>
365-
protected void Write(UInt64 data)
363+
protected void Write(ulong data)
366364
{
367365
Write(data.GetBytes());
368366
}
@@ -371,7 +369,7 @@ protected void Write(UInt64 data)
371369
/// Writes int64 data into internal buffer.
372370
/// </summary>
373371
/// <param name="data">int64 data to write.</param>
374-
protected void Write(Int64 data)
372+
protected void Write(long data)
375373
{
376374
Write(data.GetBytes());
377375
}

0 commit comments

Comments
 (0)