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
7f369318
Commit
7f369318
authored
Feb 05, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests merging empty entries in JavaNano map
parent
bd3573cb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
NanoTest.java
...nano/src/test/java/com/google/protobuf/nano/NanoTest.java
+30
-0
No files found.
javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
View file @
7f369318
...
...
@@ -3795,6 +3795,36 @@ public class NanoTest extends TestCase {
assertEquals
(
0
,
mergedValue
.
value2
);
}
/**
* Tests that when merging with empty entries,
* we will use default for the key and value, instead of null.
*/
public
void
testMapMergeEmptyEntry
()
throws
Exception
{
TestMap
testMap
=
new
TestMap
();
byte
[]
buffer
=
new
byte
[
1024
];
CodedOutputByteBufferNano
output
=
CodedOutputByteBufferNano
.
newInstance
(
buffer
);
// An empty entry for int32_to_int32 map.
output
.
writeTag
(
1
,
WireFormatNano
.
WIRETYPE_LENGTH_DELIMITED
);
output
.
writeRawVarint32
(
0
);
// An empty entry for int32_to_message map.
output
.
writeTag
(
5
,
WireFormatNano
.
WIRETYPE_LENGTH_DELIMITED
);
output
.
writeRawVarint32
(
0
);
CodedInputByteBufferNano
input
=
CodedInputByteBufferNano
.
newInstance
(
buffer
,
0
,
buffer
.
length
-
output
.
spaceLeft
());
testMap
.
mergeFrom
(
input
);
assertNotNull
(
testMap
.
int32ToInt32Field
);;
assertEquals
(
1
,
testMap
.
int32ToInt32Field
.
size
());
assertEquals
(
Integer
.
valueOf
(
0
),
testMap
.
int32ToInt32Field
.
get
(
0
));
assertNotNull
(
testMap
.
int32ToMessageField
);
assertEquals
(
1
,
testMap
.
int32ToMessageField
.
size
());
TestMap
.
MessageValue
messageValue
=
testMap
.
int32ToMessageField
.
get
(
0
);
assertNotNull
(
messageValue
);
assertEquals
(
0
,
messageValue
.
value
);
assertEquals
(
0
,
messageValue
.
value2
);
}
private
static
final
Integer
[]
int32Values
=
new
Integer
[]
{
0
,
1
,
-
1
,
Integer
.
MAX_VALUE
,
Integer
.
MIN_VALUE
,
};
...
...
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