diff options
author | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:33:35 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-08-14 20:33:35 +0100 |
commit | c0daf107249d95f454d489613de09a4898cefb20 (patch) | |
tree | bb95ccdec5b2b6156709ac29febf99ee73087e78 /csharp/ProtocolBuffers.Test | |
parent | 800f65e20915d3cda9b6b681013dc0a5dd5ddee2 (diff) | |
download | protobuf-c0daf107249d95f454d489613de09a4898cefb20.tar.gz protobuf-c0daf107249d95f454d489613de09a4898cefb20.tar.bz2 protobuf-c0daf107249d95f454d489613de09a4898cefb20.zip |
Changed fixed size methods to return unsigned integers. Finished FieldSet. Introduced mapping from FieldType to WireType and MappedType.
Diffstat (limited to 'csharp/ProtocolBuffers.Test')
4 files changed, 30 insertions, 9 deletions
diff --git a/csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs b/csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs index 8332140e..c2b2a832 100644 --- a/csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs +++ b/csharp/ProtocolBuffers.Test/CodedInputStreamTest.cs @@ -118,7 +118,7 @@ namespace Google.ProtocolBuffers { /// Parses the given bytes using ReadRawLittleEndian32() and checks /// that the result matches the given value. /// </summary> - private static void AssertReadLittleEndian32(byte[] data, int value) { + private static void AssertReadLittleEndian32(byte[] data, uint value) { CodedInputStream input = CodedInputStream.CreateInstance(data); Assert.AreEqual(value, input.ReadRawLittleEndian32()); @@ -134,7 +134,7 @@ namespace Google.ProtocolBuffers { /// Parses the given bytes using ReadRawLittleEndian64() and checks /// that the result matches the given value. /// </summary> - private static void AssertReadLittleEndian64(byte[] data, long value) { + private static void AssertReadLittleEndian64(byte[] data, ulong value) { CodedInputStream input = CodedInputStream.CreateInstance(data); Assert.AreEqual(value, input.ReadRawLittleEndian64()); @@ -149,12 +149,12 @@ namespace Google.ProtocolBuffers { [Test] public void ReadLittleEndian() { AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678); - AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), unchecked((int)0x9abcdef0)); + AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), 0x123456789abcdef0L); AssertReadLittleEndian64( - Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), unchecked((long)0x9abcdef012345678L)); + Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL); } [Test] diff --git a/csharp/ProtocolBuffers.Test/CodedOutputStreamTest.cs b/csharp/ProtocolBuffers.Test/CodedOutputStreamTest.cs index 0e97f2fd..f2f00dfe 100644 --- a/csharp/ProtocolBuffers.Test/CodedOutputStreamTest.cs +++ b/csharp/ProtocolBuffers.Test/CodedOutputStreamTest.cs @@ -106,7 +106,7 @@ namespace Google.ProtocolBuffers { AssertWriteVarint( Bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | - (0x43L << 28) | (0x49L << 35) | (0x24L << 42) | (0x49L << 49)); + (0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49)); // 11964378330978735131 AssertWriteVarint( Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), @@ -120,7 +120,7 @@ namespace Google.ProtocolBuffers { /// Parses the given bytes using WriteRawLittleEndian32() and checks /// that the result matches the given value. /// </summary> - private static void AssertWriteLittleEndian32(byte[] data, int value) { + private static void AssertWriteLittleEndian32(byte[] data, uint value) { MemoryStream rawOutput = new MemoryStream(); CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput); output.WriteRawLittleEndian32(value); @@ -141,7 +141,7 @@ namespace Google.ProtocolBuffers { /// Parses the given bytes using WriteRawLittleEndian64() and checks /// that the result matches the given value. /// </summary> - private static void AssertWriteLittleEndian64(byte[] data, long value) { + private static void AssertWriteLittleEndian64(byte[] data, ulong value) { MemoryStream rawOutput = new MemoryStream(); CodedOutputStream output = CodedOutputStream.CreateInstance(rawOutput); output.WriteRawLittleEndian64(value); @@ -164,14 +164,14 @@ namespace Google.ProtocolBuffers { [Test] public void WriteLittleEndian() { AssertWriteLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678); - AssertWriteLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), unchecked((int)0x9abcdef0)); + AssertWriteLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); AssertWriteLittleEndian64( Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), 0x123456789abcdef0L); AssertWriteLittleEndian64( Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), - unchecked((long)0x9abcdef012345678L)); + 0x9abcdef012345678UL); } /* TODO(jonskeet): Put this back when we've got the rest working! diff --git a/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj b/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj index 89c5507a..28c86b3c 100644 --- a/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj +++ b/csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj @@ -48,6 +48,7 @@ <Compile Include="CodedInputStreamTest.cs" /> <Compile Include="CodedOutputStreamTest.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="WireFormatTest.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj"> diff --git a/csharp/ProtocolBuffers.Test/WireFormatTest.cs b/csharp/ProtocolBuffers.Test/WireFormatTest.cs new file mode 100644 index 00000000..87c9dc6d --- /dev/null +++ b/csharp/ProtocolBuffers.Test/WireFormatTest.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using Google.ProtocolBuffers.Descriptors; + +namespace Google.ProtocolBuffers { + [TestFixture] + public class WireFormatTest { + + [Test] + public void FieldTypeToWireTypeMapping() { + + // Just test a few values + Assert.AreEqual(WireFormat.WireType.Fixed64, WireFormat.FieldTypeToWireFormatMap[FieldType.SFixed64]); + Assert.AreEqual(WireFormat.WireType.LengthDelimited, WireFormat.FieldTypeToWireFormatMap[FieldType.String]); + Assert.AreEqual(WireFormat.WireType.LengthDelimited, WireFormat.FieldTypeToWireFormatMap[FieldType.Message]); + } + } +} |