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
66f07459
Commit
66f07459
authored
Apr 26, 2016
by
Thomas Van Lenten
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1454 from thomasvl/enum_defaults
Proper checking of enum with non zero default
parents
40574479
18b6a321
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
4 deletions
+22
-4
GPBMessageTests.m
objectivec/Tests/GPBMessageTests.m
+7
-0
unittest_objc.proto
objectivec/Tests/unittest_objc.proto
+10
-0
objectivec_helpers.cc
...google/protobuf/compiler/objectivec/objectivec_helpers.cc
+5
-4
No files found.
objectivec/Tests/GPBMessageTests.m
View file @
66f07459
...
...
@@ -1947,4 +1947,11 @@
EnumTestMsg_MyEnum_NegTwo
);
}
-
(
void
)
testOneBasedEnumHolder
{
// Test case for https://github.com/google/protobuf/issues/1453
// Message with no explicit defaults, but a non zero default for an enum.
MessageWithOneBasedEnum
*
enumMsg
=
[
MessageWithOneBasedEnum
message
];
XCTAssertEqual
(
enumMsg
.
enumField
,
MessageWithOneBasedEnum_OneBasedEnum_One
);
}
@end
objectivec/Tests/unittest_objc.proto
View file @
66f07459
...
...
@@ -401,3 +401,13 @@ message EnumTestMsg {
repeated
MyEnum
mumble
=
4
;
}
// Test case for https://github.com/google/protobuf/issues/1453
// Message with no explicit defaults, but a non zero default for an enum.
message
MessageWithOneBasedEnum
{
enum
OneBasedEnum
{
ONE
=
1
;
TWO
=
2
;
}
optional
OneBasedEnum
enum_field
=
1
;
}
src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
View file @
66f07459
...
...
@@ -757,10 +757,11 @@ bool HasNonZeroDefaultValue(const FieldDescriptor* field) {
return
false
;
}
if
(
!
field
->
has_default_value
())
{
// No custom default set in the proto file.
return
false
;
}
// As much as checking field->has_default_value() seems useful, it isn't
// because of enums. proto2 syntax allows the first item in an enum (the
// default) to be non zero. So checking field->has_default_value() would
// result in missing this non zero default. See MessageWithOneBasedEnum in
// objectivec/Tests/unittest_objc.proto for a test Message to confirm this.
// Some proto file set the default to the zero value, so make sure the value
// isn't the zero case.
...
...
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