| Name | Message | Date |
|---|---|---|
| π Data | 8 hours ago | |
| π AsyncEnumerableTestExtensions.cs | 8 hours ago | |
| π DltArgumentTests.cs | 8 hours ago | |
| π DltFileTests.cs | 8 hours ago | |
| π DltMessageTests.cs | 8 hours ago | |
| π DltPayloadTests.cs | 8 hours ago | |
| π DltReaderTests.cs | 8 hours ago | |
| π ExtendedHeaderTests.cs | 8 hours ago | |
| π packages.lock.json | 8 hours ago | |
| π SharpDlt.Tests.csproj | 8 hours ago | |
| π StandardHeaderTests.cs | 8 hours ago | |
| π StorageHeaderTests.cs | 8 hours ago | |
| π TestDlt.cs | 8 hours ago |
📄
lib/tests/DltArgumentTests.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System.Buffers.Binary; using System.Text; using Shouldly; namespace SharpDlt.Tests; public class DltArgumentTests { [Theory] [InlineData(0, false)] [InlineData(1, true)] [InlineData(255, true)] public void Parse_Bool(byte raw, bool expected) { var data = TestDlt.Argument(TestDlt.TypeInfoBool, [raw]); var argument = DltArgument.Parse(data, msbFirst: false, encoding: null, out var bytesRead); argument.ShouldBe(new DltBoolArgument(expected)); bytesRead.ShouldBe(5); } [Fact] public void Parse_UnsignedIntegers() { AssertUnsigned(TestDlt.TypeInfoUInt8, [0xFF], 255, DltIntegerWidth.Bits8); AssertUnsigned(TestDlt.TypeInfoUInt16, [0x00, 0x01], 256, DltIntegerWidth.Bits16); AssertUnsigned(TestDlt.TypeInfoUInt32, [0x00, 0x00, 0x01, 0x00], 65536, DltIntegerWidth.Bits32); AssertUnsigned( TestDlt.TypeInfoUInt64, [0, 0, 0, 0, 0, 0, 0, 0x80], 0x8000_0000_0000_0000, DltIntegerWidth.Bits64 ); static void AssertUnsigned(uint typeInfo, byte[] payload, ulong expected, DltIntegerWidth width) { var data = TestDlt.Argument(typeInfo, payload); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltUnsignedArgument(expected, width)); bytesRead.ShouldBe(4 + payload.Length); } } [Fact] public void Parse_SignedIntegers() { AssertSigned(TestDlt.TypeInfoSInt8, [0xFF], -1, DltIntegerWidth.Bits8); AssertSigned(TestDlt.TypeInfoSInt16, [0xFF, 0xFF], -1, DltIntegerWidth.Bits16); AssertSigned(TestDlt.TypeInfoSInt32, [0xFE, 0xFF, 0xFF, 0xFF], -2, DltIntegerWidth.Bits32); AssertSigned( TestDlt.TypeInfoSInt64, [0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF], -3, DltIntegerWidth.Bits64 ); static void AssertSigned(uint typeInfo, byte[] payload, long expected, DltIntegerWidth width) { var data = TestDlt.Argument(typeInfo, payload); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltSignedArgument(expected, width)); bytesRead.ShouldBe(4 + payload.Length); } } [Fact] public void Parse_BigEndianInteger() { var data = TestDlt.Argument(TestDlt.TypeInfoUInt32, [0x00, 0x01, 0x00, 0x00], msbFirst: true); var argument = DltArgument.Parse(data, msbFirst: true, encoding: null, out _); argument.ShouldBe(new DltUnsignedArgument(65536, DltIntegerWidth.Bits32)); } [Fact] public void Parse_Float32() { var payload = new byte[4]; BinaryPrimitives.WriteSingleLittleEndian(payload, 1.5f); var data = TestDlt.Argument(TestDlt.TypeInfoFloat32, payload); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltFloatArgument(1.5, DltFloatWidth.Bits32)); bytesRead.ShouldBe(8); } [Fact] public void Parse_Float64() { var payload = new byte[8]; BinaryPrimitives.WriteDoubleBigEndian(payload, -2.25); var data = TestDlt.Argument(TestDlt.TypeInfoFloat64, payload, msbFirst: true); var argument = DltArgument.Parse(data, true, null, out var bytesRead); argument.ShouldBe(new DltFloatArgument(-2.25, DltFloatWidth.Bits64)); bytesRead.ShouldBe(12); } [Fact] public void Parse_AsciiString() { var data = TestDlt.StringArgument("hello"); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltStringArgument("hello", DltStringCoding.Ascii)); bytesRead.ShouldBe(data.Length); } [Fact] public void Parse_Utf8String() { var data = TestDlt.StringArgument("hΓ€llΓΆ", utf8: true); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltStringArgument("hΓ€llΓΆ", DltStringCoding.Utf8)); bytesRead.ShouldBe(data.Length); } [Fact] public void Parse_EmptyString() { var data = TestDlt.StringArgument(string.Empty); DltArgument .Parse(data, false, null, out _) .ShouldBe(new DltStringArgument(string.Empty, DltStringCoding.Ascii)); } [Fact] public void Parse_EightBitStringUsesConfiguredEncoding() { var latin1 = Encoding.Latin1; var encoded = latin1.GetBytes("GrΓΌΓe"); var payload = new byte[2 + encoded.Length + 1]; BinaryPrimitives.WriteUInt16LittleEndian(payload, (ushort)(encoded.Length + 1)); encoded.CopyTo(payload.AsSpan(2)); var data = TestDlt.Argument(TestDlt.TypeInfoStringAscii, payload); DltArgument.Parse(data, false, latin1, out _).ShouldBe(new DltStringArgument("GrΓΌΓe", DltStringCoding.Ascii)); } [Fact] public void Parse_Raw() { var data = TestDlt.RawArgument([0xDE, 0xAD, 0xBE, 0xEF]); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltRawArgument(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF })); argument.ToString().ShouldBe("deadbeef"); bytesRead.ShouldBe(10); } [Fact] public void Parse_TruncatedInteger_FallsBackToSmallerWidth() { // A 64 bit unsigned integer with only 4 bytes of data is read as a 32 bit integer, // which mirrors the behavior of DLT Viewer. var data = TestDlt.Argument(TestDlt.TypeInfoUInt64, [0x00, 0x00, 0x01, 0x00]); var argument = DltArgument.Parse(data, false, null, out var bytesRead); argument.ShouldBe(new DltUnsignedArgument(65536, DltIntegerWidth.Bits32)); bytesRead.ShouldBe(8); } [Fact] public void Parse_IntegerWithoutAnyData_Throws() { var data = TestDlt.Argument(TestDlt.TypeInfoUInt32, []); Should.Throw<DltParseException>(() => DltArgument.Parse(data, false, null, out _)); } [Fact] public void Parse_TruncatedFloat_Throws() { var data = TestDlt.Argument(TestDlt.TypeInfoFloat64, [0x00, 0x00]); Should.Throw<DltParseException>(() => DltArgument.Parse(data, false, null, out _)); } [Fact] public void Parse_TooShortForTypeInfo_Throws() { Should.Throw<DltParseException>(() => DltArgument.Parse(new byte[3], false, null, out _)); } [Fact] public void Parse_UnsupportedType_Throws() { // TYPE_ARRAY is not supported. var data = TestDlt.Argument(0x00000100, [0x00, 0x00, 0x00, 0x00]); Should.Throw<DltParseException>(() => DltArgument.Parse(data, false, null, out _)); } [Fact] public void ToString_UsesInvariantFormatting() { new DltBoolArgument(true).ToString().ShouldBe("True"); new DltSignedArgument(-5, DltIntegerWidth.Bits32).ToString().ShouldBe("-5"); new DltUnsignedArgument(7, DltIntegerWidth.Bits8).ToString().ShouldBe("7"); new DltFloatArgument(1.5, DltFloatWidth.Bits32).ToString().ShouldBe("1.5"); new DltStringArgument("text", DltStringCoding.Ascii).ToString().ShouldBe("text"); } [Fact] public void RawArgument_EqualityComparesContent() { new DltRawArgument(new byte[] { 1, 2 }).ShouldBe(new DltRawArgument(new byte[] { 1, 2 })); new DltRawArgument(new byte[] { 1, 2 }) .GetHashCode() .ShouldBe(new DltRawArgument(new byte[] { 1, 2 }).GetHashCode()); new DltRawArgument(new byte[] { 1, 2 }).ShouldNotBe(new DltRawArgument(new byte[] { 1 })); } }