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
61e8e218
Commit
61e8e218
authored
Feb 18, 2016
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1241 from jskeet/more-merge-wrapper-tests
Add more tests around merging wrappers
parents
d41db75d
0262e04d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
2 deletions
+41
-2
WrappersTest.cs
...p/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
+41
-2
No files found.
csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
View file @
61e8e218
...
...
@@ -319,9 +319,10 @@ namespace Google.Protobuf.WellKnownTypes
// Merging is odd with wrapper types, due to the way that default values aren't emitted in
// the binary stream. In fact we cheat a little bit - a message with an explicitly present default
// value will have that default value ignored.
// value will have that default value ignored. See issue 615. Fixing this would require significant upheaval to
// the FieldCodec side of things.
[
Test
]
public
void
Merging
CornerCas
e
()
public
void
Merging
StreamExplicitValu
e
()
{
var
message
=
new
TestWellKnownTypes
{
Int32Field
=
5
};
...
...
@@ -343,9 +344,47 @@ namespace Google.Protobuf.WellKnownTypes
message
.
MergeFrom
(
bytes
);
// A normal implementation would have 0 now, as the explicit default would have been overwritten the 5.
// With the FieldCodec for Nullable<int>, we can't tell the difference between an implicit 0 and an explicit 0.
Assert
.
AreEqual
(
5
,
message
.
Int32Field
);
}
[
Test
]
public
void
MergingStreamNoValue
()
{
var
message
=
new
TestWellKnownTypes
{
Int32Field
=
5
};
// Create a byte array which an Int32 field, but with no value.
var
bytes
=
new
TestWellKnownTypes
{
Int32Field
=
0
}.
ToByteArray
();
Assert
.
AreEqual
(
2
,
bytes
.
Length
);
// The tag for Int32Field is a single byte, then a byte indicating a 0-length message.
message
.
MergeFrom
(
bytes
);
// The "implicit" 0 did *not* overwrite the value.
// (This is the correct behaviour.)
Assert
.
AreEqual
(
5
,
message
.
Int32Field
);
}
// All permutations of origin/merging value being null, zero (default) or non-default.
// As this is the in-memory version, we don't need to worry about the difference between implicit and explicit 0.
[
Test
]
[
TestCase
(
null
,
null
,
null
)]
[
TestCase
(
null
,
0
,
0
)]
[
TestCase
(
null
,
5
,
5
)]
[
TestCase
(
0
,
null
,
0
)]
[
TestCase
(
0
,
0
,
0
)]
[
TestCase
(
0
,
5
,
5
)]
[
TestCase
(
5
,
null
,
5
)]
[
TestCase
(
5
,
0
,
5
)]
[
TestCase
(
5
,
10
,
10
)]
public
void
MergingMessageWithZero
(
int
?
originValue
,
int
?
mergingValue
,
int
?
expectedResult
)
{
// This differs from the MergingStreamCornerCase because when we merge message *objects*,
// we ignore default values from the "source".
var
message1
=
new
TestWellKnownTypes
{
Int32Field
=
originValue
};
var
message2
=
new
TestWellKnownTypes
{
Int32Field
=
mergingValue
};
message1
.
MergeFrom
(
message2
);
Assert
.
AreEqual
(
expectedResult
,
message1
.
Int32Field
);
}
[
Test
]
public
void
UnknownFieldInWrapper
()
{
...
...
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