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
d4569d1f
Commit
d4569d1f
authored
Oct 24, 2015
by
Jan Tattermusch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #908 from jskeet/oneof-equality
Use oneof case in equality tests
parents
dfae9e36
55313c9c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
36 additions
and
0 deletions
+36
-0
Conformance.cs
csharp/src/Google.Protobuf.Conformance/Conformance.cs
+6
-0
GeneratedMessageTest.cs
csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
+10
-0
UnittestIssues.cs
csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
+4
-0
UnittestProto3.cs
csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
+4
-0
UnittestWellKnownTypes.cs
...Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
+2
-0
DescriptorProtoFile.cs
csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs
+0
-0
Struct.cs
csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
+2
-0
csharp_message.cc
src/google/protobuf/compiler/csharp/csharp_message.cc
+8
-0
No files found.
csharp/src/Google.Protobuf.Conformance/Conformance.cs
View file @
d4569d1f
...
...
@@ -269,6 +269,7 @@ namespace Conformance {
if
(
ProtobufPayload
!=
other
.
ProtobufPayload
)
return
false
;
if
(
JsonPayload
!=
other
.
JsonPayload
)
return
false
;
if
(
RequestedOutputFormat
!=
other
.
RequestedOutputFormat
)
return
false
;
if
(
PayloadCase
!=
other
.
PayloadCase
)
return
false
;
return
true
;
}
...
...
@@ -277,6 +278,7 @@ namespace Conformance {
if
(
payloadCase_
==
PayloadOneofCase
.
ProtobufPayload
)
hash
^=
ProtobufPayload
.
GetHashCode
();
if
(
payloadCase_
==
PayloadOneofCase
.
JsonPayload
)
hash
^=
JsonPayload
.
GetHashCode
();
if
(
RequestedOutputFormat
!=
global
::
Conformance
.
WireFormat
.
UNSPECIFIED
)
hash
^=
RequestedOutputFormat
.
GetHashCode
();
hash
^=
(
int
)
payloadCase_
;
return
hash
;
}
...
...
@@ -512,6 +514,7 @@ namespace Conformance {
if
(
ProtobufPayload
!=
other
.
ProtobufPayload
)
return
false
;
if
(
JsonPayload
!=
other
.
JsonPayload
)
return
false
;
if
(
Skipped
!=
other
.
Skipped
)
return
false
;
if
(
ResultCase
!=
other
.
ResultCase
)
return
false
;
return
true
;
}
...
...
@@ -522,6 +525,7 @@ namespace Conformance {
if
(
resultCase_
==
ResultOneofCase
.
ProtobufPayload
)
hash
^=
ProtobufPayload
.
GetHashCode
();
if
(
resultCase_
==
ResultOneofCase
.
JsonPayload
)
hash
^=
JsonPayload
.
GetHashCode
();
if
(
resultCase_
==
ResultOneofCase
.
Skipped
)
hash
^=
Skipped
.
GetHashCode
();
hash
^=
(
int
)
resultCase_
;
return
hash
;
}
...
...
@@ -1461,6 +1465,7 @@ namespace Conformance {
if
(!
object
.
Equals
(
OneofNestedMessage
,
other
.
OneofNestedMessage
))
return
false
;
if
(
OneofString
!=
other
.
OneofString
)
return
false
;
if
(
OneofBytes
!=
other
.
OneofBytes
)
return
false
;
if
(
OneofFieldCase
!=
other
.
OneofFieldCase
)
return
false
;
return
true
;
}
...
...
@@ -1532,6 +1537,7 @@ namespace Conformance {
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofNestedMessage
)
hash
^=
OneofNestedMessage
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofString
)
hash
^=
OneofString
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofBytes
)
hash
^=
OneofBytes
.
GetHashCode
();
hash
^=
(
int
)
oneofFieldCase_
;
return
hash
;
}
...
...
csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
View file @
d4569d1f
...
...
@@ -565,6 +565,16 @@ namespace Google.Protobuf
Assert
.
AreEqual
(
TestAllTypes
.
OneofFieldOneofCase
.
None
,
message
.
OneofFieldCase
);
}
[
Test
]
public
void
Oneof_DefaultValuesNotEqual
()
{
var
message1
=
new
TestAllTypes
{
OneofString
=
""
};
var
message2
=
new
TestAllTypes
{
OneofUint32
=
0
};
Assert
.
AreEqual
(
TestAllTypes
.
OneofFieldOneofCase
.
OneofString
,
message1
.
OneofFieldCase
);
Assert
.
AreEqual
(
TestAllTypes
.
OneofFieldOneofCase
.
OneofUint32
,
message2
.
OneofFieldCase
);
Assert
.
AreNotEqual
(
message1
,
message2
);
}
[
Test
]
public
void
OneofSerialization_NonDefaultValue
()
{
...
...
csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
View file @
d4569d1f
...
...
@@ -1260,6 +1260,8 @@ namespace UnitTest.Issues.TestProtos {
if
(
PlainString
!=
other
.
PlainString
)
return
false
;
if
(
O2Int32
!=
other
.
O2Int32
)
return
false
;
if
(
O2String
!=
other
.
O2String
)
return
false
;
if
(
O1Case
!=
other
.
O1Case
)
return
false
;
if
(
O2Case
!=
other
.
O2Case
)
return
false
;
return
true
;
}
...
...
@@ -1271,6 +1273,8 @@ namespace UnitTest.Issues.TestProtos {
if
(
PlainString
.
Length
!=
0
)
hash
^=
PlainString
.
GetHashCode
();
if
(
o2Case_
==
O2OneofCase
.
O2Int32
)
hash
^=
O2Int32
.
GetHashCode
();
if
(
o2Case_
==
O2OneofCase
.
O2String
)
hash
^=
O2String
.
GetHashCode
();
hash
^=
(
int
)
o1Case_
;
hash
^=
(
int
)
o2Case_
;
return
hash
;
}
...
...
csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
View file @
d4569d1f
...
...
@@ -868,6 +868,7 @@ namespace Google.Protobuf.TestProtos {
if
(!
object
.
Equals
(
OneofNestedMessage
,
other
.
OneofNestedMessage
))
return
false
;
if
(
OneofString
!=
other
.
OneofString
)
return
false
;
if
(
OneofBytes
!=
other
.
OneofBytes
)
return
false
;
if
(
OneofFieldCase
!=
other
.
OneofFieldCase
)
return
false
;
return
true
;
}
...
...
@@ -921,6 +922,7 @@ namespace Google.Protobuf.TestProtos {
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofNestedMessage
)
hash
^=
OneofNestedMessage
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofString
)
hash
^=
OneofString
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
OneofBytes
)
hash
^=
OneofBytes
.
GetHashCode
();
hash
^=
(
int
)
oneofFieldCase_
;
return
hash
;
}
...
...
@@ -4470,6 +4472,7 @@ namespace Google.Protobuf.TestProtos {
if
(
FooInt
!=
other
.
FooInt
)
return
false
;
if
(
FooString
!=
other
.
FooString
)
return
false
;
if
(!
object
.
Equals
(
FooMessage
,
other
.
FooMessage
))
return
false
;
if
(
FooCase
!=
other
.
FooCase
)
return
false
;
return
true
;
}
...
...
@@ -4478,6 +4481,7 @@ namespace Google.Protobuf.TestProtos {
if
(
fooCase_
==
FooOneofCase
.
FooInt
)
hash
^=
FooInt
.
GetHashCode
();
if
(
fooCase_
==
FooOneofCase
.
FooString
)
hash
^=
FooString
.
GetHashCode
();
if
(
fooCase_
==
FooOneofCase
.
FooMessage
)
hash
^=
FooMessage
.
GetHashCode
();
hash
^=
(
int
)
fooCase_
;
return
hash
;
}
...
...
csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
View file @
d4569d1f
...
...
@@ -1596,6 +1596,7 @@ namespace Google.Protobuf.TestProtos {
if
(
BoolField
!=
other
.
BoolField
)
return
false
;
if
(
StringField
!=
other
.
StringField
)
return
false
;
if
(
BytesField
!=
other
.
BytesField
)
return
false
;
if
(
OneofFieldCase
!=
other
.
OneofFieldCase
)
return
false
;
return
true
;
}
...
...
@@ -1619,6 +1620,7 @@ namespace Google.Protobuf.TestProtos {
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
BoolField
)
hash
^=
BoolField
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
StringField
)
hash
^=
StringField
.
GetHashCode
();
if
(
oneofFieldCase_
==
OneofFieldOneofCase
.
BytesField
)
hash
^=
BytesField
.
GetHashCode
();
hash
^=
(
int
)
oneofFieldCase_
;
return
hash
;
}
...
...
csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs
View file @
d4569d1f
This diff is collapsed.
Click to expand it.
csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
View file @
d4569d1f
...
...
@@ -344,6 +344,7 @@ namespace Google.Protobuf.WellKnownTypes {
if
(
BoolValue
!=
other
.
BoolValue
)
return
false
;
if
(!
object
.
Equals
(
StructValue
,
other
.
StructValue
))
return
false
;
if
(!
object
.
Equals
(
ListValue
,
other
.
ListValue
))
return
false
;
if
(
KindCase
!=
other
.
KindCase
)
return
false
;
return
true
;
}
...
...
@@ -355,6 +356,7 @@ namespace Google.Protobuf.WellKnownTypes {
if
(
kindCase_
==
KindOneofCase
.
BoolValue
)
hash
^=
BoolValue
.
GetHashCode
();
if
(
kindCase_
==
KindOneofCase
.
StructValue
)
hash
^=
StructValue
.
GetHashCode
();
if
(
kindCase_
==
KindOneofCase
.
ListValue
)
hash
^=
ListValue
.
GetHashCode
();
hash
^=
(
int
)
kindCase_
;
return
hash
;
}
...
...
src/google/protobuf/compiler/csharp/csharp_message.cc
View file @
d4569d1f
...
...
@@ -323,6 +323,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
CreateFieldGeneratorInternal
(
descriptor_
->
field
(
i
)));
generator
->
WriteEquals
(
printer
);
}
for
(
int
i
=
0
;
i
<
descriptor_
->
oneof_decl_count
();
i
++
)
{
printer
->
Print
(
"if ($property_name$Case != other.$property_name$Case) return false;
\n
"
,
"property_name"
,
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
true
));
}
printer
->
Outdent
();
printer
->
Print
(
" return true;
\n
"
...
...
@@ -339,6 +343,10 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) {
CreateFieldGeneratorInternal
(
descriptor_
->
field
(
i
)));
generator
->
WriteHash
(
printer
);
}
for
(
int
i
=
0
;
i
<
descriptor_
->
oneof_decl_count
();
i
++
)
{
printer
->
Print
(
"hash ^= (int) $name$Case_;
\n
"
,
"name"
,
UnderscoresToCamelCase
(
descriptor_
->
oneof_decl
(
i
)
->
name
(),
false
));
}
printer
->
Print
(
"return hash;
\n
"
);
printer
->
Outdent
();
printer
->
Print
(
"}
\n\n
"
);
...
...
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