Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
ba02091e
Commit
ba02091e
authored
Aug 14, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New unit tests and corresponding bug fixes.
parent
bef2caf5
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
455 additions
and
78 deletions
+455
-78
DescriptorsTest.cs
csharp/ProtocolBuffers.Test/DescriptorsTest.cs
+258
-0
DynamicMessageTest.cs
csharp/ProtocolBuffers.Test/DynamicMessageTest.cs
+103
-0
ProtocolBuffers.Test.csproj
csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
+2
-0
ReflectionTester.cs
csharp/ProtocolBuffers.Test/ReflectionTester.cs
+64
-75
MessageDescriptor.cs
csharp/ProtocolBuffers/Descriptors/MessageDescriptor.cs
+7
-0
MethodDescriptor.cs
csharp/ProtocolBuffers/Descriptors/MethodDescriptor.cs
+1
-1
ServiceDescriptor.cs
csharp/ProtocolBuffers/Descriptors/ServiceDescriptor.cs
+9
-0
DynamicMessage.cs
csharp/ProtocolBuffers/DynamicMessage.cs
+4
-0
FieldSet.cs
csharp/ProtocolBuffers/FieldSet.cs
+7
-2
No files found.
csharp/ProtocolBuffers.Test/DescriptorsTest.cs
0 → 100644
View file @
ba02091e
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
NUnit.Framework
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.TestProtos
;
namespace
Google.ProtocolBuffers
{
/// <summary>
/// Tests for descriptors. (Not in its own namespace or broken up into individual classes as the
/// size doesn't warrant it. On the other hand, this makes me feel a bit dirty...)
/// </summary>
[
TestFixture
]
public
class
DescriptorsTest
{
[
Test
]
public
void
FileDescriptor
()
{
FileDescriptor
file
=
UnitTestProtoFile
.
Descriptor
;
Assert
.
AreEqual
(
"google/protobuf/unittest.proto"
,
file
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest"
,
file
.
Package
);
Assert
.
AreEqual
(
"UnittestProto"
,
file
.
Options
.
JavaOuterClassname
);
Assert
.
AreEqual
(
"google/protobuf/unittest.proto"
,
file
.
Proto
.
Name
);
Assert
.
AreEqual
(
1
,
file
.
Dependencies
.
Count
);
Assert
.
AreEqual
(
UnitTestImportProtoFile
.
Descriptor
,
file
.
Dependencies
[
0
]);
MessageDescriptor
messageType
=
TestAllTypes
.
Descriptor
;
Assert
.
AreEqual
(
messageType
,
file
.
MessageTypes
[
0
]);
Assert
.
AreEqual
(
messageType
,
file
.
FindTypeByName
<
MessageDescriptor
>(
"TestAllTypes"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
MessageDescriptor
>(
"NoSuchType"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
MessageDescriptor
>(
"protobuf_unittest.TestAllTypes"
));
for
(
int
i
=
0
;
i
<
file
.
MessageTypes
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
file
.
MessageTypes
[
i
].
Index
);
}
Assert
.
AreEqual
(
file
.
EnumTypes
[
0
],
file
.
FindTypeByName
<
EnumDescriptor
>(
"ForeignEnum"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
EnumDescriptor
>(
"NoSuchType"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
EnumDescriptor
>(
"protobuf_unittest.ForeignEnum"
));
Assert
.
AreEqual
(
1
,
UnitTestImportProtoFile
.
Descriptor
.
EnumTypes
.
Count
);
Assert
.
AreEqual
(
"ImportEnum"
,
UnitTestImportProtoFile
.
Descriptor
.
EnumTypes
[
0
].
Name
);
for
(
int
i
=
0
;
i
<
file
.
EnumTypes
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
file
.
EnumTypes
[
i
].
Index
);
}
ServiceDescriptor
service
=
TestService
.
Descriptor
;
Assert
.
AreEqual
(
service
,
file
.
Services
[
0
]);
Assert
.
AreEqual
(
service
,
file
.
FindTypeByName
<
ServiceDescriptor
>(
"TestService"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
ServiceDescriptor
>(
"NoSuchType"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
ServiceDescriptor
>(
"protobuf_unittest.TestService"
));
Assert
.
AreEqual
(
0
,
UnitTestImportProtoFile
.
Descriptor
.
Services
.
Count
);
for
(
int
i
=
0
;
i
<
file
.
Services
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
file
.
Services
[
i
].
Index
);
}
FieldDescriptor
extension
=
UnitTestProtoFile
.
OptionalInt32Extension
.
Descriptor
;
Assert
.
AreEqual
(
extension
,
file
.
Extensions
[
0
]);
Assert
.
AreEqual
(
extension
,
file
.
FindTypeByName
<
FieldDescriptor
>(
"optional_int32_extension"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
FieldDescriptor
>(
"no_such_ext"
));
Assert
.
IsNull
(
file
.
FindTypeByName
<
FieldDescriptor
>(
"protobuf_unittest.optional_int32_extension"
));
Assert
.
AreEqual
(
0
,
UnitTestImportProtoFile
.
Descriptor
.
Extensions
.
Count
);
for
(
int
i
=
0
;
i
<
file
.
Extensions
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
file
.
Extensions
[
i
].
Index
);
}
}
[
Test
]
public
void
MessageDescriptor
()
{
MessageDescriptor
messageType
=
TestAllTypes
.
Descriptor
;
MessageDescriptor
nestedType
=
TestAllTypes
.
Types
.
NestedMessage
.
Descriptor
;
Assert
.
AreEqual
(
"TestAllTypes"
,
messageType
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestAllTypes"
,
messageType
.
FullName
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
messageType
.
File
);
Assert
.
IsNull
(
messageType
.
ContainingType
);
Assert
.
AreEqual
(
DescriptorProtos
.
MessageOptions
.
DefaultInstance
,
messageType
.
Options
);
Assert
.
AreEqual
(
"TestAllTypes"
,
messageType
.
Proto
.
Name
);
Assert
.
AreEqual
(
"NestedMessage"
,
nestedType
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestAllTypes.NestedMessage"
,
nestedType
.
FullName
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
nestedType
.
File
);
Assert
.
AreEqual
(
messageType
,
nestedType
.
ContainingType
);
FieldDescriptor
field
=
messageType
.
Fields
[
0
];
Assert
.
AreEqual
(
"optional_int32"
,
field
.
Name
);
Assert
.
AreEqual
(
field
,
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"optional_int32"
));
Assert
.
IsNull
(
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"no_such_field"
));
Assert
.
AreEqual
(
field
,
messageType
.
FindFieldByNumber
(
1
));
Assert
.
IsNull
(
messageType
.
FindFieldByNumber
(
571283
));
for
(
int
i
=
0
;
i
<
messageType
.
Fields
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
messageType
.
Fields
[
i
].
Index
);
}
Assert
.
AreEqual
(
nestedType
,
messageType
.
NestedTypes
[
0
]);
Assert
.
AreEqual
(
nestedType
,
messageType
.
FindDescriptor
<
MessageDescriptor
>(
"NestedMessage"
));
Assert
.
IsNull
(
messageType
.
FindDescriptor
<
MessageDescriptor
>(
"NoSuchType"
));
for
(
int
i
=
0
;
i
<
messageType
.
NestedTypes
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
messageType
.
NestedTypes
[
i
].
Index
);
}
Assert
.
AreEqual
(
messageType
.
EnumTypes
[
0
],
messageType
.
FindDescriptor
<
EnumDescriptor
>(
"NestedEnum"
));
Assert
.
IsNull
(
messageType
.
FindDescriptor
<
EnumDescriptor
>(
"NoSuchType"
));
for
(
int
i
=
0
;
i
<
messageType
.
EnumTypes
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
messageType
.
EnumTypes
[
i
].
Index
);
}
}
[
Test
]
public
void
FieldDescriptor
()
{
MessageDescriptor
messageType
=
TestAllTypes
.
Descriptor
;
FieldDescriptor
primitiveField
=
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"optional_int32"
);
FieldDescriptor
enumField
=
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"optional_nested_enum"
);
FieldDescriptor
messageField
=
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"optional_foreign_message"
);
FieldDescriptor
cordField
=
messageType
.
FindDescriptor
<
FieldDescriptor
>(
"optional_cord"
);
FieldDescriptor
extension
=
UnitTestProtoFile
.
OptionalInt32Extension
.
Descriptor
;
FieldDescriptor
nestedExtension
=
TestRequired
.
Types
.
Single
.
Descriptor
;
Assert
.
AreEqual
(
"optional_int32"
,
primitiveField
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestAllTypes.optional_int32"
,
primitiveField
.
FullName
);
Assert
.
AreEqual
(
1
,
primitiveField
.
FieldNumber
);
Assert
.
AreEqual
(
messageType
,
primitiveField
.
ContainingType
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
primitiveField
.
File
);
Assert
.
AreEqual
(
FieldType
.
Int32
,
primitiveField
.
FieldType
);
Assert
.
AreEqual
(
MappedType
.
Int32
,
primitiveField
.
MappedType
);
Assert
.
AreEqual
(
DescriptorProtos
.
FieldOptions
.
DefaultInstance
,
primitiveField
.
Options
);
Assert
.
IsFalse
(
primitiveField
.
IsExtension
);
Assert
.
AreEqual
(
"optional_int32"
,
primitiveField
.
Proto
.
Name
);
Assert
.
AreEqual
(
"optional_nested_enum"
,
enumField
.
Name
);
Assert
.
AreEqual
(
FieldType
.
Enum
,
enumField
.
FieldType
);
Assert
.
AreEqual
(
MappedType
.
Enum
,
enumField
.
MappedType
);
// Assert.AreEqual(TestAllTypes.Types.NestedEnum.Descriptor, enumField.EnumType);
Assert
.
AreEqual
(
"optional_foreign_message"
,
messageField
.
Name
);
Assert
.
AreEqual
(
FieldType
.
Message
,
messageField
.
FieldType
);
Assert
.
AreEqual
(
MappedType
.
Message
,
messageField
.
MappedType
);
Assert
.
AreEqual
(
ForeignMessage
.
Descriptor
,
messageField
.
MessageType
);
Assert
.
AreEqual
(
"optional_cord"
,
cordField
.
Name
);
Assert
.
AreEqual
(
FieldType
.
String
,
cordField
.
FieldType
);
Assert
.
AreEqual
(
MappedType
.
String
,
cordField
.
MappedType
);
Assert
.
AreEqual
(
DescriptorProtos
.
FieldOptions
.
Types
.
CType
.
CORD
,
cordField
.
Options
.
Ctype
);
Assert
.
AreEqual
(
"optional_int32_extension"
,
extension
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.optional_int32_extension"
,
extension
.
FullName
);
Assert
.
AreEqual
(
1
,
extension
.
FieldNumber
);
Assert
.
AreEqual
(
TestAllExtensions
.
Descriptor
,
extension
.
ContainingType
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
extension
.
File
);
Assert
.
AreEqual
(
FieldType
.
Int32
,
extension
.
FieldType
);
Assert
.
AreEqual
(
MappedType
.
Int32
,
extension
.
MappedType
);
Assert
.
AreEqual
(
DescriptorProtos
.
FieldOptions
.
DefaultInstance
,
extension
.
Options
);
Assert
.
IsTrue
(
extension
.
IsExtension
);
Assert
.
AreEqual
(
null
,
extension
.
ExtensionScope
);
Assert
.
AreEqual
(
"optional_int32_extension"
,
extension
.
Proto
.
Name
);
Assert
.
AreEqual
(
"single"
,
nestedExtension
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestRequired.single"
,
nestedExtension
.
FullName
);
Assert
.
AreEqual
(
TestRequired
.
Descriptor
,
nestedExtension
.
ExtensionScope
);
}
[
Test
]
public
void
FieldDescriptorLabel
()
{
FieldDescriptor
requiredField
=
TestRequired
.
Descriptor
.
FindDescriptor
<
FieldDescriptor
>(
"a"
);
FieldDescriptor
optionalField
=
TestAllTypes
.
Descriptor
.
FindDescriptor
<
FieldDescriptor
>(
"optional_int32"
);
FieldDescriptor
repeatedField
=
TestAllTypes
.
Descriptor
.
FindDescriptor
<
FieldDescriptor
>(
"repeated_int32"
);
Assert
.
IsTrue
(
requiredField
.
IsRequired
);
Assert
.
IsFalse
(
requiredField
.
IsRepeated
);
Assert
.
IsFalse
(
optionalField
.
IsRequired
);
Assert
.
IsFalse
(
optionalField
.
IsRepeated
);
Assert
.
IsFalse
(
repeatedField
.
IsRequired
);
Assert
.
IsTrue
(
repeatedField
.
IsRepeated
);
}
[
Test
]
public
void
FieldDescriptorDefault
()
{
MessageDescriptor
d
=
TestAllTypes
.
Descriptor
;
Assert
.
IsFalse
(
d
.
FindDescriptor
<
FieldDescriptor
>(
"optional_int32"
).
HasDefaultValue
);
Assert
.
AreEqual
(
0
,
d
.
FindDescriptor
<
FieldDescriptor
>(
"optional_int32"
).
DefaultValue
);
Assert
.
IsTrue
(
d
.
FindDescriptor
<
FieldDescriptor
>(
"default_int32"
).
HasDefaultValue
);
Assert
.
AreEqual
(
41
,
d
.
FindDescriptor
<
FieldDescriptor
>(
"default_int32"
).
DefaultValue
);
d
=
TestExtremeDefaultValues
.
Descriptor
;
Assert
.
AreEqual
(
ByteString
.
CopyFrom
(
"\u0000\u0001\u0007\b\f\n\r\t\u000b\\\'\"\u00fe"
,
Encoding
.
GetEncoding
(
28591
)),
d
.
FindDescriptor
<
FieldDescriptor
>(
"escaped_bytes"
).
DefaultValue
);
Assert
.
AreEqual
(
uint
.
MaxValue
,
d
.
FindDescriptor
<
FieldDescriptor
>(
"large_uint32"
).
DefaultValue
);
Assert
.
AreEqual
(
ulong
.
MaxValue
,
d
.
FindDescriptor
<
FieldDescriptor
>(
"large_uint64"
).
DefaultValue
);
}
[
Test
]
public
void
EnumDescriptor
()
{
// Note: this test is a bit different to the Java version because there's no static way of getting to the descriptor
EnumDescriptor
enumType
=
UnitTestProtoFile
.
Descriptor
.
FindTypeByName
<
EnumDescriptor
>(
"ForeignEnum"
);
EnumDescriptor
nestedType
=
TestAllTypes
.
Descriptor
.
FindDescriptor
<
EnumDescriptor
>(
"NestedEnum"
);
Assert
.
AreEqual
(
"ForeignEnum"
,
enumType
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.ForeignEnum"
,
enumType
.
FullName
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
enumType
.
File
);
Assert
.
IsNull
(
enumType
.
ContainingType
);
Assert
.
AreEqual
(
DescriptorProtos
.
EnumOptions
.
DefaultInstance
,
enumType
.
Options
);
Assert
.
AreEqual
(
"NestedEnum"
,
nestedType
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestAllTypes.NestedEnum"
,
nestedType
.
FullName
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
nestedType
.
File
);
Assert
.
AreEqual
(
TestAllTypes
.
Descriptor
,
nestedType
.
ContainingType
);
EnumValueDescriptor
value
=
enumType
.
FindValueByName
(
"FOREIGN_FOO"
);
Assert
.
AreEqual
(
value
,
enumType
.
Values
[
0
]);
Assert
.
AreEqual
(
"FOREIGN_FOO"
,
value
.
Name
);
Assert
.
AreEqual
(
4
,
value
.
Number
);
Assert
.
AreEqual
((
int
)
ForeignEnum
.
FOREIGN_FOO
,
value
.
Number
);
Assert
.
AreEqual
(
value
,
enumType
.
FindValueByNumber
(
4
));
Assert
.
IsNull
(
enumType
.
FindValueByName
(
"NO_SUCH_VALUE"
));
for
(
int
i
=
0
;
i
<
enumType
.
Values
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
enumType
.
Values
[
i
].
Index
);
}
}
[
Test
]
public
void
ServiceDescriptor
()
{
ServiceDescriptor
service
=
TestService
.
Descriptor
;
Assert
.
AreEqual
(
"TestService"
,
service
.
Name
);
Assert
.
AreEqual
(
"protobuf_unittest.TestService"
,
service
.
FullName
);
Assert
.
AreEqual
(
UnitTestProtoFile
.
Descriptor
,
service
.
File
);
Assert
.
AreEqual
(
2
,
service
.
Methods
.
Count
);
MethodDescriptor
fooMethod
=
service
.
Methods
[
0
];
Assert
.
AreEqual
(
"Foo"
,
fooMethod
.
Name
);
Assert
.
AreEqual
(
FooRequest
.
Descriptor
,
fooMethod
.
InputType
);
Assert
.
AreEqual
(
FooResponse
.
Descriptor
,
fooMethod
.
OutputType
);
Assert
.
AreEqual
(
fooMethod
,
service
.
FindMethodByName
(
"Foo"
));
MethodDescriptor
barMethod
=
service
.
Methods
[
1
];
Assert
.
AreEqual
(
"Bar"
,
barMethod
.
Name
);
Assert
.
AreEqual
(
BarRequest
.
Descriptor
,
barMethod
.
InputType
);
Assert
.
AreEqual
(
BarResponse
.
Descriptor
,
barMethod
.
OutputType
);
Assert
.
AreEqual
(
barMethod
,
service
.
FindMethodByName
(
"Bar"
));
Assert
.
IsNull
(
service
.
FindMethodByName
(
"NoSuchMethod"
));
for
(
int
i
=
0
;
i
<
service
.
Methods
.
Count
;
i
++)
{
Assert
.
AreEqual
(
i
,
service
.
Methods
[
i
].
Index
);
}
}
}
}
csharp/ProtocolBuffers.Test/DynamicMessageTest.cs
0 → 100644
View file @
ba02091e
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
NUnit.Framework
;
using
Google.ProtocolBuffers.TestProtos
;
namespace
Google.ProtocolBuffers
{
[
TestFixture
]
public
class
DynamicMessageTest
{
private
ReflectionTester
reflectionTester
;
private
ReflectionTester
extensionsReflectionTester
;
[
SetUp
]
public
void
SetUp
()
{
reflectionTester
=
new
ReflectionTester
(
TestAllTypes
.
Descriptor
,
null
);
extensionsReflectionTester
=
new
ReflectionTester
(
TestAllExtensions
.
Descriptor
,
TestUtil
.
CreateExtensionRegistry
());
}
[
Test
]
public
void
DynamicMessageAccessors
()
{
IBuilder
builder
=
DynamicMessage
.
CreateBuilder
(
TestAllTypes
.
Descriptor
);
reflectionTester
.
SetAllFieldsViaReflection
(
builder
);
IMessage
message
=
builder
.
Build
();
reflectionTester
.
AssertAllFieldsSetViaReflection
(
message
);
}
[
Test
]
public
void
DynamicMessageExtensionAccessors
()
{
// We don't need to extensively test DynamicMessage's handling of
// extensions because, frankly, it doesn't do anything special with them.
// It treats them just like any other fields.
IBuilder
builder
=
DynamicMessage
.
CreateBuilder
(
TestAllExtensions
.
Descriptor
);
extensionsReflectionTester
.
SetAllFieldsViaReflection
(
builder
);
IMessage
message
=
builder
.
Build
();
extensionsReflectionTester
.
AssertAllFieldsSetViaReflection
(
message
);
}
[
Test
]
public
void
DynamicMessageRepeatedSetters
()
{
IBuilder
builder
=
DynamicMessage
.
CreateBuilder
(
TestAllTypes
.
Descriptor
);
reflectionTester
.
SetAllFieldsViaReflection
(
builder
);
reflectionTester
.
ModifyRepeatedFieldsViaReflection
(
builder
);
IMessage
message
=
builder
.
Build
();
reflectionTester
.
AssertRepeatedFieldsModifiedViaReflection
(
message
);
}
[
Test
]
public
void
DynamicMessageDefaults
()
{
reflectionTester
.
AssertClearViaReflection
(
DynamicMessage
.
GetDefaultInstance
(
TestAllTypes
.
Descriptor
));
reflectionTester
.
AssertClearViaReflection
(
DynamicMessage
.
CreateBuilder
(
TestAllTypes
.
Descriptor
).
Build
());
}
[
Test
]
public
void
DynamicMessageSerializedSize
()
{
TestAllTypes
message
=
TestUtil
.
GetAllSet
();
IBuilder
dynamicBuilder
=
DynamicMessage
.
CreateBuilder
(
TestAllTypes
.
Descriptor
);
reflectionTester
.
SetAllFieldsViaReflection
(
dynamicBuilder
);
IMessage
dynamicMessage
=
dynamicBuilder
.
Build
();
Assert
.
AreEqual
(
message
.
SerializedSize
,
dynamicMessage
.
SerializedSize
);
}
[
Test
]
public
void
DynamicMessageSerialization
()
{
IBuilder
builder
=
DynamicMessage
.
CreateBuilder
(
TestAllTypes
.
Descriptor
);
reflectionTester
.
SetAllFieldsViaReflection
(
builder
);
IMessage
message
=
builder
.
Build
();
ByteString
rawBytes
=
message
.
ToByteString
();
TestAllTypes
message2
=
TestAllTypes
.
ParseFrom
(
rawBytes
);
TestUtil
.
AssertAllFieldsSet
(
message2
);
// In fact, the serialized forms should be exactly the same, byte-for-byte.
Assert
.
AreEqual
(
TestUtil
.
GetAllSet
().
ToByteString
(),
rawBytes
);
}
[
Test
]
public
void
DynamicMessageParsing
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
TestUtil
.
SetAllFields
(
builder
);
TestAllTypes
message
=
builder
.
Build
();
ByteString
rawBytes
=
message
.
ToByteString
();
IMessage
message2
=
DynamicMessage
.
ParseFrom
(
TestAllTypes
.
Descriptor
,
rawBytes
);
reflectionTester
.
AssertAllFieldsSetViaReflection
(
message2
);
}
[
Test
]
public
void
DynamicMessageCopy
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
TestUtil
.
SetAllFields
(
builder
);
TestAllTypes
message
=
builder
.
Build
();
DynamicMessage
copy
=
DynamicMessage
.
CreateBuilder
(
message
).
Build
();
reflectionTester
.
AssertAllFieldsSetViaReflection
(
copy
);
}
}
}
csharp/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
View file @
ba02091e
...
@@ -48,6 +48,8 @@
...
@@ -48,6 +48,8 @@
<Compile
Include=
"ByteStringTest.cs"
/>
<Compile
Include=
"ByteStringTest.cs"
/>
<Compile
Include=
"CodedInputStreamTest.cs"
/>
<Compile
Include=
"CodedInputStreamTest.cs"
/>
<Compile
Include=
"CodedOutputStreamTest.cs"
/>
<Compile
Include=
"CodedOutputStreamTest.cs"
/>
<Compile
Include=
"DescriptorsTest.cs"
/>
<Compile
Include=
"DynamicMessageTest.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"ReflectionTester.cs"
/>
<Compile
Include=
"ReflectionTester.cs"
/>
<Compile
Include=
"TestProtos\UnitTestEmbedOptimizeForProtoFile.cs"
/>
<Compile
Include=
"TestProtos\UnitTestEmbedOptimizeForProtoFile.cs"
/>
...
...
csharp/ProtocolBuffers.Test/ReflectionTester.cs
View file @
ba02091e
...
@@ -169,12 +169,12 @@ namespace Google.ProtocolBuffers {
...
@@ -169,12 +169,12 @@ namespace Google.ProtocolBuffers {
internal
void
SetAllFieldsViaReflection
(
IBuilder
message
)
{
internal
void
SetAllFieldsViaReflection
(
IBuilder
message
)
{
message
[
f
(
"optional_int32"
)]
=
101
;
message
[
f
(
"optional_int32"
)]
=
101
;
message
[
f
(
"optional_int64"
)]
=
102L
;
message
[
f
(
"optional_int64"
)]
=
102L
;
message
[
f
(
"optional_uint32"
)]
=
103
;
message
[
f
(
"optional_uint32"
)]
=
103
U
;
message
[
f
(
"optional_uint64"
)]
=
104L
;
message
[
f
(
"optional_uint64"
)]
=
104
U
L
;
message
[
f
(
"optional_sint32"
)]
=
105
;
message
[
f
(
"optional_sint32"
)]
=
105
;
message
[
f
(
"optional_sint64"
)]
=
106L
;
message
[
f
(
"optional_sint64"
)]
=
106L
;
message
[
f
(
"optional_fixed32"
)]
=
107
;
message
[
f
(
"optional_fixed32"
)]
=
107
U
;
message
[
f
(
"optional_fixed64"
)]
=
108L
;
message
[
f
(
"optional_fixed64"
)]
=
108
U
L
;
message
[
f
(
"optional_sfixed32"
)]
=
109
;
message
[
f
(
"optional_sfixed32"
)]
=
109
;
message
[
f
(
"optional_sfixed64"
)]
=
110L
;
message
[
f
(
"optional_sfixed64"
)]
=
110L
;
message
[
f
(
"optional_float"
)]
=
111F
;
message
[
f
(
"optional_float"
)]
=
111F
;
...
@@ -199,12 +199,12 @@ namespace Google.ProtocolBuffers {
...
@@ -199,12 +199,12 @@ namespace Google.ProtocolBuffers {
message
.
AddRepeatedField
(
f
(
"repeated_int32"
),
201
);
message
.
AddRepeatedField
(
f
(
"repeated_int32"
),
201
);
message
.
AddRepeatedField
(
f
(
"repeated_int64"
),
202L
);
message
.
AddRepeatedField
(
f
(
"repeated_int64"
),
202L
);
message
.
AddRepeatedField
(
f
(
"repeated_uint32"
),
203
);
message
.
AddRepeatedField
(
f
(
"repeated_uint32"
),
203
U
);
message
.
AddRepeatedField
(
f
(
"repeated_uint64"
),
204L
);
message
.
AddRepeatedField
(
f
(
"repeated_uint64"
),
204
U
L
);
message
.
AddRepeatedField
(
f
(
"repeated_sint32"
),
205
);
message
.
AddRepeatedField
(
f
(
"repeated_sint32"
),
205
);
message
.
AddRepeatedField
(
f
(
"repeated_sint64"
),
206L
);
message
.
AddRepeatedField
(
f
(
"repeated_sint64"
),
206L
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed32"
),
207
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed32"
),
207
U
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed64"
),
208L
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed64"
),
208
U
L
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed32"
),
209
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed32"
),
209
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed64"
),
210L
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed64"
),
210L
);
message
.
AddRepeatedField
(
f
(
"repeated_float"
),
211F
);
message
.
AddRepeatedField
(
f
(
"repeated_float"
),
211F
);
...
@@ -229,12 +229,12 @@ namespace Google.ProtocolBuffers {
...
@@ -229,12 +229,12 @@ namespace Google.ProtocolBuffers {
// Add a second one of each field.
// Add a second one of each field.
message
.
AddRepeatedField
(
f
(
"repeated_int32"
),
301
);
message
.
AddRepeatedField
(
f
(
"repeated_int32"
),
301
);
message
.
AddRepeatedField
(
f
(
"repeated_int64"
),
302L
);
message
.
AddRepeatedField
(
f
(
"repeated_int64"
),
302L
);
message
.
AddRepeatedField
(
f
(
"repeated_uint32"
),
303
);
message
.
AddRepeatedField
(
f
(
"repeated_uint32"
),
303
U
);
message
.
AddRepeatedField
(
f
(
"repeated_uint64"
),
304L
);
message
.
AddRepeatedField
(
f
(
"repeated_uint64"
),
304
U
L
);
message
.
AddRepeatedField
(
f
(
"repeated_sint32"
),
305
);
message
.
AddRepeatedField
(
f
(
"repeated_sint32"
),
305
);
message
.
AddRepeatedField
(
f
(
"repeated_sint64"
),
306L
);
message
.
AddRepeatedField
(
f
(
"repeated_sint64"
),
306L
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed32"
),
307
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed32"
),
307
U
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed64"
),
308L
);
message
.
AddRepeatedField
(
f
(
"repeated_fixed64"
),
308
U
L
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed32"
),
309
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed32"
),
309
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed64"
),
310L
);
message
.
AddRepeatedField
(
f
(
"repeated_sfixed64"
),
310L
);
message
.
AddRepeatedField
(
f
(
"repeated_float"
),
311F
);
message
.
AddRepeatedField
(
f
(
"repeated_float"
),
311F
);
...
@@ -267,12 +267,12 @@ namespace Google.ProtocolBuffers {
...
@@ -267,12 +267,12 @@ namespace Google.ProtocolBuffers {
message
[
f
(
"default_int32"
)]
=
401
;
message
[
f
(
"default_int32"
)]
=
401
;
message
[
f
(
"default_int64"
)]
=
402L
;
message
[
f
(
"default_int64"
)]
=
402L
;
message
[
f
(
"default_uint32"
)]
=
403
;
message
[
f
(
"default_uint32"
)]
=
403
U
;
message
[
f
(
"default_uint64"
)]
=
404L
;
message
[
f
(
"default_uint64"
)]
=
404
U
L
;
message
[
f
(
"default_sint32"
)]
=
405
;
message
[
f
(
"default_sint32"
)]
=
405
;
message
[
f
(
"default_sint64"
)]
=
406L
;
message
[
f
(
"default_sint64"
)]
=
406L
;
message
[
f
(
"default_fixed32"
)]
=
407
;
message
[
f
(
"default_fixed32"
)]
=
407
U
;
message
[
f
(
"default_fixed64"
)]
=
408L
;
message
[
f
(
"default_fixed64"
)]
=
408
U
L
;
message
[
f
(
"default_sfixed32"
)]
=
409
;
message
[
f
(
"default_sfixed32"
)]
=
409
;
message
[
f
(
"default_sfixed64"
)]
=
410L
;
message
[
f
(
"default_sfixed64"
)]
=
410L
;
message
[
f
(
"default_float"
)]
=
411F
;
message
[
f
(
"default_float"
)]
=
411F
;
...
@@ -299,12 +299,12 @@ namespace Google.ProtocolBuffers {
...
@@ -299,12 +299,12 @@ namespace Google.ProtocolBuffers {
internal
void
ModifyRepeatedFieldsViaReflection
(
IBuilder
message
)
{
internal
void
ModifyRepeatedFieldsViaReflection
(
IBuilder
message
)
{
message
[
f
(
"repeated_int32"
),
1
]
=
501
;
message
[
f
(
"repeated_int32"
),
1
]
=
501
;
message
[
f
(
"repeated_int64"
),
1
]
=
502L
;
message
[
f
(
"repeated_int64"
),
1
]
=
502L
;
message
[
f
(
"repeated_uint32"
),
1
]
=
503
;
message
[
f
(
"repeated_uint32"
),
1
]
=
503
U
;
message
[
f
(
"repeated_uint64"
),
1
]
=
504L
;
message
[
f
(
"repeated_uint64"
),
1
]
=
504
U
L
;
message
[
f
(
"repeated_sint32"
),
1
]
=
505
;
message
[
f
(
"repeated_sint32"
),
1
]
=
505
;
message
[
f
(
"repeated_sint64"
),
1
]
=
506L
;
message
[
f
(
"repeated_sint64"
),
1
]
=
506L
;
message
[
f
(
"repeated_fixed32"
),
1
]
=
507
;
message
[
f
(
"repeated_fixed32"
),
1
]
=
507
U
;
message
[
f
(
"repeated_fixed64"
),
1
]
=
508L
;
message
[
f
(
"repeated_fixed64"
),
1
]
=
508
U
L
;
message
[
f
(
"repeated_sfixed32"
),
1
]
=
509
;
message
[
f
(
"repeated_sfixed32"
),
1
]
=
509
;
message
[
f
(
"repeated_sfixed64"
),
1
]
=
510L
;
message
[
f
(
"repeated_sfixed64"
),
1
]
=
510L
;
message
[
f
(
"repeated_float"
),
1
]
=
511F
;
message
[
f
(
"repeated_float"
),
1
]
=
511F
;
...
@@ -332,7 +332,7 @@ namespace Google.ProtocolBuffers {
...
@@ -332,7 +332,7 @@ namespace Google.ProtocolBuffers {
/// Asserts that all fields of the specified message are set to the values
/// Asserts that all fields of the specified message are set to the values
/// assigned by SetAllFields, using the IMessage reflection interface.
/// assigned by SetAllFields, using the IMessage reflection interface.
/// </summary>
/// </summary>
public
void
a
ssertAllFieldsSetViaReflection
(
IMessage
message
)
{
public
void
A
ssertAllFieldsSetViaReflection
(
IMessage
message
)
{
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_int32"
)));
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_int32"
)));
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_int64"
)));
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_int64"
)));
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_uint32"
)));
Assert
.
IsTrue
(
message
.
HasField
(
f
(
"optional_uint32"
)));
...
@@ -368,12 +368,12 @@ namespace Google.ProtocolBuffers {
...
@@ -368,12 +368,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
101
,
message
[
f
(
"optional_int32"
)]);
Assert
.
AreEqual
(
101
,
message
[
f
(
"optional_int32"
)]);
Assert
.
AreEqual
(
102L
,
message
[
f
(
"optional_int64"
)]);
Assert
.
AreEqual
(
102L
,
message
[
f
(
"optional_int64"
)]);
Assert
.
AreEqual
(
103
,
message
[
f
(
"optional_uint32"
)]);
Assert
.
AreEqual
(
103
U
,
message
[
f
(
"optional_uint32"
)]);
Assert
.
AreEqual
(
104L
,
message
[
f
(
"optional_uint64"
)]);
Assert
.
AreEqual
(
104
U
L
,
message
[
f
(
"optional_uint64"
)]);
Assert
.
AreEqual
(
105
,
message
[
f
(
"optional_sint32"
)]);
Assert
.
AreEqual
(
105
,
message
[
f
(
"optional_sint32"
)]);
Assert
.
AreEqual
(
106L
,
message
[
f
(
"optional_sint64"
)]);
Assert
.
AreEqual
(
106L
,
message
[
f
(
"optional_sint64"
)]);
Assert
.
AreEqual
(
107
,
message
[
f
(
"optional_fixed32"
)]);
Assert
.
AreEqual
(
107
U
,
message
[
f
(
"optional_fixed32"
)]);
Assert
.
AreEqual
(
108L
,
message
[
f
(
"optional_fixed64"
)]);
Assert
.
AreEqual
(
108
U
L
,
message
[
f
(
"optional_fixed64"
)]);
Assert
.
AreEqual
(
109
,
message
[
f
(
"optional_sfixed32"
)]);
Assert
.
AreEqual
(
109
,
message
[
f
(
"optional_sfixed32"
)]);
Assert
.
AreEqual
(
110L
,
message
[
f
(
"optional_sfixed64"
)]);
Assert
.
AreEqual
(
110L
,
message
[
f
(
"optional_sfixed64"
)]);
Assert
.
AreEqual
(
111F
,
message
[
f
(
"optional_float"
)]);
Assert
.
AreEqual
(
111F
,
message
[
f
(
"optional_float"
)]);
...
@@ -425,12 +425,12 @@ namespace Google.ProtocolBuffers {
...
@@ -425,12 +425,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
201
,
message
[
f
(
"repeated_int32"
),
0
]);
Assert
.
AreEqual
(
201
,
message
[
f
(
"repeated_int32"
),
0
]);
Assert
.
AreEqual
(
202L
,
message
[
f
(
"repeated_int64"
),
0
]);
Assert
.
AreEqual
(
202L
,
message
[
f
(
"repeated_int64"
),
0
]);
Assert
.
AreEqual
(
203
,
message
[
f
(
"repeated_uint32"
),
0
]);
Assert
.
AreEqual
(
203
U
,
message
[
f
(
"repeated_uint32"
),
0
]);
Assert
.
AreEqual
(
204
L
,
message
[
f
(
"repeated_uint64"
),
0
]);
Assert
.
AreEqual
(
204
U
L
,
message
[
f
(
"repeated_uint64"
),
0
]);
Assert
.
AreEqual
(
205
,
message
[
f
(
"repeated_sint32"
),
0
]);
Assert
.
AreEqual
(
205
,
message
[
f
(
"repeated_sint32"
),
0
]);
Assert
.
AreEqual
(
206L
,
message
[
f
(
"repeated_sint64"
),
0
]);
Assert
.
AreEqual
(
206L
,
message
[
f
(
"repeated_sint64"
),
0
]);
Assert
.
AreEqual
(
207
,
message
[
f
(
"repeated_fixed32"
),
0
]);
Assert
.
AreEqual
(
207
U
,
message
[
f
(
"repeated_fixed32"
),
0
]);
Assert
.
AreEqual
(
208
L
,
message
[
f
(
"repeated_fixed64"
),
0
]);
Assert
.
AreEqual
(
208
U
L
,
message
[
f
(
"repeated_fixed64"
),
0
]);
Assert
.
AreEqual
(
209
,
message
[
f
(
"repeated_sfixed32"
),
0
]);
Assert
.
AreEqual
(
209
,
message
[
f
(
"repeated_sfixed32"
),
0
]);
Assert
.
AreEqual
(
210L
,
message
[
f
(
"repeated_sfixed64"
),
0
]);
Assert
.
AreEqual
(
210L
,
message
[
f
(
"repeated_sfixed64"
),
0
]);
Assert
.
AreEqual
(
211F
,
message
[
f
(
"repeated_float"
),
0
]);
Assert
.
AreEqual
(
211F
,
message
[
f
(
"repeated_float"
),
0
]);
...
@@ -453,12 +453,12 @@ namespace Google.ProtocolBuffers {
...
@@ -453,12 +453,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
301
,
message
[
f
(
"repeated_int32"
),
1
]);
Assert
.
AreEqual
(
301
,
message
[
f
(
"repeated_int32"
),
1
]);
Assert
.
AreEqual
(
302L
,
message
[
f
(
"repeated_int64"
),
1
]);
Assert
.
AreEqual
(
302L
,
message
[
f
(
"repeated_int64"
),
1
]);
Assert
.
AreEqual
(
303
,
message
[
f
(
"repeated_uint32"
),
1
]);
Assert
.
AreEqual
(
303
U
,
message
[
f
(
"repeated_uint32"
),
1
]);
Assert
.
AreEqual
(
304
L
,
message
[
f
(
"repeated_uint64"
),
1
]);
Assert
.
AreEqual
(
304
U
L
,
message
[
f
(
"repeated_uint64"
),
1
]);
Assert
.
AreEqual
(
305
,
message
[
f
(
"repeated_sint32"
),
1
]);
Assert
.
AreEqual
(
305
,
message
[
f
(
"repeated_sint32"
),
1
]);
Assert
.
AreEqual
(
306L
,
message
[
f
(
"repeated_sint64"
),
1
]);
Assert
.
AreEqual
(
306L
,
message
[
f
(
"repeated_sint64"
),
1
]);
Assert
.
AreEqual
(
307
,
message
[
f
(
"repeated_fixed32"
),
1
]);
Assert
.
AreEqual
(
307
U
,
message
[
f
(
"repeated_fixed32"
),
1
]);
Assert
.
AreEqual
(
308
L
,
message
[
f
(
"repeated_fixed64"
),
1
]);
Assert
.
AreEqual
(
308
U
L
,
message
[
f
(
"repeated_fixed64"
),
1
]);
Assert
.
AreEqual
(
309
,
message
[
f
(
"repeated_sfixed32"
),
1
]);
Assert
.
AreEqual
(
309
,
message
[
f
(
"repeated_sfixed32"
),
1
]);
Assert
.
AreEqual
(
310L
,
message
[
f
(
"repeated_sfixed64"
),
1
]);
Assert
.
AreEqual
(
310L
,
message
[
f
(
"repeated_sfixed64"
),
1
]);
Assert
.
AreEqual
(
311F
,
message
[
f
(
"repeated_float"
),
1
]);
Assert
.
AreEqual
(
311F
,
message
[
f
(
"repeated_float"
),
1
]);
...
@@ -469,12 +469,8 @@ namespace Google.ProtocolBuffers {
...
@@ -469,12 +469,8 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
317
,((
IMessage
)
message
[
f
(
"repeatedgroup"
),
1
])[
repeatedGroupA
]);
Assert
.
AreEqual
(
317
,((
IMessage
)
message
[
f
(
"repeatedgroup"
),
1
])[
repeatedGroupA
]);
Assert
.
AreEqual
(
318
,((
IMessage
)
message
[
f
(
"repeated_nested_message"
),
1
])[
nestedB
]);
Assert
.
AreEqual
(
318
,((
IMessage
)
message
[
f
(
"repeated_nested_message"
),
1
])[
nestedB
]);
Assert
.
AreEqual
(
319
,
Assert
.
AreEqual
(
319
,((
IMessage
)
message
[
f
(
"repeated_foreign_message"
),
1
])[
foreignC
]);
((
IMessage
)
message
[
f
(
"repeated_foreign_message"
),
1
])
Assert
.
AreEqual
(
320
,((
IMessage
)
message
[
f
(
"repeated_import_message"
),
1
])[
importD
]);
[
foreignC
]);
Assert
.
AreEqual
(
320
,
((
IMessage
)
message
[
f
(
"repeated_import_message"
),
1
])
[
importD
]);
Assert
.
AreEqual
(
nestedBaz
,
message
[
f
(
"repeated_nested_enum"
),
1
]);
Assert
.
AreEqual
(
nestedBaz
,
message
[
f
(
"repeated_nested_enum"
),
1
]);
Assert
.
AreEqual
(
foreignBaz
,
message
[
f
(
"repeated_foreign_enum"
),
1
]);
Assert
.
AreEqual
(
foreignBaz
,
message
[
f
(
"repeated_foreign_enum"
),
1
]);
...
@@ -510,12 +506,12 @@ namespace Google.ProtocolBuffers {
...
@@ -510,12 +506,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
401
,
message
[
f
(
"default_int32"
)]);
Assert
.
AreEqual
(
401
,
message
[
f
(
"default_int32"
)]);
Assert
.
AreEqual
(
402L
,
message
[
f
(
"default_int64"
)]);
Assert
.
AreEqual
(
402L
,
message
[
f
(
"default_int64"
)]);
Assert
.
AreEqual
(
403
,
message
[
f
(
"default_uint32"
)]);
Assert
.
AreEqual
(
403
U
,
message
[
f
(
"default_uint32"
)]);
Assert
.
AreEqual
(
404
L
,
message
[
f
(
"default_uint64"
)]);
Assert
.
AreEqual
(
404
U
L
,
message
[
f
(
"default_uint64"
)]);
Assert
.
AreEqual
(
405
,
message
[
f
(
"default_sint32"
)]);
Assert
.
AreEqual
(
405
,
message
[
f
(
"default_sint32"
)]);
Assert
.
AreEqual
(
406L
,
message
[
f
(
"default_sint64"
)]);
Assert
.
AreEqual
(
406L
,
message
[
f
(
"default_sint64"
)]);
Assert
.
AreEqual
(
407
,
message
[
f
(
"default_fixed32"
)]);
Assert
.
AreEqual
(
407
U
,
message
[
f
(
"default_fixed32"
)]);
Assert
.
AreEqual
(
408
L
,
message
[
f
(
"default_fixed64"
)]);
Assert
.
AreEqual
(
408
U
L
,
message
[
f
(
"default_fixed64"
)]);
Assert
.
AreEqual
(
409
,
message
[
f
(
"default_sfixed32"
)]);
Assert
.
AreEqual
(
409
,
message
[
f
(
"default_sfixed32"
)]);
Assert
.
AreEqual
(
410L
,
message
[
f
(
"default_sfixed64"
)]);
Assert
.
AreEqual
(
410L
,
message
[
f
(
"default_sfixed64"
)]);
Assert
.
AreEqual
(
411F
,
message
[
f
(
"default_float"
)]);
Assert
.
AreEqual
(
411F
,
message
[
f
(
"default_float"
)]);
...
@@ -532,14 +528,11 @@ namespace Google.ProtocolBuffers {
...
@@ -532,14 +528,11 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
"425"
,
message
[
f
(
"default_cord"
)]);
Assert
.
AreEqual
(
"425"
,
message
[
f
(
"default_cord"
)]);
}
}
// -------------------------------------------------------------------
/// <summary>
/// Assert that all fields of the message are cleared, and that
/**
/// getting the fields returns their default values, using the reflection interface.
* Assert (using {@code junit.framework.Assert}} that all fields of
/// </summary>
* {@code message} are cleared, and that getting the fields returns their
public
void
AssertClearViaReflection
(
IMessage
message
)
{
* default values, using the {@link Message} reflection interface.
*/
public
void
assertClearViaReflection
(
IMessage
message
)
{
// has_blah() should initially be false for all optional fields.
// has_blah() should initially be false for all optional fields.
Assert
.
IsFalse
(
message
.
HasField
(
f
(
"optional_int32"
)));
Assert
.
IsFalse
(
message
.
HasField
(
f
(
"optional_int32"
)));
Assert
.
IsFalse
(
message
.
HasField
(
f
(
"optional_int64"
)));
Assert
.
IsFalse
(
message
.
HasField
(
f
(
"optional_int64"
)));
...
@@ -572,12 +565,12 @@ namespace Google.ProtocolBuffers {
...
@@ -572,12 +565,12 @@ namespace Google.ProtocolBuffers {
// Optional fields without defaults are set to zero or something like it.
// Optional fields without defaults are set to zero or something like it.
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_int32"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_int32"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_int64"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_int64"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_uint32"
)]);
Assert
.
AreEqual
(
0
U
,
message
[
f
(
"optional_uint32"
)]);
Assert
.
AreEqual
(
0
L
,
message
[
f
(
"optional_uint64"
)]);
Assert
.
AreEqual
(
0
U
L
,
message
[
f
(
"optional_uint64"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_sint32"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_sint32"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_sint64"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_sint64"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_fixed32"
)]);
Assert
.
AreEqual
(
0
U
,
message
[
f
(
"optional_fixed32"
)]);
Assert
.
AreEqual
(
0
L
,
message
[
f
(
"optional_fixed64"
)]);
Assert
.
AreEqual
(
0
U
L
,
message
[
f
(
"optional_fixed64"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_sfixed32"
)]);
Assert
.
AreEqual
(
0
,
message
[
f
(
"optional_sfixed32"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_sfixed64"
)]);
Assert
.
AreEqual
(
0L
,
message
[
f
(
"optional_sfixed64"
)]);
Assert
.
AreEqual
(
0F
,
message
[
f
(
"optional_float"
)]);
Assert
.
AreEqual
(
0F
,
message
[
f
(
"optional_float"
)]);
...
@@ -587,16 +580,12 @@ namespace Google.ProtocolBuffers {
...
@@ -587,16 +580,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
ByteString
.
Empty
,
message
[
f
(
"optional_bytes"
)]);
Assert
.
AreEqual
(
ByteString
.
Empty
,
message
[
f
(
"optional_bytes"
)]);
// Embedded messages should also be clear.
// Embedded messages should also be clear.
Assert
.
IsFalse
(
Assert
.
IsFalse
(((
IMessage
)
message
[
f
(
"optionalgroup"
)]).
HasField
(
groupA
));
((
IMessage
)
message
[
f
(
"optionalgroup"
)]).
HasField
(
groupA
));
Assert
.
IsFalse
(((
IMessage
)
message
[
f
(
"optional_nested_message"
)])
Assert
.
IsFalse
(
((
IMessage
)
message
[
f
(
"optional_nested_message"
)])
.
HasField
(
nestedB
));
.
HasField
(
nestedB
));
Assert
.
IsFalse
(
Assert
.
IsFalse
(((
IMessage
)
message
[
f
(
"optional_foreign_message"
)])
((
IMessage
)
message
[
f
(
"optional_foreign_message"
)])
.
HasField
(
foreignC
));
.
HasField
(
foreignC
));
Assert
.
IsFalse
(
Assert
.
IsFalse
(((
IMessage
)
message
[
f
(
"optional_import_message"
)])
((
IMessage
)
message
[
f
(
"optional_import_message"
)])
.
HasField
(
importD
));
.
HasField
(
importD
));
Assert
.
AreEqual
(
0
,((
IMessage
)
message
[
f
(
"optionalgroup"
)])[
groupA
]);
Assert
.
AreEqual
(
0
,((
IMessage
)
message
[
f
(
"optionalgroup"
)])[
groupA
]);
...
@@ -667,12 +656,12 @@ namespace Google.ProtocolBuffers {
...
@@ -667,12 +656,12 @@ namespace Google.ProtocolBuffers {
// Fields with defaults have their default values (duh).
// Fields with defaults have their default values (duh).
Assert
.
AreEqual
(
41
,
message
[
f
(
"default_int32"
)]);
Assert
.
AreEqual
(
41
,
message
[
f
(
"default_int32"
)]);
Assert
.
AreEqual
(
42L
,
message
[
f
(
"default_int64"
)]);
Assert
.
AreEqual
(
42L
,
message
[
f
(
"default_int64"
)]);
Assert
.
AreEqual
(
43
,
message
[
f
(
"default_uint32"
)]);
Assert
.
AreEqual
(
43
U
,
message
[
f
(
"default_uint32"
)]);
Assert
.
AreEqual
(
44
L
,
message
[
f
(
"default_uint64"
)]);
Assert
.
AreEqual
(
44
U
L
,
message
[
f
(
"default_uint64"
)]);
Assert
.
AreEqual
(-
45
,
message
[
f
(
"default_sint32"
)]);
Assert
.
AreEqual
(-
45
,
message
[
f
(
"default_sint32"
)]);
Assert
.
AreEqual
(
46L
,
message
[
f
(
"default_sint64"
)]);
Assert
.
AreEqual
(
46L
,
message
[
f
(
"default_sint64"
)]);
Assert
.
AreEqual
(
47
,
message
[
f
(
"default_fixed32"
)]);
Assert
.
AreEqual
(
47
U
,
message
[
f
(
"default_fixed32"
)]);
Assert
.
AreEqual
(
48
L
,
message
[
f
(
"default_fixed64"
)]);
Assert
.
AreEqual
(
48
U
L
,
message
[
f
(
"default_fixed64"
)]);
Assert
.
AreEqual
(
49
,
message
[
f
(
"default_sfixed32"
)]);
Assert
.
AreEqual
(
49
,
message
[
f
(
"default_sfixed32"
)]);
Assert
.
AreEqual
(-
50L
,
message
[
f
(
"default_sfixed64"
)]);
Assert
.
AreEqual
(-
50L
,
message
[
f
(
"default_sfixed64"
)]);
Assert
.
AreEqual
(
51.5F
,
message
[
f
(
"default_float"
)]);
Assert
.
AreEqual
(
51.5F
,
message
[
f
(
"default_float"
)]);
...
@@ -724,12 +713,12 @@ namespace Google.ProtocolBuffers {
...
@@ -724,12 +713,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
201
,
message
[
f
(
"repeated_int32"
),
0
]);
Assert
.
AreEqual
(
201
,
message
[
f
(
"repeated_int32"
),
0
]);
Assert
.
AreEqual
(
202L
,
message
[
f
(
"repeated_int64"
),
0
]);
Assert
.
AreEqual
(
202L
,
message
[
f
(
"repeated_int64"
),
0
]);
Assert
.
AreEqual
(
203
,
message
[
f
(
"repeated_uint32"
),
0
]);
Assert
.
AreEqual
(
203
U
,
message
[
f
(
"repeated_uint32"
),
0
]);
Assert
.
AreEqual
(
204
L
,
message
[
f
(
"repeated_uint64"
),
0
]);
Assert
.
AreEqual
(
204
U
L
,
message
[
f
(
"repeated_uint64"
),
0
]);
Assert
.
AreEqual
(
205
,
message
[
f
(
"repeated_sint32"
),
0
]);
Assert
.
AreEqual
(
205
,
message
[
f
(
"repeated_sint32"
),
0
]);
Assert
.
AreEqual
(
206L
,
message
[
f
(
"repeated_sint64"
),
0
]);
Assert
.
AreEqual
(
206L
,
message
[
f
(
"repeated_sint64"
),
0
]);
Assert
.
AreEqual
(
207
,
message
[
f
(
"repeated_fixed32"
),
0
]);
Assert
.
AreEqual
(
207
U
,
message
[
f
(
"repeated_fixed32"
),
0
]);
Assert
.
AreEqual
(
208
L
,
message
[
f
(
"repeated_fixed64"
),
0
]);
Assert
.
AreEqual
(
208
U
L
,
message
[
f
(
"repeated_fixed64"
),
0
]);
Assert
.
AreEqual
(
209
,
message
[
f
(
"repeated_sfixed32"
),
0
]);
Assert
.
AreEqual
(
209
,
message
[
f
(
"repeated_sfixed32"
),
0
]);
Assert
.
AreEqual
(
210L
,
message
[
f
(
"repeated_sfixed64"
),
0
]);
Assert
.
AreEqual
(
210L
,
message
[
f
(
"repeated_sfixed64"
),
0
]);
Assert
.
AreEqual
(
211F
,
message
[
f
(
"repeated_float"
),
0
]);
Assert
.
AreEqual
(
211F
,
message
[
f
(
"repeated_float"
),
0
]);
...
@@ -752,12 +741,12 @@ namespace Google.ProtocolBuffers {
...
@@ -752,12 +741,12 @@ namespace Google.ProtocolBuffers {
Assert
.
AreEqual
(
501
,
message
[
f
(
"repeated_int32"
),
1
]);
Assert
.
AreEqual
(
501
,
message
[
f
(
"repeated_int32"
),
1
]);
Assert
.
AreEqual
(
502L
,
message
[
f
(
"repeated_int64"
),
1
]);
Assert
.
AreEqual
(
502L
,
message
[
f
(
"repeated_int64"
),
1
]);
Assert
.
AreEqual
(
503
,
message
[
f
(
"repeated_uint32"
),
1
]);
Assert
.
AreEqual
(
503
U
,
message
[
f
(
"repeated_uint32"
),
1
]);
Assert
.
AreEqual
(
504
L
,
message
[
f
(
"repeated_uint64"
),
1
]);
Assert
.
AreEqual
(
504
U
L
,
message
[
f
(
"repeated_uint64"
),
1
]);
Assert
.
AreEqual
(
505
,
message
[
f
(
"repeated_sint32"
),
1
]);
Assert
.
AreEqual
(
505
,
message
[
f
(
"repeated_sint32"
),
1
]);
Assert
.
AreEqual
(
506L
,
message
[
f
(
"repeated_sint64"
),
1
]);
Assert
.
AreEqual
(
506L
,
message
[
f
(
"repeated_sint64"
),
1
]);
Assert
.
AreEqual
(
507
,
message
[
f
(
"repeated_fixed32"
),
1
]);
Assert
.
AreEqual
(
507
U
,
message
[
f
(
"repeated_fixed32"
),
1
]);
Assert
.
AreEqual
(
508
L
,
message
[
f
(
"repeated_fixed64"
),
1
]);
Assert
.
AreEqual
(
508
U
L
,
message
[
f
(
"repeated_fixed64"
),
1
]);
Assert
.
AreEqual
(
509
,
message
[
f
(
"repeated_sfixed32"
),
1
]);
Assert
.
AreEqual
(
509
,
message
[
f
(
"repeated_sfixed32"
),
1
]);
Assert
.
AreEqual
(
510L
,
message
[
f
(
"repeated_sfixed64"
),
1
]);
Assert
.
AreEqual
(
510L
,
message
[
f
(
"repeated_sfixed64"
),
1
]);
Assert
.
AreEqual
(
511F
,
message
[
f
(
"repeated_float"
),
1
]);
Assert
.
AreEqual
(
511F
,
message
[
f
(
"repeated_float"
),
1
]);
...
...
csharp/ProtocolBuffers/Descriptors/MessageDescriptor.cs
View file @
ba02091e
...
@@ -33,6 +33,13 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -33,6 +33,13 @@ namespace Google.ProtocolBuffers.Descriptors {
file
.
DescriptorPool
.
AddSymbol
(
this
);
file
.
DescriptorPool
.
AddSymbol
(
this
);
}
}
/// <value>
/// If this is a nested type, get the outer descriptor, otherwise null.
/// </value>
public
MessageDescriptor
ContainingType
{
get
{
return
containingType
;
}
}
/// <value>
/// <value>
/// An unmodifiable list of this message type's fields.
/// An unmodifiable list of this message type's fields.
/// </value>
/// </value>
...
...
csharp/ProtocolBuffers/Descriptors/MethodDescriptor.cs
View file @
ba02091e
...
@@ -28,7 +28,7 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -28,7 +28,7 @@ namespace Google.ProtocolBuffers.Descriptors {
/// The method's input type.
/// The method's input type.
/// </value>
/// </value>
public
MessageDescriptor
OutputType
{
public
MessageDescriptor
OutputType
{
get
{
return
in
putType
;
}
get
{
return
out
putType
;
}
}
}
internal
MethodDescriptor
(
MethodDescriptorProto
proto
,
FileDescriptor
file
,
internal
MethodDescriptor
(
MethodDescriptorProto
proto
,
FileDescriptor
file
,
...
...
csharp/ProtocolBuffers/Descriptors/ServiceDescriptor.cs
View file @
ba02091e
...
@@ -27,6 +27,15 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -27,6 +27,15 @@ namespace Google.ProtocolBuffers.Descriptors {
public
IList
<
MethodDescriptor
>
Methods
{
public
IList
<
MethodDescriptor
>
Methods
{
get
{
return
methods
;
}
get
{
return
methods
;
}
}
}
/// <summary>
/// Finds a method by name.
/// </summary>
/// <param name="name">The unqualified name of the method (e.g. "Foo").</param>
/// <returns>The method's decsriptor, or null if not found.</returns>
public
MethodDescriptor
FindMethodByName
(
String
name
)
{
return
File
.
DescriptorPool
.
FindSymbol
<
MethodDescriptor
>(
FullName
+
"."
+
name
);
}
internal
void
CrossLink
()
{
internal
void
CrossLink
()
{
foreach
(
MethodDescriptor
method
in
methods
)
{
foreach
(
MethodDescriptor
method
in
methods
)
{
...
...
csharp/ProtocolBuffers/DynamicMessage.cs
View file @
ba02091e
...
@@ -233,6 +233,10 @@ namespace Google.ProtocolBuffers {
...
@@ -233,6 +233,10 @@ namespace Google.ProtocolBuffers {
this
.
unknownFields
=
UnknownFieldSet
.
DefaultInstance
;
this
.
unknownFields
=
UnknownFieldSet
.
DefaultInstance
;
}
}
public
DynamicMessage
Build
()
{
return
(
DynamicMessage
)((
IBuilder
)
this
).
Build
();
}
public
override
IBuilder
Clear
()
{
public
override
IBuilder
Clear
()
{
fields
.
Clear
();
fields
.
Clear
();
return
this
;
return
this
;
...
...
csharp/ProtocolBuffers/FieldSet.cs
View file @
ba02091e
...
@@ -325,8 +325,13 @@ namespace Google.ProtocolBuffers {
...
@@ -325,8 +325,13 @@ namespace Google.ProtocolBuffers {
if
(
fields
.
TryGetValue
(
field
,
out
result
))
{
if
(
fields
.
TryGetValue
(
field
,
out
result
))
{
return
result
;
return
result
;
}
}
if
(
field
.
MappedType
==
MappedType
.
Message
)
{
// This will just do the right thing
if
(
field
.
IsRepeated
)
{
return
new
List
<
object
>();
}
else
{
return
null
;
}
}
return
field
.
DefaultValue
;
return
field
.
DefaultValue
;
}
}
set
{
set
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment