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
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
133 additions
and
3 deletions
+133
-3
DescriptorsTest.cs
csharp/ProtocolBuffers.Test/DescriptorsTest.cs
+0
-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
+0
-0
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
This diff is collapsed.
Click to expand it.
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
This diff is collapsed.
Click to expand it.
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
...
@@ -28,6 +28,15 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -28,6 +28,15 @@ namespace Google.ProtocolBuffers.Descriptors {
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
)
{
method
.
CrossLink
();
method
.
CrossLink
();
...
...
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