📄
tests/ExtendedHeaderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using Shouldly; namespace SharpDlt.Tests; public class ExtendedHeaderTests { [Fact] public void Parse_ReadsAllFields() { var data = TestDlt.ExtendedHeader( verbose: true, messageType: DltMessageType.Log, messageTypeInfo: (byte)DltLogInfo.Warn, numberOfArguments: 3, applicationId: "APP1", contextId: "CTX1" ); var header = ExtendedHeader.Parse(data); header.Verbose.ShouldBeTrue(); header.MessageType.ShouldBe(DltMessageType.Log); header.MessageTypeInfo.ShouldBe((byte)DltLogInfo.Warn); header.LogInfo.ShouldBe(DltLogInfo.Warn); header.NumberOfArguments.ShouldBe((byte)3); header.ApplicationId.ShouldBe("APP1"); header.ContextId.ShouldBe("CTX1"); header.MessageInfo.ShouldBe(data[0]); } [Theory] [InlineData(DltMessageType.Log, (byte)DltLogInfo.Fatal)] [InlineData(DltMessageType.AppTrace, (byte)DltTraceInfo.State)] [InlineData(DltMessageType.NetworkTrace, (byte)DltBusInfo.Can)] [InlineData(DltMessageType.Control, (byte)DltControlInfo.Response)] public void Parse_DecodesMessageTypeAndTypeInfo(DltMessageType messageType, byte typeInfo) { var data = TestDlt.ExtendedHeader(verbose: false, messageType: messageType, messageTypeInfo: typeInfo); var header = ExtendedHeader.Parse(data); header.Verbose.ShouldBeFalse(); header.MessageType.ShouldBe(messageType); header.MessageTypeInfo.ShouldBe(typeInfo); } [Fact] public void TypedTypeInfoAccessors_ReinterpretTheSameValue() { var header = ExtendedHeader.Parse(TestDlt.ExtendedHeader(messageTypeInfo: (byte)DltTraceInfo.FunctionIn)); header.TraceInfo.ShouldBe(DltTraceInfo.FunctionIn); header.BusInfo.ShouldBe(DltBusInfo.Can); header.ControlInfo.ShouldBe(DltControlInfo.Response); header.LogInfo.ShouldBe(DltLogInfo.Error); } [Fact] public void Parse_StripsNulPaddingOfIds() { var data = TestDlt.ExtendedHeader(applicationId: "AP", contextId: "C"); var header = ExtendedHeader.Parse(data); header.ApplicationId.ShouldBe("AP"); header.ContextId.ShouldBe("C"); } [Fact] public void Parse_TooShortData_Throws() { Should.Throw<DltParseException>(() => ExtendedHeader.Parse(new byte[9])); } }