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
b9e9469b
Commit
b9e9469b
authored
Feb 18, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for oneof equals and hash.
parent
3ab660cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
0 deletions
+81
-0
NanoTest.java
...nano/src/test/java/com/google/protobuf/nano/NanoTest.java
+80
-0
unittest_nano.proto
...rc/test/java/com/google/protobuf/nano/unittest_nano.proto
+1
-0
No files found.
javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
View file @
b9e9469b
...
@@ -3361,6 +3361,7 @@ public class NanoTest extends TestCase {
...
@@ -3361,6 +3361,7 @@ public class NanoTest extends TestCase {
TestAllTypesNano
.
BAR
,
TestAllTypesNano
.
BAR
,
TestAllTypesNano
.
BAZ
TestAllTypesNano
.
BAZ
};
};
message
.
setOneofUint32
(
3
);
return
message
;
return
message
;
}
}
...
@@ -3559,6 +3560,85 @@ public class NanoTest extends TestCase {
...
@@ -3559,6 +3560,85 @@ public class NanoTest extends TestCase {
new
NanoReferenceTypes
.
TestAllTypesNano
(),
MessageNano
.
toByteArray
(
m7
))));
new
NanoReferenceTypes
.
TestAllTypesNano
(),
MessageNano
.
toByteArray
(
m7
))));
}
}
private
static
TestAllTypesNano
generateMessageForOneof
(
int
caseNumber
)
{
TestAllTypesNano
result
=
new
TestAllTypesNano
();
TestAllTypesNano
.
NestedMessage
nested
=
new
TestAllTypesNano
.
NestedMessage
();
nested
.
bb
=
2
;
switch
(
caseNumber
)
{
case
TestAllTypesNano
.
ONEOF_UINT32_FIELD_NUMBER
:
result
.
setOneofUint32
(
1
);
break
;
case
TestAllTypesNano
.
ONEOF_ENUM_FIELD_NUMBER
:
result
.
setOneofEnum
(
TestAllTypesNano
.
BAR
);
break
;
case
TestAllTypesNano
.
ONEOF_NESTED_MESSAGE_FIELD_NUMBER
:
result
.
setOneofNestedMessage
(
nested
);
break
;
case
TestAllTypesNano
.
ONEOF_BYTES_FIELD_NUMBER
:
result
.
setOneofBytes
(
new
byte
[]
{
1
,
2
});
break
;
case
TestAllTypesNano
.
ONEOF_STRING_FIELD_NUMBER
:
result
.
setOneofString
(
"hello"
);
break
;
case
TestAllTypesNano
.
ONEOF_FIXED64_FIELD_NUMBER
:
result
.
setOneofFixed64
(-
1L
);
break
;
default
:
throw
new
RuntimeException
(
"unexpected case number: "
+
caseNumber
);
}
return
result
;
}
public
void
testOneofHashCodeEquals
()
throws
Exception
{
TestAllTypesNano
m1
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_UINT32_FIELD_NUMBER
);
assertEquals
(
m1
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_UINT32_FIELD_NUMBER
));
assertFalse
(
m1
.
equals
(
new
TestAllTypesNano
()));
TestAllTypesNano
m2
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_ENUM_FIELD_NUMBER
);
assertEquals
(
m2
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_ENUM_FIELD_NUMBER
));
assertFalse
(
m2
.
equals
(
new
TestAllTypesNano
()));
TestAllTypesNano
m3
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_NESTED_MESSAGE_FIELD_NUMBER
);
assertEquals
(
m3
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_NESTED_MESSAGE_FIELD_NUMBER
));
assertFalse
(
m3
.
equals
(
new
TestAllTypesNano
()));
TestAllTypesNano
m4
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_BYTES_FIELD_NUMBER
);
assertEquals
(
m4
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_BYTES_FIELD_NUMBER
));
assertFalse
(
m4
.
equals
(
new
TestAllTypesNano
()));
TestAllTypesNano
m5
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_STRING_FIELD_NUMBER
);
assertEquals
(
m5
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_STRING_FIELD_NUMBER
));
assertFalse
(
m5
.
equals
(
new
TestAllTypesNano
()));
TestAllTypesNano
m6
=
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_FIXED64_FIELD_NUMBER
);
assertEquals
(
m6
,
generateMessageForOneof
(
TestAllTypesNano
.
ONEOF_FIXED64_FIELD_NUMBER
));
assertFalse
(
m6
.
equals
(
new
TestAllTypesNano
()));
Map
<
TestAllTypesNano
,
Integer
>
map
=
new
HashMap
<
TestAllTypesNano
,
Integer
>();
map
.
put
(
m1
,
1
);
map
.
put
(
m2
,
2
);
map
.
put
(
m3
,
3
);
map
.
put
(
m4
,
4
);
map
.
put
(
m5
,
5
);
map
.
put
(
m6
,
6
);
assertEquals
(
6
,
map
.
size
());
}
public
void
testNullRepeatedFields
()
throws
Exception
{
public
void
testNullRepeatedFields
()
throws
Exception
{
// Check that serialization after explicitly setting a repeated field
// Check that serialization after explicitly setting a repeated field
// to null doesn't NPE.
// to null doesn't NPE.
...
...
javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto
View file @
b9e9469b
...
@@ -174,6 +174,7 @@ message TestAllTypesNano {
...
@@ -174,6 +174,7 @@ message TestAllTypesNano {
string
oneof_string
=
123
;
string
oneof_string
=
123
;
bytes
oneof_bytes
=
124
;
bytes
oneof_bytes
=
124
;
fixed64
oneof_fixed64
=
115
;
fixed64
oneof_fixed64
=
115
;
NestedEnum
oneof_enum
=
116
;
}
}
}
}
...
...
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