Skip to content

Commit 50427a3

Browse files
committed
Add test for PR #26.
Add test for PR #26.
1 parent a69a6d6 commit 50427a3

File tree

1 file changed

+74
-12
lines changed

1 file changed

+74
-12
lines changed
Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,75 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using Renci.SshNet.Tests.Common;
3-
4-
namespace Renci.SshNet.Tests.Classes.Messages.Connection
5-
{
6-
/// <summary>
7-
/// Represents "pty-req" type channel request information
8-
/// </summary>
9-
[TestClass]
10-
public class PseudoTerminalRequestInfoTest : TestBase
11-
{
12-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Text;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using Renci.SshNet.Common;
8+
using Renci.SshNet.Messages.Connection;
9+
using Renci.SshNet.Tests.Common;
10+
11+
namespace Renci.SshNet.Tests.Classes.Messages.Connection
12+
{
13+
/// <summary>
14+
/// Represents "pty-req" type channel request information
15+
/// </summary>
16+
[TestClass]
17+
public class PseudoTerminalRequestInfoTest : TestBase
18+
{
19+
private string environmentVariable;
20+
private uint columns;
21+
private uint rows;
22+
private uint width;
23+
private uint height;
24+
IDictionary<TerminalModes, uint> terminalModeValues;
25+
private byte[] _environmentVariableBytes;
26+
27+
[TestInitialize]
28+
public void Init()
29+
{
30+
var random = new Random();
31+
32+
environmentVariable = random.Next().ToString(CultureInfo.InvariantCulture);
33+
columns = (uint) random.Next(0, int.MaxValue);
34+
rows = (uint) random.Next(0, int.MaxValue);
35+
width = (uint) random.Next(0, int.MaxValue);
36+
height = (uint) random.Next(0, int.MaxValue);
37+
terminalModeValues = new Dictionary<TerminalModes, uint>();
38+
39+
40+
_environmentVariableBytes = Encoding.UTF8.GetBytes(environmentVariable);
41+
}
42+
43+
[TestMethod]
44+
public void GetBytes_TerminalModeValues_Null()
45+
{
46+
var target = new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, null);
47+
48+
var bytes = target.GetBytes();
49+
50+
var expectedBytesLength = 1; // WantReply
51+
expectedBytesLength += 4; // EnvironmentVariable length
52+
expectedBytesLength += _environmentVariableBytes.Length; // EnvironmentVariable
53+
expectedBytesLength += 4; // Columns
54+
expectedBytesLength += 4; // Rows
55+
expectedBytesLength += 4; // PixelWidth
56+
expectedBytesLength += 4; // PixelHeight
57+
expectedBytesLength += 4; // Length of "encoded terminal modes"
58+
59+
Assert.AreEqual(expectedBytesLength, bytes.Length);
60+
61+
var sshDataStream = new SshDataStream(bytes);
62+
63+
Assert.AreEqual(1, sshDataStream.ReadByte()); // WantReply
64+
// Assert.AreEqual((uint) _environmentVariableBytes.Length, sshDataStream.ReadUInt32());
65+
Assert.AreEqual(environmentVariable, sshDataStream.ReadString(Encoding.UTF8));
66+
Assert.AreEqual(columns, sshDataStream.ReadUInt32());
67+
Assert.AreEqual(rows, sshDataStream.ReadUInt32());
68+
Assert.AreEqual(width, sshDataStream.ReadUInt32());
69+
Assert.AreEqual(height, sshDataStream.ReadUInt32());
70+
Assert.AreEqual(0, sshDataStream.ReadUInt32());
71+
72+
Assert.IsTrue(sshDataStream.IsEndOfData);
73+
}
74+
}
1375
}

0 commit comments

Comments
 (0)