• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision092711336fbbf7739569751e48eb2a2c70b253a6 (tree)
Time2012-06-08 20:52:31
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

パケットのToString()対応

Change Summary

Incremental Difference

--- a/Yubeshi/UnknownPacket.cs
+++ b/Yubeshi/UnknownPacket.cs
@@ -36,5 +36,26 @@ namespace Yubeshi
3636 }
3737
3838 #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
3960 }
4061 }
--- /dev/null
+++ b/YubeshiTest/UnknownPacketTest.cs
@@ -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+}
--- a/YubeshiTest/YubeshiTest.csproj
+++ b/YubeshiTest/YubeshiTest.csproj
@@ -66,6 +66,7 @@
6666 <Compile Include="UbxTest\InfPacketTest.cs" />
6767 <Compile Include="YumaAlmanacReaderTest.cs" />
6868 <Compile Include="HeightTest.cs" />
69+ <Compile Include="UnknownPacketTest.cs" />
6970 </ItemGroup>
7071 <ItemGroup>
7172 <None Include="app.config" />
Show on old repository browser