source codes and tests
Revision | 092711336fbbf7739569751e48eb2a2c70b253a6 (tree) |
---|---|
Time | 2012-06-08 20:52:31 |
Author | kimikage <kimikage_ceo@hotm...> |
Commiter | kimikage |
パケットのToString()対応
@@ -36,5 +36,26 @@ namespace Yubeshi | ||
36 | 36 | } |
37 | 37 | |
38 | 38 | #endregion |
39 | + | |
40 | + #region public methods | |
41 | + | |
42 | + public override string ToString() | |
43 | + { | |
44 | + StringBuilder builder = new StringBuilder(Raw.Length); | |
45 | + for (int i = 0; i < Raw.Length; ++i) | |
46 | + { | |
47 | + byte c = Raw[i]; | |
48 | + if (c < 32 || c > 127) | |
49 | + { | |
50 | + builder.Append(@"\x" + c.ToString("X2")); | |
51 | + } | |
52 | + else | |
53 | + { | |
54 | + builder.Append(Char.ConvertFromUtf32(c)); | |
55 | + } | |
56 | + } | |
57 | + return builder.ToString(); | |
58 | + } | |
59 | + #endregion | |
39 | 60 | } |
40 | 61 | } |
@@ -0,0 +1,33 @@ | ||
1 | +/* | |
2 | + * Yubeshi GPS Parser | |
3 | + * | |
4 | + * This software is distributed under a zlib-style license. | |
5 | + * See license.txt for more information. | |
6 | + */ | |
7 | + | |
8 | +using System; | |
9 | +using System.Collections.Generic; | |
10 | +using System.Text; | |
11 | +using NUnit.Framework; | |
12 | +using Yubeshi; | |
13 | + | |
14 | +namespace YubeshiTest | |
15 | +{ | |
16 | + [TestFixture] | |
17 | + class UnknownPacketTest | |
18 | + { | |
19 | + [Test] | |
20 | + public new void ToString() | |
21 | + { | |
22 | + byte[] sentence = new byte[]{ | |
23 | + 0x24, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, | |
24 | + 0x20, 0x61, 0x6e, 0x20, 0x75, 0x6e, 0x6b, 0x6e, | |
25 | + 0x6f, 0x77, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, | |
26 | + 0x65, 0x74, 0xff, 0x0d, 0x0a | |
27 | + }; | |
28 | + UnknownPacket p = new UnknownPacket(sentence, sentence.Length); | |
29 | + Assert.AreEqual(@"$This is an unknown packet\xFF\x0D\x0A", | |
30 | + p.ToString()); | |
31 | + } | |
32 | + } | |
33 | +} |
@@ -66,6 +66,7 @@ | ||
66 | 66 | <Compile Include="UbxTest\InfPacketTest.cs" /> |
67 | 67 | <Compile Include="YumaAlmanacReaderTest.cs" /> |
68 | 68 | <Compile Include="HeightTest.cs" /> |
69 | + <Compile Include="UnknownPacketTest.cs" /> | |
69 | 70 | </ItemGroup> |
70 | 71 | <ItemGroup> |
71 | 72 | <None Include="app.config" /> |