NetBiosTests.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Copyright (C) 2017-2019 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using Microsoft.VisualStudio.TestTools.UnitTesting;
  10. using SMBLibrary.NetBios;
  11. using Utilities;
  12. namespace SMBLibrary.Tests
  13. {
  14. [TestClass]
  15. public class NetBiosTests
  16. {
  17. [TestMethod]
  18. public void Test1()
  19. {
  20. byte[] buffer = new byte[] { 0x20, 0x46, 0x47, 0x45, 0x4e, 0x44, 0x4a, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x00 };
  21. int offset = 0;
  22. string name = NetBiosUtils.DecodeName(buffer, ref offset);
  23. byte[] encodedName = NetBiosUtils.EncodeName(name, String.Empty);
  24. Assert.IsTrue(ByteUtils.AreByteArraysEqual(buffer, encodedName));
  25. }
  26. [TestMethod]
  27. public void Test2()
  28. {
  29. byte[] buffer = new byte[] { 0x20, 0x46, 0x47, 0x45, 0x4e, 0x44, 0x4a, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x43, 0x41, 0x41, 0x41, 0x00 };
  30. int offset = 0;
  31. string name = NetBiosUtils.DecodeName(buffer, ref offset);
  32. byte[] encodedName = NetBiosUtils.EncodeName(name, String.Empty);
  33. Assert.IsTrue(ByteUtils.AreByteArraysEqual(buffer, encodedName));
  34. }
  35. public void TestAll()
  36. {
  37. Test1();
  38. Test2();
  39. }
  40. }
  41. }