PseudoTerminalInfoTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. namespace Renci.SshNet.Tests.Classes.Messages.Connection
  11. {
  12. /// <summary>
  13. /// Represents "pty-req" type channel request information
  14. /// </summary>
  15. [TestClass]
  16. public class PseudoTerminalRequestInfoTest : TestBase
  17. {
  18. private string environmentVariable;
  19. private uint columns;
  20. private uint rows;
  21. private uint width;
  22. private uint height;
  23. IDictionary<TerminalModes, uint> terminalModeValues;
  24. private byte[] _environmentVariableBytes;
  25. [TestInitialize]
  26. public void Init()
  27. {
  28. var random = new Random();
  29. environmentVariable = random.Next().ToString(CultureInfo.InvariantCulture);
  30. columns = (uint) random.Next(0, int.MaxValue);
  31. rows = (uint) random.Next(0, int.MaxValue);
  32. width = (uint) random.Next(0, int.MaxValue);
  33. height = (uint) random.Next(0, int.MaxValue);
  34. terminalModeValues = new Dictionary<TerminalModes, uint>();
  35. _environmentVariableBytes = Encoding.UTF8.GetBytes(environmentVariable);
  36. }
  37. [TestMethod]
  38. public void GetBytes_TerminalModeValues_Null()
  39. {
  40. var target = new PseudoTerminalRequestInfo(environmentVariable, columns, rows, width, height, null);
  41. var bytes = target.GetBytes();
  42. var expectedBytesLength = 1; // WantReply
  43. expectedBytesLength += 4; // EnvironmentVariable length
  44. expectedBytesLength += _environmentVariableBytes.Length; // EnvironmentVariable
  45. expectedBytesLength += 4; // Columns
  46. expectedBytesLength += 4; // Rows
  47. expectedBytesLength += 4; // PixelWidth
  48. expectedBytesLength += 4; // PixelHeight
  49. expectedBytesLength += 4; // Length of "encoded terminal modes"
  50. Assert.AreEqual(expectedBytesLength, bytes.Length);
  51. var sshDataStream = new SshDataStream(bytes);
  52. Assert.AreEqual(1, sshDataStream.ReadByte()); // WantReply
  53. // Assert.AreEqual((uint) _environmentVariableBytes.Length, sshDataStream.ReadUInt32());
  54. Assert.AreEqual(environmentVariable, sshDataStream.ReadString(Encoding.UTF8));
  55. Assert.AreEqual(columns, sshDataStream.ReadUInt32());
  56. Assert.AreEqual(rows, sshDataStream.ReadUInt32());
  57. Assert.AreEqual(width, sshDataStream.ReadUInt32());
  58. Assert.AreEqual(height, sshDataStream.ReadUInt32());
  59. Assert.AreEqual(0, sshDataStream.ReadUInt32());
  60. Assert.IsTrue(sshDataStream.IsEndOfData);
  61. }
  62. }
  63. }