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
6b90ac13
Commit
6b90ac13
authored
May 28, 2019
by
Sydney Acksman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize some tests
parent
bf4f6c54
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
268 deletions
+90
-268
GeneratedMessageTest.Proto2.cs
...p/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
+0
-0
GeneratedMessageTest.cs
csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
+1
-204
CustomOptionsTest.cs
.../src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
+8
-7
FieldAccessTest.cs
...rp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
+81
-57
No files found.
csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
0 → 100644
View file @
6b90ac13
This diff is collapsed.
Click to expand it.
csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
View file @
6b90ac13
...
...
@@ -45,7 +45,7 @@ namespace Google.Protobuf
/// <summary>
/// Tests around the generated TestAllTypes message.
/// </summary>
public
class
GeneratedMessageTest
public
partial
class
GeneratedMessageTest
{
[
Test
]
public
void
EmptyMessageFieldDistinctFromMissingMessageField
()
...
...
@@ -112,50 +112,6 @@ namespace Google.Protobuf
Assert
.
AreEqual
(
""
,
message
.
OneofString
);
Assert
.
AreEqual
(
ByteString
.
Empty
,
message
.
OneofBytes
);
Assert
.
IsNull
(
message
.
OneofNestedMessage
);
// proto2 default values
var
message2
=
new
Proto2
.
TestAllTypes
();
Assert
.
AreEqual
(
true
,
message2
.
DefaultBool
);
Assert
.
AreEqual
(
ByteString
.
CopyFromUtf8
(
"world"
),
message2
.
DefaultBytes
);
Assert
.
AreEqual
(
"123"
,
message2
.
DefaultCord
);
Assert
.
AreEqual
(
52
e3
,
message2
.
DefaultDouble
);
Assert
.
AreEqual
(
47
,
message2
.
DefaultFixed32
);
Assert
.
AreEqual
(
48
,
message2
.
DefaultFixed64
);
Assert
.
AreEqual
(
51.5
,
message2
.
DefaultFloat
);
Assert
.
AreEqual
(
Proto2
.
ForeignEnum
.
ForeignBar
,
message2
.
DefaultForeignEnum
);
Assert
.
AreEqual
(
Proto2
.
ImportEnum
.
ImportBar
,
message2
.
DefaultImportEnum
);
Assert
.
AreEqual
(
41
,
message2
.
DefaultInt32
);
Assert
.
AreEqual
(
42
,
message2
.
DefaultInt64
);
Assert
.
AreEqual
(
Proto2
.
TestAllTypes
.
Types
.
NestedEnum
.
Bar
,
message2
.
DefaultNestedEnum
);
Assert
.
AreEqual
(
49
,
message2
.
DefaultSfixed32
);
Assert
.
AreEqual
(-
50
,
message2
.
DefaultSfixed64
);
Assert
.
AreEqual
(-
45
,
message2
.
DefaultSint32
);
Assert
.
AreEqual
(
46
,
message2
.
DefaultSint64
);
Assert
.
AreEqual
(
"hello"
,
message2
.
DefaultString
);
Assert
.
AreEqual
(
"abc"
,
message2
.
DefaultStringPiece
);
Assert
.
AreEqual
(
43
,
message2
.
DefaultUint32
);
Assert
.
AreEqual
(
44
,
message2
.
DefaultUint64
);
Assert
.
False
(
message2
.
HasDefaultBool
);
Assert
.
False
(
message2
.
HasDefaultBytes
);
Assert
.
False
(
message2
.
HasDefaultCord
);
Assert
.
False
(
message2
.
HasDefaultDouble
);
Assert
.
False
(
message2
.
HasDefaultFixed32
);
Assert
.
False
(
message2
.
HasDefaultFixed64
);
Assert
.
False
(
message2
.
HasDefaultFloat
);
Assert
.
False
(
message2
.
HasDefaultForeignEnum
);
Assert
.
False
(
message2
.
HasDefaultImportEnum
);
Assert
.
False
(
message2
.
HasDefaultInt32
);
Assert
.
False
(
message2
.
HasDefaultInt64
);
Assert
.
False
(
message2
.
HasDefaultNestedEnum
);
Assert
.
False
(
message2
.
HasDefaultSfixed32
);
Assert
.
False
(
message2
.
HasDefaultSfixed64
);
Assert
.
False
(
message2
.
HasDefaultSint32
);
Assert
.
False
(
message2
.
HasDefaultSint64
);
Assert
.
False
(
message2
.
HasDefaultString
);
Assert
.
False
(
message2
.
HasDefaultStringPiece
);
Assert
.
False
(
message2
.
HasDefaultUint32
);
Assert
.
False
(
message2
.
HasDefaultUint64
);
}
[
Test
]
...
...
@@ -168,115 +124,6 @@ namespace Google.Protobuf
Assert
.
Throws
<
ArgumentNullException
>(()
=>
message
.
OneofBytes
=
null
);
}
[
Test
]
public
void
FieldPresence
()
{
var
message
=
new
Proto2
.
TestAllTypes
();
Assert
.
False
(
message
.
HasOptionalBool
);
Assert
.
False
(
message
.
OptionalBool
);
message
.
OptionalBool
=
true
;
Assert
.
True
(
message
.
HasOptionalBool
);
Assert
.
True
(
message
.
OptionalBool
);
message
.
OptionalBool
=
false
;
Assert
.
True
(
message
.
HasOptionalBool
);
Assert
.
False
(
message
.
OptionalBool
);
message
.
ClearOptionalBool
();
Assert
.
False
(
message
.
HasOptionalBool
);
Assert
.
False
(
message
.
OptionalBool
);
Assert
.
False
(
message
.
HasDefaultBool
);
Assert
.
True
(
message
.
DefaultBool
);
message
.
DefaultBool
=
false
;
Assert
.
True
(
message
.
HasDefaultBool
);
Assert
.
False
(
message
.
DefaultBool
);
message
.
DefaultBool
=
true
;
Assert
.
True
(
message
.
HasDefaultBool
);
Assert
.
True
(
message
.
DefaultBool
);
message
.
ClearDefaultBool
();
Assert
.
False
(
message
.
HasDefaultBool
);
Assert
.
True
(
message
.
DefaultBool
);
}
[
Test
]
public
void
RequiredFields
()
{
var
message
=
new
Proto2
.
TestRequired
();
Assert
.
False
(
message
.
IsInitialized
());
message
.
A
=
1
;
message
.
B
=
2
;
message
.
C
=
3
;
Assert
.
True
(
message
.
IsInitialized
());
}
[
Test
]
public
void
RequiredFieldsInExtensions
()
{
var
message
=
new
Proto2
.
TestAllExtensions
();
Assert
.
True
(
message
.
IsInitialized
());
message
.
SetExtension
(
Proto2
.
TestRequired
.
Extensions
.
Single
,
new
Proto2
.
TestRequired
());
Assert
.
False
(
message
.
IsInitialized
());
var
extensionMessage
=
message
.
GetExtension
(
Proto2
.
TestRequired
.
Extensions
.
Single
);
extensionMessage
.
A
=
1
;
extensionMessage
.
B
=
2
;
extensionMessage
.
C
=
3
;
Assert
.
True
(
message
.
IsInitialized
());
message
.
GetOrRegisterExtension
(
Proto2
.
TestRequired
.
Extensions
.
Multi
);
Assert
.
True
(
message
.
IsInitialized
());
message
.
GetExtension
(
Proto2
.
TestRequired
.
Extensions
.
Multi
).
Add
(
new
Proto2
.
TestRequired
());
Assert
.
False
(
message
.
IsInitialized
());
extensionMessage
=
message
.
GetExtension
(
Proto2
.
TestRequired
.
Extensions
.
Multi
)[
0
];
extensionMessage
.
A
=
1
;
extensionMessage
.
B
=
2
;
extensionMessage
.
C
=
3
;
Assert
.
True
(
message
.
IsInitialized
());
message
.
SetExtension
(
Proto2
.
UnittestExtensions
.
OptionalBoolExtension
,
true
);
Assert
.
True
(
message
.
IsInitialized
());
message
.
GetOrRegisterExtension
(
Proto2
.
UnittestExtensions
.
RepeatedBoolExtension
).
Add
(
true
);
Assert
.
True
(
message
.
IsInitialized
());
}
[
Test
]
public
void
RequiredFieldInNestedMessageMapValue
()
{
var
message
=
new
Proto2
.
TestRequiredMap
();
message
.
Foo
.
Add
(
0
,
new
Proto2
.
TestRequiredMap
.
Types
.
NestedMessage
());
Assert
.
False
(
message
.
IsInitialized
());
message
.
Foo
[
0
].
RequiredInt32
=
12
;
Assert
.
True
(
message
.
IsInitialized
());
}
[
Test
]
public
void
RoundTrip_Empty
()
{
...
...
@@ -356,56 +203,6 @@ namespace Google.Protobuf
Assert
.
AreEqual
(
message
,
parsed
);
}
[
Test
]
public
void
RoundTrip_Groups
()
{
var
message
=
new
Proto2
.
TestAllTypes
{
OptionalGroup
=
new
Proto2
.
TestAllTypes
.
Types
.
OptionalGroup
{
A
=
10
},
RepeatedGroup
=
{
new
Proto2
.
TestAllTypes
.
Types
.
RepeatedGroup
{
A
=
10
},
new
Proto2
.
TestAllTypes
.
Types
.
RepeatedGroup
{
A
=
20
},
new
Proto2
.
TestAllTypes
.
Types
.
RepeatedGroup
{
A
=
30
}
}
};
byte
[]
bytes
=
message
.
ToByteArray
();
Proto2
.
TestAllTypes
parsed
=
Proto2
.
TestAllTypes
.
Parser
.
ParseFrom
(
bytes
);
Assert
.
AreEqual
(
message
,
parsed
);
}
[
Test
]
public
void
RoundTrip_ExtensionGroups
()
{
var
message
=
new
Proto2
.
TestAllExtensions
();
message
.
SetExtension
(
Proto2
.
UnittestExtensions
.
OptionalGroupExtension
,
new
Proto2
.
OptionalGroup_extension
{
A
=
10
});
message
.
GetOrRegisterExtension
(
Proto2
.
UnittestExtensions
.
RepeatedGroupExtension
).
AddRange
(
new
[]
{
new
Proto2
.
RepeatedGroup_extension
{
A
=
10
},
new
Proto2
.
RepeatedGroup_extension
{
A
=
20
},
new
Proto2
.
RepeatedGroup_extension
{
A
=
30
}
});
byte
[]
bytes
=
message
.
ToByteArray
();
Proto2
.
TestAllExtensions
extendable_parsed
=
Proto2
.
TestAllExtensions
.
Parser
.
WithExtensionRegistry
(
new
ExtensionRegistry
()
{
Proto2
.
UnittestExtensions
.
OptionalGroupExtension
,
Proto2
.
UnittestExtensions
.
RepeatedGroupExtension
}).
ParseFrom
(
bytes
);
Assert
.
AreEqual
(
message
,
extendable_parsed
);
}
[
Test
]
public
void
RoundTrip_NestedExtensionGroup
()
{
var
message
=
new
Proto2
.
TestGroupExtension
();
message
.
SetExtension
(
Proto2
.
TestNestedExtension
.
Extensions
.
OptionalGroupExtension
,
new
Proto2
.
TestNestedExtension
.
Types
.
OptionalGroup_extension
{
A
=
10
});
byte
[]
bytes
=
message
.
ToByteArray
();
Proto2
.
TestGroupExtension
extendable_parsed
=
Proto2
.
TestGroupExtension
.
Parser
.
WithExtensionRegistry
(
new
ExtensionRegistry
()
{
Proto2
.
TestNestedExtension
.
Extensions
.
OptionalGroupExtension
}).
ParseFrom
(
bytes
);
Assert
.
AreEqual
(
message
,
extendable_parsed
);
}
// Note that not every map within map_unittest_proto3 is used. They all go through very
// similar code paths. The fact that all maps are present is validation that we have codecs
// for every type.
...
...
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
View file @
6b90ac13
...
...
@@ -73,8 +73,8 @@ namespace Google.Protobuf.Test.Reflection
[
Test
]
public
void
ScalarOptions
()
{
var
options
=
CustomOptionOtherValues
.
Descriptor
.
CustomOptions
;
var
d
=
CustomOptionOtherValues
.
Descriptor
;
var
options
=
d
.
CustomOptions
;
AssertOption
(-
100
,
options
.
TryGetInt32
,
Int32Opt
,
d
.
GetOption
);
AssertOption
(
12.3456789f
,
options
.
TryGetFloat
,
FloatOpt
,
d
.
GetOption
);
AssertOption
(
1.234567890123456789d
,
options
.
TryGetDouble
,
DoubleOpt
,
d
.
GetOption
);
...
...
@@ -86,8 +86,9 @@ namespace Google.Protobuf.Test.Reflection
[
Test
]
public
void
MessageOptions
()
{
var
options
=
VariousComplexOptions
.
Descriptor
.
CustomOptions
;
AssertOption
(
new
ComplexOptionType1
{
Foo
=
42
,
Foo4
=
{
99
,
88
}
},
options
.
TryGetMessage
,
ComplexOpt1
,
VariousComplexOptions
.
Descriptor
.
GetOption
);
var
d
=
VariousComplexOptions
.
Descriptor
;
var
options
=
d
.
CustomOptions
;
AssertOption
(
new
ComplexOptionType1
{
Foo
=
42
,
Foo4
=
{
99
,
88
}
},
options
.
TryGetMessage
,
ComplexOpt1
,
d
.
GetOption
);
AssertOption
(
new
ComplexOptionType2
{
Baz
=
987
,
...
...
@@ -95,8 +96,8 @@ namespace Google.Protobuf.Test.Reflection
Fred
=
new
ComplexOptionType4
{
Waldo
=
321
},
Barney
=
{
new
ComplexOptionType4
{
Waldo
=
101
},
new
ComplexOptionType4
{
Waldo
=
212
}
}
},
options
.
TryGetMessage
,
ComplexOpt2
,
VariousComplexOptions
.
Descriptor
.
GetOption
);
AssertOption
(
new
ComplexOptionType3
{
Qux
=
9
},
options
.
TryGetMessage
,
ComplexOpt3
,
VariousComplexOptions
.
Descriptor
.
GetOption
);
options
.
TryGetMessage
,
ComplexOpt2
,
d
.
GetOption
);
AssertOption
(
new
ComplexOptionType3
{
Qux
=
9
},
options
.
TryGetMessage
,
ComplexOpt3
,
d
.
GetOption
);
}
[
Test
]
...
...
@@ -132,8 +133,8 @@ namespace Google.Protobuf.Test.Reflection
[
Test
]
public
void
MinValues
()
{
var
options
=
CustomOptionMinIntegerValues
.
Descriptor
.
CustomOptions
;
var
d
=
CustomOptionMinIntegerValues
.
Descriptor
;
var
options
=
d
.
CustomOptions
;
AssertOption
(
false
,
options
.
TryGetBool
,
BoolOpt
,
d
.
GetOption
);
AssertOption
(
int
.
MinValue
,
options
.
TryGetInt32
,
Int32Opt
,
d
.
GetOption
);
AssertOption
(
long
.
MinValue
,
options
.
TryGetInt64
,
Int64Opt
,
d
.
GetOption
);
...
...
@@ -150,8 +151,8 @@ namespace Google.Protobuf.Test.Reflection
[
Test
]
public
void
MaxValues
()
{
var
options
=
CustomOptionMaxIntegerValues
.
Descriptor
.
CustomOptions
;
var
d
=
CustomOptionMaxIntegerValues
.
Descriptor
;
var
options
=
d
.
CustomOptions
;
AssertOption
(
true
,
options
.
TryGetBool
,
BoolOpt
,
d
.
GetOption
);
AssertOption
(
int
.
MaxValue
,
options
.
TryGetInt32
,
Int32Opt
,
d
.
GetOption
);
AssertOption
(
long
.
MaxValue
,
options
.
TryGetInt64
,
Int64Opt
,
d
.
GetOption
);
...
...
csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
View file @
6b90ac13
...
...
@@ -86,64 +86,40 @@ namespace Google.Protobuf.Reflection
var
dictionary
=
(
IDictionary
)
fields
[
TestMap
.
MapStringStringFieldNumber
].
Accessor
.
GetValue
(
mapMessage
);
Assert
.
AreEqual
(
mapMessage
.
MapStringString
,
dictionary
);
Assert
.
AreEqual
(
"value1"
,
dictionary
[
"key1"
]);
}
[
Test
]
public
void
GetValue_IncorrectType
()
{
IMessage
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
Assert
.
Throws
<
InvalidCastException
>(()
=>
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
GetValue
(
new
TestMap
()));
}
[
Test
]
public
void
GetExtensionValue
()
public
void
HasValue_Proto3
()
{
var
message
=
SampleMessages
.
CreateFullTestAllExtensions
();
// test that the reflector works, since the reflector just runs through IExtendableMessage
Assert
.
AreEqual
(
message
.
GetExtension
(
OptionalBoolExtension
),
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
OptionalBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
IMessage
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
Assert
.
Throws
<
InvalidOperationException
>(()
=>
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
HasValue
(
message
));
}
[
Test
]
public
void
GetRepeatedExtension
Value
()
public
void
Has
Value
()
{
// check to make sure repeated accessor uses GetOrRegister
var
message
=
new
Proto2
.
TestAllExtensions
();
IMessage
message
=
new
Proto2
.
TestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
var
accessor
=
fields
[
Proto2
.
TestAllTypes
.
OptionalBoolFieldNumber
].
Accessor
;
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
Assert
.
IsNotNull
(
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
RepeatedBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
Assert
.
IsNotNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
Assert
.
False
(
accessor
.
HasValue
(
message
));
message
.
ClearExtension
(
RepeatedBoolExtension
);
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
}
[
Test
]
public
void
Clear
()
{
var
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
TestProtos
.
TestAllTypes
.
Descriptor
.
Fields
;
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleInt32FieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleStringFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleBytesFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleForeignEnumFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleForeignMessageFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
RepeatedDoubleFieldNumber
].
Accessor
.
Clear
(
message
);
var
expected
=
new
TestAllTypes
(
SampleMessages
.
CreateFullTestAllTypes
())
{
SingleBool
=
false
,
SingleInt32
=
0
,
SingleString
=
""
,
SingleBytes
=
ByteString
.
Empty
,
SingleForeignEnum
=
0
,
SingleForeignMessage
=
null
,
};
expected
.
RepeatedDouble
.
Clear
();
Assert
.
AreEqual
(
expected
,
message
);
// Separately, maps.
var
mapMessage
=
new
TestMap
{
MapStringString
=
{
{
"key1"
,
"value1"
},
{
"key2"
,
"value2"
}
}
};
fields
=
TestMap
.
Descriptor
.
Fields
;
fields
[
TestMap
.
MapStringStringFieldNumber
].
Accessor
.
Clear
(
mapMessage
);
Assert
.
AreEqual
(
0
,
mapMessage
.
MapStringString
.
Count
);
accessor
.
SetValue
(
message
,
true
);
Assert
.
True
(
accessor
.
HasValue
(
message
));
accessor
.
Clear
(
message
);
Assert
.
False
(
accessor
.
HasValue
(
message
));
}
[
Test
]
public
void
SetValue_SingleFields
()
{
...
...
@@ -170,8 +146,8 @@ namespace Google.Protobuf.Reflection
};
Assert
.
AreEqual
(
expected
,
message
);
}
}
[
Test
]
public
void
SetValue_SingleFields_WrongType
()
{
...
...
@@ -196,14 +172,6 @@ namespace Google.Protobuf.Reflection
Assert
.
Throws
<
InvalidOperationException
>(()
=>
fields
[
TestProtos
.
TestAllTypes
.
RepeatedDoubleFieldNumber
].
Accessor
.
SetValue
(
message
,
new
double
[
10
]));
}
[
Test
]
public
void
GetValue_IncorrectType
()
{
IMessage
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
message
.
Descriptor
.
Fields
;
Assert
.
Throws
<
InvalidCastException
>(()
=>
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
GetValue
(
new
TestMap
()));
}
[
Test
]
public
void
Oneof
()
{
...
...
@@ -222,6 +190,39 @@ namespace Google.Protobuf.Reflection
oneof
.
Accessor
.
Clear
(
message
);
Assert
.
AreEqual
(
TestProtos
.
TestAllTypes
.
OneofFieldOneofCase
.
None
,
message
.
OneofFieldCase
);
}
[
Test
]
public
void
Clear
()
{
var
message
=
SampleMessages
.
CreateFullTestAllTypes
();
var
fields
=
TestProtos
.
TestAllTypes
.
Descriptor
.
Fields
;
fields
[
TestProtos
.
TestAllTypes
.
SingleBoolFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleInt32FieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleStringFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleBytesFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleForeignEnumFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
SingleForeignMessageFieldNumber
].
Accessor
.
Clear
(
message
);
fields
[
TestProtos
.
TestAllTypes
.
RepeatedDoubleFieldNumber
].
Accessor
.
Clear
(
message
);
var
expected
=
new
TestAllTypes
(
SampleMessages
.
CreateFullTestAllTypes
())
{
SingleBool
=
false
,
SingleInt32
=
0
,
SingleString
=
""
,
SingleBytes
=
ByteString
.
Empty
,
SingleForeignEnum
=
0
,
SingleForeignMessage
=
null
,
};
expected
.
RepeatedDouble
.
Clear
();
Assert
.
AreEqual
(
expected
,
message
);
// Separately, maps.
var
mapMessage
=
new
TestMap
{
MapStringString
=
{
{
"key1"
,
"value1"
},
{
"key2"
,
"value2"
}
}
};
fields
=
TestMap
.
Descriptor
.
Fields
;
fields
[
TestMap
.
MapStringStringFieldNumber
].
Accessor
.
Clear
(
mapMessage
);
Assert
.
AreEqual
(
0
,
mapMessage
.
MapStringString
.
Count
);
}
[
Test
]
...
...
@@ -240,5 +241,28 @@ namespace Google.Protobuf.Reflection
Assert
.
Throws
<
KeyNotFoundException
>(()
=>
descriptor
.
Fields
[
999999
].
ToString
());
Assert
.
Throws
<
KeyNotFoundException
>(()
=>
descriptor
.
Fields
[
"not found"
].
ToString
());
}
[
Test
]
public
void
GetExtensionValue
()
{
var
message
=
SampleMessages
.
CreateFullTestAllExtensions
();
// test that the reflector works, since the reflector just runs through IExtendableMessage
Assert
.
AreEqual
(
message
.
GetExtension
(
OptionalBoolExtension
),
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
OptionalBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
}
[
Test
]
public
void
GetRepeatedExtensionValue
()
{
// check to make sure repeated accessor uses GetOrRegister
var
message
=
new
Proto2
.
TestAllExtensions
();
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
Assert
.
IsNotNull
(
Proto2
.
TestAllExtensions
.
Descriptor
.
FindFieldByNumber
(
RepeatedBoolExtension
.
FieldNumber
).
Accessor
.
GetValue
(
message
));
Assert
.
IsNotNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
message
.
ClearExtension
(
RepeatedBoolExtension
);
Assert
.
IsNull
(
message
.
GetExtension
(
RepeatedBoolExtension
));
}
}
}
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