Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

75 řádky
2.3 KiB

  1. using JT808.Protocol.Enums;
  2. using JT808.Protocol.Extensions;
  3. using JT808.Protocol.Interfaces;
  4. using JT808.Protocol.Internal;
  5. using JT808.Protocol.MessageBody;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Xunit;
  13. namespace JT808.Protocol.Test
  14. {
  15. public class JT808SerializerTest
  16. {
  17. [Fact]
  18. public void ParallelTest1()
  19. {
  20. var result = Parallel.For(0, 100, new ParallelOptions { MaxDegreeOfParallelism = 2 }, (i) =>
  21. {
  22. IJT808Config jT808Config = new DefaultGlobalConfig();
  23. JT808Serializer jT808Serializer = new JT808Serializer(jT808Config);
  24. });
  25. if (result.IsCompleted)
  26. {
  27. }
  28. }
  29. [Fact]
  30. public void ReadOnlySpanTest1()
  31. {
  32. IJT808Config jT808Config = new DefaultGlobalConfig();
  33. JT808Serializer jT808Serializer = new JT808Serializer(jT808Config);
  34. JT808Package jT808Package = new JT808Package
  35. {
  36. Header = new JT808Header
  37. {
  38. MsgId = Enums.JT808MsgId.终端通用应答.ToUInt16Value(),
  39. MsgNum = 1203,
  40. TerminalPhoneNo = "012345678900",
  41. MessageBodyProperty=new JT808HeaderMessageBodyProperty()
  42. },
  43. Bodies = new JT808_0x0001
  44. {
  45. ReplyMsgId = Enums.JT808MsgId.终端心跳.ToUInt16Value(),
  46. ReplyMsgNum = 1000,
  47. JT808TerminalResult = Enums.JT808TerminalResult.Success
  48. }
  49. };
  50. var hexSpan = jT808Serializer.SerializeReadOnlySpan(jT808Package);
  51. Assert.Equal(0x7e, hexSpan[0]);
  52. }
  53. [Fact]
  54. public unsafe void DefaultGlobalConfigTest1()
  55. {
  56. List<DefaultGlobalConfig> defaultGlobalConfigs = new List<DefaultGlobalConfig>();
  57. for(var i = 0; i < 100; i++)
  58. {
  59. if (i % 2 == 0)
  60. {
  61. defaultGlobalConfigs.Add(new DefaultGlobalConfig(i.ToString()));
  62. }
  63. else
  64. {
  65. defaultGlobalConfigs.Add(new DefaultGlobalConfig(i.ToString()));
  66. }
  67. }
  68. }
  69. }
  70. }